class Test2d:
    def setup_method(self, method):
        self.s = BaseSignal(np.random.random((2, 3)))  # (|3, 2)

    def test_as_signal2D_T(self):
        assert (self.s.data.T.shape == self.s.as_signal2D((1, 0)).data.shape)

    def test_as_signal2D(self):
        assert (self.s.data.shape == self.s.as_signal2D((0, 1)).data.shape)

    def test_as_signal1D_T(self):
        assert (self.s.data.T.shape == self.s.as_signal1D(1).data.shape)

    def test_as_signal1D(self):
        assert (self.s.data.shape == self.s.as_signal1D(0).data.shape)

    def test_s2EELS2im2s(self):
        s = self.s.as_signal1D(0)
        s.set_signal_type("EELS")
        im = s.as_signal2D((1, 0))
        assert im.metadata.Signal.signal_type == "EELS"
        s = im.as_signal1D(0)
        assert s.metadata.Signal.signal_type == "EELS"
        if s._lazy:
            _class = _lazy_signals.LazyEELSSpectrum
        else:
            _class = signals.EELSSpectrum
        assert isinstance(s, _class)
class Test3d:
    def setUp(self):
        self.s = BaseSignal(np.random.random((2, 3, 4)))  # (|4, 3, 2)

    def test_as_signal2D_contigous(self):
        nt.assert_true(self.s.as_signal2D((0, 1)).data.flags["C_CONTIGUOUS"])

    def test_as_signal2D_1(self):
        nt.assert_equal(self.s.as_signal2D((0, 1)).data.shape, (2, 3, 4))  # (2| 4, 3)

    def test_as_signal2D_2(self):
        nt.assert_equal(self.s.as_signal2D((1, 0)).data.shape, (2, 4, 3))  # (2| 3, 4)

    def test_as_signal2D_3(self):
        nt.assert_equal(self.s.as_signal2D((1, 2)).data.shape, (4, 2, 3))  # (4| 3, 2)

    def test_as_signal1D_contigous(self):
        nt.assert_true(self.s.as_signal1D(0).data.flags["C_CONTIGUOUS"])

    def test_as_signal1D_0(self):
        nt.assert_equal(self.s.as_signal1D(0).data.shape, (2, 3, 4))  # (3, 2| 4)

    def test_as_signal1D_1(self):
        nt.assert_equal(self.s.as_signal1D(1).data.shape, (2, 4, 3))  # (4, 2| 3)

    def test_as_signal1D_2(self):
        nt.assert_equal(self.s.as_signal1D(2).data.shape, (3, 4, 2))  # (4, 3| 2)

    def test_remove_axis(self):
        im = self.s.as_signal2D((-2, -1))
        im._remove_axis(-1)
        nt.assert_is_instance(im, signals.Signal1D)
Exemplo n.º 3
0
class Test2d:
    def setUp(self):
        self.s = BaseSignal(np.random.random((2, 3)))  # (|3, 2)

    def test_as_signal2D_T(self):
        nt.assert_equal(self.s.data.T.shape,
                        self.s.as_signal2D((1, 0)).data.shape)

    def test_as_signal2D(self):
        nt.assert_equal(self.s.data.shape,
                        self.s.as_signal2D((0, 1)).data.shape)

    def test_as_signal1D_T(self):
        nt.assert_equal(self.s.data.T.shape, self.s.as_signal1D(1).data.shape)

    def test_as_signal1D(self):
        nt.assert_equal(self.s.data.shape, self.s.as_signal1D(0).data.shape)

    def test_s2EELS2im2s(self):
        s = self.s.as_signal1D(0)
        s.set_signal_type("EELS")
        im = s.as_signal2D((1, 0))
        nt.assert_equal(im.metadata.Signal.signal_type, "EELS")
        s = im.as_signal1D(0)
        nt.assert_equal(s.metadata.Signal.signal_type, "EELS")
        nt.assert_is_instance(s, signals.EELSSpectrum)
class Test2d:

    def setup_method(self, method):
        self.s = BaseSignal(np.random.random((2, 3)))  # (|3, 2)

    def test_as_signal2D_T(self):
        assert (
            self.s.data.T.shape == self.s.as_signal2D((1, 0)).data.shape)

    def test_as_signal2D(self):
        assert (
            self.s.data.shape == self.s.as_signal2D((0, 1)).data.shape)

    def test_as_signal1D_T(self):
        assert (
            self.s.data.T.shape == self.s.as_signal1D(1).data.shape)

    def test_as_signal1D(self):
        assert (
            self.s.data.shape == self.s.as_signal1D(0).data.shape)

    def test_s2EELS2im2s(self):
        s = self.s.as_signal1D(0)
        s.set_signal_type("EELS")
        im = s.as_signal2D((1, 0))
        assert im.metadata.Signal.signal_type == "EELS"
        s = im.as_signal1D(0)
        assert s.metadata.Signal.signal_type == "EELS"
        if s._lazy:
            _class = signals.LazyEELSSpectrum
        else:
            _class = signals.EELSSpectrum
        assert isinstance(s, _class)
class Test1d:
    def setUp(self):
        self.s = BaseSignal(np.arange(2))

    @nt.raises(DataDimensionError)
    def test_as_signal2D(self):
        nt.assert_true((self.s.data == self.s.as_signal2D((0, 1)).data).all())

    def test_as_signal1D(self):
        nt.assert_true((self.s.data == self.s.as_signal1D(0).data).all())

    def test_set_EELS(self):
        s = self.s.as_signal1D(0)
        s.set_signal_type("EELS")
        nt.assert_equal(s.metadata.Signal.signal_type, "EELS")
        nt.assert_is_instance(s, signals.EELSSpectrum)
Exemplo n.º 6
0
class Test1d:
    def setUp(self):
        self.s = BaseSignal(np.arange(2))

    @nt.raises(DataDimensionError)
    def test_as_signal2D(self):
        nt.assert_true((self.s.data == self.s.as_signal2D((0, 1)).data).all())

    def test_as_signal1D(self):
        nt.assert_true((self.s.data == self.s.as_signal1D(0).data).all())

    def test_set_EELS(self):
        s = self.s.as_signal1D(0)
        s.set_signal_type("EELS")
        nt.assert_equal(s.metadata.Signal.signal_type, "EELS")
        nt.assert_is_instance(s, signals.EELSSpectrum)
Exemplo n.º 7
0
    def _denoised_data_to_signal(self):
        """Converts denoised data back to a HyperSpy signal."""
        signal = BaseSignal(self.Y_)

        if self._signal_type == "spectrum":
            return signal.as_signal1D(2)

        if self._signal_type == "image":
            return signal.as_signal2D((1, 2))
Exemplo n.º 8
0
class Test3d:

    def setup_method(self, method):
        self.s = BaseSignal(np.random.random((2, 3, 4)))  # (|4, 3, 2)

    def test_as_signal2D_contigous(self):
        if self.s._lazy:
            pytest.skip("Dask array flags not supported")
        assert self.s.as_signal2D((0, 1)).data.flags['C_CONTIGUOUS']

    def test_as_signal2D_1(self):
        assert (
            self.s.as_signal2D((0, 1)).data.shape == (2, 3, 4))  # (2| 4, 3)

    def test_as_signal2D_2(self):
        assert (
            self.s.as_signal2D((1, 0)).data.shape == (2, 4, 3))  # (2| 3, 4)

    def test_as_signal2D_3(self):
        assert (
            self.s.as_signal2D((1, 2)).data.shape == (4, 2, 3))  # (4| 3, 2)

    def test_as_signal1D_contigous(self):
        if self.s._lazy:
            pytest.skip("Dask array flags not supported")
        assert self.s.as_signal1D(0).data.flags['C_CONTIGUOUS']

    def test_as_signal1D_0(self):
        assert (
            self.s.as_signal1D(0).data.shape == (2, 3, 4))  # (3, 2| 4)

    def test_as_signal1D_1(self):
        assert (
            self.s.as_signal1D(1).data.shape == (2, 4, 3))  # (4, 2| 3)

    def test_as_signal1D_2(self):
        assert (
            self.s.as_signal1D(2).data.shape == (3, 4, 2))  # (4, 3| 2)

    def test_remove_axis(self):
        im = self.s.as_signal2D((-2, -1))
        im._remove_axis(-1)
        assert isinstance(im, signals.Signal1D)
class Test3d:

    def setup_method(self, method):
        self.s = BaseSignal(np.random.random((2, 3, 4)))  # (|4, 3, 2)

    def test_as_signal2D_contigous(self):
        if self.s._lazy:
            pytest.skip("Dask array flags not supported")
        assert self.s.as_signal2D((0, 1)).data.flags['C_CONTIGUOUS']

    def test_as_signal2D_1(self):
        assert (
            self.s.as_signal2D((0, 1)).data.shape == (2, 3, 4))  # (2| 4, 3)

    def test_as_signal2D_2(self):
        assert (
            self.s.as_signal2D((1, 0)).data.shape == (2, 4, 3))  # (2| 3, 4)

    def test_as_signal2D_3(self):
        assert (
            self.s.as_signal2D((1, 2)).data.shape == (4, 2, 3))  # (4| 3, 2)

    def test_as_signal1D_contigous(self):
        if self.s._lazy:
            pytest.skip("Dask array flags not supported")
        assert self.s.as_signal1D(0).data.flags['C_CONTIGUOUS']

    def test_as_signal1D_0(self):
        assert (
            self.s.as_signal1D(0).data.shape == (2, 3, 4))  # (3, 2| 4)

    def test_as_signal1D_1(self):
        assert (
            self.s.as_signal1D(1).data.shape == (2, 4, 3))  # (4, 2| 3)

    def test_as_signal1D_2(self):
        assert (
            self.s.as_signal1D(2).data.shape == (3, 4, 2))  # (4, 3| 2)

    def test_remove_axis(self):
        im = self.s.as_signal2D((-2, -1))
        im._remove_axis(-1)
        assert isinstance(im, signals.Signal1D)
class Test1d:
    def setup_method(self, method):
        self.s = BaseSignal(np.arange(2))

    def test_as_signal2D(self):
        with pytest.raises(DataDimensionError):
            assert (self.s.data == self.s.as_signal2D((0, 1)).data).all()

    def test_as_signal1D(self):
        assert (self.s.data == self.s.as_signal1D(0).data).all()

    def test_set_EELS(self):
        s = self.s.as_signal1D(0)
        s.set_signal_type("EELS")
        assert s.metadata.Signal.signal_type == "EELS"
        if s._lazy:
            _class = _lazy_signals.LazyEELSSpectrum
        else:
            _class = signals.EELSSpectrum
        assert isinstance(s, _class)
class Test1d:

    def setup_method(self, method):
        self.s = BaseSignal(np.arange(2))

    def test_as_signal2D(self):
        with pytest.raises(DataDimensionError):
            assert (self.s.data == self.s.as_signal2D(
                    (0, 1)).data).all()

    def test_as_signal1D(self):
        assert (self.s.data == self.s.as_signal1D(0).data).all()

    def test_set_EELS(self):
        s = self.s.as_signal1D(0)
        s.set_signal_type("EELS")
        assert s.metadata.Signal.signal_type == "EELS"
        if s._lazy:
            _class = signals.LazyEELSSpectrum
        else:
            _class = signals.EELSSpectrum
        assert isinstance(s, _class)
Exemplo n.º 12
0
class Test3d:
    def setUp(self):
        self.s = BaseSignal(np.random.random((2, 3, 4)))  # (|4, 3, 2)

    def test_as_signal2D_contigous(self):
        nt.assert_true(self.s.as_signal2D((0, 1)).data.flags['C_CONTIGUOUS'])

    def test_as_signal2D_1(self):
        nt.assert_equal(self.s.as_signal2D((0, 1)).data.shape,
                        (2, 3, 4))  # (2| 4, 3)

    def test_as_signal2D_2(self):
        nt.assert_equal(self.s.as_signal2D((1, 0)).data.shape,
                        (2, 4, 3))  # (2| 3, 4)

    def test_as_signal2D_3(self):
        nt.assert_equal(self.s.as_signal2D((1, 2)).data.shape,
                        (4, 2, 3))  # (4| 3, 2)

    def test_as_signal1D_contigous(self):
        nt.assert_true(self.s.as_signal1D(0).data.flags['C_CONTIGUOUS'])

    def test_as_signal1D_0(self):
        nt.assert_equal(self.s.as_signal1D(0).data.shape,
                        (2, 3, 4))  # (3, 2| 4)

    def test_as_signal1D_1(self):
        nt.assert_equal(self.s.as_signal1D(1).data.shape,
                        (2, 4, 3))  # (4, 2| 3)

    def test_as_signal1D_2(self):
        nt.assert_equal(self.s.as_signal1D(2).data.shape,
                        (3, 4, 2))  # (4, 3| 2)

    def test_remove_axis(self):
        im = self.s.as_signal2D((-2, -1))
        im._remove_axis(-1)
        nt.assert_is_instance(im, signals.Signal1D)
class Test2d:
    def setUp(self):
        self.s = BaseSignal(np.random.random((2, 3)))  # (|3, 2)

    def test_as_signal2D_T(self):
        nt.assert_equal(self.s.data.T.shape, self.s.as_signal2D((1, 0)).data.shape)

    def test_as_signal2D(self):
        nt.assert_equal(self.s.data.shape, self.s.as_signal2D((0, 1)).data.shape)

    def test_as_signal1D_T(self):
        nt.assert_equal(self.s.data.T.shape, self.s.as_signal1D(1).data.shape)

    def test_as_signal1D(self):
        nt.assert_equal(self.s.data.shape, self.s.as_signal1D(0).data.shape)

    def test_s2EELS2im2s(self):
        s = self.s.as_signal1D(0)
        s.set_signal_type("EELS")
        im = s.as_signal2D((1, 0))
        nt.assert_equal(im.metadata.Signal.signal_type, "EELS")
        s = im.as_signal1D(0)
        nt.assert_equal(s.metadata.Signal.signal_type, "EELS")
        nt.assert_is_instance(s, signals.EELSSpectrum)
    def to_signal(self, mask=None):
        """
            Creates a hyperspy.Signal1D object with the same spectral image.

            The resulting hyperspy.Signal1D contains the full spectral image.

            Returns
            ----------
                s : hyperspy.Signal1D
                    hyperspy object
        """
        (nz, ny, nx, nf) = np.shape(self.spec_im)

        dx = (self.x_array[1] - self.x_array[0])
        dy = (self.y_array[1] - self.y_array[0])
        (units, scale) = self.get_unit_scaling()
        dx *= scale
        dy *= scale

        spec_name = 'index'
        if self.spec_units in ['nm', 'um']:
            spec_name = 'Wavelength'
        elif self.spec_units == 'eV':
            spec_name = 'E'

        dict_y = {'name': 'y', 'units': units, 'scale': dy, 'size': ny}
        dict_x = {'name': 'x', 'units': units, 'scale': dx, 'size': nx}
        dict_f = {
            'name': spec_name,
            'units': self.spec_units,
            'scale': self.spec_x_array[1] - self.spec_x_array[0],
            'size': nf,
            'offset': self.spec_x_array[0]
        }
        dict_z = {'name': 'z', 'units': units, 'size': nz}

        if nz == 1:
            s = Signal1D(np.squeeze(self.spec_im),
                         axes=[dict_y, dict_x, dict_f],
                         mask=mask)
            s.change_dtype('float64')
            return s
        else:
            dz = (self.z_array[1] - self.z_array[0]) * scale
            dict_z['scale'] = dz
            s = BaseSignal(self.spec_im, axes=[dict_z, dict_y, dict_x, dict_f])
            s.change_dtype('float64')
            return s.as_signal1D(0)