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 @@ -169,7 +169,7 @@ def main():
recipe = makeRecipe(stru1, stru2, data)
from diffpy.srfit.fitbase.fithook import PlotFitHook

recipe.pushFitHook(PlotFitHook())
recipe.push_fit_hook(PlotFitHook())
recipe.fithooks[0].verbose = 3

# Optimize - we do this in steps to help convergence
Expand Down
8 changes: 4 additions & 4 deletions docs/examples/npintensityII.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,17 +248,17 @@ def main():
# fit.
recipe.fix("all")
recipe.free("bcoeffs1")
recipe.setWeight(recipe.bucky2, 0)
recipe.set_weight(recipe.bucky2, 0)
scipyOptimize(recipe)
# Now do the same for the second background
recipe.fix("all")
recipe.free("bcoeffs1")
recipe.setWeight(recipe.bucky2, 1)
recipe.setWeight(recipe.bucky1, 0)
recipe.set_weight(recipe.bucky2, 1)
recipe.set_weight(recipe.bucky1, 0)
scipyOptimize(recipe)
# Now refine everything with the structure parameters included
recipe.free("all")
recipe.setWeight(recipe.bucky1, 1)
recipe.set_weight(recipe.bucky1, 1)
scipyOptimize(recipe)

# Generate and print the FitResults
Expand Down
10 changes: 5 additions & 5 deletions docs/examples/nppdfsas.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,23 +122,23 @@ def fitRecipe(recipe):
"""We refine in stages to help the refinement converge."""

# Tune SAS.
recipe.setWeight(recipe.pdf, 0)
recipe.set_weight(recipe.pdf, 0)
recipe.fix("all")
recipe.free("radius_a", "radius_b", iqscale=1e8)
recipe.constrain("radius_b", "radius_a")
scipyOptimize(recipe)
recipe.unconstrain("radius_b")

# Tune PDF
recipe.setWeight(recipe.pdf, 1)
recipe.setWeight(recipe.sas, 0)
recipe.set_weight(recipe.pdf, 1)
recipe.set_weight(recipe.sas, 0)
recipe.fix("all")
recipe.free("a", "Biso_0", "scale", "delta2")
scipyOptimize(recipe)

# Tune all
recipe.setWeight(recipe.pdf, 1)
recipe.setWeight(recipe.sas, 1)
recipe.set_weight(recipe.pdf, 1)
recipe.set_weight(recipe.sas, 1)
recipe.free("all")
scipyOptimize(recipe)

Expand Down
2 changes: 1 addition & 1 deletion docs/source/extending.rst
Original file line number Diff line number Diff line change
Expand Up @@ -263,5 +263,5 @@ overload.
* .. automethod:: FitHook.postcall

To use a custom ``FitHook``, assign an instance to a ``FitRecipe`` using the
``pushFitHook`` method. All ``FitHook`` instances held by a ``FitRecipe`` will
``push_fit_hook`` method. All ``FitHook`` instances held by a ``FitRecipe`` will
be used in sequence during a call to ``FitRecipe.residual``.
31 changes: 31 additions & 0 deletions news/fithook-and-weights-dep.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
**Added:**

* Added ``set_weight`` method to ``FitRecipe`` to replace ``setWeight``.
* Added ``get_fit_hooks`` method to ``FitRecipe`` to replace ``getFitHooks``.
* Added ``clear_fit_hooks`` method to ``FitRecipe`` to replace ``clearFitHooks``.
* Added ``pop_fit_hook`` method to ``FitRecipe`` to replace ``popFitHook``.
* Added ``push_fit_hook`` method to ``FitRecipe`` to replace ``pushFitHook``.

**Changed:**

* <news item>

**Deprecated:**

* Deprecated ``setWeight`` in ``FitRecipe`` for removal in 4.0.0.
* Deprecated ``getFitHooks`` in ``FitRecipe`` for removal in 4.0.0.
* Deprecated ``clearFitHooks`` in ``FitRecipe`` for removal in 4.0.0.
* Deprecated ``popFitHook`` in ``FitRecipe`` for removal in 4.0.0.
* Deprecated ``pushFitHook`` in ``FitRecipe`` for removal in 4.0.0.

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
8 changes: 4 additions & 4 deletions src/diffpy/srfit/fitbase/fithook.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ class FitHook(object):
"""Base class for inspecting the progress of a FitRecipe refinement.

Can serve as a fithook for the FitRecipe class (see
FitRecipe.pushFitHook method.) The methods in this class are called
during the preparation of the FitRecipe for refinement, and during
the residual call. See the class methods for a description of their
purpose.
FitRecipe.push_fit_hook method.) The methods in this class are
called during the preparation of the FitRecipe for refinement, and
during the residual call. See the class methods for a description of
their purpose.
"""

def reset(self, recipe):
Expand Down
76 changes: 71 additions & 5 deletions src/diffpy/srfit/fitbase/fitrecipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,26 @@
base, "addContribution", "add_contribution", removal_version
)

pushfithook_dep_msg = build_deprecation_message(
base, "pushFitHook", "push_fit_hook", removal_version
)

popfithook_dep_msg = build_deprecation_message(
base, "popFitHook", "pop_fit_hook", removal_version
)

getfithooks_dep_msg = build_deprecation_message(
base, "getFitHooks", "get_fit_hooks", removal_version
)

clearfithooks_dep_msg = build_deprecation_message(
base, "clearFitHooks", "clear_fit_hooks", removal_version
)

setweight_dep_msg = build_deprecation_message(
base, "setWeight", "set_weight", removal_version
)


class FitRecipe(_fitrecipe_interface, RecipeOrganizer):
"""FitRecipe class.
Expand Down Expand Up @@ -191,7 +211,7 @@ def __init__(self, name="fit"):
}
return

def pushFitHook(self, fithook, index=None):
def push_fit_hook(self, fithook, index=None):
"""Add a FitHook to be called within the residual method.

The hook is an object for reporting updates, or more fundamentally,
Expand All @@ -214,7 +234,17 @@ def pushFitHook(self, fithook, index=None):
self._update_configuration()
return

def popFitHook(self, fithook=None, index=-1):
@deprecated(pushfithook_dep_msg)
def pushFitHook(self, fithook, index=None):
"""This function has been deprecated and will be removed in version
4.0.0.

Please use diffpy.srfit.fitbase.FitRecipe.push_fit_hook instead.
"""
self.push_fit_hook(fithook, index)
return

def pop_fit_hook(self, fithook=None, index=-1):
"""Remove a FitHook by index or reference.

Attributes
Expand All @@ -236,15 +266,42 @@ def popFitHook(self, fithook=None, index=-1):
self.fithook.remove(index)
return

def getFitHooks(self):
@deprecated(popfithook_dep_msg)
def popFitHook(self, fithook=None, index=-1):
"""This function has been deprecated and will be removed in version
4.0.0.

Please use diffpy.srfit.fitbase.FitRecipe.pop_fit_hook instead.
"""
self.pop_fit_hook(fithook, index)
return

def get_fit_hooks(self):
"""Get the sequence of FitHook instances."""
return self.fithooks[:]

def clearFitHooks(self):
@deprecated(getfithooks_dep_msg)
def getFitHooks(self):
"""This function has been deprecated and will be removed in version
4.0.0.

Please use diffpy.srfit.fitbase.FitRecipe.get_fit_hooks instead."""
return self.get_fit_hooks()

def clear_fit_hooks(self):
"""Clear the FitHook sequence."""
del self.fithooks[:]
return

@deprecated(clearfithooks_dep_msg)
def clearFitHooks(self):
"""This function has been deprecated and will be removed in version
4.0.0.

Please use diffpy.srfit.fitbase.FitRecipe.clear_fit_hooks instead."""
self.clear_fit_hooks()
return

def add_contribution(self, con, weight=1.0):
"""Add a FitContribution to the FitRecipe.

Expand Down Expand Up @@ -273,12 +330,21 @@ def addContribution(self, con, weight=1.0):
self.add_contribution(con, weight)
return

def setWeight(self, con, weight):
def set_weight(self, con, weight):
"""Set the weight of a FitContribution."""
idx = list(self._contributions.values()).index(con)
self._weights[idx] = weight
return

@deprecated(setweight_dep_msg)
def setWeight(self, con, weight):
"""This function has been deprecated and will be removed in version
4.0.0.

Please use diffpy.srfit.fitbase.FitRecipe.set_weight instead."""
self.set_weight(con, weight)
return

def addParameterSet(self, parset):
"""Add a ParameterSet to the hierarchy.

Expand Down
2 changes: 1 addition & 1 deletion tests/test_fitrecipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def test_add_contribution(capturestdout):

recipe.addVar(fitcontribution.c)
recipe.restrain("c", lb=5)
(pfh,) = recipe.getFitHooks()
(pfh,) = recipe.get_fit_hooks()
out = capturestdout(recipe.scalarResidual)
assert "" == out
pfh.verbose = 1
Expand Down
Loading