Exemplo n.º 1
0
def test_function():
    g = GaussianHF()
    g.centre.value = 1
    g.fwhm.value = 2
    g.height.value = 3
    assert g.function(2) == 1.5
    assert g.function(1) == 3
Exemplo n.º 2
0
def test_function():
    g = GaussianHF()
    g.centre.value = 1
    g.fwhm.value = 2
    g.height.value = 3
    assert g.function(2) == 1.5
    assert g.function(1) == 3
Exemplo n.º 3
0
def test_estimate_parameters_binned(only_current, binned, lazy, uniform):
    s = Signal1D(np.empty((100,)))
    s.axes_manager.signal_axes[0].is_binned = binned
    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)
    if not uniform:
        axis.convert_to_non_uniform_axis()
    if lazy:
        s = s.as_lazy()
    g2 = GaussianHF()
    if binned and uniform:
        factor = axis.scale
    elif binned:
        factor = np.gradient(axis.axis)
    else:
        factor = 1
    assert g2.estimate_parameters(s, axis.low_value, axis.high_value,
                                  only_current=only_current)
    assert g2._axes_manager[-1].is_binned == binned
    np.testing.assert_allclose(g1.height.value, g2.height.value * factor)
    assert abs(g2.centre.value - g1.centre.value) <= 1e-3
    assert abs(g2.fwhm.value - g1.fwhm.value) <= 0.1
Exemplo n.º 4
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)
Exemplo n.º 5
0
def test_integral_as_signal():
    s = Signal1D(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)
    assert_allclose(s_out.data, ref)
Exemplo n.º 6
0
def test_integral_as_signal():
    s = Signal1D(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)
    assert_allclose(s_out.data, ref)
Exemplo n.º 7
0
def test_estimate_parameters_binned():
    s = Signal1D(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)
    assert_allclose(
        g1.height.value / axis.scale,
        g2.height.value)
    assert abs(g2.centre.value - g1.centre.value) <= 1e-3
    assert abs(g2.fwhm.value - g1.fwhm.value) <= 0.1
Exemplo n.º 8
0
def test_function_nd(binned):
    s = Signal1D(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 = binned

    s2 = stack([s] * 2)
    g2 = GaussianHF()
    factor = axis.scale if binned else 1
    g2.estimate_parameters(s2, axis.low_value, axis.high_value, False)
    assert g2.binned == binned
    # TODO: sort out while the rtol to be so high...
    assert_allclose(g2.function_nd(axis.axis) * factor, s2.data, rtol=0.05)
Exemplo n.º 9
0
def test_function_nd(binned):
    s = Signal1D(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 = binned

    s2 = stack([s] * 2)
    g2 = GaussianHF()
    factor = axis.scale if binned else 1
    g2.estimate_parameters(s2, axis.low_value, axis.high_value, False)
    assert g2.binned == binned
    # TODO: sort out while the rtol to be so high...
    assert_allclose(g2.function_nd(axis.axis) * factor, s2.data, rtol=0.05)
Exemplo n.º 10
0
def test_estimate_parameters_binned(only_current, binned):
    s = Signal1D(np.empty((100,)))
    s.metadata.Signal.binned = binned
    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)
    g2 = GaussianHF()
    factor = axis.scale if binned else 1
    assert g2.estimate_parameters(s, axis.low_value, axis.high_value,
                                  only_current=only_current)
    assert g2.binned == binned
    assert_allclose(g1.height.value, g2.height.value * factor)
    assert abs(g2.centre.value - g1.centre.value) <= 1e-3
    assert abs(g2.fwhm.value - g1.fwhm.value) <= 0.1
Exemplo n.º 11
0
def test_estimate_parameters_binned(only_current, binned):
    s = Signal1D(np.empty((100, )))
    s.metadata.Signal.binned = binned
    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)
    g2 = GaussianHF()
    factor = axis.scale if binned else 1
    assert g2.estimate_parameters(s,
                                  axis.low_value,
                                  axis.high_value,
                                  only_current=only_current)
    assert g2.binned == binned
    assert_allclose(g1.height.value, g2.height.value * factor)
    assert abs(g2.centre.value - g1.centre.value) <= 1e-3
    assert abs(g2.fwhm.value - g1.fwhm.value) <= 0.1