コード例 #1
0
def test_estimate_parameters_binned():
    s = Spectrum(np.empty((100,)))
    axis = s.axes_manager.signal_axes[0]
    axis.scale = 2.
    axis.offset = -30
    g1 = GaussianHF(50015.156, 23, 10)
    s.data = g1.function(axis.axis)
    s.metadata.Signal.binned = True
    g2 = GaussianHF()
    g2.estimate_parameters(s, axis.low_value, axis.high_value, True)
    nt.assert_almost_equal(
        g1.height.value / axis.scale,
        g2.height.value)
    nt.assert_almost_equal(g2.centre.value, g1.centre.value, delta=1e-3)
    nt.assert_almost_equal(g2.fwhm.value, g1.fwhm.value, delta=0.1)
コード例 #2
0
def test_integral_as_signal():
    s = Spectrum(np.zeros((2, 3, 100)))
    g1 = GaussianHF(fwhm=3.33, centre=20.)
    h_ref = np.linspace(0.1, 3.0, s.axes_manager.navigation_size)
    for d, h in zip(s._iterate_signal(), h_ref):
        g1.height.value = h
        d[:] = g1.function(s.axes_manager.signal_axes[0].axis)
    m = s.create_model()
    g2 = GaussianHF()
    m.append(g2)
    g2.estimate_parameters(s, 0, 100, True)
    m.multifit()
    s_out = g2.integral_as_signal()
    ref = (h_ref * 3.33 * sqrt2pi / sigma2fwhm).reshape(s_out.data.shape)
    np.testing.assert_almost_equal(
        s_out.data, ref)
コード例 #3
0
ファイル: test_spectrum.py プロジェクト: Emilieringe/hyperspy
class Test2D():
    def setUp(self):
        self.s = Spectrum(np.random.random((2, 3)))
    def test_to_image(self):
        im = self.s.to_image()
        assert_true(isinstance(im, Image))
        assert_equal(im.data.shape, self.s.data.T.shape)
        assert_true(im.data.flags["C_CONTIGUOUS"])
コード例 #4
0
ファイル: test_spectrum.py プロジェクト: temcode/hyperspy
class Test2D:
    def setUp(self):
        self.s = Spectrum(np.random.random((2, 3)))

    def test_to_image(self):
        im = self.s.to_image()
        nose.tools.assert_true(isinstance(im, Image))
        nose.tools.assert_equal(im.data.shape, self.s.data.T.shape)
        nose.tools.assert_true(im.data.flags["C_CONTIGUOUS"])
コード例 #5
0
ファイル: test_spectrum.py プロジェクト: mfm24/hyperspy
class Test4D():
    def setUp(self):
        self.s = Spectrum(np.random.random((2, 3, 4, 5)))

    def test_to_image(self):
        im = self.s.to_image()
        assert_true(isinstance(im, Image))
        assert_equal(im.data.shape, (5, 2, 3, 4))
        assert_true(im.data.flags["C_CONTIGUOUS"])
コード例 #6
0
    def setUp(self):
        np.random.seed(0)  # Same random every time, Line2DROi test requires it
        self.s_s = Spectrum(np.random.rand(50, 60, 4))
        self.s_s.axes_manager[0].scale = 5
        self.s_s.axes_manager[0].units = 'nm'
        self.s_s.axes_manager[1].scale = 5
        self.s_s.axes_manager[1].units = 'nm'

        # 4D dataset
        self.s_i = Image(np.random.rand(100, 100, 4, 4))
コード例 #7
0
ファイル: test_spectrum.py プロジェクト: gdonval/hyperspy
class Test4D():

    def setUp(self):
        self.s = Spectrum(np.random.random((2, 3, 4, 5)))

    def test_to_image(self):
        im = self.s.to_image()
        nose.tools.assert_true(isinstance(im, Image))
        nose.tools.assert_equal(im.data.shape, (5, 2, 3, 4))
        nose.tools.assert_true(im.data.flags["C_CONTIGUOUS"])
コード例 #8
0
ファイル: test_spectrum.py プロジェクト: temcode/hyperspy
 def setUp(self):
     self.s = Spectrum(np.random.random((2, 3)))
コード例 #9
0
ファイル: test_spectrum.py プロジェクト: LewysJones/hyperspy
 def setUp(self):
     self.s = Spectrum(np.random.random((2, 3)))
コード例 #10
0
ファイル: test_bss.py プロジェクト: lu-chi/hyperspy
 def setUp(self):
     ics = np.random.laplace(size=(3, 1000))
     np.random.seed(1)
     mixing_matrix = np.random.random((100, 3))
     self.s = Spectrum(np.dot(mixing_matrix, ics))
     self.s.decomposition()
コード例 #11
0
ファイル: test_bss.py プロジェクト: lu-chi/hyperspy
class TestBSS1D:

    def setUp(self):
        ics = np.random.laplace(size=(3, 1000))
        np.random.seed(1)
        mixing_matrix = np.random.random((100, 3))
        self.s = Spectrum(np.dot(mixing_matrix, ics))
        self.s.decomposition()

    def test_on_loadings(self):
        if not sklearn_installed:
            raise SkipTest
        self.s.blind_source_separation(
            3, diff_order=0, fun="exp", on_loadings=False)
        s2 = self.s.as_spectrum(0)
        s2.decomposition()
        s2.blind_source_separation(
            3, diff_order=0, fun="exp", on_loadings=True)
        nose.tools.assert_true(are_bss_components_equivalent(
            self.s.get_bss_factors(), s2.get_bss_loadings()))

    def test_mask_diff_order_0(self):
        if not sklearn_installed:
            raise SkipTest
        # This test, unlike most other tests, either passes or raises an error.
        # It is designed to test if the mask is correctly dilated inside the
        # `blind_source_separation_method`. If the mask is not correctely
        # dilated the nan in the loadings should raise an error.
        mask = self.s._get_signal_signal(dtype="bool")
        mask[5] = True
        self.s.learning_results.factors[5, :] = np.nan
        self.s.blind_source_separation(3, diff_order=0, mask=mask)

    def test_mask_diff_order_1(self):
        if not sklearn_installed:
            raise SkipTest
        # This test, unlike most other tests, either passes or raises an error.
        # It is designed to test if the mask is correctly dilated inside the
        # `blind_source_separation_method`. If the mask is not correctely
        # dilated the nan in the loadings should raise an error.
        mask = self.s._get_signal_signal(dtype="bool")
        mask[5] = True
        self.s.learning_results.factors[5, :] = np.nan
        self.s.blind_source_separation(3, diff_order=1, mask=mask)

    def test_mask_diff_order_0_on_loadings(self):
        if not sklearn_installed:
            raise SkipTest
        # This test, unlike most other tests, either passes or raises an error.
        # It is designed to test if the mask is correctly dilated inside the
        # `blind_source_separation_method`. If the mask is not correctely
        # dilated the nan in the loadings should raise an error.
        mask = self.s._get_navigation_signal(dtype="bool")
        mask[5] = True
        self.s.learning_results.loadings[5, :] = np.nan
        self.s.blind_source_separation(3, diff_order=0, mask=mask,
                                       on_loadings=True)

    def test_mask_diff_order_1_on_loadings(self):
        if not sklearn_installed:
            raise SkipTest
        # This test, unlike most other tests, either passes or raises an error.
        # It is designed to test if the mask is correctly dilated inside the
        # `blind_source_separation_method`. If the mask is not correctely
        # dilated the nan in the loadings should raise an error.
        mask = self.s._get_navigation_signal(dtype="bool")
        mask[5] = True
        self.s.learning_results.loadings[5, :] = np.nan
        self.s.blind_source_separation(3, diff_order=1, mask=mask,
                                       on_loadings=True)