How to use the hyperspy.signal.Signal 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 hyperspy / hyperspyUI / hyperspyui / hooksignal.py View on Github external
#
# HyperSpyUI is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with HyperSpyUI.  If not, see .
"""
Created on Sat Feb 28 17:52:42 2015

@author: Vidar Tonaas Fauske
"""

import hyperspy.signal
orig_signal = hyperspy.signal.Signal


class HookedSignal(orig_signal):

    def plot(self, *args, **kwargs):
        _on_plotting(self, navigator="auto", axes_manager=None)
        r = super(HookedSignal, self).plot(*args, **kwargs)
        _on_plotted(self, navigator="auto", axes_manager=None)
        return r


def hook_signal():
    """
    Call this function to enable hooks of Signal
    """
    hyperspy.signal.Signal = HookedSignal
github hyperspy / hyperspy / hyperspy / _signals / spectrum.py View on Github external
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with  HyperSpy.  If not, see .

import warnings

import matplotlib.pyplot as plt
import numpy as np

from hyperspy.exceptions import DataDimensionError
from hyperspy.signal import Signal
from hyperspy.gui.egerton_quantification import SpikesRemoval


class Spectrum(Signal):

    """
    """
    _record_by = 'spectrum'

    def __init__(self, *args, **kwargs):
        Signal.__init__(self, *args, **kwargs)
        self.axes_manager.set_signal_dimension(1)

    def to_image(self):
        """Returns the spectrum as an image.

        See Also
        --------
        as_image : a method for the same purpose with more options.
        signals.Spectrum.to_image : performs the inverse operation on images.
github hyperspy / hyperspy / hyperspy / signals / aggregate.py View on Github external
if len(args)<1:
            pass
        else:
            for arg in args:
                if arg.__class__.__name__=='str':
                    if '*' in arg:
                        from glob import glob
                        flist=glob(arg)
                        for f in flist:
                            d=load(f)
                            if d.mapped_parameters.record_by=="spectrum":
                                self._add_object(d)
                    else:
                        arg=load(arg)
                        self._add_object(arg)
                elif isinstance(arg,Signal):
                    self._add_object(arg)
                else:
                    # skip over appending if something like a dict is passed as arg
                    return
            self.axes_manager.set_signal_dimension()
            smp.title="Aggregate Spectra: %s"%smp.original_files.keys()
github hyperspy / hyperspy / hyperspy / _signals / spectrum.py View on Github external
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with  HyperSpy.  If not, see .

import warnings

import matplotlib.pyplot as plt
import numpy as np

from hyperspy.exceptions import DataDimensionError
from hyperspy.signal import Signal
from hyperspy.gui.egerton_quantification import SpikesRemoval


class Spectrum(Signal):

    """
    """
    _record_by = 'spectrum'

    def __init__(self, *args, **kwargs):
        Signal.__init__(self, *args, **kwargs)
        self.axes_manager.set_signal_dimension(1)

    def to_EELS(self):
        warnings.warn(
            'This method is deprecated and and will be removed '
            'in the next version. '
            'Please use `set_signal_type("EELS")` instead',
            DeprecationWarning)
        s = self.deepcopy()
github hyperspy / hyperspy / hyperspy / _signals / fourier_transform_signal.py View on Github external
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
#  Hyperspy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with  Hyperspy.  If not, see .

import numpy as np

from hyperspy.signal import Signal

class FourierTransformSignal(Signal):
    #_signal_origin = "fourier_transform"
    _is_ft = True
    
    
    def __init__(self, *args, **kwargs):
        Signal.__init__(self, *args, **kwargs)

        
    def ifft(self, s=None, axes=None):
        """
        Compute the inverse discrete Fourier Transform.

        This function computes the inverse of the discrete
        Fourier Transform over any number of axes in an M-dimensional array by
        means of the Fast Fourier Transform (FFT).  In other words,
        ``ifftn(fftn(a)) == a`` to within numerical accuracy.
github hyperspy / hyperspyUI / hyperspyui / hooksignal.py View on Github external
def dehook_signal():
    """
    Call this function to remove hooks from Signal
    """
    hyperspy.signal.Signal = orig_signal
github hyperspy / hyperspy / hyperspy / misc / export_dictionary.py View on Github external
def reconstruct_object(flags, value):
    """ Reconstructs the value (if necessary) after having saved it in a
    dictionary
    """
    if not isinstance(flags, list):
        flags = parse_flag_string(flags)
    if 'sig' in flags:
        if isinstance(value, dict):
            from hyperspy.signal import Signal
            value = Signal(**value)
            value._assign_subclass()
        return value
    if 'fn' in flags:
        ifdill, thing = value
        if ifdill is None:
            return thing
        if ifdill in [False, 'False', b'False']:
            return types.FunctionType(marshal.loads(thing), globals())
        if ifdill in [True, 'True', b'True']:
            if not dill_avail:
                raise ValueError("the dictionary was constructed using "
                                 "\"dill\" package, which is not available on the system")
            else:
                return dill.loads(thing)
        # should not be reached
        raise ValueError("The object format is not recognized")
github hyperspy / hyperspy / hyperspy / drawing / demos.py View on Github external
def line_spectrum():
    s = Signal({'data' : np.random.random((100,1024))})
    s.plot()
github hyperspy / hyperspy / hyperspy / _signals / fourier_transform_signal.py View on Github external
Notes
        -----        
        For further information see the documentation of numpy.fft.ifft, 
        numpy.fft.ifft2 or numpy.fft.ifftn
        
        """
        dim=len(self.axes_manager.shape)
        if dim==1:
            if axes==None:
                axis=-1
            im_ifft=Signal(np.fft.ifft(self.data,n=s,axis=axis).real)
        elif dim==2:
            if axes==None:
                axes=(-2,-1)
            im_ifft=Signal(np.fft.ifft2(self.data,s=s,axes=axes).real)
        else:
            im_ifft=Signal(np.fft.ifftn(self.data,s=s,axes=axes).real)
        
        if self.axes_manager.signal_dimension==2:
            im_ifft.axes_manager.set_signal_dimension(2)
        #scale,, to be verified
        for i in range(dim):
            im_ifft.axes_manager[i].scale=1/self.axes_manager[i].scale

        return im_ifft
github hyperspy / hyperspy / hyperspy / drawing / demos.py View on Github external
def four_d_image():
    s = Signal({'data' : np.random.random((16,16,32,32))})
    s.axes_manager.axes[2].slice_bool = True
    s.plot()