Example #1
0
def test_function():
    g = GaussianHF()
    g.centre.value = 1
    g.fwhm.value = 2
    g.height.value = 3
    nt.assert_equal(g.function(2), 1.5)
    nt.assert_equal(g.function(1), 3)
Example #2
0
def test_integral_as_signal():
    s = Spectrum(np.zeros((2, 3, 100)))
    g1 = GaussianHF(fwhm=3.33, centre=20.)
    h_ref = np.linspace(0.1, 3.0, s.axes_manager.navigation_size)
    for d, h in zip(s._iterate_signal(), h_ref):
        g1.height.value = h
        d[:] = g1.function(s.axes_manager.signal_axes[0].axis)
    m = s.create_model()
    g2 = GaussianHF()
    m.append(g2)
    g2.estimate_parameters(s, 0, 100, True)
    m.multifit()
    s_out = g2.integral_as_signal()
    ref = (h_ref * 3.33 * sqrt2pi / sigma2fwhm).reshape(s_out.data.shape)
    np.testing.assert_almost_equal(
        s_out.data, ref)
Example #3
0
def test_estimate_parameters_binned():
    s = Spectrum(np.empty((100,)))
    axis = s.axes_manager.signal_axes[0]
    axis.scale = 2.
    axis.offset = -30
    g1 = GaussianHF(50015.156, 23, 10)
    s.data = g1.function(axis.axis)
    s.metadata.Signal.binned = True
    g2 = GaussianHF()
    g2.estimate_parameters(s, axis.low_value, axis.high_value, True)
    nt.assert_almost_equal(
        g1.height.value / axis.scale,
        g2.height.value)
    nt.assert_almost_equal(g2.centre.value, g1.centre.value, delta=1e-3)
    nt.assert_almost_equal(g2.fwhm.value, g1.fwhm.value, delta=0.1)
Example #4
0
def test_util_fwhm_get():
    g1 = GaussianHF(fwhm=0.33)
    g1.height.value = 1.0
    nt.assert_almost_equal(g1.A, 1.0 * sqrt2pi * 0.33 / sigma2fwhm)
Example #5
0
def test_util_fwhm_set():
    g1 = GaussianHF(fwhm=0.33)
    g1.A = 1.0
    nt.assert_almost_equal(g1.height.value, 1.0 * sigma2fwhm / (
        0.33 * sqrt2pi))
Example #6
0
def test_util_sigma_getset():
    g1 = GaussianHF()
    g1.sigma = 1.0
    nt.assert_almost_equal(g1.sigma, 1.0)
Example #7
0
def test_util_sigma_get():
    g1 = GaussianHF()
    g1.fwhm.value = 1.0
    nt.assert_almost_equal(g1.sigma, 1.0 / sigma2fwhm)
Example #8
0
def test_util_sigma_set():
    g1 = GaussianHF()
    g1.sigma = 1.0
    nt.assert_almost_equal(g1.fwhm.value, 1.0 * sigma2fwhm)
Example #9
0
def test_util_fwhm_getset():
    g1 = GaussianHF(fwhm=0.33)
    g1.A = 1.0
    nt.assert_almost_equal(g1.A, 1.0)