Exemplo n.º 1
0
 def test_running(self, extrapolate_lowloss):
     s = hs.signals.EELSSpectrum(np.arange(200))
     gaussian = Gaussian()
     gaussian.A.value = 50
     gaussian.sigma.value = 10
     gaussian.centre.value = 20
     s_ll = hs.signals.EELSSpectrum(gaussian.function(np.arange(0, 200, 1)))
     s_ll.axes_manager[0].offset = -50
     s.fourier_ratio_deconvolution(s_ll,
                                   extrapolate_lowloss=extrapolate_lowloss)
Exemplo n.º 2
0
    def setup_method(self, method):
        # Create an empty spectrum
        s = hs.signals.EELSSpectrum(np.zeros((3, 2, 1024)))
        energy_axis = s.axes_manager.signal_axes[0]
        energy_axis.scale = 0.02
        energy_axis.offset = -5

        gauss = Gaussian()
        gauss.centre.value = 0
        gauss.A.value = 5000
        gauss.sigma.value = 0.5
        gauss2 = Gaussian()
        gauss2.sigma.value = 0.5
        # Inflexion point 1.5
        gauss2.A.value = 5000
        gauss2.centre.value = 5
        s.data[:] = (gauss.function(energy_axis.axis) +
                     gauss2.function(energy_axis.axis))
        self.signal = s
Exemplo n.º 3
0
    def setup_method(self, method):
        # Create an empty spectrum
        s = hs.signals.EELSSpectrum(np.zeros((2, 3, 64)))
        energy_axis = s.axes_manager.signal_axes[0]
        energy_axis.scale = 0.2
        energy_axis.offset = -5

        gauss = Gaussian()
        gauss.centre.value = 0
        gauss.A.value = 5000
        gauss.sigma.value = 0.5
        s.data = s.data + gauss.function(energy_axis.axis)
        np.random.seed(1)
        s.add_gaussian_noise(1)
        self.signal = s
Exemplo n.º 4
0
class SEE(Component):
    """Secondary electron emission component for Photoemission Spectroscopy

    Attributes
    ----------
    A : float
    Phi : float
    B : float
    sigma : float
        Resolution parameter.

    """
    def __init__(self, A=1., Phi=1., B=0., sigma=0):
        Component.__init__(self, ('A', 'Phi', 'B', 'sigma'))
        self.A.value, self.Phi.value, self.B.value, self.sigma.value = \
            A, Phi, B, sigma

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

        self.convolved = True

        # Gradients
        self.A.grad = self.grad_A
        self.Phi.grad = self.grad_Phi
        self.B.grad = self.grad_B
        self.sigma.grad = self.grad_sigma

        # Resolution functions
        self.gaussian = Gaussian()
        self.gaussian.centre.free, self.gaussian.A.free = False, False
        self.gaussian.sigma.free = True
        self.gaussian.A.value = 1.

    def __repr__(self):
        return 'SEE'

    def function(self, x):
        """
        """
        if self.sigma.value:
            self.gaussian.sigma.value = self.sigma.value
            self.gaussian.origin.value = (x[-1] + x[0]) / 2
            return np.convolve(
                self.gaussian.function(x),
                np.where(
                    x > self.Phi.value,
                    self.A.value * (x - self.Phi.value) /
                    (x - self.Phi.value + self.B.value)**4, 0), 'same')
        else:
            return np.where(
                x > self.Phi.value,
                self.A.value * (x - self.Phi.value) /
                (x - self.Phi.value + self.B.value)**4, 0)

    def grad_A(self, x):
        """
        """
        if self.sigma.value:
            self.gaussian.sigma.value = self.sigma.value
            self.gaussian.origin.value = (x[-1] + x[0]) / 2
            return np.convolve(
                self.gaussian.function(x),
                np.where(x > self.Phi.value, (x - self.Phi.value) /
                         (x - self.Phi.value + self.B.value)**4, 0), 'same')
        else:
            return np.where(x > self.Phi.value, (x - self.Phi.value) /
                            (x - self.Phi.value + self.B.value)**4, 0)

    def grad_sigma(self, x):
        """
        """
        self.gaussian.sigma.value = self.sigma.value
        self.gaussian.origin.value = (x[-1] + x[0]) / 2
        return np.convolve(
            self.gaussian.grad_sigma(x),
            np.where(
                x > self.Phi.value,
                self.A.value * (x - self.Phi.value) /
                (x - self.Phi.value + self.B.value)**4, 0), 'same')

    def grad_Phi(self, x):
        """
        """
        if self.sigma.value:
            self.gaussian.sigma.value = self.sigma.value
            self.gaussian.origin.value = (x[-1] + x[0]) / 2
            return np.convolve(
                self.gaussian.function(x),
                np.where(x > self.Phi.value,
                         (4 * (x - self.Phi.value) * self.A.value) /
                         (self.B.value + x - self.Phi.value)**5 -
                         self.A.value / (self.B.value + x - self.Phi.value)**4,
                         0), 'same')
        else:
            return np.where(
                x > self.Phi.value, (4 * (x - self.Phi.value) * self.A.value) /
                (self.B.value + x - self.Phi.value)**5 - self.A.value /
                (self.B.value + x - self.Phi.value)**4, 0)

    def grad_B(self, x):
        if self.sigma.value:
            self.gaussian.sigma.value = self.sigma.value
            self.gaussian.origin.value = (x[-1] + x[0]) / 2
            return np.convolve(
                self.gaussian.function(x),
                np.where(
                    x > self.Phi.value,
                    -(4 * (x - self.Phi.value) * self.A.value) /
                    (self.B.value + x - self.Phi.value)**5, 0), 'same')
        else:
            return np.where(
                x > self.Phi.value,
                -(4 * (x - self.Phi.value) * self.A.value) /
                (self.B.value + x - self.Phi.value)**5, 0)
Exemplo n.º 5
0
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'])
        self.left.value = np.nan
        self.right.value = np.nan
        self.side_vignetting = False
        self.fix_side_vignetting()
        self.gaussian = Gaussian()
        self.gaussian.centre.free, self.gaussian.A.free = False, False
        self.sigma.value = 1.
        self.gaussian.A.value = 1.
        self.period.value = 1.
        self.extension_nch = 100
        self._position = self.optical_center

    def function(self, x):
        sigma = self.sigma.value
        x0 = self.optical_center.value
        A = self.height.value
        period = self.period.value
        la = self.left_slope.value
        ra = self.right_slope.value
        l = self.left.value
        r = self.right.value
        ex = self.extension_nch
        if self.side_vignetting is True:

            x = x.tolist()
            x = list(range(-ex, 0)) + x + \
                list(range(int(x[-1]) + 1, int(x[-1]) + ex + 1))
            x = np.array(x)
            v1 = A * np.cos((x - x0) / (2 * np.pi * period)) ** 4
            v2 = np.where(x < l,
                          1. - (l - x) * la,
                          np.where(x < r,
                                   1.,
                                   1. - (x - r) * ra))
            self.gaussian.sigma.value = sigma
            self.gaussian.origin.value = (x[-1] + x[0]) / 2
            result = np.convolve(self.gaussian.function(x), v1 * v2, 'same')
            return result[ex:-ex]
        else:
            return A * np.cos((x - x0) / (2 * np.pi * period)) ** 4

    def free_side_vignetting(self):
        self.left.free = True
        self.right.free = True
        self.left_slope.free = True
        self.right_slope.free = True
        self.sigma.free = True

    def fix_side_vignetting(self):
        self.left.free = False
        self.right.free = False
        self.left_slope.free = False
        self.right_slope.free = False
        self.sigma.free = False

    def free_cos_vignetting(self):
        self.optical_center.free = True
        self.period.free = True
        self.height.free = True

    def fix_cos_vignetting(self):
        self.optical_center.free = False
        self.period.free = False
        self.height.free = False