Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/examples/coreshellnp.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ def makeRecipe(stru1, stru2, datname):
# The FitContribution
# Add both generators and the profile to the FitContribution.
contribution = FitContribution("cdszns")
contribution.addProfileGenerator(generator_cds)
contribution.addProfileGenerator(generator_zns)
contribution.add_profile_generator(generator_cds)
contribution.add_profile_generator(generator_zns)
contribution.set_profile(profile, xname="r")

# Set up the characteristic functions. We use a spherical CF for the core
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/crystalpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def makeRecipe(ciffile, datname):
# Here we associate the Profile and ProfileGenerator, as has been done
# before.
contribution = FitContribution("nickel")
contribution.addProfileGenerator(generator)
contribution.add_profile_generator(generator)
contribution.set_profile(profile, xname="r")

# Make the FitRecipe and add the FitContribution.
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/crystalpdfall.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def makeProfile(datafile):
def makeContribution(name, generator, profile):
"""Make a FitContribution and add a generator and profile."""
contribution = FitContribution(name)
contribution.addProfileGenerator(generator)
contribution.add_profile_generator(generator)
contribution.set_profile(profile, xname="r")
return contribution

Expand Down Expand Up @@ -93,7 +93,7 @@ def makeRecipe(
xcontribution_sini = makeContribution(
"xsini", xgenerator_sini_ni, xprofile_sini
)
xcontribution_sini.addProfileGenerator(xgenerator_sini_si)
xcontribution_sini.add_profile_generator(xgenerator_sini_si)
xcontribution_sini.setEquation("scale * (xG_sini_ni + xG_sini_si)")

# As explained in another example, we want to minimize using Rw^2.
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/crystalpdfobjcryst.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def makeRecipe(ciffile, datname):

# The FitContribution
contribution = FitContribution("nickel")
contribution.addProfileGenerator(generator)
contribution.add_profile_generator(generator)
contribution.set_profile(profile, xname="r")

# Make the FitRecipe and add the FitContribution.
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/crystalpdftwodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ def makeRecipe(ciffile, xdatname, ndatname):
# The FitContributions
# We associate the x-ray PDFGenerator and Profile in one FitContribution...
xcontribution = FitContribution("xnickel")
xcontribution.addProfileGenerator(xgenerator)
xcontribution.add_profile_generator(xgenerator)
xcontribution.set_profile(xprofile, xname="r")
# and the neutron objects in another.
ncontribution = FitContribution("nnickel")
ncontribution.addProfileGenerator(ngenerator)
ncontribution.add_profile_generator(ngenerator)
ncontribution.set_profile(nprofile, xname="r")

# This example is different than the previous ones in that we are composing
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/crystalpdftwophase.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ def makeRecipe(niciffile, siciffile, datname):
# Add both generators to the FitContribution. Add the Profile. This will
# send the metadata to the generators.
contribution = FitContribution("nisi")
contribution.addProfileGenerator(generator_ni)
contribution.addProfileGenerator(generator_si)
contribution.add_profile_generator(generator_ni)
contribution.add_profile_generator(generator_si)
contribution.set_profile(profile, xname="r")

# Write the fitting equation. We want to sum the PDFs from each phase and
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/ellipsoidsas.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def makeRecipe(datname):
# Here we associate the Profile and ProfileGenerator, as has been done
# before.
contribution = FitContribution("ellipsoid")
contribution.addProfileGenerator(generator)
contribution.add_profile_generator(generator)
contribution.set_profile(profile, xname="q")

# We want to fit the log of the signal to the log of the data so that the
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/gaussiangenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def makeRecipe():
# attribute of the FitContribution by its name ("g"). Note that this will
# set the fitting equation to "g", which calls the GaussianGenerator.
contribution = FitContribution("g1")
contribution.addProfileGenerator(generator)
contribution.add_profile_generator(generator)
contribution.set_profile(profile)

# The FitRecipe
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/npintensity.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def makeRecipe(strufile, datname):
# the FitContribution to name the x-variable of the profile "q", so we can
# use it in equations with this name.
contribution = FitContribution("bucky")
contribution.addProfileGenerator(generator)
contribution.add_profile_generator(generator)
contribution.set_profile(profile, xname="q")

# Now we're ready to define the fitting equation for the FitContribution.
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/npintensityII.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ def makeRecipe(strufile, datname1, datname2):
# The FitContributions
# Create the FitContributions.
contribution1 = FitContribution("bucky1")
contribution1.addProfileGenerator(generator1)
contribution1.add_profile_generator(generator1)
contribution1.set_profile(profile1, xname="q")
contribution2 = FitContribution("bucky2")
contribution2.addProfileGenerator(generator2)
contribution2.add_profile_generator(generator2)
contribution2.set_profile(profile2, xname="q")

# Now we're ready to define the fitting equation for each FitContribution.
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/nppdfcrystal.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def makeRecipe(ciffile, grdata):
pdfgenerator.setQmax(30.0)
stru = loadCrystal(ciffile)
pdfgenerator.setStructure(stru)
pdfcontribution.addProfileGenerator(pdfgenerator)
pdfcontribution.add_profile_generator(pdfgenerator)

# Register the nanoparticle shape factor.
from diffpy.srfit.pdf.characteristicfunctions import sphericalCF
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/nppdfobjcryst.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def makeRecipe(molecule, datname):

# The FitContribution
contribution = FitContribution("bucky")
contribution.addProfileGenerator(generator)
contribution.add_profile_generator(generator)
contribution.set_profile(profile, xname="r")

# Make a FitRecipe.
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/nppdfsas.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def makeRecipe(ciffile, grdata, iqdata):
pdfgenerator.setQmax(30.0)
stru = loadCrystal(ciffile)
pdfgenerator.setStructure(stru)
pdfcontribution.addProfileGenerator(pdfgenerator)
pdfcontribution.add_profile_generator(pdfgenerator)
pdfcontribution.setResidualEquation("resv")

# Create a SAS contribution as well. We assume the nanoparticle is roughly
Expand All @@ -77,7 +77,7 @@ def makeRecipe(ciffile, grdata, iqdata):

model = EllipsoidModel()
sasgenerator = SASGenerator("generator", model)
sascontribution.addProfileGenerator(sasgenerator)
sascontribution.add_profile_generator(sasgenerator)
sascontribution.setResidualEquation("resv")

# Now we set up a characteristic function calculator that depends on the
Expand Down
23 changes: 23 additions & 0 deletions news/addprofilegenerator-dep.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* Added ``add_profile_generator`` to replace deprecated function.

**Changed:**

* <news item>

**Deprecated:**

* Deprecated ``addProfileGenerator`` for removal in 4.0.0.

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
21 changes: 20 additions & 1 deletion src/diffpy/srfit/fitbase/fitcontribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@
removal_version,
)

addprofilegenerator_dep_msg = build_deprecation_message(
base,
"addProfileGenerator",
"add_profile_generator",
removal_version,
)


class FitContribution(ParameterSet):
"""FitContribution class.
Expand Down Expand Up @@ -179,7 +186,7 @@ def setProfile(self, profile, xname=None, yname=None, dyname=None):
profile, xname=xname, yname=yname, dyname=dyname
)

def addProfileGenerator(self, gen, name=None):
def add_profile_generator(self, gen, name=None):
"""Add a ProfileGenerator to be used by this FitContribution.
The ProfileGenerator is given a name so that it can be used as part of
Expand Down Expand Up @@ -223,6 +230,18 @@ def addProfileGenerator(self, gen, name=None):

return

@deprecated(addprofilegenerator_dep_msg)
def addProfileGenerator(self, gen, name=None):
"""This function has been deprecated and will be removed in version
4.0.0.
Please use
diffpy.srfit.fitbase.FitContribution.add_profile_generator
instead.
"""
self.add_profile_generator(gen, name=name)
return

def setEquation(self, eqstr, ns={}):
"""Set the profile equation for the FitContribution.
Expand Down
2 changes: 1 addition & 1 deletion src/diffpy/srfit/pdf/pdfcontribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def _setup_generator(self, gen):
with setStructure or setPhase.
"""
# Add the generator to this FitContribution
self.addProfileGenerator(gen)
self.add_profile_generator(gen)

# Set the proper equation for the fit, depending on the number of
# phases we have.
Expand Down
18 changes: 15 additions & 3 deletions tests/test_contribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ def testAddProfileGenerator(self):
self.assertTrue(fc._eq is not None)
return

def test_add_profile_generator(self):
fc = self.fitcontribution
gen = self.gen
fc.add_profile_generator(gen, "gen")

xobs = arange(0, 10, 0.5)
self.assertTrue(array_equal(xobs, gen(xobs)))

self.assertTrue(gen.profile is None)
self.assertTrue(fc._eq is not None)
return

def testInteraction(self):
"""Test the interaction between the profile and profile generator."""
fc = self.fitcontribution
Expand All @@ -75,7 +87,7 @@ def testInteraction(self):

# Add the calculator and profile
fc.set_profile(profile)
fc.addProfileGenerator(gen, "I")
fc.add_profile_generator(gen, "I")

# Check attributes are created
self.assertTrue(fc.profile is profile)
Expand Down Expand Up @@ -120,7 +132,7 @@ def testReplacements(self):

# Validate equations
fc.set_profile(profile)
fc.addProfileGenerator(gen, "I")
fc.add_profile_generator(gen, "I")
self.assertTrue(array_equal(gen.value, xobs))
self.assertTrue(array_equal(fc._eq(), xobs))
self.assertAlmostEqual(0, sum(fc._reseq()))
Expand Down Expand Up @@ -196,7 +208,7 @@ def testResidual(noObserversInGlobalBuilders):
# Add the calculator and profile
fc.set_profile(profile)
assert fc.profile is profile
fc.addProfileGenerator(gen, "I")
fc.add_profile_generator(gen, "I")
assert fc._eq._value is None
assert fc._reseq._value is None
assert 1 == len(fc._generators)
Expand Down
Loading