Skip to content

Commit

Permalink
fix: ancillary parameters not computed from user-defined initial para…
Browse files Browse the repository at this point in the history
…meters
  • Loading branch information
paulmueller committed Jan 23, 2020
1 parent 836fcc8 commit 2542970
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
0.6.3
- fix: support JPK data recorded in the "force-modulation" feedback mode
(bump afmformats from 0.5.0 to 0.5.1)
- fix: make sure ancillary parameters are computed from the initial
parameters set in the user interface (not from the default model
parameters)
0.6.2
- enh: allow to select which metadata is exported
- fix: do not apply and fit to all before exporting metadata
Expand Down
8 changes: 7 additions & 1 deletion pyjibe/fd/tab_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ def fit_model(self):

def anc_update_parameters(self, fdist):
model_key = self.fit_model.model_key
# Apply the current set of parameters
# (some ancillary parameters depend on the correct initial parameters)
fdist.fit_properties["params_initial"] = self.fit_parameters()
# ancillaries
anc = fdist.get_ancillary_parameters(model_key=model_key)
anc_used = [ak for ak in anc if ak in self.fit_model.parameter_keys]
Expand Down Expand Up @@ -282,18 +285,21 @@ def fit_parameters(self):
return params

def fit_update_parameters(self, fdist):
"""Update the ancillary and initial parameters"""
"""Update the ancillary and initial parameters in the UI"""
model_key = self.fit_model.model_key
# set the model
# - resets params_initial if model changed
# - important for computing ancillary parameters
fdist.fit_properties["model_key"] = model_key
if fdist.fit_properties.get("params_initial", False):
# (cannot coerce this into one line, because "params_initial"
# can be None.)
# set the parameters of the previous fit
params = fdist.fit_properties["params_initial"]
else:
# use the initial model parameters
params = self.fit_parameters()

# parameter table
itab = self.table_parameters_initial

Expand Down
46 changes: 46 additions & 0 deletions tests/test_fd_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,52 @@ def test_remember_initial_params(qtbot):
assert float(itab.item(1, 1).text()) == 5


def test_update_ancillary_init(qtbot):
with MockModel(
compute_ancillaries=lambda x: {
# take initial fit parameter of E
"E": x.get_initial_fit_parameters(
model_ancillaries=False)["E"].value},
parameter_anc_keys=["E"],
parameter_anc_names=["ancillary E guess"],
parameter_anc_units=["Pa"],
model_key="test1"):

main_window = pyjibe.head.PyJibe()
main_window.load_data(files=[jpkfile, jpkfile])
war = main_window.subwindows[0].widget()
# clear data
war.tab_preprocess.list_preproc_applied.clear()
war.cb_autosave.setChecked(0)
# perform simple filter
item = QtWidgets.QListWidgetItem()
item.setText("compute_tip_position")
war.tab_preprocess.list_preproc_applied.addItem(item)
# disable weighting
war.tab_fit.cb_weight_cp.setCheckState(0)
# set mock model
idx = war.tab_fit.cb_model.findData("test1")
war.tab_fit.cb_model.setCurrentIndex(idx)
# perform fitting with standard parameters
# set initial parameters in user interface
itab = war.tab_fit.table_parameters_initial
atab = war.tab_fit.table_parameters_anc
war.on_tab_changed(1)
assert len(war.data_set[0].preprocessing) == 1
assert war.tab_preprocess.list_preproc_applied.count() == 1
# The ancillary parameter gets its value from the default parameters
assert atab.item(0, 1).text() == "3000"
assert itab.item(0, 1).text() == "3000"
# Now we change the initial parameter "E" and move on to the next
# curve. Ancillary parameter "F" should also change.
itab.item(0, 1).setText("2000")
assert atab.item(0, 1).text() == "2000"
it = war.list_curves.topLevelItem(1)
war.list_curves.setCurrentItem(it)
assert itab.item(0, 1).text() == "2000"
assert atab.item(0, 1).text() == "2000"


def test_update_ancillary_nan(qtbot):
with MockModel(
compute_ancillaries=lambda x: {"E": np.nan},
Expand Down

0 comments on commit 2542970

Please sign in to comment.