Skip to content

Commit 0625461

Browse files
committed
use get_results_dictionary method to get params_dict
1 parent 0c25030 commit 0625461

3 files changed

Lines changed: 21 additions & 23 deletions

File tree

src/diffpy/srfit/fitbase/fitrecipe.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,8 +1230,18 @@ def initialize_recipe_with_results(self, results, verbose=True):
12301230
If the input results is not a FitResults object or a path to a
12311231
results file.
12321232
"""
1233-
if hasattr(results, "print_results"):
1234-
params_dict = utils.get_dict_from_results_object(results)
1233+
if hasattr(results, "get_results_dictionary"):
1234+
params_dict = results.get_results_dictionary()
1235+
metrics_in_dict = [
1236+
"Residual",
1237+
"Contributions",
1238+
"Restraints",
1239+
"Chi2",
1240+
"Reduced Chi2",
1241+
"Rw",
1242+
]
1243+
for metric in metrics_in_dict:
1244+
params_dict.pop(metric, None)
12351245
elif isinstance(results, (str, Path)):
12361246
params_dict = utils.get_dict_from_results_file(results)
12371247
else:

src/diffpy/srfit/fitbase/fitresults.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@
6666
new_base="diffpy.srfit.fitbase.FitResults",
6767
)
6868

69+
initializeRecipe_dep_msg = build_deprecation_message(
70+
"diffpy.srfit.fitbase",
71+
"initializeRecipe",
72+
"FitRecipe.in",
73+
removal_version,
74+
new_base="diffpy.srfit.fitbase.FitResults",
75+
)
76+
6977

7078
class FitResults(object):
7179
"""Class for processing, presenting and storing results of a fit.
@@ -820,6 +828,7 @@ def resultsDictionary(results):
820828
return mpairs
821829

822830

831+
@deprecated(initializeRecipe_dep_msg)
823832
def initializeRecipe(recipe, results):
824833
"""Initialize the variables of a recipe from a results file.
825834

src/diffpy/srfit/util/inpututils.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -92,25 +92,4 @@ def get_dict_from_results_file(
9292
return parsed_results_dict
9393

9494

95-
def get_dict_from_results_object(results_object) -> dict[str, float]:
96-
"""Get a dictionary of parameter names and values from a FitResults
97-
object.
98-
99-
Parameters
100-
----------
101-
results_object : FitResults
102-
The FitResults object containing the parameter names and values.
103-
104-
Returns
105-
-------
106-
params_dict : dict
107-
The dictionary where keys are parameter names and values are the
108-
corresponding parameter values as floats.
109-
"""
110-
param_names = results_object.varnames
111-
param_vals = results_object.varvals
112-
params_dict = dict(zip(param_names, param_vals))
113-
return params_dict
114-
115-
11695
# End of file

0 commit comments

Comments
 (0)