Exemplo n.º 1
0
def test_estimate_parameters_binned(only_current, binned, lazy, uniform):
    s = Signal1D(np.empty((200, )))
    s.axes_manager.signal_axes[0].is_binned = binned
    axis = s.axes_manager.signal_axes[0]
    axis.scale = .05
    axis.offset = -5
    g1 = Voigt(centre=1, area=5, gamma=0.001, sigma=0.5, legacy=False)
    s.data = g1.function(axis.axis)
    if lazy:
        s = s.as_lazy()
    g2 = Voigt(legacy=False)
    if not uniform:
        axis.convert_to_non_uniform_axis()
    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(g2.sigma.value, 0.5, 0.01)
    np.testing.assert_allclose(g1.area.value, g2.area.value * factor, 0.01)
    np.testing.assert_allclose(g2.centre.value, 1, 1e-3)
Exemplo n.º 2
0
def test_function():
    g = Voigt(legacy=False)
    g.area.value = 5
    g.sigma.value = 0.5
    g.gamma.value = 0.2
    g.centre.value = 1
    assert_allclose(g.function(0), 0.78853024)
    assert_allclose(g.function(1), 2.97832092)
Exemplo n.º 3
0
def test_legacy():
    """Legacy test, to be removed in v2.0."""
    with pytest.warns(
            VisibleDeprecationWarning,
            match="API of the `Voigt` component will change",
    ):
        g = Voigt(legacy=True)
        g.area.value = 5
        g.FWHM.value = 0.5
        g.gamma.value = 0.2
        g.centre.value = 1
        np.testing.assert_allclose(g.function(0), 0.35380168)
        np.testing.assert_allclose(g.function(1), 5.06863535)
Exemplo n.º 4
0
def test_function_nd(binned, lazy):
    s = Signal1D(np.empty((200, )))
    s.metadata.Signal.binned = binned
    axis = s.axes_manager.signal_axes[0]
    axis.scale = .05
    axis.offset = -5
    g1 = Voigt(centre=1, area=5, gamma=0, sigma=0.5, legacy=False)
    s.data = g1.function(axis.axis)
    s2 = stack([s] * 2)
    if lazy:
        s2 = s2.as_lazy()
    g2 = Voigt(legacy=False)
    factor = axis.scale if binned else 1
    g2.estimate_parameters(s2, axis.low_value, axis.high_value, False)
    assert g2.binned == binned
    assert_allclose(g2.function_nd(axis.axis) * factor, s2.data)
Exemplo n.º 5
0
def test_estimate_parameters_binned(only_current, binned, lazy):
    s = Signal1D(np.empty((200, )))
    s.metadata.Signal.binned = binned
    axis = s.axes_manager.signal_axes[0]
    axis.scale = .05
    axis.offset = -5
    g1 = Voigt(centre=1, area=5, gamma=0.001, sigma=0.5, legacy=False)
    s.data = g1.function(axis.axis)
    if lazy:
        s = s.as_lazy()
    g2 = Voigt(legacy=False)
    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(g2.sigma.value, 0.5, 0.01)
    assert_allclose(g1.area.value, g2.area.value * factor, 0.01)
    assert_allclose(g2.centre.value, 1, 1e-3)