How to use the hyperspy.components1d.Gaussian 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 / _signals / signal1d.py View on Github external
"""

        self._check_signal_dimension_equals_one()
        if signal_range == 'interactive':
            br = BackgroundRemoval(self, background_type=background_type,
                                   polynomial_order=polynomial_order,
                                   fast=fast,
                                   plot_remainder=plot_remainder,
                                   show_progressbar=show_progressbar,
                                   zero_fill=zero_fill)
            return br.gui(display=display, toolkit=toolkit)
        else:
            if background_type in ('PowerLaw', 'Power Law'):
                background_estimator = components1d.PowerLaw()
            elif background_type == 'Gaussian':
                background_estimator = components1d.Gaussian()
            elif background_type == 'Offset':
                background_estimator = components1d.Offset()
            elif background_type == 'Polynomial':
                background_estimator = components1d.Polynomial(
                    polynomial_order)
            else:
                raise ValueError(
                    "Background type: " +
                    background_type +
                    " not recognized")
            spectra = self._remove_background_cli(
                signal_range=signal_range,
                background_estimator=background_estimator,
                fast=fast,
                zero_fill=zero_fill,
                show_progressbar=show_progressbar)
github hyperspy / hyperspy / hyperspy / datasets / artificial_data.py View on Github external
-------
    >>> s = hs.datasets.artificial_data.get_core_loss_eels_signal()
    >>> s.plot()

    See also
    --------
    get_low_loss_eels_model : get a low loss signal
    get_core_loss_eels_model : get a model instead of a signal
    get_low_loss_eels_line_scan_signal : get EELS low loss line scan
    get_core_loss_eels_line_scan_signal : get EELS core loss line scan

    """
    x = np.arange(400, 800, 1)
    arctan = components1d.Arctan(A=1, k=0.2, x0=688)
    arctan.minimum_at_zero = True
    mn_l3_g = components1d.Gaussian(A=100, centre=695, sigma=4)
    mn_l2_g = components1d.Gaussian(A=20, centre=720, sigma=4)

    data = arctan.function(x)
    data += mn_l3_g.function(x)
    data += mn_l2_g.function(x)
    data += np.random.random(size=len(x))*0.7

    s = EELSSpectrum(data)
    s.axes_manager[0].offset = x[0]
    s.metadata.General.title = 'Artifical core loss EEL spectrum'
    s.axes_manager[0].name = 'Electron energy loss'
    s.axes_manager[0].units = 'eV'
    s.set_microscope_parameters(
            beam_energy=200, convergence_angle=26, collection_angle=20)
    return s
github hyperspy / hyperspy / hyperspy / models / edsmodel.py View on Github external
raise ValueError(
                    "No elements defined, set them with `add_elements`")

        components_names = [xr.name for xr in self.xray_lines]
        xray_lines = filter(lambda x: x not in components_names, xray_lines)
        xray_lines, xray_not_here = self.signal.\
            _get_xray_lines_in_spectral_range(xray_lines)
        for xray in xray_not_here:
            warnings.warn("%s is not in the data energy range." % (xray))

        for xray_line in xray_lines:
            element, line = utils_eds._get_element_and_line(xray_line)
            line_energy, line_FWHM = self.signal._get_line_energy(
                xray_line,
                FWHM_MnKa='auto')
            component = create_component.Gaussian()
            component.centre.value = line_energy
            component.fwhm = line_FWHM
            component.centre.free = False
            component.sigma.free = False
            component.name = xray_line
            self.append(component)
            self.xray_lines.append(component)
            self[xray_line].A.map[
                'values'] = self.signal.isig[line_energy].data * \
                line_FWHM / self.signal.axes_manager[-1].scale
            self[xray_line].A.map['is_set'] = (
                np.ones(self.signal.isig[line_energy].data.shape) == 1)
            component.A.ext_force_positive = True
            for li in elements_db[element]['Atomic_properties']['Xray_lines']:
                if line[0] in li and line != li:
                    xray_sub = element + '_' + li
github hyperspy / hyperspy / hyperspy / datasets / artificial_data.py View on Github external
>>> s = hs.datasets.artificial_data.get_core_loss_eels_signal()
    >>> s.plot()

    See also
    --------
    get_low_loss_eels_model : get a low loss signal
    get_core_loss_eels_model : get a model instead of a signal
    get_low_loss_eels_line_scan_signal : get EELS low loss line scan
    get_core_loss_eels_line_scan_signal : get EELS core loss line scan

    """
    x = np.arange(400, 800, 1)
    arctan = components1d.Arctan(A=1, k=0.2, x0=688)
    arctan.minimum_at_zero = True
    mn_l3_g = components1d.Gaussian(A=100, centre=695, sigma=4)
    mn_l2_g = components1d.Gaussian(A=20, centre=720, sigma=4)

    data = arctan.function(x)
    data += mn_l3_g.function(x)
    data += mn_l2_g.function(x)
    data += np.random.random(size=len(x))*0.7

    s = EELSSpectrum(data)
    s.axes_manager[0].offset = x[0]
    s.metadata.General.title = 'Artifical core loss EEL spectrum'
    s.axes_manager[0].name = 'Electron energy loss'
    s.axes_manager[0].units = 'eV'
    s.set_microscope_parameters(
            beam_energy=200, convergence_angle=26, collection_angle=20)
    return s
github hyperspy / hyperspy / hyperspy / signal_tools.py View on Github external
def set_background_estimator(self):
        if self.background_type == 'Power Law':
            self.background_estimator = components1d.PowerLaw()
            self.bg_line_range = 'from_left_range'
        elif self.background_type == 'Gaussian':
            self.background_estimator = components1d.Gaussian()
            self.bg_line_range = 'full'
        elif self.background_type == 'Offset':
            self.background_estimator = components1d.Offset()
            self.bg_line_range = 'full'
        elif self.background_type == 'Polynomial':
            with ignore_warning(message="The API of the `Polynomial` component"):
                self.background_estimator = components1d.Polynomial(
                    self.polynomial_order)
            self.bg_line_range = 'full'
        elif self.background_type == 'Lorentzian':
            self.background_estimator = components1d.Lorentzian()
            self.bg_line_range = 'full'
        elif self.background_type == 'SkewNormal':
            self.background_estimator = components1d.SkewNormal()
            self.bg_line_range = 'full'
github hyperspy / hyperspy / hyperspy / gui / egerton_quantification.py View on Github external
def set_background_estimator(self):

        if self.background_type == 'Power Law':
            self.background_estimator = components1d.PowerLaw()
            self.bg_line_range = 'from_left_range'
        elif self.background_type == 'Gaussian':
            self.background_estimator = components1d.Gaussian()
            self.bg_line_range = 'full'
        elif self.background_type == 'Offset':
            self.background_estimator = components1d.Offset()
            self.bg_line_range = 'full'
        elif self.background_type == 'Polynomial':
            self.background_estimator = components1d.Polynomial(
                self.polynomial_order)
            self.bg_line_range = 'full'
github hyperspy / hyperspy / hyperspy / datasets / artificial_data.py View on Github external
Example
    -------
    >>> s = hs.datasets.artificial_data.get_low_loss_eels_signal()
    >>> s.plot()

    See also
    --------
    get_core_loss_eels_signal : get a core loss signal
    get_core_loss_eels_model : get a core loss model
    get_low_loss_eels_line_scan_signal : get EELS low loss line scan
    get_core_loss_eels_line_scan_signal : get EELS core loss line scan

    """
    x = np.arange(-100, 400, 0.5)
    zero_loss = components1d.Gaussian(A=100, centre=4.1, sigma=1)
    plasmon = components1d.Gaussian(A=100, centre=60, sigma=20)

    data = zero_loss.function(x)
    data += plasmon.function(x)
    data += np.random.random(size=len(x))*0.7

    s = EELSSpectrum(data)
    s.axes_manager[0].offset = x[0]
    s.axes_manager[0].scale = x[1] - x[0]
    s.metadata.General.title = 'Artifical low loss EEL spectrum'
    s.axes_manager[0].name = 'Electron energy loss'
    s.axes_manager[0].units = 'eV'
    s.set_microscope_parameters(
            beam_energy=200, convergence_angle=26, collection_angle=20)
    return s
github hyperspy / hyperspy / hyperspy / misc / eds / utils.py View on Github external
energy_resolution_MnKa=energy_resolution_MnKa)
    s.add_elements(elements)
    counts_rate = 1.
    live_time = 1.
    if weight_percents is None:
        weight_percents = [100. / len(elements)] * len(elements)
    m = s.create_model()
    if len(elements) == len(weight_percents):
        for (element, weight_percent) in zip(elements, weight_percents):
            for line, properties in elements_db[
                    element]['Atomic_properties']['Xray_lines'].items():
                line_energy = properties['energy (keV)']
                ratio_line = properties['weight']
                if s._get_xray_lines_in_spectral_range(
                        [element + '_' + line])[1] == []:
                    g = components1d.Gaussian()
                    g.centre.value = line_energy
                    g.sigma.value = get_FWHM_at_Energy(
                        energy_resolution_MnKa, line_energy) / sigma2fwhm
                    g.A.value = live_time * counts_rate * \
                        weight_percent / 100 * ratio_line
                    m.append(g)
    else:
        raise ValueError("The number of elements specified is not the same \
                         as the number of weight_percents")

    s.data = m.as_signal().data
    return s
github hyperspy / hyperspy / hyperspy / datasets / artificial_data.py View on Github external
Example
    -------
    >>> s = hs.datasets.artificial_data.get_low_loss_eels_signal()
    >>> s.plot()

    See also
    --------
    get_core_loss_eels_signal : get a core loss signal
    get_core_loss_eels_model : get a core loss model
    get_core_loss_eels_line_scan_signal : core loss signal with the same size

    """
    x = np.arange(-100, 400, 0.5)
    zero_loss = components1d.Gaussian(A=100, centre=4.1, sigma=1)
    plasmon = components1d.Gaussian(A=100, centre=60, sigma=20)

    data_signal = zero_loss.function(x)
    data_signal += plasmon.function(x)
    data = np.zeros((12, len(x)))
    for i in range(12):
        data[i] += data_signal
        data[i] += np.random.random(size=len(x))*0.7

    s = EELSSpectrum(data)
    s.axes_manager.signal_axes[0].offset = x[0]
    s.axes_manager.signal_axes[0].scale = x[1] - x[0]
    s.metadata.General.title = 'Artifical low loss EEL spectrum'
    s.axes_manager.signal_axes[0].name = 'Electron energy loss'
    s.axes_manager.signal_axes[0].units = 'eV'
    s.axes_manager.navigation_axes[0].name = 'Probe position'
    s.axes_manager.navigation_axes[0].units = 'nm'