How to use the hyperspy.signals.Signal2D function in hyperspy

To help you get started, we’ve selected a few hyperspy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pyxem / pyxem / tests / test_diffraction_signal.py View on Github external
def test_get_direct_beam_mask(self, diffraction_pattern, center, mask_expected):
        mask_calculated = diffraction_pattern.get_direct_beam_mask(2, center=center)
        assert isinstance(mask_calculated, Signal2D)
        assert np.equal(mask_calculated, mask_expected)
github pyxem / pyxem / pycrystem / utils / strain_utils.py View on Github external
"""
    arr_shape = (R.axes_manager._navigation_shape_in_array
                 if R.axes_manager.navigation_size > 0
                 else [1, ])
    T = np.zeros(arr_shape, dtype=object)


    for z, indices in zip(R._iterate_signal(),
                          R.axes_manager._array_indices_generator()):
        # T[indices] = math.acos(R.data[indices][0,0])
        # Insert check here to make sure that R is valid rotation matrix.
        # theta12 = math.asin(R.data[indices][0,1])
        T[indices] = -math.asin(R.data[indices][1,0])
        # theta22 = math.acos(R.data[10,30][1,1])
    X = Signal2D(T.astype(float))

    return X
github pyxem / pyxem / pyxem / signals / electron_diffraction.py View on Github external
Radius for the circular mask in pixel units.
        center : tuple, optional
            User specified (x, y) position of the diffraction pattern center.
            i.e. the direct beam position. If None (default) it is assumed that
            the direct beam is at the center of the diffraction pattern.

        Return
        ------
        signal-mask : ndarray
            The mask of the direct beam
        """
        shape = self.axes_manager.signal_shape
        if center is None:
            center = (shape[1] - 1) / 2, (shape[0] - 1) / 2

        signal_mask = Signal2D(circular_mask(shape=shape,
                                             radius=radius,
                                             center=center))

        return signal_mask
github pyxem / pyxem / pyxem / signals / segments.py View on Github external
correlated_loadings = np.append(
                correlated_loadings,
                np.array([np.sum(loadings[add_indices], axis=0)]),
                axis=0)
            correlated_factors = np.append(
                correlated_factors,
                np.array([np.sum(factors[add_indices], axis=0)]),
                axis=0)

            loadings = np.delete(loadings, add_indices, axis=0)
            factors = np.delete(factors, add_indices, axis=0)

        correlated_loadings = Signal2D(np.delete(
            correlated_loadings, 0, axis=0))
        correlated_factors = Signal2D(np.delete(correlated_factors, 0, axis=0))
        learning_segment = LearningSegment(
            factors=correlated_factors, loadings=correlated_loadings)
        return learning_segment
github pyxem / pyxem / pyxem / signals / electron_diffraction.py View on Github external
def __init__(self, *args, **kwargs):
        Signal2D.__init__(self, *args, **kwargs)
        # Set default attributes
        if 'Acquisition_instrument.TEM' not in self.metadata:
            if 'Acquisition_instrument.SEM' in self.metadata:
                self.metadata.set_item(
                    "Acquisition_instrument.TEM",
                    self.metadata.Acquisition_instrument.SEM)
                del self.metadata.Acquisition_instrument.SEM
        self.decomposition.__func__.__doc__ = BaseSignal.decomposition.__doc__
github hyperspy / hyperspy / hyperspy / _signals / hologram_image.py View on Github external
--------
        >>> import hyperspy.api as hs
        >>> s = hs.datasets.example_signals.object_hologram()
        >>> sb_position = s.estimate_sideband_position()
        >>> sb_size = s.estimate_sideband_size(sb_position)
        >>> sb_size.data
        >>> wave = s.reconstruct_phase(sb_position=sb_position, sb_size=sb_size)

        """

        # TODO: Use defaults for choosing sideband, smoothness, relative filter size and output shape if not provided
        # TODO: Plot FFT with marked SB and SB filter if plotting is enabled

        # Parsing reference:
        if not isinstance(reference, HologramImage):
            if isinstance(reference, Signal2D):
                if (not reference.axes_manager.navigation_shape == self.axes_manager.navigation_shape
                    and reference.axes_manager.navigation_size):

                    raise ValueError('The navigation dimensions of object and reference holograms do not match')

                _logger.warning('The reference image signal type is not HologramImage. It will '
                                'be converted to HologramImage automatically.')
                reference.set_signal_type('hologram')
            elif reference is not None:
                reference = HologramImage(reference)

        # Testing match of navigation axes of reference and self (exception: reference nav_dim=1):
        if (reference and not reference.axes_manager.navigation_shape == self.axes_manager.navigation_shape
            and reference.axes_manager.navigation_size):

            raise ValueError('The navigation dimensions of object and reference holograms do not match')
github pyxem / pyxem / pyxem / signals / diffraction2d.py View on Github external
"""Generate a signal mask for the direct beam.

        Parameters
        ----------
        radius : float
            Radius for the circular mask in pixel units.

        Return
        ------
        signal-mask : ndarray
            The mask of the direct beam
        """
        shape = self.axes_manager.signal_shape
        center = (shape[1] - 1) / 2, (shape[0] - 1) / 2

        signal_mask = Signal2D(circular_mask(shape=shape,
                                             radius=radius,
                                             center=center))

        return signal_mask
github pyxem / pyxem / pyxem / generators / variance_generator.py View on Github external
-------

        vardps : DiffractionVariance2D
            A DiffractionVariance2D object containing the mean DP, mean
            squared DP, and variance DP.
        """

        dp = self.signal
        mean_dp = dp.mean((0, 1))
        if set_data_type is None:
            meansq_dp = Signal2D(np.square(dp.data)).mean((0, 1))
        else:
            meansq_dp = Signal2D(np.square(dp.data.astype(set_data_type))).mean((0, 1))

        normvar = (meansq_dp.data / np.square(mean_dp.data)) - 1.
        var_dp = Signal2D(normvar)
        corr_var_array = var_dp.data - (np.divide(dqe, mean_dp.data))
        corr_var_array[np.isinf(corr_var_array)] = 0
        corr_var_array[np.isnan(corr_var_array)] = 0
        corr_var = Signal2D(corr_var_array)
        vardps = stack((mean_dp, meansq_dp, var_dp, corr_var))
        sig_x = vardps.data.shape[1]
        sig_y = vardps.data.shape[2]

        dv = DiffractionVariance2D(vardps.data.reshape((2, 2, sig_x, sig_y)))

        dv = transfer_signal_axes(dv, self.signal)

        return dv
github pyxem / pyxem / pyxem / signals / electron_diffraction.py View on Github external
"""Signal class for Electron Diffraction data

"""

from hyperspy._signals.lazy import LazySignal
from hyperspy.api import interactive, stack
from hyperspy.components1d import Voigt, Exponential, Polynomial
from hyperspy.signals import Signal1D, Signal2D, BaseSignal
from pyxem.signals.diffraction_profile import DiffractionProfile
from pyxem.signals.diffraction_vectors import DiffractionVectors
from pyxem.utils.expt_utils import *
from pyxem.utils.peakfinders2D import *
from pyxem.utils import peakfinder2D_gui


class ElectronDiffraction(Signal2D):
    _signal_type = "electron_diffraction"

    def __init__(self, *args, **kwargs):
        Signal2D.__init__(self, *args, **kwargs)
        # Set default attributes
        if 'Acquisition_instrument.TEM' not in self.metadata:
            if 'Acquisition_instrument.SEM' in self.metadata:
                self.metadata.set_item(
                    "Acquisition_instrument.TEM",
                    self.metadata.Acquisition_instrument.SEM)
                del self.metadata.Acquisition_instrument.SEM
        self.decomposition.__func__.__doc__ = BaseSignal.decomposition.__doc__

    def set_experimental_parameters(self,
                                    accelerating_voltage=None,
                                    camera_length=None,
github hyperspy / hyperspyUI / hyperspyui / mainwindow.py View on Github external
# The list of signal types is maintained as a list here and in
        # self.signal_types, as the names can be adapted, and since they need
        # to be diferentiated based on behavior either way.
        if signal is None:
            signal = self.get_selected_wrapper()
        self.record_code("signal = ui.get_selected_signal()")

        # Sanity check
        if signal_type not in list(self.signal_types.keys()):
            raise ValueError()

        self.setUpdatesEnabled(False)
        try:
            if signal_type in ['2D Signal', 'Complex Signal 2D']:
                if not isinstance(signal.signal,
                                  (hyperspy.signals.Signal2D,
                                   hyperspy.signals.ComplexSignal2D)):
                    signal.as_signal2D((0, 1))
                    self.record_code("signal = signal.as_signal2D((0, 1))")
            else:
                if isinstance(signal.signal,
                              (hyperspy.signals.Signal2D,
                               hyperspy.signals.ComplexSignal2D)):
                    signal.as_signal1D(0)
                    self.record_code("signal = signal.as_signal1D(0)")

            if signal_type in ['EELS', 'EDS SEM', 'EDS TEM']:
                underscored = signal_type.replace(" ", "_")
                signal.signal.set_signal_type(underscored)
                self.record_code("signal.set_signal_type('%s')" % underscored)

            signal.plot()