Skip to content

Commit 9296fc6

Browse files
committed
setWeight deprecation
1 parent ca3d83e commit 9296fc6

3 files changed

Lines changed: 23 additions & 10 deletions

File tree

docs/examples/npintensityII.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,17 +248,17 @@ def main():
248248
# fit.
249249
recipe.fix("all")
250250
recipe.free("bcoeffs1")
251-
recipe.setWeight(recipe.bucky2, 0)
251+
recipe.set_weight(recipe.bucky2, 0)
252252
scipyOptimize(recipe)
253253
# Now do the same for the second background
254254
recipe.fix("all")
255255
recipe.free("bcoeffs1")
256-
recipe.setWeight(recipe.bucky2, 1)
257-
recipe.setWeight(recipe.bucky1, 0)
256+
recipe.set_weight(recipe.bucky2, 1)
257+
recipe.set_weight(recipe.bucky1, 0)
258258
scipyOptimize(recipe)
259259
# Now refine everything with the structure parameters included
260260
recipe.free("all")
261-
recipe.setWeight(recipe.bucky1, 1)
261+
recipe.set_weight(recipe.bucky1, 1)
262262
scipyOptimize(recipe)
263263

264264
# Generate and print the FitResults

docs/examples/nppdfsas.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,23 +122,23 @@ def fitRecipe(recipe):
122122
"""We refine in stages to help the refinement converge."""
123123

124124
# Tune SAS.
125-
recipe.setWeight(recipe.pdf, 0)
125+
recipe.set_weight(recipe.pdf, 0)
126126
recipe.fix("all")
127127
recipe.free("radius_a", "radius_b", iqscale=1e8)
128128
recipe.constrain("radius_b", "radius_a")
129129
scipyOptimize(recipe)
130130
recipe.unconstrain("radius_b")
131131

132132
# Tune PDF
133-
recipe.setWeight(recipe.pdf, 1)
134-
recipe.setWeight(recipe.sas, 0)
133+
recipe.set_weight(recipe.pdf, 1)
134+
recipe.set_weight(recipe.sas, 0)
135135
recipe.fix("all")
136136
recipe.free("a", "Biso_0", "scale", "delta2")
137137
scipyOptimize(recipe)
138138

139139
# Tune all
140-
recipe.setWeight(recipe.pdf, 1)
141-
recipe.setWeight(recipe.sas, 1)
140+
recipe.set_weight(recipe.pdf, 1)
141+
recipe.set_weight(recipe.sas, 1)
142142
recipe.free("all")
143143
scipyOptimize(recipe)
144144

src/diffpy/srfit/fitbase/fitrecipe.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@
7171
base, "clearFitHooks", "clear_fit_hooks", removal_version
7272
)
7373

74+
setweight_dep_msg = build_deprecation_message(
75+
base, "setWeight", "set_weight", removal_version
76+
)
77+
7478

7579
class FitRecipe(_fitrecipe_interface, RecipeOrganizer):
7680
"""FitRecipe class.
@@ -326,12 +330,21 @@ def addContribution(self, con, weight=1.0):
326330
self.add_contribution(con, weight)
327331
return
328332

329-
def setWeight(self, con, weight):
333+
def set_weight(self, con, weight):
330334
"""Set the weight of a FitContribution."""
331335
idx = list(self._contributions.values()).index(con)
332336
self._weights[idx] = weight
333337
return
334338

339+
@deprecated(setweight_dep_msg)
340+
def setWeight(self, con, weight):
341+
"""This function has been deprecated and will be removed in version
342+
4.0.0.
343+
344+
Please use diffpy.srfit.fitbase.FitRecipe.set_weight instead."""
345+
self.set_weight(con, weight)
346+
return
347+
335348
def addParameterSet(self, parset):
336349
"""Add a ParameterSet to the hierarchy.
337350

0 commit comments

Comments
 (0)