Skip to content

Commit ca4e85c

Browse files
committed
setResidualEquation deprecation
1 parent 1befd11 commit ca4e85c

7 files changed

Lines changed: 52 additions & 22 deletions

File tree

docs/examples/crystalpdfall.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ def makeRecipe(
9797
xcontribution_sini.set_equation("scale * (xG_sini_ni + xG_sini_si)")
9898

9999
# As explained in another example, we want to minimize using Rw^2.
100-
xcontribution_ni.setResidualEquation("resv")
101-
xcontribution_si.setResidualEquation("resv")
102-
ncontribution_ni.setResidualEquation("resv")
103-
xcontribution_sini.setResidualEquation("resv")
100+
xcontribution_ni.set_residual_equation("resv")
101+
xcontribution_si.set_residual_equation("resv")
102+
ncontribution_ni.set_residual_equation("resv")
103+
xcontribution_sini.set_residual_equation("resv")
104104

105105
# Make the FitRecipe and add the FitContributions.
106106
recipe = FitRecipe()

docs/examples/crystalpdftwodata.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ def makeRecipe(ciffile, xdatname, ndatname):
105105
# The contribution's residual can be either chi^2, Rw^2, or custom crafted.
106106
# In this case, we should minimize Rw^2 of each contribution so that each
107107
# one can contribute roughly equally to the fit.
108-
xcontribution.setResidualEquation("resv")
109-
ncontribution.setResidualEquation("resv")
108+
xcontribution.set_residual_equation("resv")
109+
ncontribution.set_residual_equation("resv")
110110

111111
# Make the FitRecipe and add the FitContributions.
112112
recipe = FitRecipe()

docs/examples/ellipsoidsas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def makeRecipe(datname):
6464
# higher-Q information remains significant. There are no I(Q) uncertainty
6565
# values with the data, so we do not need to worry about the effect this
6666
# will have on the estimated parameter uncertainties.
67-
contribution.setResidualEquation("log(eq) - log(y)")
67+
contribution.set_residual_equation("log(eq) - log(y)")
6868

6969
# Make the FitRecipe and add the FitContribution.
7070
recipe = FitRecipe()

docs/examples/nppdfsas.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def makeRecipe(ciffile, grdata, iqdata):
5959
stru = loadCrystal(ciffile)
6060
pdfgenerator.setStructure(stru)
6161
pdfcontribution.add_profile_generator(pdfgenerator)
62-
pdfcontribution.setResidualEquation("resv")
62+
pdfcontribution.set_residual_equation("resv")
6363

6464
# Create a SAS contribution as well. We assume the nanoparticle is roughly
6565
# elliptical.
@@ -78,7 +78,7 @@ def makeRecipe(ciffile, grdata, iqdata):
7878
model = EllipsoidModel()
7979
sasgenerator = SASGenerator("generator", model)
8080
sascontribution.add_profile_generator(sasgenerator)
81-
sascontribution.setResidualEquation("resv")
81+
sascontribution.set_residual_equation("resv")
8282

8383
# Now we set up a characteristic function calculator that depends on the
8484
# sas model.

src/diffpy/srfit/fitbase/fitcontribution.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@
6363
removal_version,
6464
)
6565

66+
setresidualequation_dep_msg = build_deprecation_message(
67+
base,
68+
"setResidualEquation",
69+
"set_residual_equation",
70+
removal_version,
71+
)
72+
6673

6774
class FitContribution(ParameterSet):
6875
"""FitContribution class.
@@ -186,7 +193,7 @@ def set_profile(self, profile, xname=None, yname=None, dyname=None):
186193

187194
# If we have _eq, but not _reseq, set the residual
188195
if self._eq is not None and self._reseq is None:
189-
self.setResidualEquation("chiv")
196+
self.set_residual_equation("chiv")
190197

191198
return
192199

@@ -262,7 +269,7 @@ def set_equation(self, eqstr, ns={}):
262269
263270
This sets the equation that will be used when generating the residual
264271
for this FitContribution. The equation will be usable within
265-
setResidualEquation as "eq", and it takes no arguments.
272+
set_residual_equation as "eq", and it takes no arguments.
266273
267274
Attributes
268275
----------
@@ -296,7 +303,7 @@ def set_equation(self, eqstr, ns={}):
296303

297304
# Set the residual if we need to
298305
if self.profile is not None and self._reseq is None:
299-
self.setResidualEquation("chiv")
306+
self.set_residual_equation("chiv")
300307

301308
return
302309

@@ -334,7 +341,7 @@ def getEquation(self):
334341
"""
335342
return self.get_equation()
336343

337-
def setResidualEquation(self, eqstr):
344+
def set_residual_equation(self, eqstr):
338345
"""Set the residual equation for the FitContribution.
339346
340347
Attributes
@@ -378,6 +385,18 @@ def setResidualEquation(self, eqstr):
378385

379386
return
380387

388+
@deprecated(setresidualequation_dep_msg)
389+
def setResidualEquation(self, eqstr):
390+
"""This function has been deprecated and will be removed in version
391+
4.0.0.
392+
393+
Please use
394+
diffpy.srfit.fitbase.FitContribution.set_residual_equation
395+
instead.
396+
"""
397+
self.set_residual_equation(eqstr)
398+
return
399+
381400
def getResidualEquation(self):
382401
"""Get math expression string for the active residual equation.
383402
@@ -402,7 +421,7 @@ def residual(self):
402421
chiv = (eq() - self.profile.y) / self.profile.dy
403422
The value that is optimized is dot(chiv, chiv).
404423
405-
The residual equation can be changed with the setResidualEquation
424+
The residual equation can be changed with the set_residual_equation
406425
method.
407426
"""
408427
# Assign the calculated profile

src/diffpy/srfit/fitbase/simplerecipe.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,8 @@ def set_equation(self, eqstr, ns={}):
288288
"""Set the profile equation for the FitContribution.
289289
290290
This sets the equation that will be used when generating the residual.
291-
The equation will be usable within setResidualEquation as "eq", and it
292-
takes no arguments.
291+
The equation will be usable within set_residual_equation as "eq", and
292+
it takes no arguments.
293293
294294
Attributes
295295
----------

tests/test_contribution.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,17 @@ def testReplacements(self):
155155
self.assertEqual(len(xobs2), len(fc.residual()))
156156
return
157157

158+
def test_get_residual_equation(self):
159+
"""Check getting the current formula for residual equation."""
160+
fc = self.fitcontribution
161+
self.assertEqual("", fc.getResidualEquation())
162+
fc.set_profile(self.profile)
163+
fc.set_equation("A * x + B")
164+
self.assertEqual("((eq - y) / dy)", fc.getResidualEquation())
165+
fc.set_residual_equation("2 * (eq - y)")
166+
self.assertEqual("(2 * (eq - y))", fc.getResidualEquation())
167+
return
168+
158169
def test_getResidualEquation(self):
159170
"""Check getting the current formula for residual equation."""
160171
fc = self.fitcontribution
@@ -175,7 +186,7 @@ def test_releaseOldEquations(self):
175186
self.assertEqual(1, len(fc._eqfactory.equations))
176187
fc.set_profile(self.profile)
177188
for i in range(5):
178-
fc.setResidualEquation("chiv")
189+
fc.set_residual_equation("chiv")
179190
self.assertEqual(2, len(fc._eqfactory.equations))
180191
return
181192

@@ -258,26 +269,26 @@ def testResidual(noObserversInGlobalBuilders):
258269

259270
# Choose a new residual.
260271
fc.set_equation("2*I")
261-
fc.setResidualEquation("resv")
272+
fc.set_residual_equation("resv")
262273
chiv = fc.residual()
263274
assert dot(chiv, chiv) == pytest.approx(
264275
sum((2 * xobs - yobs) ** 2) / sum(yobs**2)
265276
)
266277

267278
# Make a custom residual.
268-
fc.setResidualEquation("abs(eq-y)**0.5")
279+
fc.set_residual_equation("abs(eq-y)**0.5")
269280
chiv = fc.residual()
270281
assert dot(chiv, chiv) == pytest.approx(sum(abs(2 * xobs - yobs)))
271282

272283
# Test configuration checks
273284
fc1 = FitContribution("test1")
274285
with pytest.raises(SrFitError):
275-
fc1.setResidualEquation("chiv")
286+
fc1.set_residual_equation("chiv")
276287
fc1.set_profile(profile)
277288
with pytest.raises(SrFitError):
278-
fc1.setResidualEquation("chiv")
289+
fc1.set_residual_equation("chiv")
279290
fc1.set_equation("A * x")
280-
fc1.setResidualEquation("chiv")
291+
fc1.set_residual_equation("chiv")
281292
assert noObserversInGlobalBuilders
282293
return
283294

0 commit comments

Comments
 (0)