diff --git a/news/param-dep.rst b/news/param-dep.rst new file mode 100644 index 00000000..e0b8eabe --- /dev/null +++ b/news/param-dep.rst @@ -0,0 +1,27 @@ +**Added:** + +* Added ``is_constant`` method to ``Parameter``. +* Added ``bound_range`` method to ``Parameter``. +* Added ``bound_window`` method to ``Parameter``. + +**Changed:** + +* + +**Deprecated:** + +* Deprecated ``isConst`` method of ``Parameter``. Use ``is_constant`` instead. +* Deprecated ``boundRange`` method of ``Parameter``. Use ``bound_range`` instead. +* Deprecated ``boundWindow`` method of ``Parameter``. Use ``bound_window`` instead. + +**Removed:** + +* + +**Fixed:** + +* + +**Security:** + +* diff --git a/src/diffpy/srfit/equation/builder.py b/src/diffpy/srfit/equation/builder.py index 0c9ffafb..0bb81350 100644 --- a/src/diffpy/srfit/equation/builder.py +++ b/src/diffpy/srfit/equation/builder.py @@ -493,7 +493,7 @@ def __eval_binary(self, other, OperatorClass, onleft=True): Other can be an BaseBuilder or a constant. - Attributes + Parameters ---------- onleft Indicates that the operator was passed on the left side @@ -666,7 +666,7 @@ def __call__(self, *args): This creates a new builder that encapsulates the operation. - Attributes + Parameters ---------- args Arguments of the operation. @@ -730,7 +730,7 @@ def wrapOperator(name, op): def wrapFunction(name, func, nin=2, nout=1): """Wrap a function in an OperatorBuilder instance. - Attributes + Parameters ---------- name The name of the function diff --git a/src/diffpy/srfit/equation/equationmod.py b/src/diffpy/srfit/equation/equationmod.py index 4a40aeb7..5be7ba0c 100644 --- a/src/diffpy/srfit/equation/equationmod.py +++ b/src/diffpy/srfit/equation/equationmod.py @@ -91,7 +91,7 @@ class Equation(Operator): def __init__(self, name=None, root=None): """Initialize. - Attributes + Parameters ---------- name A name for this Equation. diff --git a/src/diffpy/srfit/equation/literals/argument.py b/src/diffpy/srfit/equation/literals/argument.py index a99fb7f1..c468d516 100644 --- a/src/diffpy/srfit/equation/literals/argument.py +++ b/src/diffpy/srfit/equation/literals/argument.py @@ -62,7 +62,7 @@ def getValue(self): def set_value(self, val): """Set the value of the Literal. - Attributes + Parameters ---------- val The value to assign diff --git a/src/diffpy/srfit/equation/literals/operators.py b/src/diffpy/srfit/equation/literals/operators.py index 9b78b77c..bb830b05 100644 --- a/src/diffpy/srfit/equation/literals/operators.py +++ b/src/diffpy/srfit/equation/literals/operators.py @@ -347,7 +347,7 @@ def __init__(self, op): Arguments - Attributes + Parameters ---------- op A numpy ufunc diff --git a/src/diffpy/srfit/equation/visitors/__init__.py b/src/diffpy/srfit/equation/visitors/__init__.py index ef50ec43..82239eb4 100644 --- a/src/diffpy/srfit/equation/visitors/__init__.py +++ b/src/diffpy/srfit/equation/visitors/__init__.py @@ -35,7 +35,7 @@ def getArgs(literal, getconsts=True): """Get the Arguments of a Literal tree. - Attributes + Parameters ---------- getconsts If True (default), then Arguments designated as constant @@ -50,7 +50,7 @@ def getArgs(literal, getconsts=True): def getExpression(literal, eqskip=None): """Get math expression string from the Literal tree object. - Attributes + Parameters ---------- eqskip regular expression pattern for Equation objects that should diff --git a/src/diffpy/srfit/equation/visitors/printer.py b/src/diffpy/srfit/equation/visitors/printer.py index d3aa5ee7..4fcb717b 100644 --- a/src/diffpy/srfit/equation/visitors/printer.py +++ b/src/diffpy/srfit/equation/visitors/printer.py @@ -29,8 +29,6 @@ class Printer(Visitor): """Printer for printing a Literal tree. - Attributes: - Attributes ---------- eqskip diff --git a/src/diffpy/srfit/equation/visitors/swapper.py b/src/diffpy/srfit/equation/visitors/swapper.py index c27cf85e..ddd49ef6 100644 --- a/src/diffpy/srfit/equation/visitors/swapper.py +++ b/src/diffpy/srfit/equation/visitors/swapper.py @@ -38,7 +38,7 @@ class Swapper(Visitor): def __init__(self, oldlit, newlit): """Initialize. - Attributes + Parameters ---------- oldlit The literal to be replaced. diff --git a/src/diffpy/srfit/fitbase/fitcontribution.py b/src/diffpy/srfit/fitbase/fitcontribution.py index feda75ba..710f492c 100644 --- a/src/diffpy/srfit/fitbase/fitcontribution.py +++ b/src/diffpy/srfit/fitbase/fitcontribution.py @@ -147,7 +147,7 @@ def __init__(self, name): def set_profile(self, profile, xname=None, yname=None, dyname=None): """Assign the Profile for this FitContribution. - Attributes + Parameters ---------- profile A Profile that specifies the calculation points and that @@ -227,7 +227,7 @@ def add_profile_generator(self, gen, name=None): Calling addProfileGenerator sets the profile equation to call the calculator and if there is not a profile equation already. - Attributes + Parameters ---------- gen A ProfileGenerator instance @@ -278,7 +278,7 @@ def set_equation(self, eqstr, ns={}): for this FitContribution. The equation will be usable within set_residual_equation as "eq", and it takes no arguments. - Attributes + Parameters ---------- eqstr A string representation of the equation. Any Parameter @@ -353,7 +353,7 @@ def getEquation(self): def set_residual_equation(self, eqstr): """Set the residual equation for the FitContribution. - Attributes + Parameters ---------- eqstr A string representation of the residual. If eqstr is None diff --git a/src/diffpy/srfit/fitbase/fithook.py b/src/diffpy/srfit/fitbase/fithook.py index 3afa90d9..43e2c84e 100644 --- a/src/diffpy/srfit/fitbase/fithook.py +++ b/src/diffpy/srfit/fitbase/fithook.py @@ -58,7 +58,7 @@ def precall(self, recipe): """This is called within FitRecipe.residual, before the calculation. - Attributes + Parameters ---------- recipe The FitRecipe instance @@ -69,7 +69,7 @@ def postcall(self, recipe, chiv): """This is called within FitRecipe.residual, after the calculation. - Attributes + Parameters ---------- recipe The FitRecipe instance @@ -88,8 +88,6 @@ class PrintFitHook(FitHook): This FitHook prints out a running count of the number of times the residual has been called, or other information, based on the verbosity. - Attributes - Attributes ---------- count @@ -127,7 +125,7 @@ def precall(self, recipe): """This is called within FitRecipe.residual, before the calculation. - Attributes + Parameters ---------- recipe The FitRecipe instance @@ -141,7 +139,7 @@ def postcall(self, recipe, chiv): """This is called within FitRecipe.residual, after the calculation. - Attributes + Parameters ---------- recipe The FitRecipe instance @@ -237,7 +235,7 @@ def postcall(self, recipe, chiv): Find data and plot it. - Attributes + Parameters ---------- recipe The FitRecipe instance diff --git a/src/diffpy/srfit/fitbase/fitrecipe.py b/src/diffpy/srfit/fitbase/fitrecipe.py index 0961b504..d4fdf279 100644 --- a/src/diffpy/srfit/fitbase/fitrecipe.py +++ b/src/diffpy/srfit/fitbase/fitrecipe.py @@ -906,7 +906,7 @@ def _new_parameter(self, name, value, check=True): def __get_var_and_check(self, var): """Get the actual variable from var. - Attributes + Parameters ---------- var A variable of the FitRecipe, or the name of a variable. diff --git a/src/diffpy/srfit/fitbase/fitresults.py b/src/diffpy/srfit/fitbase/fitresults.py index d8310109..18f0423c 100644 --- a/src/diffpy/srfit/fitbase/fitresults.py +++ b/src/diffpy/srfit/fitbase/fitresults.py @@ -162,7 +162,7 @@ class FitResults(object): def __init__(self, recipe, update=True, showfixed=True, showcon=False): """Initialize the attributes. - Attributes + Parameters ---------- recipe : FitRecipe The recipe containing the results. @@ -733,7 +733,7 @@ class ContributionResults(object): def __init__(self, con, weight, fitres): """Initialize the attributes. - Attributes + Parameters ---------- con The FitContribution @@ -829,7 +829,7 @@ def resultsDictionary(results): This reads the results from file and stores them in a dictionary to be returned to the caller. The dictionary may contain non-result entries. - Attributes + Parameters ---------- results An open file-like object, name of a file that contains @@ -865,7 +865,7 @@ def initializeRecipe(recipe, results): free) in the recipe to the results values. Note that the recipe has to be configured, with variables. This does not reconstruct a FitRecipe. - Attributes + Parameters ---------- recipe A configured recipe with variables diff --git a/src/diffpy/srfit/fitbase/parameter.py b/src/diffpy/srfit/fitbase/parameter.py index 6bddf43b..4fa2c2b6 100644 --- a/src/diffpy/srfit/fitbase/parameter.py +++ b/src/diffpy/srfit/fitbase/parameter.py @@ -42,6 +42,18 @@ parameter_base, "setValue", "set_value", removal_version ) +setConst_dep_msg = build_deprecation_message( + parameter_base, "setConst", "set_constant", removal_version +) + +boundRange_dep_msg = build_deprecation_message( + parameter_base, "boundRange", "bound_range", removal_version +) + +boundWindow_dep_msg = build_deprecation_message( + parameter_base, "boundWindow", "bound_window", removal_version +) + class Parameter(_parameter_interface, Argument, Validatable): """Parameter class. @@ -68,7 +80,7 @@ class Parameter(_parameter_interface, Argument, Validatable): def __init__(self, name, value=None, const=False): """Initialization. - Attributes + Parameters ---------- name The name of this Parameter (must be a valid attribute @@ -91,7 +103,7 @@ def __init__(self, name, value=None, const=False): def set_value(self, val): """Set the value of the Parameter and the bounds. - Attributes + Parameters ---------- val The value to assign. @@ -119,17 +131,17 @@ def setValue(self, val): """ return self.set_value(val) - def setConst(self, const=True, value=None): + def set_constant(self, is_constant=True, value=None): """Toggle the Parameter as constant. - Attributes + Parameters ---------- - const - Flag indicating if the parameter is constant (default + is_constant : bool, optional + The flag indicating if the parameter is constant (default True). - value - An optional value for the parameter (default None). If this - is not None, then the parameter will get a new value, + value : float, optional + The value value for the parameter to be set to (default None). + If this is not None, then the parameter will get a new value, constant or otherwise. Returns @@ -137,15 +149,25 @@ def setConst(self, const=True, value=None): self Returns self so that mutators can be chained. """ - self.const = bool(const) + self.const = bool(is_constant) if value is not None: self.set_value(value) return self - def boundRange(self, lower_bound=None, upper_bound=None): + @deprecated(setConst_dep_msg) + def setConst(self, const=True, value=None): + """This function has been deprecated and will be removed in + version 4.0.0. + + Please use diffpy.srfit.fitbase.Parameter.set_constant instead. + """ + self.set_constant(const, value) + return self + + def bound_range(self, lower_bound=None, upper_bound=None): """Set lower and upper bound of the Parameter. - Attributes + Parameters ---------- lower_bound : float The lower bound for the bounds list. @@ -163,18 +185,28 @@ def boundRange(self, lower_bound=None, upper_bound=None): self.bounds[1] = upper_bound return self - def boundWindow(self, lr=0, ur=None): + @deprecated(boundRange_dep_msg) + def boundRange(self, lower_bound=None, upper_bound=None): + """This function has been deprecated and will be removed in + version 4.0.0. + + Please use diffpy.srfit.fitbase.Parameter.bound_range instead. + """ + self.bound_range(lower_bound, upper_bound) + return self + + def bound_window(self, lower_radius=0, upper_radius=None): """Create bounds centered on the current value of the Parameter. - Attributes + Parameters ---------- - lr + lower_radius : float, optional The radius of the lower bound (default 0). The lower bound is - computed as value - lr. - ur + computed as value - lower_radius. + upper_radius : float, optional The radius of the upper bound. The upper bound is computed as - value + ur. If this is None (default), then the value of the - lower radius is used. + value + upper_radius. If this is None (default), then the value + of the lower radius is used. Returns ------- @@ -182,13 +214,23 @@ def boundWindow(self, lr=0, ur=None): Returns self so that mutators can be chained. """ val = self.getValue() - lower_bound = val - lr - if ur is None: - ur = lr - upper_bound = val + ur + lower_bound = val - lower_radius + if upper_radius is None: + upper_radius = lower_radius + upper_bound = val + upper_radius self.bounds = [lower_bound, upper_bound] return self + @deprecated(boundWindow_dep_msg) + def boundWindow(self, lr=0, ur=None): + """This function has been deprecated and will be removed in + version 4.0.0. + + Please use diffpy.srfit.fitbase.Parameter.bound_window instead. + """ + self.bound_window(lr, ur) + return self + def _validate(self): """Validate my state. @@ -221,7 +263,7 @@ class ParameterProxy(Parameter): def __init__(self, name, par): """Initialization. - Attributes + Parameters ---------- name The name of this ParameterProxy. @@ -278,17 +320,17 @@ def set_value(self, val): def getValue(self): return self.par.getValue() - @wraps(Parameter.setConst) - def setConst(self, const=True, value=None): - return self.par.setConst(const, value) + @wraps(Parameter.set_constant) + def set_constant(self, const=True, value=None): + return self.par.set_constant(const, value) - @wraps(Parameter.boundRange) - def boundRange(self, lower_bound=None, upper_bound=None): - return self.par.boundRange(lower_bound, upper_bound) + @wraps(Parameter.bound_range) + def bound_range(self, lower_bound=None, upper_bound=None): + return self.par.bound_range(lower_bound, upper_bound) - @wraps(Parameter.boundWindow) - def boundWindow(self, lr=0, ur=None): - return self.par.boundWindow(lr, ur) + @wraps(Parameter.bound_window) + def bound_window(self, lr=0, ur=None): + return self.par.bound_window(lr, ur) def _validate(self): """Validate my state. @@ -316,7 +358,7 @@ class ParameterAdapter(Parameter): def __init__(self, name, obj, getter=None, setter=None, attr=None): """Wrap an object as a Parameter. - Attributes + Parameters ---------- name The name of this Parameter. diff --git a/src/diffpy/srfit/fitbase/parameterset.py b/src/diffpy/srfit/fitbase/parameterset.py index 6ebc4fc7..edaac6f5 100644 --- a/src/diffpy/srfit/fitbase/parameterset.py +++ b/src/diffpy/srfit/fitbase/parameterset.py @@ -38,6 +38,10 @@ base, "removeParameterSet", "remove_parameter_set", removal_version ) +setConst_dep_msg = build_deprecation_message( + base, "setConst", "set_constant", removal_version +) + class ParameterSet(RecipeOrganizer): """Class for organizing Parameters and other ParameterSets. @@ -83,7 +87,7 @@ class ParameterSet(RecipeOrganizer): def __init__(self, name): """Initialize. - Attributes + Parameters ---------- name The name of this ParameterSet. @@ -102,7 +106,7 @@ def __init__(self, name): def add_parameter_set(self, parset): """Add a ParameterSet to the hierarchy. - Attributes + Parameters ---------- parset The ParameterSet to be stored. @@ -147,18 +151,29 @@ def removeParameterSet(self, parset): self.remove_parameter_set(parset) return - def setConst(self, const=True): + def set_constant(self, is_constant=True): """Set every parameter within the set to a constant. - Attributes + Parameters ---------- - const - Flag indicating if the parameter is constant (default + is_constant : bool, optional + The flag indicating if the parameter is constant (default True). """ for par in self.iterate_over_parameters(): - par.setConst(const) + par.set_constant(is_constant) + return + @deprecated(setConst_dep_msg) + def setConst(self, const=True): + """This function has been deprecated and will be removed in + version 4.0.0. + + Please use + diffpy.srfit.fitbase.parameterset.ParameterSet.set_constant + instead. + """ + self.set_constant(const) return diff --git a/src/diffpy/srfit/fitbase/profile.py b/src/diffpy/srfit/fitbase/profile.py index 684a0313..bc598d3f 100644 --- a/src/diffpy/srfit/fitbase/profile.py +++ b/src/diffpy/srfit/fitbase/profile.py @@ -71,8 +71,6 @@ class Profile(Observable, Validatable): Profile is an Observable. The xpar, ypar and dypar attributes are observed by the Profile, which can in turn be observed by some other object. - Attributes - Attributes ---------- _xobs diff --git a/src/diffpy/srfit/fitbase/profilegenerator.py b/src/diffpy/srfit/fitbase/profilegenerator.py index c45e93aa..e0206084 100644 --- a/src/diffpy/srfit/fitbase/profilegenerator.py +++ b/src/diffpy/srfit/fitbase/profilegenerator.py @@ -156,7 +156,7 @@ def operation(self): def set_profile(self, profile): """Assign the profile. - Attributes + Parameters ---------- profile A Profile that specifies the calculation points and which @@ -171,10 +171,10 @@ def set_profile(self, profile): # Merge the profiles metadata with our own self.meta.update(self.profile.meta) - self.processMetaData() + self._process_metadata() return - def processMetaData(self): + def _process_metadata(self): """Process the metadata. This can be used to configure a ProfileGenerator upon a change diff --git a/src/diffpy/srfit/fitbase/recipeorganizer.py b/src/diffpy/srfit/fitbase/recipeorganizer.py index a3d442f7..20d16c49 100644 --- a/src/diffpy/srfit/fitbase/recipeorganizer.py +++ b/src/diffpy/srfit/fitbase/recipeorganizer.py @@ -413,7 +413,7 @@ def getValues(self): def _add_object(self, obj, d, check=True): """Add an object to a managed dictionary. - Attributes + Parameters ---------- obj The object to be stored. @@ -482,7 +482,7 @@ def _remove_object(self, obj, d): def _locate_managed_object(self, obj): """Find the location a managed object within the hierarchy. - Attributes + Parameters ---------- obj The object to find. @@ -610,7 +610,7 @@ def _add_parameter(self, parameter, check=True): Parameters added in this way are registered with the _eqfactory. - Attributes + Parameters ---------- parameter The Parameter to be stored. @@ -657,7 +657,7 @@ def register_calculator(self, calculator, argnames=None): arguments like a function or without, in which case the values of the Parameters created from argnames will be be used to compute the value. - Attributes + Parameters ---------- calculator : Calculator object The Calculator to register. @@ -1047,7 +1047,7 @@ def remove_constraint(self, *pars): This removes any constraints on a Parameter. - Attributes + Parameters ---------- *pars : str or Parameter The names of Parameters or Parameters to unconstrain. @@ -1114,7 +1114,7 @@ def get_constrained_parmeters(self, recurse=False): def getConstrainedPars(self, recurse=False): """Get a list of constrained managed Parameters in this object. - Attributes + Parameters ---------- recurse Recurse into managed objects and retrieve their constrained @@ -1294,7 +1294,7 @@ def addRestraint(self, res): def remove_soft_bounds(self, *ress): """Remove a Restraint from the RecipeOrganizer. - Attributes + Parameters ---------- *ress : Restraint The Restraints returned from the 'add_soft_bounds' method or added @@ -1328,7 +1328,7 @@ def unrestrain(self, *ress): def clear_all_soft_bounds(self, recurse=False): """Clear all restraints. - Attributes + Parameters ---------- recurse Recurse into managed objects and clear all restraints @@ -1543,7 +1543,7 @@ def get_equation_from_string( ): """Make an Equation object from a string. - Attributes + Parameters ---------- eqstr : str A string representation of the equation. The equation must diff --git a/src/diffpy/srfit/fitbase/restraint.py b/src/diffpy/srfit/fitbase/restraint.py index 7b6ec747..fb0006d2 100644 --- a/src/diffpy/srfit/fitbase/restraint.py +++ b/src/diffpy/srfit/fitbase/restraint.py @@ -59,7 +59,7 @@ def __init__( ): """Restrain an equation to specified bounds. - Attributes + Parameters ---------- eq An equation whose evaluation is compared against the @@ -87,7 +87,7 @@ def __init__( def penalty(self, w=1.0): """Calculate the penalty of the restraint. - Attributes + Parameters ---------- w The point-average chi^2 which is optionally used to scale the diff --git a/src/diffpy/srfit/fitbase/simplerecipe.py b/src/diffpy/srfit/fitbase/simplerecipe.py index e9da1f2c..5f27889b 100644 --- a/src/diffpy/srfit/fitbase/simplerecipe.py +++ b/src/diffpy/srfit/fitbase/simplerecipe.py @@ -306,7 +306,7 @@ def set_equation(self, eqstr, ns={}): The equation will be usable within set_residual_equation as "eq", and it takes no arguments. - Attributes + Parameters ---------- eqstr A string representation of the equation. Variables will be @@ -352,7 +352,7 @@ def __call__(self): def print_results(self, header="", footer=""): """Format and print the results. - Attributes + Parameters ---------- header A header to add to the output (default "") diff --git a/src/diffpy/srfit/pdf/basepdfgenerator.py b/src/diffpy/srfit/pdf/basepdfgenerator.py index d19005cf..e8566b84 100644 --- a/src/diffpy/srfit/pdf/basepdfgenerator.py +++ b/src/diffpy/srfit/pdf/basepdfgenerator.py @@ -117,13 +117,13 @@ def _set_calculator(self, calc): self._calc = calc for pname in self.__class__._parnames: self.addParameter(ParameterAdapter(pname, self._calc, attr=pname)) - self.processMetaData() + self._process_metadata() return def parallel(self, ncpu, mapfunc=None): """Run calculation in parallel. - Attributes + Parameters ---------- ncpu Number of parallel processes. Revert to serial mode when 1. @@ -154,9 +154,9 @@ def parallel(self, ncpu, mapfunc=None): self._calc = createParallelCalculator(calc_serial, ncpu, mapfunc) return - def processMetaData(self): + def _process_metadata(self): """Process the metadata once it gets set.""" - ProfileGenerator.processMetaData(self) + ProfileGenerator._process_metadata(self) stype = self.meta.get("stype") if stype is not None: @@ -181,7 +181,7 @@ def processMetaData(self): def setScatteringType(self, stype="X"): """Set the scattering type. - Attributes + Parameters ---------- stype "X" for x-ray, "N" for neutron, "E" for electrons, @@ -230,7 +230,7 @@ def setStructure(self, stru, name="phase", periodic=True): See those classes (located in diffpy.srfit.structure) for how they are used. The resulting ParameterSet will be managed by this generator. - Attributes + Parameters ---------- stru diffpy.structure.Structure, pyobjcryst.crystal.Crystal or @@ -260,7 +260,7 @@ def setPhase(self, parset, periodic=True): object (from diffpy or pyobjcryst). The passed ParameterSet will be managed by this generator. - Attributes + Parameters ---------- parset A SrRealParSet that holds the structural information. diff --git a/src/diffpy/srfit/pdf/characteristicfunctions.py b/src/diffpy/srfit/pdf/characteristicfunctions.py index ca24dfc1..19f8364a 100644 --- a/src/diffpy/srfit/pdf/characteristicfunctions.py +++ b/src/diffpy/srfit/pdf/characteristicfunctions.py @@ -48,7 +48,7 @@ def sphericalCF(r, psize): """Spherical nanoparticle characteristic function. - Attributes + Parameters ---------- r distance of interaction @@ -73,7 +73,7 @@ def spheroidalCF(r, erad, prad): Spheroid with radii (erad, erad, prad) - Attributes + Parameters ---------- prad polar radius @@ -95,7 +95,7 @@ def spheroidalCF2(r, psize, axrat): Form factor for ellipsoid with radii (psize/2, psize/2, axrat*psize/2) - Attributes + Parameters ---------- r distance of interaction @@ -206,7 +206,7 @@ def lognormalSphericalCF(r, psize, psig): """Spherical nanoparticle characteristic function with lognormal size distribution. - Attributes + Parameters ---------- r distance of interaction @@ -263,7 +263,7 @@ def lognormalSphericalCF(r, psize, psig): def sheetCF(r, sthick): """Nanosheet characteristic function. - Attributes + Parameters ---------- r distance of interaction @@ -293,7 +293,7 @@ def sheetCF(r, sthick): def shellCF(r, radius, thickness): """Spherical shell characteristic function. - Attributes + Parameters ---------- radius Inner radius @@ -313,7 +313,7 @@ def shellCF(r, radius, thickness): def shellCF2(r, a, delta): """Spherical shell characteristic function. - Attributes + Parameters ---------- a Central radius @@ -378,7 +378,7 @@ class SASCF(Calculator): def __init__(self, name, model): """Initialize the generator. - Attributes + Parameters ---------- name A name for the SASCF diff --git a/src/diffpy/srfit/pdf/debyepdfgenerator.py b/src/diffpy/srfit/pdf/debyepdfgenerator.py index 641c577f..ba84faac 100644 --- a/src/diffpy/srfit/pdf/debyepdfgenerator.py +++ b/src/diffpy/srfit/pdf/debyepdfgenerator.py @@ -92,7 +92,7 @@ def setStructure(self, stru, name="phase", periodic=False): See those classes (located in diffpy.srfit.structure) for how they are used. The resulting ParameterSet will be managed by this generator. - Attributes + Parameters ---------- stru diffpy.structure.Structure, pyobjcryst.crystal.Crystal or @@ -116,7 +116,7 @@ def setPhase(self, parset, periodic=False): object (from diffpy or pyobjcryst). The passed ParameterSet will be managed by this generator. - Attributes + Parameters ---------- parset A SrRealParSet that holds the structural information. diff --git a/src/diffpy/srfit/pdf/pdfcontribution.py b/src/diffpy/srfit/pdf/pdfcontribution.py index 07d33c5d..c884641b 100644 --- a/src/diffpy/srfit/pdf/pdfcontribution.py +++ b/src/diffpy/srfit/pdf/pdfcontribution.py @@ -84,7 +84,7 @@ class PDFContribution(FitContribution): def __init__(self, name): """Create the PDFContribution. - Attributes + Parameters ---------- name The name of the contribution. @@ -111,7 +111,7 @@ def loadData(self, data): This uses the PDFParser to load the data and then passes it to the built-in profile with load_parsed_data. - Attributes + Parameters ---------- data An open file-like object, name of a file that contains data @@ -180,7 +180,7 @@ def savetxt(self, fname, **kwargs): def addStructure(self, name, stru, periodic=True): """Add a phase that goes into the PDF calculation. - Attributes + Parameters ---------- name A name to give the generator that will manage the PDF @@ -224,7 +224,7 @@ def addStructure(self, name, stru, periodic=True): def addPhase(self, name, parset, periodic=True): """Add a phase that goes into the PDF calculation. - Attributes + Parameters ---------- name A name to give the generator that will manage the PDF @@ -284,7 +284,7 @@ def _setup_generator(self, gen): # Update with our metadata gen.meta.update(self._meta) - gen.processMetaData() + gen._process_metadata() # Constrain the shared parameters self.add_constraint(gen.qdamp, self.qdamp) @@ -307,7 +307,7 @@ def _get_meta_value(self, kwd): def setScatteringType(self, type="X"): """Set the scattering type. - Attributes + Parameters ---------- type "X" for x-ray or "N" for neutron diff --git a/src/diffpy/srfit/pdf/pdfparser.py b/src/diffpy/srfit/pdf/pdfparser.py index f2d32ccd..75d9c81f 100644 --- a/src/diffpy/srfit/pdf/pdfparser.py +++ b/src/diffpy/srfit/pdf/pdfparser.py @@ -33,8 +33,6 @@ class PDFParser(ProfileParser): """Class for holding a diffraction pattern. - Attributes - Attributes ---------- _format diff --git a/src/diffpy/srfit/sas/prcalculator.py b/src/diffpy/srfit/sas/prcalculator.py index 4030aa94..00d3c8e8 100644 --- a/src/diffpy/srfit/sas/prcalculator.py +++ b/src/diffpy/srfit/sas/prcalculator.py @@ -66,7 +66,7 @@ class PrCalculator(Calculator): def __init__(self, name): """Initialize the generator. - Attributes + Parameters ---------- name A name for the PrCalculator diff --git a/src/diffpy/srfit/sas/sasgenerator.py b/src/diffpy/srfit/sas/sasgenerator.py index 238ae43f..a986e283 100644 --- a/src/diffpy/srfit/sas/sasgenerator.py +++ b/src/diffpy/srfit/sas/sasgenerator.py @@ -43,7 +43,7 @@ class SASGenerator(ProfileGenerator): def __init__(self, name, model): """Initialize the generator. - Attributes + Parameters ---------- name A name for the SASGenerator diff --git a/src/diffpy/srfit/sas/sasimport.py b/src/diffpy/srfit/sas/sasimport.py index 2c15c4ad..cfd10fa8 100644 --- a/src/diffpy/srfit/sas/sasimport.py +++ b/src/diffpy/srfit/sas/sasimport.py @@ -18,7 +18,7 @@ def sasimport(modname): """Import specified module from the SasView sas package. - Attributes + Parameters ---------- modname absolute module name contained in the sas package. diff --git a/src/diffpy/srfit/sas/sasparameter.py b/src/diffpy/srfit/sas/sasparameter.py index 28ae4834..b74a58f1 100644 --- a/src/diffpy/srfit/sas/sasparameter.py +++ b/src/diffpy/srfit/sas/sasparameter.py @@ -52,7 +52,7 @@ class SASParameter(Parameter): def __init__(self, name, model, parname=None): """Create the Parameter. - Attributes + Parameters ---------- name Name of the Parameter diff --git a/src/diffpy/srfit/sas/sasparser.py b/src/diffpy/srfit/sas/sasparser.py index 12583d6b..22da76f8 100644 --- a/src/diffpy/srfit/sas/sasparser.py +++ b/src/diffpy/srfit/sas/sasparser.py @@ -30,8 +30,6 @@ class SASParser(ProfileParser): This uses a sas DataLoader to load the data. The DataInfo object it returns is held in the metadata under the name "datainfo". - Attributes - Attributes ---------- _format diff --git a/src/diffpy/srfit/sas/sasprofile.py b/src/diffpy/srfit/sas/sasprofile.py index a4b313f7..2ac6ab3b 100644 --- a/src/diffpy/srfit/sas/sasprofile.py +++ b/src/diffpy/srfit/sas/sasprofile.py @@ -30,8 +30,6 @@ class SASProfile(Profile): Otherwise, use the SASParser class and load the data into a base Profile object. - Attributes - Attributes ---------- _xobs @@ -78,7 +76,7 @@ class SASProfile(Profile): def __init__(self, datainfo): """Initialize the attributes. - Attributes + Parameters ---------- datainfo The DataInfo object this wraps. diff --git a/src/diffpy/srfit/structure/__init__.py b/src/diffpy/srfit/structure/__init__.py index f479cf50..d09aa5cc 100644 --- a/src/diffpy/srfit/structure/__init__.py +++ b/src/diffpy/srfit/structure/__init__.py @@ -25,7 +25,7 @@ def struToParameterSet(name, stru): This returns a ParameterSet adapted for the structure depending on its type. - Attributes + Parameters ---------- stru a structure object known by this module diff --git a/src/diffpy/srfit/structure/bvsrestraint.py b/src/diffpy/srfit/structure/bvsrestraint.py index f8af1ebe..ec156449 100644 --- a/src/diffpy/srfit/structure/bvsrestraint.py +++ b/src/diffpy/srfit/structure/bvsrestraint.py @@ -47,7 +47,7 @@ class BVSRestraint(Restraint): def __init__(self, parset, sig=1, scaled=False): """Initialize the Restraint. - Attributes + Parameters ---------- parset SrRealParSet that creates this BVSRestraint. @@ -69,7 +69,7 @@ def __init__(self, parset, sig=1, scaled=False): def penalty(self, w=1.0): """Calculate the penalty of the restraint. - Attributes + Parameters ---------- w The point-average chi^2 which is optionally used to scale the diff --git a/src/diffpy/srfit/structure/cctbxparset.py b/src/diffpy/srfit/structure/cctbxparset.py index e546e61d..544d1f3f 100644 --- a/src/diffpy/srfit/structure/cctbxparset.py +++ b/src/diffpy/srfit/structure/cctbxparset.py @@ -56,7 +56,7 @@ class CCTBXScattererParSet(ParameterSet): def __init__(self, name, strups, idx): """Initialize. - Attributes + Parameters ---------- name The name of this scatterer. @@ -153,7 +153,7 @@ class CCTBXUnitCellParSet(ParameterSet): def __init__(self, strups): """Initialize. - Attributes + Parameters ---------- strups The CCTBXCrystalParSet that contains the cctbx structure @@ -228,7 +228,7 @@ class CCTBXCrystalParSet(BaseStructureParSet): def __init__(self, name, stru): """Initialize. - Attributes + Parameters ---------- name A name for this diff --git a/src/diffpy/srfit/structure/diffpyparset.py b/src/diffpy/srfit/structure/diffpyparset.py index 0a22685f..452dd6ed 100644 --- a/src/diffpy/srfit/structure/diffpyparset.py +++ b/src/diffpy/srfit/structure/diffpyparset.py @@ -91,7 +91,7 @@ class DiffpyAtomParSet(ParameterSet): def __init__(self, name, atom): """Initialize. - Attributes + Parameters ---------- atom A diffpy.structure.Atom instance @@ -205,7 +205,7 @@ class DiffpyLatticeParSet(ParameterSet): def __init__(self, lattice): """Initialize. - Attributes + Parameters ---------- lattice A diffpy.structure.Lattice instance @@ -275,7 +275,7 @@ class DiffpyStructureParSet(SrRealParSet): def __init__(self, name, stru): """Initialize. - Attributes + Parameters ---------- name A name for the structure diff --git a/src/diffpy/srfit/structure/objcrystparset.py b/src/diffpy/srfit/structure/objcrystparset.py index f50650b6..25cd50d8 100644 --- a/src/diffpy/srfit/structure/objcrystparset.py +++ b/src/diffpy/srfit/structure/objcrystparset.py @@ -56,6 +56,37 @@ ) from diffpy.srfit.fitbase.parameterset import ParameterSet from diffpy.srfit.structure.srrealparset import SrRealParSet +from diffpy.utils._deprecator import build_deprecation_message, deprecated + +removal_version = "4.0.0" +bl_base = "diffpy.srfit.structure.objcrystparset.ObjCrystBondLengthParameter" + +bl_setConst_dep_msg = build_deprecation_message( + bl_base, + "setConst", + "set_constant", + removal_version, +) + +ba_base = "diffpy.srfit.structure.objcrystparset.ObjCrystBondAngleParameter" + +ba_setConst_dep_msg = build_deprecation_message( + ba_base, + "setConst", + "set_constant", + removal_version, +) + +da_base = ( + "diffpy.srfit.structure.objcrystparset.ObjCrystDihedralAngleParameter" +) + +da_setConst_dep_msg = build_deprecation_message( + da_base, + "setConst", + "set_constant", + removal_version, +) class ObjCrystScattererParSet(ParameterSet): @@ -83,7 +114,7 @@ class ObjCrystScattererParSet(ParameterSet): def __init__(self, name, scat, parent): """Initialize. - Attributes + Parameters ---------- name The name of the scatterer @@ -145,7 +176,7 @@ class ObjCrystAtomParSet(ObjCrystScattererParSet): def __init__(self, name, atom, parent): """Initialize. - Attributes + Parameters ---------- name The name of the scatterer @@ -221,7 +252,7 @@ class ObjCrystMoleculeParSet(ObjCrystScattererParSet): def __init__(self, name, molecule, parent=None): """Initialize. - Attributes + Parameters ---------- name The name of the scatterer @@ -402,7 +433,7 @@ def restrainBondLength( This creates an instance of ObjCrystBondLengthRestraint and adds it to the ObjCrystMoleculeParSet. - Attributes + Parameters ---------- atom1 First atom (ObjCrystMolAtomParSet) in the bond @@ -440,7 +471,7 @@ def restrainBondLengthParameter( This creates an instance of ObjCrystBondLengthRestraint and adds it to the ObjCrystMoleculeParSet. - Attributes + Parameters ---------- par A ObjCrystBondLengthParameter (see addBondLengthParameter) @@ -473,7 +504,7 @@ def restrainBondAngle( This creates an instance of ObjCrystBondAngleRestraint and adds it to the ObjCrystMoleculeParSet. - Attributes + Parameters ---------- atom1 First atom (ObjCrystMolAtomParSet) in the bond angle @@ -514,7 +545,7 @@ def restrainBondAngleParameter( This creates an instance of ObjCrystBondAngleRestraint and adds it to the ObjCrystMoleculeParSet. - Attributes + Parameters ---------- par A ObjCrystBondAngleParameter (see addBondAngleParameter) @@ -547,7 +578,7 @@ def restrainDihedralAngle( This creates an instance of ObjCrystDihedralAngleRestraint and adds it to the ObjCrystMoleculeParSet. - Attributes + Parameters ---------- atom1 First atom (ObjCrystMolAtomParSet) in the angle @@ -589,7 +620,7 @@ def restrainDihedralAngleParameter( This creates an instance of ObjCrystDihedralAngleRestraint and adds it to the ObjCrystMoleculeParSet. - Attributes + Parameters ---------- par A ObjCrystDihedralAngleParameter (see @@ -630,7 +661,7 @@ def addBondLengthParameter( This creates a ObjCrystBondLengthParameter to the ObjCrystMoleculeParSet that can be adjusted during the fit. - Attributes + Parameters ---------- name The name of the ObjCrystBondLengthParameter @@ -665,7 +696,7 @@ def addBondAngleParameter( This creates a ObjCrystBondAngleParameter to the ObjCrystMoleculeParSet that can be adjusted during the fit. - Attributes + Parameters ---------- name The name of the ObjCrystBondAngleParameter @@ -705,7 +736,7 @@ def addDihedralAngleParameter( This creates a ObjCrystDihedralAngleParameter to the ObjCrystMoleculeParSet that can be adjusted during the fit. - Attributes + Parameters ---------- name The name of the ObjCrystDihedralAngleParameter. @@ -778,7 +809,7 @@ class ObjCrystMolAtomParSet(ObjCrystScattererParSet): def __init__(self, name, scat, parent): """Initialize. - Attributes + Parameters ---------- name The name of the scatterer @@ -850,7 +881,7 @@ class ObjCrystMoleculeRestraint(object): def __init__(self, res, scaled=False): """Create a Restraint-like from a pyobjcryst Molecule restraint. - Attributes + Parameters ---------- res The pyobjcryst Molecule restraint. @@ -866,7 +897,7 @@ def __init__(self, res, scaled=False): def penalty(self, w=1.0): """Calculate the penalty of the restraint. - Attributes + Parameters ---------- w The point-average chi^2 which is optionally used to scale the @@ -907,7 +938,7 @@ class ObjCrystBondLengthRestraint(ObjCrystMoleculeRestraint): def __init__(self, atom1, atom2, length, sigma, delta, scaled=False): """Create a bond length restraint. - Attributes + Parameters ---------- atom1 First atom (ObjCrystMolAtomParSet) in the bond @@ -979,7 +1010,7 @@ class ObjCrystBondAngleRestraint(ObjCrystMoleculeRestraint): def __init__(self, atom1, atom2, atom3, angle, sigma, delta, scaled=False): """Create a bond angle restraint. - Attributes + Parameters ---------- atom1 First atom (ObjCrystMolAtomParSet) in the bond angle @@ -1061,7 +1092,7 @@ def __init__( ): """Create a dihedral angle restraint. - Attributes + Parameters ---------- atom1 First atom (ObjCrystMolAtomParSet) in the angle @@ -1137,7 +1168,7 @@ class StretchModeParameter(Parameter): def __init__(self, name, value=None, const=False): """Initialization. - Attributes + Parameters ---------- name The name of this Parameter (must be a valid attribute @@ -1283,7 +1314,7 @@ class ObjCrystBondLengthParameter(StretchModeParameter): def __init__(self, name, atom1, atom2, value=None, const=False, mode=None): """Create a ObjCrystBondLengthParameter. - Attributes + Parameters ---------- name The name of the ObjCrystBondLengthParameter @@ -1327,31 +1358,49 @@ def __init__(self, name, atom1, atom2, value=None, const=False, mode=None): if value is None: value = GetBondLength(atom1.scat, atom2.scat) StretchModeParameter.__init__(self, name, value, const) - self.setConst(const) + self.set_constant(const) return - def setConst(self, const=True, value=None): + def set_constant(self, is_constant=True, value=None): """Toggle the Parameter as constant. - This sets the underlying ObjCrystMolAtomParSet positions const as well. + This sets the underlying ObjCrystMolAtomParSet positions + constant as well. - Attributes + Parameters ---------- - const + is_constant Flag indicating if the Parameter is constant (default True). value An optional value for the Parameter (default None). If this is not None, then the Parameter will get a new value, constant or otherwise. + + Return + ------ + self + Returns self so that mutators can be chained. """ - StretchModeParameter.setConst(self, const, value) + StretchModeParameter.set_constant(self, is_constant, value) for a in [self.atom1, self.atom2]: - a.x.setConst(const) - a.y.setConst(const) - a.z.setConst(const) + a.x.set_constant(is_constant) + a.y.set_constant(is_constant) + a.z.set_constant(is_constant) + return self + + @deprecated(bl_setConst_dep_msg) + def setConst(self, const=True, value=None): + """This function has been deprecated and will be removed in version + 4.0.0. + + Please use + diffpy.srfit.structure.objcryst.ObjCrystBondLengthParameter.set_constant + instead. + """ + self.set_constant(const, value) return self def getValue(self): @@ -1423,7 +1472,7 @@ def __init__( ): """Create a ObjCrystBondAngleParameter. - Attributes + Parameters ---------- name The name of the ObjCrystBondAngleParameter. @@ -1472,30 +1521,48 @@ def __init__( if value is None: value = GetBondAngle(atom1.scat, atom2.scat, atom3.scat) StretchModeParameter.__init__(self, name, value, const) - self.setConst(const) + self.set_constant(const) return - def setConst(self, const=True, value=None): + def set_constant(self, is_constant=True, value=None): """Toggle the Parameter as constant. - This sets the underlying ObjCrystMolAtomParSet positions const as well. + This sets the underlying ObjCrystMolAtomParSet positions + constant as well. - Attributes + Parameters ---------- - const + is_constant Flag indicating if the Parameter is constant (default True). value An optional value for the Parameter (default None). If this is not None, then the Parameter will get a new value, constant or otherwise. + + Return + ------ + self + Returns self so that mutators can be chained. """ - StretchModeParameter.setConst(self, const, value) + StretchModeParameter.set_constant(self, is_constant, value) for a in [self.atom1, self.atom2, self.atom3]: - a.x.setConst(const) - a.y.setConst(const) - a.z.setConst(const) + a.x.set_constant(is_constant) + a.y.set_constant(is_constant) + a.z.set_constant(is_constant) + return self + + @deprecated(ba_setConst_dep_msg) + def setConst(self, const=True, value=None): + """This function has been deprecated and will be removed in + version 4.0.0. + + Please use + diffpy.srfit.structure.objcryst.ObjCrystBondAngleParameter.set_constant + instead. + """ + self.set_constant(const, value) return self def getValue(self): @@ -1582,7 +1649,7 @@ def __init__( ): """Create a ObjCrystDihedralAngleParameter. - Attributes + Parameters ---------- name The name of the ObjCrystDihedralAngleParameter @@ -1636,30 +1703,47 @@ def __init__( atom1.scat, atom2.scat, atom3.scat, atom4.scat ) StretchModeParameter.__init__(self, name, value, const) - self.setConst(const) + self.set_constant(const) return - def setConst(self, const=True, value=None): + def set_constant(self, is_constant=True, value=None): """Toggle the Parameter as constant. This sets the underlying ObjCrystMolAtomParSet positions const as well. - Attributes + Parameters ---------- - const + is_constant Flag indicating if the Parameter is constant (default True). value An optional value for the Parameter (default None). If this is not None, then the Parameter will get a new value, constant or otherwise. + + Return + ------ + self + Returns self so that mutators can be chained. """ - StretchModeParameter.setConst(self, const, value) + StretchModeParameter.set_constant(self, is_constant, value) for a in [self.atom1, self.atom2, self.atom3, self.atom4]: - a.x.setConst(const) - a.y.setConst(const) - a.z.setConst(const) + a.x.set_constant(is_constant) + a.y.set_constant(is_constant) + a.z.set_constant(is_constant) + return self + + @deprecated(da_setConst_dep_msg) + def setConst(self, const=True, value=None): + """This function has been deprecated and will be removed in + version 4.0.0. + + Please use + diffpy.srfit.structure.objcryst.ObjCrystDihedralAngleParameter.set_constant + instead. + """ + self.set_constant(const, value) return self def getValue(self): @@ -1722,7 +1806,7 @@ class ObjCrystCrystalParSet(SrRealParSet): def __init__(self, name, cryst): """Initialize. - Attributes + Parameters ---------- name A name for this ParameterSet @@ -1797,7 +1881,7 @@ def _constrain_space_group(self): def _create_space_group(sgobjcryst): """Create a diffpy.structure SpaceGroup object from pyobjcryst. - Attributes + Parameters ---------- sgobjcryst A pyobjcryst.spacegroup.SpaceGroup instance. diff --git a/src/diffpy/srfit/structure/sgconstraints.py b/src/diffpy/srfit/structure/sgconstraints.py index 2b48ec1d..666e360d 100644 --- a/src/diffpy/srfit/structure/sgconstraints.py +++ b/src/diffpy/srfit/structure/sgconstraints.py @@ -190,7 +190,7 @@ def __init__(self, name="sgpars"): def addParameter(self, par, check=True): """Store a Parameter. - Attributes + Parameters ---------- par The Parameter to be stored. @@ -392,7 +392,7 @@ def _clear_constraints(self): for par in [scatterer.x, scatterer.y, scatterer.z]: if scatterer.is_constrained(par): scatterer.remove_constraint(par) - par.setConst(False) + par.set_constant(False) # Clear the lattice if self.constrainlat: @@ -409,7 +409,7 @@ def _clear_constraints(self): for par in latpars: if lattice.is_constrained(par): lattice.remove_constraint(par) - par.setConst(False) + par.set_constant(False) # Clear ADPs if self.constrainadps: @@ -419,14 +419,14 @@ def _clear_constraints(self): if par is not None: if scatterer.is_constrained(par): scatterer.remove_constraint(par) - par.setConst(False) + par.set_constant(False) for pname in adpsymbols: par = scatterer.get(pname) if par is not None: if scatterer.is_constrained(par): scatterer.remove_constraint(par) - par.setConst(False) + par.set_constant(False) return @@ -470,7 +470,7 @@ def _constrain_lattice(self): def _constrain_xyzs(self, positions): """Constrain the positions. - Attributes + Parameters ---------- positions The coordinates of the scatterers. @@ -513,7 +513,7 @@ def _constrain_xyzs(self, positions): def _constrain_adps(self, positions): """Constrain the ADPs. - Attributes + Parameters ---------- positions The coordinates of the scatterers. @@ -618,7 +618,7 @@ def _constrain_adps(self, positions): def __add_par(self, parname, par): """Constrain a parameter via proxy with a specified name. - Attributes + Parameters ---------- par Parameter to constrain @@ -652,14 +652,14 @@ def _constrain_monoclinic(lattice): if lattice.angunits == "rad": afactor = deg2rad ang90 = 90.0 * afactor - lattice.alpha.setConst(True, ang90) + lattice.alpha.set_constant(True, ang90) beta = lattice.beta.getValue() gamma = lattice.gamma.getValue() if ang90 != beta and ang90 == gamma: - lattice.gamma.setConst(True, ang90) + lattice.gamma.set_constant(True, ang90) else: - lattice.beta.setConst(True, ang90) + lattice.beta.set_constant(True, ang90) return @@ -672,9 +672,9 @@ def _constrain_orthorhombic(lattice): if lattice.angunits == "rad": afactor = deg2rad ang90 = 90.0 * afactor - lattice.alpha.setConst(True, ang90) - lattice.beta.setConst(True, ang90) - lattice.gamma.setConst(True, ang90) + lattice.alpha.set_constant(True, ang90) + lattice.beta.set_constant(True, ang90) + lattice.gamma.set_constant(True, ang90) return @@ -688,9 +688,9 @@ def _constrain_tetragonal(lattice): if lattice.angunits == "rad": afactor = deg2rad ang90 = 90.0 * afactor - lattice.alpha.setConst(True, ang90) - lattice.beta.setConst(True, ang90) - lattice.gamma.setConst(True, ang90) + lattice.alpha.set_constant(True, ang90) + lattice.beta.set_constant(True, ang90) + lattice.gamma.set_constant(True, ang90) lattice.add_constraint(lattice.b, lattice.a) return @@ -709,9 +709,9 @@ def _constrain_trigonal(lattice): ang120 = 120.0 * afactor if lattice.gamma.getValue() == ang120: lattice.add_constraint(lattice.b, lattice.a) - lattice.alpha.setConst(True, ang90) - lattice.beta.setConst(True, ang90) - lattice.gamma.setConst(True, ang120) + lattice.alpha.set_constant(True, ang90) + lattice.beta.set_constant(True, ang90) + lattice.gamma.set_constant(True, ang120) else: lattice.add_constraint(lattice.b, lattice.a) lattice.add_constraint(lattice.c, lattice.a) @@ -732,9 +732,9 @@ def _constrain_hexagonal(lattice): ang90 = 90.0 * afactor ang120 = 120.0 * afactor lattice.add_constraint(lattice.b, lattice.a) - lattice.alpha.setConst(True, ang90) - lattice.beta.setConst(True, ang90) - lattice.gamma.setConst(True, ang120) + lattice.alpha.set_constant(True, ang90) + lattice.beta.set_constant(True, ang90) + lattice.gamma.set_constant(True, ang120) return @@ -750,9 +750,9 @@ def _constrain_cubic(lattice): ang90 = 90.0 * afactor lattice.add_constraint(lattice.b, lattice.a) lattice.add_constraint(lattice.c, lattice.a) - lattice.alpha.setConst(True, ang90) - lattice.beta.setConst(True, ang90) - lattice.gamma.setConst(True, ang90) + lattice.alpha.set_constant(True, ang90) + lattice.beta.set_constant(True, ang90) + lattice.gamma.set_constant(True, ang90) return @@ -772,7 +772,7 @@ def _constrain_cubic(lattice): def _makeconstraint(parname, formula, scatterer, idx, ns={}): """Constrain a parameter according to a formula. - Attributes + Parameters ---------- parname Name of parameter @@ -805,7 +805,7 @@ def _makeconstraint(parname, formula, scatterer, idx, ns={}): # Check to see if it is a constant fval = _get_float(formula) if fval is not None: - par.setConst() + par.set_constant() return # If we got here, then we have a constraint equation diff --git a/src/diffpy/srfit/structure/srrealparset.py b/src/diffpy/srfit/structure/srrealparset.py index 5a5e5028..4ed31ffc 100644 --- a/src/diffpy/srfit/structure/srrealparset.py +++ b/src/diffpy/srfit/structure/srrealparset.py @@ -52,7 +52,7 @@ def restrainBVS(self, sig=1, scaled=False): this is also scaled by the current point-averaged chi^2 value so the restraint is roughly equally weighted in the fit. - Attributes + Parameters ---------- sig The uncertainty on the BVS (default 1). diff --git a/src/diffpy/srfit/util/inpututils.py b/src/diffpy/srfit/util/inpututils.py index f2e0a9df..1e0d83fa 100644 --- a/src/diffpy/srfit/util/inpututils.py +++ b/src/diffpy/srfit/util/inpututils.py @@ -26,7 +26,7 @@ def inputToString(input): This is useful when you want a method to accept a string, open file object or file name. - Attributes + Parameters ---------- input An open file-like object, name of a file diff --git a/src/diffpy/srfit/util/tagmanager.py b/src/diffpy/srfit/util/tagmanager.py index 9e981d64..37c58a3d 100644 --- a/src/diffpy/srfit/util/tagmanager.py +++ b/src/diffpy/srfit/util/tagmanager.py @@ -53,7 +53,7 @@ def tag(self, obj, *tags): Tags are stored as strings. - Attributes + Parameters ---------- obj Any hashable object to be untagged. @@ -71,7 +71,7 @@ def tag(self, obj, *tags): def untag(self, obj, *tags): """Remove tags from an object. - Attributes + Parameters ---------- obj Any hashable object to be untagged. diff --git a/tests/test_constraint.py b/tests/test_constraint.py index d045feb5..f173de14 100644 --- a/tests/test_constraint.py +++ b/tests/test_constraint.py @@ -46,7 +46,7 @@ def test_constrain_parameter(self): eq2 = get_equation_from_string("2*p2+1", factory) c2 = Constraint() self.assertRaises(ValueError, c2.constrain, p1, eq2) - p2.setConst() + p2.set_constant() eq3 = get_equation_from_string("p1", factory) self.assertRaises(ValueError, c2.constrain, p2, eq3) diff --git a/tests/test_parameter.py b/tests/test_parameter.py index 90606179..a56d3ddf 100644 --- a/tests/test_parameter.py +++ b/tests/test_parameter.py @@ -16,6 +16,9 @@ import unittest +import numpy as np +import pytest + from diffpy.srfit.fitbase.parameter import ( Parameter, ParameterAdapter, @@ -121,5 +124,95 @@ def testWrapper(self): return +@pytest.mark.parametrize( + "lower, upper, expected", + [ + # User sets both lower and upper bounds explicitly. + (1, 10, [1, 10]), + # User sets only a lower bound. + (2, None, [2, np.inf]), + # User sets only an upper bound. + (None, 8, [-np.inf, 8]), + # User overwrites existing bounds. + (2, 6, [2, 6]), + ], +) +def test_bound_range(lower, upper, expected): + p = Parameter("a", value=5) + # If testing overwrite, pre-set bounds to see overwrite effect + if expected == [2, 6]: + p.bound_range(0, 10) + p.bound_range(lower_bound=lower, upper_bound=upper) + actual = p.bounds + assert actual == expected + + +@pytest.mark.parametrize( + "lower, upper, expected", + [ + # User sets both lower and upper bounds explicitly. + (1, 10, [1, 10]), + # User sets only a lower bound. + (2, None, [2, np.inf]), + # User sets only an upper bound. + (None, 8, [-np.inf, 8]), + # User overwrites existing bounds. + (2, 6, [2, 6]), + ], +) +def test_boundRange(lower, upper, expected): + p = Parameter("a", value=5) + # If testing overwrite, pre-set bounds to see overwrite effect + if expected == [2, 6]: + p.boundRange(0, 10) + p.boundRange(lower_bound=lower, upper_bound=upper) + actual = p.bounds + assert actual == expected + + +@pytest.mark.parametrize( + "value, lower_radius, upper_radius, expected", + [ + # Symmetric radius (upper_radius None, uses lower_radius) + (10, 2, None, [8, 12]), + # Asymmetric radius + (10, 3, 5, [7, 15]), + # Zero radius + (4, 0, None, [4, 4]), + # Current value updated before bounding + (20, 2, None, [18, 22]), + ], +) +def test_bound_window(value, lower_radius, upper_radius, expected): + p = Parameter("a", value=5) + if value != 5: + p.set_value(value) + p.bound_window(lower_radius=lower_radius, upper_radius=upper_radius) + actual = p.bounds + assert actual == expected + + +@pytest.mark.parametrize( + "value, lower_radius, upper_radius, expected", + [ + # Symmetric radius (upper_radius None, uses lower_radius) + (10, 2, None, [8, 12]), + # Asymmetric radius + (10, 3, 5, [7, 15]), + # Zero radius + (4, 0, None, [4, 4]), + # Current value updated before bounding + (20, 2, None, [18, 22]), + ], +) +def test_boundWindow(value, lower_radius, upper_radius, expected): + p = Parameter("a", value=5) + if value != 5: + p.set_value(value) + p.boundWindow(lr=lower_radius, ur=upper_radius) + actual = p.bounds + assert actual == expected + + if __name__ == "__main__": unittest.main()