def test_compute_constant_term(): s = Signal1D(np.random.random(10)) m = s.create_model() lin = Expression("a*x + b", name='linear') m.append(lin) lin.a.value = 2 lin.b.value = 3 lin.b.free = False np.testing.assert_allclose(lin._compute_constant_term(), 3)
def test_constant_from_expression(self): expression = "a * x + b" g = Expression(expression, name="test_constant", a=20.0, b=4.0) g.b.free = False assert g._constant_term == 4.0 self.m.append(g) assert g._constant_term == 4.0
def setup_method(self, method): s = Signal1D(np.arange(1000).reshape((10, 100))) np.random.seed(0) s.add_poissonian_noise() m = s.create_model() line = Expression("a * x", name="line", a=1) m.append(line) self.m = m
def setup_method(self, method): s = EDS_SEM_Spectrum().isig[5.0:15.0] m = s.create_model(auto_background=False) c = Expression('a*x+b', 'line with offset') m.append(c) self.s = s self.m = m self.c = c
def test_model2D_polyexpression(self, nav2d): poly = "a*x**2 + b*x - c*y**2 + d*y + e" P = Expression(poly, 'poly') P.a.value = 6 P.b.value = 5 P.c.value = 4 P.d.value = 3 P.e.value = 2 data = P.function(*self.mesh) s = Signal2D(data) if nav2d: s = hs.stack([s] * 2) s = hs.stack([s] * 3) m = s.create_model() m.append(P) m.fit(optimizer='lstsq') diff = (s - m.as_signal(show_progressbar=False)) np.testing.assert_allclose(diff.data, 0.0, atol=1E-7) np.testing.assert_allclose(m.p_std, 0.0, atol=1E-7)
def test_constant_from_expression2(self): expression = "A * exp(-(x-centre)**2/(2*sigma**2))" h = Expression(expression, name="test_constant2", A=20.0, centre=4.0, sigma=1.0) self.m.append(h) assert h._constant_term == 0 h.centre.free = False h.sigma.free = False assert h._constant_term == 0
def setup_method(self, method): s = Signal1D(range(100)) m = s.create_model() m.append(Gaussian(A=13)) m[-1].name = 'something' m.append(GaussianHF(module="numpy")) m[-1].height.value = 3 m.append( Expression(name="Line", expression="a * x + b", a=1, c=0, rename_pars={"b": "c"})) self.m = m
def test_sympy_linear_expression2(): expression = "a * x + b" g = Expression(expression, name="Test_function2") assert g.a._linear assert g.b._linear
def test_sympy_linear_expression(): expression = "height * exp(-(x - centre) ** 2 * 4 * log(2)/ fwhm ** 2)" g = Expression(expression, name="Test_function") assert g.height._linear assert not g.centre._linear assert not g.fwhm._linear
def test_constant_term_without_model(self): expression = "a * x + b" g = Expression(expression, name="test_constant", a=20.0, b=4.0) assert g._constant_term == 0 self.m.append(g) assert g._constant_term == 0