Пример #1
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)
Пример #2
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)
Пример #3
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)