def test_user_training_set(): tdir = setup_training_set() # load a curve idnt = IndentationGroup(jpkfile)[0] # fit it idnt.fit_model( model_key="sneddon_spher_approx", preprocessing=["compute_tip_position", "correct_force_offset"]) r1 = idnt.rate_quality(regressor="Extra Trees", training_set="zef18") assert r1 > 9, "sanity check" r2 = idnt.rate_quality(regressor="Extra Trees", training_set=tdir) assert 4 < r2 < 5, "with the given random state we end up at 4.55"
def test_change_model_key(): ar = IndentationGroup(jpkfile)[0] # Prepprocessing ar.apply_preprocessing( ["compute_tip_position", "correct_tip_offset", "correct_force_offset"]) # Fitting the data set will populate the dict ar.fit_model(model_key="hertz_para") # Change the model assert ar.fit_properties["params_initial"] is not None ar.fit_properties["model_key"] = "hertz_cone" # Changing the model key should reset the initial parameters assert ar.fit_properties["params_initial"] is None
def test_wrong_params_initial(): ar = IndentationGroup(jpkfile)[0] # Prepprocessing ar.apply_preprocessing( ["compute_tip_position", "correct_tip_offset", "correct_force_offset"]) md = model.models_available["hertz_para"] params = md.get_parameter_defaults() ar.fit_properties["model_key"] = "hertz_cone" try: ar.fit_model(params_initial=params) except FitKeyError: # We forced the wrong fitting parameters. pass else: raise ValueError("Should not be able to use wrong fit parameters!")
def test_process_flipsign(): # This is a curve extracted from a map file. When loading it # with nanite, the sign of the force curve was flipped. flipped = datadir / "flipsign_2015.05.22-15.31.49.352.jpk-force" idnt = IndentationGroup(flipped)[0] idnt.apply_preprocessing([ "compute_tip_position", "correct_force_offset", "correct_tip_offset", "correct_split_approach_retract" ]) # We set the baseline fixed, because this test was written so) params_initial = idnt.get_initial_fit_parameters(model_key="hertz_para") params_initial["baseline"].set(vary=False) idnt.fit_model(model_key="hertz_para", weight_cp=False, params_initial=params_initial) assert np.allclose(idnt.fit_properties["params_fitted"]["E"].value, 5257.047288859021)
def setup_indent(): idnt = IndentationGroup(jpkfile)[0] idnt.apply_preprocessing(["compute_tip_position"]) inparams = model.model_hertz_paraboloidal.get_parameter_defaults() inparams["baseline"].vary = True inparams["contact_point"].set(1.8e-5) # Fit with absolute full range idnt.fit_model(model_key="hertz_para", params_initial=inparams, range_x=(0, 0), range_type="absolute", x_axis="tip position", y_axis="force", segment="approach", weight_cp=False) return idnt
def test_changed_fit_properties(): ar = IndentationGroup(jpkfile)[0] # Initially, fit properties are not set assert not ar.fit_properties assert isinstance(ar.fit_properties, dict) # Prepprocessing ar.apply_preprocessing( ["compute_tip_position", "correct_tip_offset", "correct_force_offset"]) ar.fit_model() hash1 = ar.fit_properties["hash"] pinit = copy.deepcopy(ar.fit_properties["params_initial"]) pinit["E"].vary = False assert "hash" in ar.fit_properties, "make sure we didn't change anything" ar.fit_properties["params_initial"] = pinit assert "hash" not in ar.fit_properties ar.fit_model() assert hash1 != ar.fit_properties["hash"]
def test_with_dataset(): ar = IndentationGroup(jpkfile)[0] # Initially, fit properties are not set assert not ar.fit_properties assert isinstance(ar.fit_properties, dict) # Prepprocessing ar.apply_preprocessing(["compute_tip_position", "correct_tip_offset", "correct_force_offset"]) # Fitting the data set will populate the dict ar.fit_model() assert isinstance(ar.fit_properties, dict) assert isinstance(ar.fit_properties, FitProperties) assert "hash" in ar.fit_properties assert ar.fit_properties["success"] hash1 = ar.fit_properties["hash"] # Change something ar.fit_properties["weight_cp"] = 0 assert "hash" not in ar.fit_properties ar.fit_model() hash2 = ar.fit_properties["hash"] assert hash1 != hash2 # Change it back ar.fit_properties["weight_cp"] = FP_DEFAULT["weight_cp"] ar.fit_model() hash3 = ar.fit_properties["hash"] assert hash1 == hash3