Skip to content
Open
8 changes: 4 additions & 4 deletions docs/examples/coreshellnp.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ 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.setProfile(profile, xname="r")
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
# and a spherical shell CF for the shell. Since this is set up as two
Expand All @@ -81,7 +81,7 @@ def makeRecipe(stru1, stru2, datname):

# Write the fitting equation. We want to sum the PDFs from each phase and
# multiply it by a scaling factor.
contribution.setEquation("scale * (f_CdS * G_CdS + f_ZnS * G_ZnS)")
contribution.set_equation("scale * (f_CdS * G_CdS + f_ZnS * G_ZnS)")

# Make the FitRecipe and add the FitContribution.
recipe = FitRecipe()
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/crystalpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ def makeRecipe(ciffile, datname):
# Here we associate the Profile and ProfileGenerator, as has been done
# before.
contribution = FitContribution("nickel")
contribution.addProfileGenerator(generator)
contribution.setProfile(profile, xname="r")
contribution.add_profile_generator(generator)
contribution.set_profile(profile, xname="r")

# Make the FitRecipe and add the FitContribution.
recipe = FitRecipe()
Expand Down
16 changes: 8 additions & 8 deletions docs/examples/crystalpdfall.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def makeProfile(datafile):
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.add_profile_generator(generator)
contribution.set_profile(profile, xname="r")
return contribution


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

# As explained in another example, we want to minimize using Rw^2.
xcontribution_ni.setResidualEquation("resv")
xcontribution_si.setResidualEquation("resv")
ncontribution_ni.setResidualEquation("resv")
xcontribution_sini.setResidualEquation("resv")
xcontribution_ni.set_residual_equation("resv")
xcontribution_si.set_residual_equation("resv")
ncontribution_ni.set_residual_equation("resv")
xcontribution_sini.set_residual_equation("resv")

# Make the FitRecipe and add the FitContributions.
recipe = FitRecipe()
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/crystalpdfobjcryst.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def makeRecipe(ciffile, datname):

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

# Make the FitRecipe and add the FitContribution.
recipe = FitRecipe()
Expand Down
12 changes: 6 additions & 6 deletions docs/examples/crystalpdftwodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ 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.setProfile(xprofile, xname="r")
xcontribution.add_profile_generator(xgenerator)
xcontribution.set_profile(xprofile, xname="r")
# and the neutron objects in another.
ncontribution = FitContribution("nnickel")
ncontribution.addProfileGenerator(ngenerator)
ncontribution.setProfile(nprofile, xname="r")
ncontribution.add_profile_generator(ngenerator)
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 All @@ -105,8 +105,8 @@ def makeRecipe(ciffile, xdatname, ndatname):
# The contribution's residual can be either chi^2, Rw^2, or custom crafted.
# In this case, we should minimize Rw^2 of each contribution so that each
# one can contribute roughly equally to the fit.
xcontribution.setResidualEquation("resv")
ncontribution.setResidualEquation("resv")
xcontribution.set_residual_equation("resv")
ncontribution.set_residual_equation("resv")

# Make the FitRecipe and add the FitContributions.
recipe = FitRecipe()
Expand Down
8 changes: 4 additions & 4 deletions docs/examples/crystalpdftwophase.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ 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.setProfile(profile, xname="r")
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
# multiply it by a scaling factor. We also want a certain phase scaling
# relationship between the PDFs which we will enforce with constraints in
# the FitRecipe.
contribution.setEquation("scale * (G_ni + G_si)")
contribution.set_equation("scale * (G_ni + G_si)")

# Make the FitRecipe and add the FitContribution.
recipe = FitRecipe()
Expand Down
4 changes: 2 additions & 2 deletions 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 All @@ -126,7 +126,7 @@ def makeRecipe():
# the debye equation to be positive, so we specify the input as abs(thetaD)
# in the equation below. Furthermore, we know 'm', the mass of lead, so we
# can specify that as well.
contribution.setEquation("debye(T, 207.2, abs(thetaD)) + offset")
contribution.set_equation("debye(T, 207.2, abs(thetaD)) + offset")

# The FitRecipe
# The FitRecipe lets us define what we want to fit. It is where we can
Expand Down
6 changes: 3 additions & 3 deletions docs/examples/ellipsoidsas.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ def makeRecipe(datname):
# Here we associate the Profile and ProfileGenerator, as has been done
# before.
contribution = FitContribution("ellipsoid")
contribution.addProfileGenerator(generator)
contribution.setProfile(profile, xname="q")
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
# higher-Q information remains significant. There are no I(Q) uncertainty
# values with the data, so we do not need to worry about the effect this
# will have on the estimated parameter uncertainties.
contribution.setResidualEquation("log(eq) - log(y)")
contribution.set_residual_equation("log(eq) - log(y)")

# Make the FitRecipe and add the FitContribution.
recipe = FitRecipe()
Expand Down
11 changes: 6 additions & 5 deletions docs/examples/gaussiangenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@

Extensions

- Remove the amplitude from GaussianGenerator and instead use the 'setEquation'
method of the FitContribution to account for it. Note that the
GaussianGenerator will be accessible by its name, "g".
- Remove the amplitude from GaussianGenerator and instead use the
'set_equation' method of the FitContribution to account for it.
Note that the GaussianGenerator will be accessible by
its name, "g".
"""

from numpy import exp
Expand Down Expand Up @@ -144,8 +145,8 @@ 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.setProfile(profile)
contribution.add_profile_generator(generator)
contribution.set_profile(profile)

# The FitRecipe
# Now we create the FitRecipe and add the FitContribution.
Expand Down
4 changes: 2 additions & 2 deletions 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 All @@ -124,7 +124,7 @@ def makeRecipe():
# contribution by name. Since we told the contribution that our
# independent variable is named "x", this value will be substituted into
# the fitting equation whenever it is called.
contribution.setEquation("A * exp(-0.5*(x-x0)**2/sigma**2)")
contribution.set_equation("A * exp(-0.5*(x-x0)**2/sigma**2)")

# To demonstrate how these parameters are used, we will give "A" an initial
# value. Note that Parameters are not numbers, but are containers for
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def main():
# FitContribution operations
# "<<" - Inject a parameter value
c = FitContribution("g1")
c.setProfile(p)
c.setEquation("A * exp(-0.5*(x-x0)**2/sigma**2)")
c.set_profile(p)
c.set_equation("A * exp(-0.5*(x-x0)**2/sigma**2)")
c.A << 0.5
c.x0 << 5
c.sigma << 1
Expand Down
6 changes: 3 additions & 3 deletions docs/examples/npintensity.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ 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.setProfile(profile, xname="q")
contribution.add_profile_generator(generator)
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 Expand Up @@ -256,7 +256,7 @@ def gaussian(q, q0, width):
# convolve the signal with the Gaussian to broaden it. Recall that we don't
# need to supply arguments to the registered functions unless we want to
# make changes to their input values.
contribution.setEquation("scale * convolve(I, gaussian) + bkgd")
contribution.set_equation("scale * convolve(I, gaussian) + bkgd")

# Make the FitRecipe and add the FitContribution.
recipe = FitRecipe()
Expand Down
12 changes: 6 additions & 6 deletions docs/examples/npintensityII.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ def makeRecipe(strufile, datname1, datname2):
# The FitContributions
# Create the FitContributions.
contribution1 = FitContribution("bucky1")
contribution1.addProfileGenerator(generator1)
contribution1.setProfile(profile1, xname="q")
contribution1.add_profile_generator(generator1)
contribution1.set_profile(profile1, xname="q")
contribution2 = FitContribution("bucky2")
contribution2.addProfileGenerator(generator2)
contribution2.setProfile(profile2, xname="q")
contribution2.add_profile_generator(generator2)
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 Expand Up @@ -125,8 +125,8 @@ def gaussian(q, q0, width):

# Now we can incorporate the scale and bkgd into our calculation. We also
# convolve the signal with the gaussian to broaden it.
contribution1.setEquation("scale * convolve(I, gaussian) + bkgd")
contribution2.setEquation("scale * convolve(I, gaussian) + bkgd")
contribution1.set_equation("scale * convolve(I, gaussian) + bkgd")
contribution2.set_equation("scale * convolve(I, gaussian) + bkgd")

# Make a FitRecipe and associate the FitContributions.
recipe = FitRecipe()
Expand Down
6 changes: 3 additions & 3 deletions docs/examples/nppdfcrystal.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,21 @@ 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)
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

pdfcontribution.registerFunction(sphericalCF, name="f")

# Now we set up the fitting equation.
pdfcontribution.setEquation("f * G")
pdfcontribution.set_equation("f * G")

# Now make the recipe. Make sure we fit the characteristic function shape
# parameters, in this case 'psize', which is the diameter of the particle.
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/nppdfobjcryst.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def makeRecipe(molecule, datname):

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

# Make a FitRecipe.
recipe = FitRecipe()
Expand Down
14 changes: 7 additions & 7 deletions docs/examples/nppdfsas.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ 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)
stru = loadCrystal(ciffile)
pdfgenerator.setStructure(stru)
pdfcontribution.addProfileGenerator(pdfgenerator)
pdfcontribution.setResidualEquation("resv")
pdfcontribution.add_profile_generator(pdfgenerator)
pdfcontribution.set_residual_equation("resv")

# Create a SAS contribution as well. We assume the nanoparticle is roughly
# elliptical.
Expand All @@ -71,14 +71,14 @@ def makeRecipe(ciffile, grdata, iqdata):
sasprofile.dy[:] = 1

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

from sas.models.EllipsoidModel import EllipsoidModel

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

# Now we set up a characteristic function calculator that depends on the
# sas model.
Expand All @@ -89,7 +89,7 @@ def makeRecipe(ciffile, grdata, iqdata):
pdfcontribution.registerCalculator(cfcalculator)
# The PDF for a nanoscale crystalline is approximated by
# Gnano = f * Gcryst
pdfcontribution.setEquation("f * G")
pdfcontribution.set_equation("f * G")

# Moving on
recipe = FitRecipe()
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/simplerecipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def main():
# Set the equation. The variable "x" is taken from the data that was just
# loaded. The other variables, "A", "x0" and "sigma" are turned into
# attributes with an initial value of 0.
recipe.setEquation("A * exp(-0.5*(x-x0)**2/sigma**2)")
recipe.set_equation("A * exp(-0.5*(x-x0)**2/sigma**2)")

# We can give them other values here.
recipe.A = 1
Expand Down
4 changes: 2 additions & 2 deletions 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 All @@ -77,7 +77,7 @@ def delta(t, mu):
contribution.registerStringFunction(bkgdstr, "bkgd")

# Now define our fitting equation. We will hardcode the peak ratios.
contribution.setEquation(
contribution.set_equation(
"A1 * ( convolve( delta(t, mu11), peakshape(t, c, sig11) ) \
+ 0.23*convolve( delta(t, mu12), peakshape(t, c, sig12) ) ) + \
A2 * ( convolve( delta(t, mu21), peakshape(t, c, sig21) ) \
Expand Down
23 changes: 23 additions & 0 deletions news/fitcontribution-dep.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* <news item>

**Changed:**

* <news item>

**Deprecated:**

* Deprecate camel case naming convention in ``FitContribution`` and replace it with snake case. The following changes are, ``setProfile``-> ``set_profile``, ``addProfileGenerator`` -> ``add_profile_generator``, ``setEquation`` -> ``set_equation``, ``setResidualEquation`` -> ``set_residual_equation``, and ``getResidualEquation`` -> ``get_residual_equation``.

**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
@@ -1,3 +1,4 @@
matplotlib-base
numpy
scipy
diffpy.utils
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make sure we have an issue to remove this from conda.txt and pip.txt when the old API is removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Loading
Loading