Skip to content

Commit 1699096

Browse files
committed
Ensure all settings in state file are loaded
Some settings like rietveld-specific or texture-specific were not being loaded correctly from state files. We needed to wait until the parameters list was updated before loading them. This also ensures the latest parameter values get saved before users do things like save to state files. Signed-off-by: Patrick Avery <[email protected]>
1 parent ae0fcb0 commit 1699096

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

hexrdgui/calibration/wppf_options_dialog.py

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,10 @@ def load_settings(self):
821821
'background_method_dict',
822822
]
823823

824+
skip_list = [
825+
'params_dict',
826+
]
827+
824828
with block_signals(*self.all_widgets):
825829
for k in apply_first_keys:
826830
if k in settings:
@@ -832,14 +836,9 @@ def load_settings(self):
832836
# as it is no longer compatible.
833837
continue
834838

835-
if k == 'params_dict':
836-
# For backward-compatibility
837-
for d in v.values():
838-
if 'lb' in d:
839-
d['min'] = d.pop('lb')
840-
841-
if 'ub' in d:
842-
d['max'] = d.pop('ub')
839+
if k in skip_list:
840+
# We apply this later...
841+
continue
843842

844843
if not hasattr(self, k) or k in apply_first_keys:
845844
# Skip it...
@@ -851,6 +850,21 @@ def load_settings(self):
851850
self.update_params()
852851
self.update_enable_states()
853852

853+
# Now apply the params dict after updating default parameters.
854+
# This is so that settings specific to things like texture, or
855+
# Rietveld, can be loaded correctly.
856+
if 'params_dict' in settings:
857+
v = settings['params_dict']
858+
# For backward-compatibility
859+
for d in v.values():
860+
if 'lb' in d:
861+
d['min'] = d.pop('lb')
862+
863+
if 'ub' in d:
864+
d['max'] = d.pop('ub')
865+
866+
self.params_dict = v
867+
854868
def save_settings(self):
855869
settings = HexrdConfig().config['calibration'].setdefault('wppf', {})
856870
keys = [
@@ -1672,6 +1686,7 @@ def load_params(self, filename):
16721686
self.params[key] = dict_to_param(import_params[key])
16731687

16741688
self.update_tree_view()
1689+
self.save_settings()
16751690

16761691
def validate_import_params(self, import_params, filename):
16771692
here = self.params.keys()
@@ -2241,14 +2256,6 @@ def generate_params(method, materials, peak_shape, bkgmethod, amorphous_model,
22412256

22422257

22432258
def param_to_dict(param):
2244-
# Make sure these are non-numpy types
2245-
def _dict_to_basic(d):
2246-
for k, v in list(d.items()):
2247-
if isinstance(v, np.generic):
2248-
d[k] = v.item()
2249-
2250-
return d
2251-
22522259
return _dict_to_basic({
22532260
'name': param.name,
22542261
'value': param.value,
@@ -2264,9 +2271,19 @@ def dict_to_param(d):
22642271
d = d.copy()
22652272
del d['stderr']
22662273

2274+
d = _dict_to_basic(d.copy())
22672275
return lmfit.Parameter(**d)
22682276

22692277

2278+
# Ensure dict values are basic types, and not numpy types
2279+
def _dict_to_basic(d):
2280+
for k, v in list(d.items()):
2281+
if isinstance(v, np.generic):
2282+
d[k] = v.item()
2283+
2284+
return d
2285+
2286+
22702287
LOADED_YAML_DICTS = {}
22712288

22722289

hexrdgui/calibration/wppf_runner.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ def run_wppf(self):
8080
self.write_params_to_materials()
8181
self.update_param_values()
8282

83+
# Save the new settings so state files will have them
84+
dialog.save_settings()
85+
8386
def rerender_wppf(self):
8487
self.clear_wppf_plots()
8588
obj = self.wppf_object

0 commit comments

Comments
 (0)