예제 #1
0
 def setup_method(self, method):
     s = EDS_SEM_Spectrum().isig[5.0:15.0]
     m = s.create_model(auto_background=False)
     c = Expression('a*x+b', 'line with offset')
     m.append(c)
     self.s = s
     self.m = m
     self.c = c
예제 #2
0
 def setup_method(self):
     self.model = EDS_SEM_Spectrum().create_model()
     self.component = self.model[1]
     # We use bmin instead of A because it's a bit more exotic
     self.component.A.bmin = 1.23456789012
     self.component_not_free = self.model[3]
     self.component_not_free.set_parameters_not_free()
     self.component_not_free.A.bmin = 9.87654321098
     self.component_inactive = self.model[4]
     self.component_inactive.active = False
     self.component_inactive.A.bmin = 5.67890123456
예제 #3
0
class TestSetParameters:
    def setup_method(self):
        self.model = EDS_SEM_Spectrum().create_model()

    @pytest.mark.parametrize("fancy", (True, False))
    def test_component_print_current_values(self, fancy):
        self.model[0].print_current_values(fancy=fancy)

    @pytest.mark.parametrize("fancy", (True, False))
    def test_model_print_current_values(self, fancy):
        self.model.print_current_values(fancy=fancy)
예제 #4
0
class TestSetParameters:
    def setup_method(self):
        self.model = EDS_SEM_Spectrum().create_model()
        self.component = self.model[1]
        # We use bmin instead of A because it's a bit more exotic
        self.component.A.bmin = 1.23456789012
        self.component_not_free = self.model[3]
        self.component_not_free.set_parameters_not_free()
        self.component_not_free.A.bmin = 9.87654321098
        self.component_inactive = self.model[4]
        self.component_inactive.active = False
        self.component_inactive.A.bmin = 5.67890123456

    @pytest.mark.parametrize("only_free, only_active", [(True, False),
                                                        (True, False)])
    def test_component_current_component_values(self, only_free, only_active):
        "Many decimals aren't printed, few decimals are"
        string_representation = str(
            current_component_values(self.component, only_free,
                                     only_active).__repr__())
        html_representation = str(
            current_component_values(self.component, only_free,
                                     only_active)._repr_html_())
        assert "1.234" in string_representation
        assert "1.23456789012" not in string_representation
        assert "1.234" in html_representation
        assert "1.23456789012" not in html_representation

    def test_component_current_component_values_only_free(
            self, only_free=True, only_active=False):
        "Parameters with free=False values should not be present in repr"
        string_representation = str(
            current_component_values(self.component_not_free, only_free,
                                     only_active).__repr__())
        html_representation = str(
            current_component_values(self.component_not_free, only_free,
                                     only_active)._repr_html_())
        assert "9.87" not in string_representation
        assert "9.87" not in html_representation

    @pytest.mark.parametrize("only_free, only_active", [(True, False),
                                                        (True, False)])
    def test_component_current_model_values(self, only_free, only_active):
        "Many decimals aren't printed, few decimals are"
        string_representation = str(
            current_model_values(self.model, only_free,
                                 only_active).__repr__())
        html_representation = str(
            current_model_values(self.model, only_free,
                                 only_active)._repr_html_())
        assert "1.234" in string_representation
        assert "1.23456789012" not in string_representation
        assert "1.234" in html_representation
        assert "1.23456789012" not in html_representation

        if only_free:
            # Parameters with free=False values should not be present in repr
            assert "9.87" not in string_representation
            assert "9.87" not in html_representation
        if only_active:
            # components with active=False values should not be present in repr"
            assert "5.67" not in string_representation
            assert "5.67" not in html_representation

    @pytest.mark.parametrize("only_free, only_active", [(True, False),
                                                        (True, False)])
    def test_component_current_model_values_comp_list(self, only_free,
                                                      only_active):
        comp_list = [
            self.component, self.component_not_free, self.component_inactive
        ]
        string_representation = str(
            current_model_values(self.model, only_free, only_active,
                                 comp_list).__repr__())
        html_representation = str(
            current_model_values(self.model, only_free, only_active,
                                 comp_list)._repr_html_())
        assert "1.234" in string_representation
        assert "1.23456789012" not in string_representation
        assert "1.234" in html_representation
        assert "1.23456789012" not in html_representation

        if only_free:
            assert "9.87" not in string_representation
            assert "9.87" not in html_representation
        if only_active:
            assert "5.67" not in string_representation
            assert "5.67" not in html_representation

    @pytest.mark.parametrize("fancy", (True, False))
    def test_model_current_model_values(self, fancy):
        self.model.print_current_values(fancy=fancy)

    @pytest.mark.parametrize("fancy", (True, False))
    def test_component_print_current_values(self, fancy):
        self.model[0].print_current_values(fancy=fancy)

    @pytest.mark.parametrize("fancy", (True, False))
    def test_model_print_current_values(self, fancy):
        self.model.print_current_values(fancy=fancy)

    def test_zero_in_fancy_print(self):
        "Ensure parameters with value=0 are printed too"
        assert "<td>a1</td><td>True</td><td>     0</td>" in current_component_values(
            self.model[0])._repr_html_()

    def test_zero_in_normal_print(self):
        "Ensure parameters with value=0 are printed too"
        assert "            a0 |    True |          0 |" in str(
            current_component_values(self.model[0]).__repr__)

    def test_twinned_in_print(self):
        assert "             A | Twinned |" in str(
            current_component_values(self.model[2]).__repr__()).split('\n')[4]

    def test_related_tools(self):
        assert _is_iter([1, 2, 3])
        assert _is_iter((1, 2, 3))
        assert not _is_iter(1)

        assert _iter_join([1.2345678, 5.67890]) == '(1.23457, 5.6789)'
        assert _iter_join([1.2345678, 5.67890]) == '(1.23457, 5.6789)'
        assert _iter_join([1, 5]) == '(     1,      5)'

        assert _non_iter(None) == ""
        assert _non_iter(5) == '     5'
        assert _non_iter(5.123456789) == '5.12346'
예제 #5
0
 def setup_method(self):
     self.m = EDS_SEM_Spectrum().create_model(auto_background=False)
예제 #6
0
class TestCustomComponent:
    def setup_method(self):
        self.m = EDS_SEM_Spectrum().create_model(auto_background=False)

    def test_custom_comp_w_two_linear_attributes(self):
        c = MultiLinearCustomComponent()
        self.m.append(c)
        with pytest.raises(AttributeError, match="has more than one free"):
            self.m.fit(optimizer='lstsq')

    def test_custom_comp(self):
        c = MultiLinearCustomComponent()
        c.a0.free = False
        self.m.append(c)
        self.m.fit(optimizer='lstsq')

    def test_compare_custom_comp(self):
        c = MultiLinearCustomComponent()
        c.a0.free = False
        c.a0.value = 0

        self.m.append(c)
        self.m.fit(optimizer='lstsq')
        linear = c.a1.value

        self.m.fit()
        nonlinear = c.a1.value

        np.testing.assert_allclose(linear, nonlinear)
예제 #7
0
 def setup_method(self):
     m = EDS_SEM_Spectrum().create_model()
     m2 = EDS_SEM_Spectrum().isig[5.:15.].create_model()
     self.m = m
     self.m2 = m2
예제 #8
0
 def setup_method(self, method):
     s = EDS_SEM_Spectrum().isig[5.0:15.0]
     m = s.create_model(auto_background=False)
     self.m = m
예제 #9
0
 def setup_method(self):
     self.model = EDS_SEM_Spectrum().create_model()