예제 #1
0
def test_function_nd(binned, lazy):
    s = Signal1D(np.empty((250,)))
    axis = s.axes_manager.signal_axes[0]
    axis.scale = .2
    axis.offset = -15
    g1 = Lorentzian(52342, 2, 10)
    s.data = g1.function(axis.axis)
    s.metadata.Signal.binned = binned
    s2 = stack([s] * 2)
    if lazy:
        s2 = s2.as_lazy()
    g2 = Lorentzian()
    factor = axis.scale if binned else 1
    g2.estimate_parameters(s2, axis.low_value, axis.high_value, False)
    assert g2.binned == binned
    np.testing.assert_allclose(g2.function_nd(axis.axis) * factor, s2.data,0.16)
예제 #2
0
def test_estimate_parameters_binned(only_current, binned, lazy, uniform):
    s = Signal1D(np.empty((250, )))
    s.axes_manager.signal_axes[0].is_binned = binned
    axis = s.axes_manager.signal_axes[0]
    axis.scale = .2
    axis.offset = -15
    g1 = Lorentzian(52342, 2, 10)
    s.data = g1.function(axis.axis)
    if not uniform:
        axis.convert_to_non_uniform_axis()
    if lazy:
        s = s.as_lazy()
    g2 = Lorentzian()
    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.A.value, g2.A.value * factor, 0.1)
    assert abs(g2.centre.value - g1.centre.value) <= 0.2
    assert abs(g2.gamma.value - g1.gamma.value) <= 0.1
예제 #3
0
def test_estimate_parameters_binned(only_current, binned, lazy):
    s = Signal1D(np.empty((250,)))
    s.metadata.Signal.binned = binned
    axis = s.axes_manager.signal_axes[0]
    axis.scale = .2
    axis.offset = -15
    g1 = Lorentzian(52342, 2, 10)
    s.data = g1.function(axis.axis)
    if lazy:
        s = s.as_lazy()
    g2 = Lorentzian()
    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
    np.testing.assert_allclose(g1.A.value, g2.A.value * factor,0.1)
    assert abs(g2.centre.value - g1.centre.value) <= 0.2
    assert abs(g2.gamma.value - g1.gamma.value) <= 0.1