hyperspy.models.edsmodel module

class hyperspy.models.edsmodel.EDSModel(spectrum, auto_background=True, auto_add_lines=True, *args, **kwargs)

Bases: hyperspy.models.model1d.Model1D

Build and fit a model of an EDS Signal1D.

Parameters
  • spectrum (an EDSSpectrum (or any EDSSpectrum subclass) instance.) –

  • auto_add_lines (boolean) – If True, automatically add Gaussians for all X-rays generated in the energy range by an element, using the edsmodel.add_family_lines method.

  • auto_background (boolean) – If True, adds automatically a polynomial order 6 to the model, using the edsmodel.add_polynomial_background method.

  • extra arguments are passed to the Model creator. (Any) –

Example

>>> m = s.create_model()
>>> m.fit()
>>> m.fit_background()
>>> m.calibrate_energy_axis('resolution')
>>> m.calibrate_xray_lines('energy', ['Au_Ma'])
>>> m.calibrate_xray_lines('sub_weight',['Mn_La'], bound=10)
add_family_lines(xray_lines='from_elements')

Create the Xray-lines instances and configure them appropiately

If a X-ray line is given, all the the lines of the familiy is added. For instance if Zn Ka is given, Zn Kb is added too. The main lines (alpha) is added to self.xray_lines

Parameters

xray_lines ({None, 'from_elements', list of string}) – If None, if metadata contains xray_lines list of lines use those. If ‘from_elements’, add all lines from the elements contains in metadata. Alternatively, provide an iterable containing a list of valid X-ray lines symbols. (eg. (‘Al_Ka’,’Zn_Ka’)).

add_polynomial_background(order=6)

Add a polynomial background.

the background is added to self.background_components

Parameters

order (int) – The order of the polynomial

as_dictionary(fullcopy=True)

Returns a dictionary of the model, including all components, degrees of freedom (dof) and chi-squared (chisq) with values.

Parameters

fullcopy (Bool (optional, True)) – Copies of objects are stored, not references. If any found, functions will be pickled and signals converted to dictionaries

Returns

  • dictionary (a complete dictionary of the model, which includes at)

  • least the following fields

    componentslist

    a list of dictionaries of components, one per

    _whitelistdictionary

    a dictionary with keys used as references for saved attributes, for more information, see hyperspy.misc.export_dictionary.export_to_dictionary()

    • any field from _whitelist.keys() *

Examples

>>> s = signals.Signal1D(np.random.random((10,100)))
>>> m = s.create_model()
>>> l1 = components1d.Lorentzian()
>>> l2 = components1d.Lorentzian()
>>> m.append(l1)
>>> m.append(l2)
>>> d = m.as_dictionary()
>>> m2 = s.create_model(dictionary=d)
calibrate_energy_axis(calibrate='resolution', xray_lines='all_alpha', **kwargs)

Calibrate the resolution, the scale or the offset of the energy axis by fitting.

Parameters
  • calibrate ('resolution' or 'scale' or 'offset') – If ‘resolution’, fits the width of Gaussians place at all x-ray lines. The width is given by a model of the detector resolution, obtained by extrapolating the energy_resolution_MnKa in metadata metadata. This method will update the value of energy_resolution_MnKa. If ‘scale’, calibrate the scale of the energy axis If ‘offset’, calibrate the offset of the energy axis

  • xray_lines (list of str or 'all_alpha') – The Xray lines. If ‘all_alpha’, fit all using all alpha lines

  • **kwargs (extra key word arguments) – All extra key word arguments are passed to fit or multifit, depending on the value of kind.

calibrate_xray_lines(calibrate='energy', xray_lines='all', bound=1, kind='single', **kwargs)

Calibrate individually the X-ray line parameters.

The X-ray line energy, the weight of the sub-lines and the X-ray line width can be calibrated.

Parameters
  • calibrate ('energy' or 'sub_weight' or 'width') – If ‘energy’, calibrate the X-ray line energy. If ‘sub_weight’, calibrate the ratio between the main line alpha and the other sub-lines of the family If ‘width’, calibrate the X-ray line width.

  • xray_lines (list of str or 'all') – The Xray lines. If ‘all’, fit all lines

  • bounds (float) – for ‘energy’ and ‘width’ the bound in energy, in eV for ‘sub_weight’ Bound the height of the peak to fraction of its height

  • kind ({'single', 'multi'}) – If ‘single’ fit only the current location. If ‘multi’ use multifit.

  • **kwargs (extra key word arguments) – All extra key word arguments are passed to fit or multifit, depending on the value of kind.

disable_xray_lines()

Disable the X-ray lines components.

enable_xray_lines()

Enable the X-ray lines components.

fit_background(start_energy=None, end_energy=None, windows_sigma=(4.0, 3.0), kind='single', **kwargs)

Fit the background in the energy range containing no X-ray line.

After the fit, the background is fixed.

Parameters
  • start_energy ({float, None}) – If float, limit the range of energies from the left to the given value.

  • end_energy ({float, None}) – If float, limit the range of energies from the right to the given value.

  • windows_sigma (tuple of two float) – The (lower, upper) bounds around each X-ray line, each as a float, to define the energy range free of X-ray lines.

  • kind ({'single', 'multi'}) – If ‘single’ fit only the current location. If ‘multi’ use multifit.

  • **kwargs (extra key word arguments) – All extra key word arguments are passed to fit or

fix_background()

Fix the background components.

fix_sub_xray_lines_weight(xray_lines='all')

Fix the weight of a sub X-ray lines to the main X-ray lines

Establish the twin on the height of sub-Xray lines (non alpha)

fix_xray_lines_energy(xray_lines='all')

Fix the X-ray line energy (shift or centre of the Gaussian)

Parameters
  • xray_lines (list of str, 'all', or 'all_alpha') – The Xray lines. If ‘all’, fit all lines. If ‘all_alpha’ fit all using all alpha lines.

  • bound (float) – the bound around the actual energy, in keV or eV

fix_xray_lines_width(xray_lines='all')

Fix the X-ray line width (sigma of the Gaussian)

Parameters
  • xray_lines (list of str, 'all', or 'all_alpha') – The Xray lines. If ‘all’, fit all lines. If ‘all_alpha’ fit all using all alpha lines.

  • bound (float) – the bound around the actual energy, in keV or eV

free_background()

Free the yscale of the background components.

free_sub_xray_lines_weight(xray_lines='all', bound=0.01)

Free the weight of a sub X-ray lines

Remove the twin on the height of sub-Xray lines (non alpha)

Parameters
  • xray_lines (list of str or 'all') – The Xray lines. If ‘all’, fit all lines

  • bounds (float) – Bound the height of the peak to a fraction of its height

free_xray_lines_energy(xray_lines='all', bound=0.001)

Free the X-ray line energy (shift or centre of the Gaussian)

Parameters
  • xray_lines (list of str or 'all') – The Xray lines. If ‘all’, fit all lines

  • bound (float) – the bound around the actual energy, in keV or eV

free_xray_lines_width(xray_lines='all', bound=0.01)

Free the X-ray line width (sigma of the Gaussian)

Parameters
  • xray_lines (list of str or 'all') – The Xray lines. If ‘all’, fit all lines

  • bound (float) – the bound around the actual energy, in keV or eV

get_lines_intensity(xray_lines=None, plot_result=False, only_one=True, only_lines=('a', ), **kwargs)

Return the fitted intensity of the X-ray lines.

Return the area under the gaussian corresping to the X-ray lines

Parameters
  • xray_lines ({None, list of string}) – If None, if metadata.Sample.elements.xray_lines contains a list of lines use those. If metadata.Sample.elements.xray_lines is undefined or empty but metadata.Sample.elements is defined, use the same syntax as add_line to select a subset of lines for the operation. Alternatively, provide an iterable containing a list of valid X-ray lines symbols.

  • plot_result (bool) – If True, plot the calculated line intensities. If the current object is a single spectrum it prints the result instead.

  • only_one (bool) – If False, use all the lines of each element in the data spectral range. If True use only the line at the highest energy above an overvoltage of 2 (< beam energy / 2).

  • only_lines ({None, list of strings}) – If not None, use only the given lines.

  • kwargs – The extra keyword arguments for plotting. See utils.plot.plot_signals

Returns

intensities – A list containing the intensities as Signal subclasses.

Return type

list

Examples

>>> m.multifit()
>>> m.get_lines_intensity(["C_Ka", "Ta_Ma"])
remove(thing)

Remove component from model.

Examples

>>> s = hs.signals.Signal1D(np.empty(1))
>>> m = s.create_model()
>>> g = hs.model.components1D.Gaussian()
>>> m.append(g)

You could remove g like this

>>> m.remove(g)

Like this:

>>> m.remove("Gaussian")

Or like this:

>>> m.remove(0)
property spectrum
property units_factor
hyperspy.models.edsmodel.eV2keV = 1000.0
hyperspy.models.edsmodel.sigma2fwhm = 2.3548200450309493