def test_table_output(self): pcs = [1547, 1655] mlist = [ lmfit.models.VoigtModel(prefix=f"v{i}_") for i in range(len(pcs)) ] model = reduce(lambda x, y: x + y, mlist) params = model.make_params() for i, center in enumerate(pcs): p = f"v{i}_" dx = 20 params[p + "center"].set(value=center, min=center - dx, max=center + dx) params[p + "sigma"].set(max=50) params[p + "amplitude"].set(min=0.0001) out_result = model.fit(self.data.X[0], params, x=getx(self.data)) out_table = fit_peaks(self.data, model, params) out_row = out_table[0] self.assertEqual(out_row.x.shape[0], len(pcs) + len(out_result.var_names) + 1) attrs = [a.name for a in out_table.domain.attributes[:4]] self.assertEqual(attrs, ["v0 area", "v0 amplitude", "v0 center", "v0 sigma"]) self.assertNotEqual(0, out_row["v0 area"].value) self.assertEqual(out_result.best_values["v0_amplitude"], out_row["v0 amplitude"].value) self.assertEqual(out_result.best_values["v0_center"], out_row["v0 center"].value) self.assertEqual(out_result.best_values["v0_sigma"], out_row["v0 sigma"].value) self.assertEqual(out_result.redchi, out_row["Reduced chi-square"].value) self.assertEqual(out_row.id, self.data.ids[0])
def test_same_output(self): model, params = self.matched_models() out_fit = fit_peaks(self.data, model, params) self.widget.unconditional_commit() self.wait_until_finished() out = self.get_output(self.widget.Outputs.fit_params) self.assertEqual(out_fit.domain.attributes, out.domain.attributes) np.testing.assert_array_equal(out_fit.X, out.X)
def test_fit_peaks(self): model = lmfit.models.VoigtModel(prefix="v1_") params = model.make_params(center=1655) out = fit_peaks(self.data, model, params) assert len(out) == len(self.data)
def test_same_output(self): out_fit = fit_peaks(self.data, self.model, self.params) out = self.get_output(self.widget.Outputs.fit_params) self.assertEqual(out_fit.domain.attributes, out.domain.attributes) np.testing.assert_array_equal(out_fit.X, out.X)