Skip to content

Commit 5e91f9b

Browse files
authored
Merge pull request #168 from cadenmyers13/recipeorg-dep1
Deprecate: deprecate methods in `RecipeOrganizer` pt1
2 parents 61d845d + 1c11b31 commit 5e91f9b

21 files changed

+649
-272
lines changed

docs/examples/coreshellnp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ def makeRecipe(stru1, stru2, datname):
7676
# very little to the PDF.
7777
from diffpy.srfit.pdf.characteristicfunctions import shellCF, sphericalCF
7878

79-
contribution.registerFunction(sphericalCF, name="f_CdS")
80-
contribution.registerFunction(shellCF, name="f_ZnS")
79+
contribution.register_function(sphericalCF, name="f_CdS")
80+
contribution.register_function(shellCF, name="f_ZnS")
8181

8282
# Write the fitting equation. We want to sum the PDFs from each phase and
8383
# multiply it by a scaling factor.

docs/examples/debyemodel.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,14 @@ def makeRecipe():
106106
contribution.set_profile(profile, xname="T")
107107

108108
# We now need to create the fitting equation. We tell the FitContribution
109-
# to use the 'debye' function defined below. The 'registerFunction' method
109+
# to use the 'debye' function defined below. The 'register_function' method
110110
# will let us do this. Since we haven't told it otherwise,
111-
# 'registerFunction' will extract the name of the function ('debye') and
111+
# 'register_function' will extract the name of the function ('debye') and
112112
# the names of the arguments ('T', 'm', 'thetaD'). These arguments will
113113
# become Parameters of the FitContribution. Since we named the x-variable
114114
# 'T' above, the 'T' in the 'debye' equation will refer to this x-variable
115115
# whenever it is used.
116-
contribution.registerFunction(debye)
116+
contribution.register_function(debye)
117117

118118
# Now we can create the fitting equation. We want to extend the 'debye'
119119
# equation by adding a vertical offset. We could wrap 'debye' in a new

docs/examples/debyemodelII.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@ def plotResults(recipe):
107107
recipe.highT.profile.set_calculation_range(xmin="obs", xmax="obs")
108108
T = recipe.lowT.profile.x
109109
U = recipe.lowT.profile.y
110-
# We can use a FitContribution's 'evaluateEquation' method to evaluate
110+
# We can use a FitContribution's 'evaluate_equation' method to evaluate
111111
# expressions involving the Parameters and other aspects of the
112112
# FitContribution. Here we evaluate the fitting equation, which is always
113113
# accessed using the name "eq". We access it this way (rather than through
114114
# the Profile's ycalc attribute) because we changed the calculation range
115115
# above, and we therefore need to recalculate the profile.
116-
lowU = recipe.lowT.evaluateEquation("eq")
117-
highU = recipe.highT.evaluateEquation("eq")
116+
lowU = recipe.lowT.evaluate_equation("eq")
117+
highU = recipe.highT.evaluate_equation("eq")
118118

119119
# Now we can plot this.
120120
import pylab

docs/examples/npintensity.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def makeRecipe(strufile, datname):
231231

232232
# This creates a callable equation named "bkgd" within the FitContribution,
233233
# and turns the polynomial coefficients into Parameters.
234-
contribution.registerStringFunction(bkgdstr, "bkgd")
234+
contribution.register_string_function(bkgdstr, "bkgd")
235235

236236
# We will create the broadening function that we need by creating a python
237237
# function and registering it with the FitContribution.
@@ -247,7 +247,7 @@ def gaussian(q, q0, width):
247247

248248
# This registers the python function and extracts the name and creates
249249
# Parameters from the arguments.
250-
contribution.registerFunction(gaussian)
250+
contribution.register_function(gaussian)
251251

252252
# Center the Gaussian so it is not truncated.
253253
contribution.q0.value = x[len(x) // 2]
@@ -342,7 +342,7 @@ def plotResults(recipe):
342342

343343
Imeas = recipe.bucky.profile.y
344344
Icalc = recipe.bucky.profile.ycalc
345-
bkgd = recipe.bucky.evaluateEquation("bkgd")
345+
bkgd = recipe.bucky.evaluate_equation("bkgd")
346346
diff = Imeas - Icalc
347347

348348
import pylab

docs/examples/npintensityII.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ def makeRecipe(strufile, datname1, datname2):
105105
bkgdstr = "b0 + b1*q + b2*q**2 + b3*q**3 + b4*q**4 + b5*q**5 + b6*q**6 +\
106106
b7*q**7 +b8*q**8 + b9*q**9"
107107

108-
contribution1.registerStringFunction(bkgdstr, "bkgd")
109-
contribution2.registerStringFunction(bkgdstr, "bkgd")
108+
contribution1.register_string_function(bkgdstr, "bkgd")
109+
contribution2.register_string_function(bkgdstr, "bkgd")
110110

111111
# We will create the broadening function by registering a python function.
112112
pi = numpy.pi
@@ -119,8 +119,8 @@ def gaussian(q, q0, width):
119119
* exp(-0.5 * ((q - q0) / width) ** 2)
120120
)
121121

122-
contribution1.registerFunction(gaussian)
123-
contribution2.registerFunction(gaussian)
122+
contribution1.register_function(gaussian)
123+
contribution2.register_function(gaussian)
124124
# Center the gaussian
125125
contribution1.q0.value = x[len(x) // 2]
126126
contribution2.q0.value = x[len(x) // 2]
@@ -196,11 +196,11 @@ def plotResults(recipe):
196196
# Plot this for fun.
197197
I1 = recipe.bucky1.profile.y
198198
Icalc1 = recipe.bucky1.profile.ycalc
199-
bkgd1 = recipe.bucky1.evaluateEquation("bkgd")
199+
bkgd1 = recipe.bucky1.evaluate_equation("bkgd")
200200
diff1 = I1 - Icalc1
201201
I2 = recipe.bucky2.profile.y
202202
Icalc2 = recipe.bucky2.profile.ycalc
203-
bkgd2 = recipe.bucky2.evaluateEquation("bkgd")
203+
bkgd2 = recipe.bucky2.evaluate_equation("bkgd")
204204
diff2 = I2 - Icalc2
205205
offset = 1.2 * max(I2) * numpy.ones_like(I2)
206206
I1 += offset

docs/examples/nppdfcrystal.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def makeRecipe(ciffile, grdata):
5959
# Register the nanoparticle shape factor.
6060
from diffpy.srfit.pdf.characteristicfunctions import sphericalCF
6161

62-
pdfcontribution.registerFunction(sphericalCF, name="f")
62+
pdfcontribution.register_function(sphericalCF, name="f")
6363

6464
# Now we set up the fitting equation.
6565
pdfcontribution.set_equation("f * G")
@@ -91,10 +91,10 @@ def plotResults(recipe):
9191
diffzero = -0.8 * max(g) * numpy.ones_like(g)
9292
diff = g - gcalc + diffzero
9393

94-
gcryst = recipe.pdf.evaluateEquation("G")
94+
gcryst = recipe.pdf.evaluate_equation("G")
9595
gcryst /= recipe.scale.value
9696

97-
fr = recipe.pdf.evaluateEquation("f")
97+
fr = recipe.pdf.evaluate_equation("f")
9898
fr *= max(g) / fr[0]
9999

100100
import pylab

docs/examples/nppdfsas.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def makeRecipe(ciffile, grdata, iqdata):
8787

8888
# Register the calculator with the pdf contribution and define the fitting
8989
# equation.
90-
pdfcontribution.registerCalculator(cfcalculator)
90+
pdfcontribution.register_calculator(cfcalculator)
9191
# The PDF for a nanoscale crystalline is approximated by
9292
# Gnano = f * Gcryst
9393
pdfcontribution.set_equation("f * G")
@@ -156,10 +156,10 @@ def plotResults(recipe):
156156
diffzero = -0.8 * max(g) * numpy.ones_like(g)
157157
diff = g - gcalc + diffzero
158158

159-
gcryst = recipe.pdf.evaluateEquation("G")
159+
gcryst = recipe.pdf.evaluate_equation("G")
160160
gcryst /= recipe.scale.value
161161

162-
fr = recipe.pdf.evaluateEquation("f")
162+
fr = recipe.pdf.evaluate_equation("f")
163163
fr *= max(g) / fr[0]
164164

165165
import pylab

docs/examples/threedoublepeaks.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def makeRecipe():
5959
def gaussian(t, mu, sig):
6060
return 1 / (2 * pi * sig**2) ** 0.5 * exp(-0.5 * ((t - mu) / sig) ** 2)
6161

62-
contribution.registerFunction(gaussian, name="peakshape")
62+
contribution.register_function(gaussian, name="peakshape")
6363

6464
def delta(t, mu):
6565
"""Calculate a delta-function.
@@ -70,12 +70,12 @@ def delta(t, mu):
7070
sig = t[1] - t[0]
7171
return gaussian(t, mu, sig)
7272

73-
contribution.registerFunction(delta)
73+
contribution.register_function(delta)
7474

7575
# Here is another one
7676
bkgdstr = "b0 + b1*t + b2*t**2 + b3*t**3 + b4*t**4 + b5*t**5 + b6*t**6"
7777

78-
contribution.registerStringFunction(bkgdstr, "bkgd")
78+
contribution.register_string_function(bkgdstr, "bkgd")
7979

8080
# Now define our fitting equation. We will hardcode the peak ratios.
8181
contribution.set_equation(
@@ -120,7 +120,7 @@ def peakloc(mu):
120120
l2 = 1.0
121121
return 180 / pi * arcsin(pi / 180 * l2 * sin(mu) / l1)
122122

123-
recipe.registerFunction(peakloc)
123+
recipe.register_function(peakloc)
124124
recipe.constrain(contribution.mu12, "peakloc(mu11)")
125125
recipe.constrain(contribution.mu22, "peakloc(mu21)")
126126
recipe.constrain(contribution.mu32, "peakloc(mu31)")
@@ -134,7 +134,7 @@ def sig(sig0, dsig, mu):
134134
"""Calculate the peak broadening with respect to position."""
135135
return sig0 * (1 - dsig * mu**2)
136136

137-
recipe.registerFunction(sig)
137+
recipe.register_function(sig)
138138
recipe.fix("mu")
139139
# Now constrain the peak widths to this
140140
recipe.sig0.value = 0.001

news/recipeorg-dep1.rst

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
**Added:**
2+
3+
* Added ``iterate_over_parameters`` method.
4+
* Added ``register_calculator`` method.
5+
* Added ``register_function`` method.
6+
* Added ``register_string_function`` method.
7+
* Added ``evaluate_equation`` method.
8+
* Added ``is_constrained`` method.
9+
* Added ``get_constrained_parameters`` method.
10+
* Added ``clear_all_constraints`` method.
11+
12+
**Changed:**
13+
14+
* <news item>
15+
16+
**Deprecated:**
17+
18+
* Deprecated ``iterPars`` method. Use ``iterate_over_parameters`` instead.
19+
* Deprecated ``registerCalculator`` method. Use ``register_calculator`` instead.
20+
* Deprecated ``registerFunction`` method. Use ``register_function`` instead.
21+
* Deprecated ``registerStringFunction`` method. Use ``register_string_function`` instead.
22+
* Deprecated ``evaluateEquation`` method. Use ``evaluate_equation`` instead.
23+
* Deprecated ``isConstrained`` method. Use ``is_constrained`` instead.
24+
* Deprecated ``getConstrainedPars`` method. Use ``get_constrained_parameters`` instead.
25+
* Deprecated ``clearConstraints`` method. Use ``clear_all_constraints`` instead.
26+
27+
**Removed:**
28+
29+
* <news item>
30+
31+
**Fixed:**
32+
33+
* <news item>
34+
35+
**Security:**
36+
37+
* <news item>

src/diffpy/srfit/equation/builder.py

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,16 @@
106106

107107
_builders = {}
108108

109+
EquationFactory_base = "diffpy.srfit.equation.builder.EquationFactory"
110+
removal_version = "4.0.0"
111+
112+
registerFunction_dep_msg = build_deprecation_message(
113+
EquationFactory_base,
114+
"registerFunction",
115+
"register_function",
116+
removal_version,
117+
)
118+
109119

110120
class EquationFactory(object):
111121
"""A Factory for equations.
@@ -208,23 +218,26 @@ def registerOperator(self, name, op):
208218
opbuilder = wrapOperator(name, op)
209219
return self.registerBuilder(name, opbuilder)
210220

211-
def registerFunction(self, name, func, argnames):
221+
def register_function(self, name, func, argnames):
212222
"""Register a named function with the factory.
213223
214224
This will register a builder for the function.
215225
216-
Attributes
226+
Parameters
217227
----------
218-
name
228+
name : str
219229
The name of the function
220-
func
221-
A callable python object
222-
argnames
230+
func : callable
231+
The callable python object
232+
argnames : list of str
223233
The argument names for func. If these names do not
224234
correspond to builders, then new constants with value 0
225235
will be created for each name.
226236
227-
Returns the registered builder.
237+
Returns
238+
-------
239+
registered_builder : OperatorBuilder
240+
The registered builder.
228241
"""
229242
for n in argnames:
230243
if n not in self.builders:
@@ -234,8 +247,19 @@ def registerFunction(self, name, func, argnames):
234247
builder = self.builders[argname]
235248
argliteral = builder.literal
236249
opbuilder.literal.addLiteral(argliteral)
250+
registered_builder = self.registerBuilder(name, opbuilder)
251+
return registered_builder
237252

238-
return self.registerBuilder(name, opbuilder)
253+
@deprecated(registerFunction_dep_msg)
254+
def registerFunction(self, name, func, argnames):
255+
"""This function has been deprecated and will be removed in
256+
version 4.0.0.
257+
258+
Please use
259+
diffpy.srfit.equation.builder.EquationFactory.register_function
260+
instead.
261+
"""
262+
return self.register_function(name, func, argnames)
239263

240264
def registerBuilder(self, name, builder):
241265
"""Register builder in this module so it can be used in

0 commit comments

Comments
 (0)