Ejemplo n.º 1
0
def test_model_expr_base(qtbot):
    """Expressions sanity check

    This test is just to make sure that parameters that have an
    expression are not overridden by the UI.
    """
    with MockModelModuleExpr() as mod:
        main_window = pyjibe.head.PyJibe()
        main_window.load_data(files=make_directory_with_data(2))
        war = main_window.subwindows[0].widget()
        # clear data
        war.cb_autosave.setChecked(0)
        # perform simple filter
        war.tab_preprocess.set_preprocessing(["compute_tip_position"])
        # set mock model
        idx = war.tab_fit.cb_model.findData(mod.model_key)
        war.tab_fit.cb_model.setCurrentIndex(idx)
        # Now there should be fit results
        itab = war.tab_fit.table_parameters_initial
        # set better value for contact point
        itab.item(5, 1).setText(str(18000))
        fdist = war.data_set[0]
        parmsi = fdist.fit_properties["params_initial"]
        parmsf = fdist.fit_properties["params_fitted"]
        assert parmsi["E1"].expr == "virtual_parameter+E"
        assert parmsf["E1"].expr == "virtual_parameter+E"
        assert np.allclose(parmsf["E1"].value, 15388.14166)
Ejemplo n.º 2
0
def test_ancillary_update_nan(qtbot):
    with MockModelModule(compute_ancillaries=lambda x: {"E": np.nan},
                         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=make_directory_with_data(2))
        war = main_window.subwindows[0].widget()
        # clear data
        war.cb_autosave.setChecked(0)
        # perform simple filter
        war.tab_preprocess.set_preprocessing(["compute_tip_position"])
        # 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
        assert atab.item(0, 1).text() == "nan"
        assert itab.item(0, 1).text() == "3000"
Ejemplo n.º 3
0
def test_clear_and_verify_data(qtbot):
    main_window = pyjibe.head.PyJibe()
    main_window.load_data(files=make_directory_with_data())
    war = main_window.subwindows[0].widget()
    # clear data
    tpp = war.tab_preprocess
    war.cb_autosave.setChecked(0)
    # perform simple filter
    tpp.set_preprocessing(["compute_tip_position"])
    # perform fitting with standard parameters
    # set initial parameters in user interface
    itab = war.tab_fit.table_parameters_initial
    # disable weighting
    war.tab_fit.cb_weight_cp.setCheckState(0)
    # enable fitting of force offset
    itab.item(4, 0).setCheckState(0)
    # set better value for contact point
    itab.item(3, 1).setText(str(18000))
    apret = war.data_set[0]
    war.tab_fit.fit_approach_retract(apret)
    # Now check something
    ftab = war.tab_fit.table_parameters_fitted
    # E
    assert np.allclose(apret.fit_properties["params_fitted"]["E"].value,
                       14741.958242422093,
                       atol=1e-4,
                       rtol=0)
    assert float(ftab.item(0, 0).text()) == 14742
    # contact_point
    assert float(ftab.item(1, 0).text()) == 18029
    # baseline_offset
    assert float(ftab.item(2, 0).text()) == -480.67
Ejemplo n.º 4
0
def test_fit_all(qtbot):
    """Perform a simple fit with the standard parameters"""
    main_window = pyjibe.head.PyJibe()
    main_window.load_data(files=make_directory_with_data(2))
    war = main_window.subwindows[0].widget()
    war.cb_autosave.setChecked(0)
    war.on_fit_all()
    a1 = war.data_set[0]
    a2 = war.data_set[1]
    assert a1.fit_properties == a2.fit_properties
Ejemplo n.º 5
0
def test_qmap_with_unused_curves(qtbot):
    """Uncheck "use" in the curve list and switch to the qmap tab"""
    main_window = pyjibe.head.PyJibe()
    main_window.load_data(files=make_directory_with_data())
    war = main_window.subwindows[0].widget()
    # uncheck first curve
    cl1 = war.list_curves.currentItem()
    cl1.setCheckState(3, QtCore.Qt.Unchecked)
    war.tabs.setCurrentIndex(5)
    QtWidgets.QApplication.processEvents()
Ejemplo n.º 6
0
def test_preprocessing_poc_estimation(method, contact_point):
    main_window = pyjibe.head.PyJibe()
    main_window.load_data(files=make_directory_with_data(2))
    war = main_window.subwindows[0].widget()
    # clear data
    war.cb_autosave.setChecked(0)
    war.tabs.setCurrentIndex(0)
    # perform simple filter
    war.tab_preprocess.set_preprocessing(
        preprocessing=["compute_tip_position", "correct_tip_offset"],
        options={"correct_tip_offset": {"method": method}}
    )
    war.tabs.setCurrentIndex(1)
    fd = war.data_set[0]
    assert np.argmin(np.abs(fd["tip position"])) == contact_point
Ejemplo n.º 7
0
def test_ancillary_update_preproc_change(qtbot):
    with MockModelModule(
            compute_ancillaries=lambda x: {
                # i.e. model works only if there are multiple preproc steps
                "E": np.nan if len(x.preprocessing) == 1 else 2345
            },
            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=make_directory_with_data(2))
        war = main_window.subwindows[0].widget()
        # clear data
        war.cb_autosave.setChecked(0)
        # perform simple filter
        war.tab_preprocess.set_preprocessing(["compute_tip_position"])
        # 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()
        assert len(war.data_set[0].preprocessing) == 1
        assert len(war.tab_preprocess.current_preprocessing()[0]) == 1
        assert atab.item(0, 1).text() == "nan"
        assert itab.item(0, 1).text() == "3000"
        # up until here this is the same as `test_update_ancillary_nan`
        # now change preprocessing
        war.tabs.setCurrentIndex(0)  # actually switch tabs like a user
        # manually check the "correct_tip_offset" widget
        for pwid, k in war.tab_preprocess._map_widgets_to_preproc_ids.items():
            if k == "correct_tip_offset":
                pwid.setChecked(True)
        war.tabs.setCurrentIndex(1)  # triggers recomputation of anc
        assert len(war.data_set[0].preprocessing) == 2
        assert len(war.tab_preprocess.current_preprocessing()[0]) == 2
        assert atab.item(0, 1).text() == "2345"
        assert itab.item(0, 1).text() == "2345"
Ejemplo n.º 8
0
def test_change_model_keep_parms(qtbot):
    main_window = pyjibe.head.PyJibe()
    main_window.load_data(files=make_directory_with_data(2))
    war = main_window.subwindows[0].widget()
    # clear data
    war.cb_autosave.setChecked(0)
    # perform simple filter
    war.tab_preprocess.set_preprocessing(["compute_tip_position"])
    # perform fitting with standard parameters
    # set initial parameters in user interface
    itab = war.tab_fit.table_parameters_initial
    # set value for contact point
    itab.item(3, 1).setText(str(12345))
    # change the model to pyramidal
    pyr_name = nmodel.model_hertz_three_sided_pyramid.model_name
    pyr_idx = war.tab_fit.cb_model.findText(pyr_name)
    war.tab_fit.cb_model.setCurrentIndex(pyr_idx)
    # check that contact point is still the same
    assert float(itab.item(3, 1).text()) == 12345
Ejemplo n.º 9
0
def test_ancillary_update_init(qtbot):
    with MockModelModule(
            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=make_directory_with_data(2))
        war = main_window.subwindows[0].widget()
        # clear data
        war.cb_autosave.setChecked(0)
        # perform simple filter
        war.tab_preprocess.set_preprocessing(["compute_tip_position"])
        # 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()
        assert len(war.data_set[0].preprocessing) == 1
        assert len(war.tab_preprocess.current_preprocessing()[0]) == 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"
Ejemplo n.º 10
0
def test_set_indentation_depth_manually_infdoublespinbox(qtbot):
    main_window = pyjibe.head.PyJibe()
    main_window.load_data(files=make_directory_with_data(2))
    war = main_window.subwindows[0].widget()
    # perform fitting with standard parameters
    # set initial parameters in user interface
    itab = war.tab_fit.table_parameters_initial
    # set value for contact point
    itab.item(3, 1).setText(str(12345))
    # change the model to pyramidal
    pyr_name = nmodel.model_hertz_three_sided_pyramid.model_name
    pyr_idx = war.tab_fit.cb_model.findText(pyr_name)
    war.tab_fit.cb_model.setCurrentIndex(pyr_idx)
    # set left fitting range
    for text_entered, resulting_value in [["-1.40", -1.4], ["1...2", 1.2],
                                          ["1.0e-4", 1e-4], ["inf", np.inf],
                                          ["1.10201", 1.10201],
                                          ["1.001", 1.001], ["-1.04", -1.04]]:
        war.tab_fit.sp_range_1.clear()
        qtbot.keyClicks(war.tab_fit.sp_range_1, text_entered)
        assert war.tab_fit.sp_range_1.value() == resulting_value
Ejemplo n.º 11
0
def test_hidden_parameters(qtbot):
    def get_parameter_defaults():
        params = lmfit.Parameters()
        params.add("E", value=3e3, min=0)
        params.add("R", value=10e-6, min=0, vary=False)
        params.add("_nu", value=.5, min=0, max=0.5, vary=False)
        params.add("contact_point", value=0)
        params.add("baseline", value=0)
        return params

    def model_func(delta, E, R, _nu, contact_point=0, baseline=0):
        return model_hertz_paraboloidal.hertz_paraboloidal(
            delta=delta,
            E=E,
            R=R,
            nu=_nu,
            contact_point=contact_point,
            baseline=baseline)
    with MockModelModule(
            model_key="petperpan",
            parameter_keys=["E", "R", "_nu", "contact_point", "baseline"],
            model_func=model_func,
            model=nres.get_default_modeling_wrapper(model_func),
            residual=nres.get_default_residuals_wrapper(model_func),
            get_parameter_defaults=get_parameter_defaults) as mod:
        main_window = pyjibe.head.PyJibe()
        # disable developer mode
        main_window.settings.setValue("advanced/developer mode", 0)
        main_window.load_data(files=make_directory_with_data(2))
        war = main_window.subwindows[0].widget()
        # clear data
        war.cb_autosave.setChecked(0)
        # perform simple filter
        war.tab_preprocess.set_preprocessing(["compute_tip_position"])
        # set mock model
        idx = war.tab_fit.cb_model.findData(mod.model_key)
        war.tab_fit.cb_model.setCurrentIndex(idx)
        # Check visibility of Poisson's ratio
        itab = war.tab_fit.table_parameters_initial
        assert itab.rowCount() == 4
Ejemplo n.º 12
0
def test_remember_initial_params(qtbot):
    main_window = pyjibe.head.PyJibe()
    main_window.load_data(files=make_directory_with_data(2))
    war = main_window.subwindows[0].widget()
    # clear data
    war.cb_autosave.setChecked(0)
    # perform simple filter
    war.tab_preprocess.set_preprocessing(["compute_tip_position"])
    # perform fitting with standard parameters
    # set initial parameters in user interface
    itab = war.tab_fit.table_parameters_initial
    # disable weighting
    war.tab_fit.cb_weight_cp.setCheckState(0)
    # enable fitting of force offset
    itab.item(4, 0).setCheckState(0)
    # set better value for contact point
    itab.item(3, 1).setText(str(18000))
    # change standard tip radius from 10 to 5
    assert float(itab.item(1, 1).text()) == 10
    itab.item(1, 1).setText(str(5))
    cl1 = war.list_curves.currentItem()
    cl2 = war.list_curves.itemBelow(cl1)
    war.list_curves.setCurrentItem(cl2)
    assert float(itab.item(1, 1).text()) == 5