Skip to content

Commit 2542970

Browse files
committed
fix: ancillary parameters not computed from user-defined initial parameters
1 parent 836fcc8 commit 2542970

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
0.6.3
22
- fix: support JPK data recorded in the "force-modulation" feedback mode
33
(bump afmformats from 0.5.0 to 0.5.1)
4+
- fix: make sure ancillary parameters are computed from the initial
5+
parameters set in the user interface (not from the default model
6+
parameters)
47
0.6.2
58
- enh: allow to select which metadata is exported
69
- fix: do not apply and fit to all before exporting metadata

pyjibe/fd/tab_fit.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ def fit_model(self):
6464

6565
def anc_update_parameters(self, fdist):
6666
model_key = self.fit_model.model_key
67+
# Apply the current set of parameters
68+
# (some ancillary parameters depend on the correct initial parameters)
69+
fdist.fit_properties["params_initial"] = self.fit_parameters()
6770
# ancillaries
6871
anc = fdist.get_ancillary_parameters(model_key=model_key)
6972
anc_used = [ak for ak in anc if ak in self.fit_model.parameter_keys]
@@ -282,18 +285,21 @@ def fit_parameters(self):
282285
return params
283286

284287
def fit_update_parameters(self, fdist):
285-
"""Update the ancillary and initial parameters"""
288+
"""Update the ancillary and initial parameters in the UI"""
286289
model_key = self.fit_model.model_key
287290
# set the model
288291
# - resets params_initial if model changed
289292
# - important for computing ancillary parameters
290293
fdist.fit_properties["model_key"] = model_key
291294
if fdist.fit_properties.get("params_initial", False):
295+
# (cannot coerce this into one line, because "params_initial"
296+
# can be None.)
292297
# set the parameters of the previous fit
293298
params = fdist.fit_properties["params_initial"]
294299
else:
295300
# use the initial model parameters
296301
params = self.fit_parameters()
302+
297303
# parameter table
298304
itab = self.table_parameters_initial
299305

tests/test_fd_fit.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,52 @@ def test_remember_initial_params(qtbot):
101101
assert float(itab.item(1, 1).text()) == 5
102102

103103

104+
def test_update_ancillary_init(qtbot):
105+
with MockModel(
106+
compute_ancillaries=lambda x: {
107+
# take initial fit parameter of E
108+
"E": x.get_initial_fit_parameters(
109+
model_ancillaries=False)["E"].value},
110+
parameter_anc_keys=["E"],
111+
parameter_anc_names=["ancillary E guess"],
112+
parameter_anc_units=["Pa"],
113+
model_key="test1"):
114+
115+
main_window = pyjibe.head.PyJibe()
116+
main_window.load_data(files=[jpkfile, jpkfile])
117+
war = main_window.subwindows[0].widget()
118+
# clear data
119+
war.tab_preprocess.list_preproc_applied.clear()
120+
war.cb_autosave.setChecked(0)
121+
# perform simple filter
122+
item = QtWidgets.QListWidgetItem()
123+
item.setText("compute_tip_position")
124+
war.tab_preprocess.list_preproc_applied.addItem(item)
125+
# disable weighting
126+
war.tab_fit.cb_weight_cp.setCheckState(0)
127+
# set mock model
128+
idx = war.tab_fit.cb_model.findData("test1")
129+
war.tab_fit.cb_model.setCurrentIndex(idx)
130+
# perform fitting with standard parameters
131+
# set initial parameters in user interface
132+
itab = war.tab_fit.table_parameters_initial
133+
atab = war.tab_fit.table_parameters_anc
134+
war.on_tab_changed(1)
135+
assert len(war.data_set[0].preprocessing) == 1
136+
assert war.tab_preprocess.list_preproc_applied.count() == 1
137+
# The ancillary parameter gets its value from the default parameters
138+
assert atab.item(0, 1).text() == "3000"
139+
assert itab.item(0, 1).text() == "3000"
140+
# Now we change the initial parameter "E" and move on to the next
141+
# curve. Ancillary parameter "F" should also change.
142+
itab.item(0, 1).setText("2000")
143+
assert atab.item(0, 1).text() == "2000"
144+
it = war.list_curves.topLevelItem(1)
145+
war.list_curves.setCurrentItem(it)
146+
assert itab.item(0, 1).text() == "2000"
147+
assert atab.item(0, 1).text() == "2000"
148+
149+
104150
def test_update_ancillary_nan(qtbot):
105151
with MockModel(
106152
compute_ancillaries=lambda x: {"E": np.nan},

0 commit comments

Comments
 (0)