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
2 changes: 1 addition & 1 deletion docs/examples/coreshellnp.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def makeRecipe(stru1, stru2, datname):
contribution = FitContribution("cdszns")
contribution.addProfileGenerator(generator_cds)
contribution.addProfileGenerator(generator_zns)
contribution.setProfile(profile, xname="r")
contribution.set_profile(profile, xname="r")

# Set up the characteristic functions. We use a spherical CF for the core
# and a spherical shell CF for the shell. Since this is set up as two
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/crystalpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def makeRecipe(ciffile, datname):
# before.
contribution = FitContribution("nickel")
contribution.addProfileGenerator(generator)
contribution.setProfile(profile, xname="r")
contribution.set_profile(profile, xname="r")

# Make the FitRecipe and add the FitContribution.
recipe = FitRecipe()
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/crystalpdfall.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def makeContribution(name, generator, profile):
"""Make a FitContribution and add a generator and profile."""
contribution = FitContribution(name)
contribution.addProfileGenerator(generator)
contribution.setProfile(profile, xname="r")
contribution.set_profile(profile, xname="r")
return contribution


Expand Down
2 changes: 1 addition & 1 deletion docs/examples/crystalpdfobjcryst.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def makeRecipe(ciffile, datname):
# The FitContribution
contribution = FitContribution("nickel")
contribution.addProfileGenerator(generator)
contribution.setProfile(profile, xname="r")
contribution.set_profile(profile, xname="r")

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

# This example is different than the previous ones in that we are composing
# a residual function from other residuals (one for the x-ray contribution
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/crystalpdftwophase.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def makeRecipe(niciffile, siciffile, datname):
contribution = FitContribution("nisi")
contribution.addProfileGenerator(generator_ni)
contribution.addProfileGenerator(generator_si)
contribution.setProfile(profile, xname="r")
contribution.set_profile(profile, xname="r")

# Write the fitting equation. We want to sum the PDFs from each phase and
# multiply it by a scaling factor. We also want a certain phase scaling
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/debyemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def makeRecipe():
# independent variable (the temperature) from the data to calculate the
# theoretical signal, so give it an informative name ('T') that we can use
# later.
contribution.setProfile(profile, xname="T")
contribution.set_profile(profile, xname="T")

# We now need to create the fitting equation. We tell the FitContribution
# to use the 'debye' function defined below. The 'registerFunction' method
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/ellipsoidsas.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def makeRecipe(datname):
# before.
contribution = FitContribution("ellipsoid")
contribution.addProfileGenerator(generator)
contribution.setProfile(profile, xname="q")
contribution.set_profile(profile, xname="q")

# We want to fit the log of the signal to the log of the data so that the
# higher-Q information remains significant. There are no I(Q) uncertainty
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/gaussiangenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def makeRecipe():
# set the fitting equation to "g", which calls the GaussianGenerator.
contribution = FitContribution("g1")
contribution.addProfileGenerator(generator)
contribution.setProfile(profile)
contribution.set_profile(profile)

# The FitRecipe
# Now we create the FitRecipe and add the FitContribution.
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/gaussianrecipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def makeRecipe():
# us access to the data held within the Profile. Here, we can tell it what
# name we want to use for the independent variable. We tell it to use the
# name "x".
contribution.setProfile(profile, xname="x")
contribution.set_profile(profile, xname="x")

# Now we need to create a fitting equation. We do that by writing out the
# equation as a string. The FitContribution will turn this into a callable
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def main():
# FitContribution operations
# "<<" - Inject a parameter value
c = FitContribution("g1")
c.setProfile(p)
c.set_profile(p)
c.setEquation("A * exp(-0.5*(x-x0)**2/sigma**2)")
c.A << 0.5
c.x0 << 5
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/npintensity.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def makeRecipe(strufile, datname):
# use it in equations with this name.
contribution = FitContribution("bucky")
contribution.addProfileGenerator(generator)
contribution.setProfile(profile, xname="q")
contribution.set_profile(profile, xname="q")

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

# Now we're ready to define the fitting equation for each FitContribution.
# The functions registered below will be independent, even though they take
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/nppdfcrystal.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def makeRecipe(ciffile, grdata):
pdfprofile.setCalculationRange(xmin=0.1, xmax=20)

pdfcontribution = FitContribution("pdf")
pdfcontribution.setProfile(pdfprofile, xname="r")
pdfcontribution.set_profile(pdfprofile, xname="r")

pdfgenerator = PDFGenerator("G")
pdfgenerator.setQmax(30.0)
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/nppdfobjcryst.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def makeRecipe(molecule, datname):
# The FitContribution
contribution = FitContribution("bucky")
contribution.addProfileGenerator(generator)
contribution.setProfile(profile, xname="r")
contribution.set_profile(profile, xname="r")

# Make a FitRecipe.
recipe = 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 @@ -52,7 +52,7 @@ def makeRecipe(ciffile, grdata, iqdata):
pdfprofile.setCalculationRange(xmin=0.1, xmax=20)

pdfcontribution = FitContribution("pdf")
pdfcontribution.setProfile(pdfprofile, xname="r")
pdfcontribution.set_profile(pdfprofile, xname="r")

pdfgenerator = PDFGenerator("G")
pdfgenerator.setQmax(30.0)
Expand All @@ -71,7 +71,7 @@ def makeRecipe(ciffile, grdata, iqdata):
sasprofile.dy[:] = 1

sascontribution = FitContribution("sas")
sascontribution.setProfile(sasprofile)
sascontribution.set_profile(sasprofile)

from sas.models.EllipsoidModel import EllipsoidModel

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/threedoublepeaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def makeRecipe():

# Create the contribution
contribution = FitContribution("peaks")
contribution.setProfile(profile, xname="t")
contribution.set_profile(profile, xname="t")
pi = numpy.pi
exp = numpy.exp

Expand Down
23 changes: 23 additions & 0 deletions news/dep-setprofile.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* <news item>

**Changed:**

* <news item>

**Deprecated:**

* Deprecate ``setProfile`` for removal in version 4.0.0.

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
1 change: 1 addition & 0 deletions requirements/conda.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ matplotlib-base
numpy
scipy
bg-mpl-stylesheets
diffpy.utils
1 change: 1 addition & 0 deletions requirements/pip.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ matplotlib
numpy
scipy
bg-mpl-stylesheets
diffpy.utils
28 changes: 25 additions & 3 deletions src/diffpy/srfit/fitbase/fitcontribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@
from diffpy.srfit.fitbase.parameterset import ParameterSet
from diffpy.srfit.fitbase.profile import Profile
from diffpy.srfit.fitbase.recipeorganizer import equationFromString
from diffpy.utils._deprecator import build_deprecation_message, deprecated

base = "diffpy.srfit.fitbase.FitContribution"
removal_version = "4.0.0"

setprofile_dep_msg = build_deprecation_message(
base,
"setProfile",
"set_profile",
removal_version,
)


class FitContribution(ParameterSet):
Expand Down Expand Up @@ -97,7 +108,7 @@ def __init__(self, name):
self._manage(self._generators)
return

def setProfile(self, profile, xname=None, yname=None, dyname=None):
def set_profile(self, profile, xname=None, yname=None, dyname=None):
"""Assign the Profile for this FitContribution.

Attributes
Expand Down Expand Up @@ -149,14 +160,25 @@ def setProfile(self, profile, xname=None, yname=None, dyname=None):

# If we have ProfileGenerators, set their Profiles.
for gen in self._generators.values():
gen.setProfile(profile)
gen.set_profile(profile)

# If we have _eq, but not _reseq, set the residual
if self._eq is not None and self._reseq is None:
self.setResidualEquation("chiv")

return

@deprecated(setprofile_dep_msg)
def setProfile(self, profile, xname=None, yname=None, dyname=None):
"""This function has been deprecated and will be removed in version
4.0.0.

Please use diffpy.srfit.fitbase.FitContribution.set_profile instead.
"""
return self.set_profile(
profile, xname=xname, yname=yname, dyname=dyname
)

def addProfileGenerator(self, gen, name=None):
"""Add a ProfileGenerator to be used by this FitContribution.

Expand Down Expand Up @@ -192,7 +214,7 @@ def addProfileGenerator(self, gen, name=None):

# If we have a profile, set the profile of the generator.
if self.profile is not None:
gen.setProfile(self.profile)
gen.set_profile(self.profile)

# Make this our equation if we don't have one. This will set the
# residual equation if necessary.
Expand Down
2 changes: 1 addition & 1 deletion src/diffpy/srfit/fitbase/profilegenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def operation(self):
y = self.__call__(self.profile.x)
return y

def setProfile(self, profile):
def set_profile(self, profile):
"""Assign the profile.

Attributes
Expand Down
2 changes: 1 addition & 1 deletion src/diffpy/srfit/fitbase/simplerecipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def __init__(self, name="fit", conclass=FitContribution):
self.fithooks[0].verbose = 3
contribution = conclass("contribution")
self.profile = Profile()
contribution.setProfile(self.profile)
contribution.set_profile(self.profile)
self.addContribution(contribution)
self.results = FitResults(self, update=False)

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 @@ -93,7 +93,7 @@ def __init__(self, name):
self._meta = {}
# Add the profile
profile = Profile()
self.setProfile(profile, xname="r")
self.set_profile(profile, xname="r")

# Need a parameter for the overall scale, in the case that this is a
# multi-phase fit.
Expand Down
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def build_recipe_one_contribution():
y = sin(x)
profile.setObservedProfile(x, y)
contribution = FitContribution("c1")
contribution.setProfile(profile)
contribution.set_profile(profile)
contribution.setEquation("A*sin(k*x + c)")
recipe = FitRecipe()
recipe.addContribution(contribution)
Expand All @@ -172,14 +172,14 @@ def build_recipe_two_contributions():
y1 = sin(x)
profile1.setObservedProfile(x, y1)
contribution1 = FitContribution("c1")
contribution1.setProfile(profile1)
contribution1.set_profile(profile1)
contribution1.setEquation("A*sin(k*x + c)")

profile2 = Profile()
y2 = 0.5 * sin(2 * x)
profile2.setObservedProfile(x, y2)
contribution2 = FitContribution("c2")
contribution2.setProfile(profile2)
contribution2.set_profile(profile2)
contribution2.setEquation("B*sin(m*x + d)")
recipe = FitRecipe()
recipe.addContribution(contribution1)
Expand Down
Loading
Loading