Exemple #1
0
def test_function():
    g = PowerLaw()
    g.A.value = 1
    g.r.value = 2
    g.origin.value = 3
    assert g.function(2) == 1
    assert g.function(1) == 0.25
Exemple #2
0
    def __init__(self,
                 signal1D,
                 auto_background=True,
                 auto_add_edges=True,
                 ll=None,
                 GOS=None,
                 dictionary=None):
        Model1D.__init__(self, signal1D)

        # When automatically setting the fine structure energy regions,
        # the fine structure of an EELS edge component is automatically
        # disable if the next ionisation edge onset distance to the
        # higher energy side of the fine structure region is lower that
        # the value of this parameter
        self._min_distance_between_edges_for_fine_structure = 0
        self._preedge_safe_window_width = 2
        self.signal1D = signal1D
        self._suspend_auto_fine_structure_width = False
        self.convolved = False
        self.low_loss = ll
        self.GOS = GOS
        self.edges = []
        self._background_components = []
        if dictionary is not None:
            auto_background = False
            auto_add_edges = False
            self._load_dictionary(dictionary)

        if auto_background is True:
            background = PowerLaw()
            self.append(background)

        if self.signal.subshells and auto_add_edges is True:
            self._add_edges_from_subshells_names()
Exemple #3
0
    def __init__(self,
                 signal1D,
                 auto_background=True,
                 auto_add_edges=True,
                 ll=None,
                 GOS=None,
                 dictionary=None):
        Model1D.__init__(self, signal1D)
        self._suspend_auto_fine_structure_width = False
        self.convolved = False
        self.low_loss = ll
        self.GOS = GOS
        self.edges = []
        self._background_components = []
        if dictionary is not None:
            auto_background = False
            auto_add_edges = False
            self._load_dictionary(dictionary)

        if auto_background is True:
            background = PowerLaw()
            self.append(background)

        if self.signal.subshells and auto_add_edges is True:
            self._add_edges_from_subshells_names()
Exemple #4
0
def test_linear_override():
    g = PowerLaw()
    for para in g.parameters:
        if para is g.A:
            assert para._linear
        else:
            assert not para._linear
Exemple #5
0
def test_function_nd(binned):
    s = Signal1D(np.empty((100, )))
    axis = s.axes_manager.signal_axes[0]
    axis.scale = 0.02
    axis.offset = 1
    g1 = PowerLaw(50015.156, 1.2)
    s.data = g1.function(axis.axis)
    s.metadata.Signal.binned = binned
    s2 = stack([s] * 2)
    g2 = PowerLaw()
    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, rtol=0.05)
Exemple #6
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 = 0.02
    axis.offset = 1
    g1 = PowerLaw(50015.156, 1.2)
    s.data = g1.function(axis.axis)
    g2 = PowerLaw()
    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
    # error of the estimate function is rather large, esp. when binned=FALSE
    assert_allclose(g1.A.value, g2.A.value * factor, rtol=0.05)
    assert abs(g2.r.value - g1.r.value) <= 2e-2