How to use the hyperspy.component.Component 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 / hyperspy / hyperspy / _components / voigt.py View on Github external
Notes
    -----
    Ref: W.I.F. David, J. Appl. Cryst. (1986). 19, 63-64

    adjusted to use stddev and HWHM rather than FWHM parameters

    """
    # wofz function = w(z) = Fad[d][e][y]eva function = exp(-z**2)erfc(-iz)
    from scipy.special import wofz
    sigma = FWHM / 2.3548200450309493
    z = (np.asarray(x) - center + 1j * gamma) / (sigma * math.sqrt(2))
    V = wofz(z) / (math.sqrt(2 * np.pi) * sigma)
    return scale * V.real


class Voigt(Component):

    """Voigt profile component with support for shirley background,
    non_isochromaticity,transmission_function corrections and spin orbit
    splitting specially suited for Photoemission spectroscopy data analysis.

    f(x) = G(x)*L(x) where G(x) is the Gaussian function and L(x) is the
    Lorentzian function

    Attributes
    ----------

    area : Parameter
    centre: Parameter
    FWHM : Parameter
    gamma : Parameter
    resolution : Parameter
github hyperspy / hyperspy / hyperspy / gui / egerton_quantification.py View on Github external
from hyperspy.gui.tools import SpanSelectorInSignal1D


class BackgroundRemoval(SpanSelectorInSignal1D):
    background_type = t.Enum(
        'Power Law',
        'Gaussian',
        'Offset',
        'Polynomial',
        default='Power Law')
    polynomial_order = t.Range(1, 10)
    fast = t.Bool(True,
                  desc=("Perform a fast (analytic, but possibly less accurate)"
                        " estimation of the background. Otherwise use "
                        "non-linear least squares."))
    background_estimator = t.Instance(Component)
    bg_line_range = t.Enum('from_left_range',
                           'full',
                           'ss_range',
                           default='full')
    hi = t.Int(0)

    def __init__(self, signal):
        super(BackgroundRemoval, self).__init__(signal)
        self.set_background_estimator()
        self.bg_line = None

    def on_disabling_span_selector(self):
        if self.bg_line is not None:
            self.bg_line.close()
            self.bg_line = None
github hyperspy / hyperspy / hyperspy / _components / expression.py View on Github external
... name='my function')
        >>> comp.parameters
        (,
         )

        """

        import sympy
        self._add_rotation = add_rotation
        self._str_expression = expression
        if rotation_center is None:
            self.compile_function(module=module, position=position)
        else:
            self.compile_function(module=module, position=rotation_center)
        # Initialise component
        Component.__init__(self, self._parameter_strings)
        # When creating components using Expression (for example GaussianHF)
        # we shouldn't add anything else to the _whitelist as the
        # component should be initizialized with its own kwargs.
        # An exception is "module"
        self._whitelist['module'] = ('init', module)
        if self.__class__ is Expression:
            self._whitelist['expression'] = ('init', expression)
            self._whitelist['name'] = ('init', name)
            self._whitelist['position'] = ('init', position)
            if self._is2D:
                self._whitelist['add_rotation'] = ('init', self._add_rotation)
                self._whitelist['rotation_center'] = ('init', rotation_center)
        self.name = name
        # Set the position parameter
        if position:
            if self._is2D:
github hyperspy / hyperspy / hyperspy / _components / error_function.py View on Github external
def __init__(self):
        Component.__init__(self, ['A', 'sigma', 'origin'])

        # Boundaries
        self.A.bmin = 0.
        self.A.bmax = None

        self.sigma.bmin = None
        self.sigma.bmax = None

        self.isbackground = False
        self.convolved = True

        # Gradients
        self.A.grad = self.grad_A
        self.sigma.grad = self.grad_sigma
        self.origin.grad = self.grad_origin
        self._position = self.origin
github hyperspy / hyperspy / hyperspy / _components / scalable_fixed_pattern2d.py View on Github external
# (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 .


from hyperspy.component import Component
from scipy.interpolate import interp2d


class ScalableFixedPattern2D(Component):
    #TODO: updated docstring
    """Fixed pattern component with interpolation support.

        f(x,y) = a*s(b*x-x0) + c

    +------------+-----------+
    | Parameter  | Attribute |
    +------------+-----------+
    +------------+-----------+
    |     a      |  yscale   |
    +------------+-----------+
    |     b      |  xscale   |
    +------------+-----------+
    |    x0      |  shift    |
    +------------+-----------+
github hyperspy / hyperspy / hyperspy / _components / eels_vignetting.py View on Github external
# (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.component import Component
from hyperspy._components.gaussian import Gaussian


class Vignetting(Component):

    """
    Model the vignetting of the lens with a cos^4 law multiplied by lines on
    the edges
    """

    def __init__(self):
        Component.__init__(self,
                           ['optical_center',
                            'height',
                            'period',
                            'left_slope',
                            'right_slope',
                            'left',
                            'right',
                            'sigma'])
github hyperspy / hyperspy / hyperspy / _components / exponential.py View on Github external
# (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.component import Component


class Exponential(Component):

    """Exponentian function components

    f(x) = A*e^{-x/k}

    +------------+-----------+
    | Parameter  | Attribute |
    +------------+-----------+
    +------------+-----------+
    |     A      |     A     |
    +------------+-----------+
    |     k      |    tau    |
    +------------+-----------+

    """
github hyperspy / hyperspy / hyperspy / signal_tools.py View on Github external
'Lorentzian',
        'SkewNormal',
        default='Power Law')
    polynomial_order = t.Range(1, 10)
    fast = t.Bool(True,
                  desc=("Perform a fast (analytic, but possibly less accurate)"
                        " estimation of the background. Otherwise use "
                        "use non-linear least squares."))
    zero_fill = t.Bool(
        False,
        desc=("Set all spectral channels lower than the lower \n"
              "bound of the fitting range to zero (this is the \n"
              "default behavior of Gatan's DigitalMicrograph). \n"
              "Otherwise leave the pre-fitting region as-is \n"
              "(useful for inspecting quality of background fit)."))
    background_estimator = t.Instance(Component)
    bg_line_range = t.Enum('from_left_range',
                           'full',
                           'ss_range',
                           default='full')
    hi = t.Int(0)

    def __init__(self, signal, background_type='Power Law', polynomial_order=2,
                 fast=True, plot_remainder=True, zero_fill=False,
                 show_progressbar=None):
        super(BackgroundRemoval, self).__init__(signal)
        # setting the polynomial order will change the backgroud_type to
        # polynomial, so we set it before setting the background type
        self.polynomial_order = polynomial_order
        self.background_type = background_type
        self.set_background_estimator()
        self.fast = fast
github pyxem / pyxem / pyxem / components / scalable_reference_pattern.py View on Github external
# pyXem 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 pyXem.  If not, see .


import numpy as np
from hyperspy.component import Component
from pyxem.signals.tensor_field import DisplacementGradientMap
from skimage import transform as tf


class ScalableReferencePattern(Component):
    """Fixed diffraction pattern component which is scaled by a 2D affine
    transformation of the form:

        X = d11*x + d12*y
        Y = d21*x + d21*y

    The fixed two-dimensional pattern is defined by a single image which must
    be passed to the ScalableReferencePattern2D constructor, e.g.:

    .. code-block:: ipython

        In [1]: im = load('my_image_data.hdf5')
        In [2] : ref = components.ScalableFixedPattern(im.inav[11,30]))

    Attributes
    ----------