hyperspy._signals.eds module

class hyperspy._signals.eds.EDSSpectrum(*args, **kwards)

Bases: hyperspy._signals.eds.EDS_mixin, hyperspy._signals.signal1d.Signal1D

class hyperspy._signals.eds.EDS_mixin(*args, **kwards)

Bases: object

add_elements(elements)

Add elements and the corresponding X-ray lines.

The list of elements is stored in metadata.Sample.elements

Parameters

elements (list of strings) – The symbol of the elements.

Examples

>>> s = hs.datasets.example_signals.EDS_SEM_Spectrum()
>>> print(s.metadata.Sample.elements)
>>> s.add_elements(['Ar'])
>>> print(s.metadata.Sample.elements)
['Al' 'C' 'Cu' 'Mn' 'Zr']
['Al', 'Ar', 'C', 'Cu', 'Mn', 'Zr']
add_lines(lines=(), only_one=True, only_lines=('a', ))

Add X-rays lines to the internal list.

Although most functions do not require an internal list of X-ray lines because they can be calculated from the internal list of elements, ocassionally it might be useful to customize the X-ray lines to be use by all functions by default using this method. The list of X-ray lines is stored in metadata.Sample.xray_lines

Parameters
  • lines (list of strings) – A list of valid element X-ray lines to add e.g. Fe_Kb. Additionally, if metadata.Sample.elements is defined, add the lines of those elements that where not given in this list. If the list is empty (default), and metadata.Sample.elements is defined, add the lines of all those elements.

  • only_one (bool) – If False, add all the lines of each element in metadata.Sample.elements that has not line defined in lines. If True (default), only add the line at the highest energy above an overvoltage of 2 (< beam energy / 2).

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

Examples

>>> s = hs.datasets.example_signals.EDS_SEM_Spectrum()
>>> s.add_lines()
>>> print(s.metadata.Sample.xray_lines)
['Al_Ka', 'C_Ka', 'Cu_La', 'Mn_La', 'Zr_La']
>>> s = hs.datasets.example_signals.EDS_SEM_Spectrum()
>>> s.set_microscope_parameters(beam_energy=30)
>>> s.add_lines()
>>> print(s.metadata.Sample.xray_lines)
['Al_Ka', 'C_Ka', 'Cu_Ka', 'Mn_Ka', 'Zr_La']
>>> s = hs.datasets.example_signals.EDS_SEM_Spectrum()
>>> s.add_lines()
>>> print(s.metadata.Sample.xray_lines)
>>> s.add_lines(['Cu_Ka'])
>>> print(s.metadata.Sample.xray_lines)
['Al_Ka', 'C_Ka', 'Cu_La', 'Mn_La', 'Zr_La']
['Al_Ka', 'C_Ka', 'Cu_Ka', 'Cu_La', 'Mn_La', 'Zr_La']
add_xray_lines_markers(xray_lines)

Add marker on a spec.plot() with the name of the selected X-ray lines

Parameters

xray_lines (list of string) – A valid list of X-ray lines

estimate_background_windows(line_width=[2, 2], windows_width=1, xray_lines=None)

Estimate two windows around each X-ray line containing only the background.

Parameters
  • line_width (list of two floats) – The position of the two windows around the X-ray line is given by the line_width (left and right) times the calculated FWHM of the line.

  • windows_width (float) – The width of the windows is is the windows_width times the calculated FWHM of the line.

  • xray_lines (None or list of string) – If None, use metadata.Sample.elements.xray_lines. Else, provide an iterable containing a list of valid X-ray lines symbols.

Returns

windows_position – The position of the windows in energy. Each line corresponds to a X-ray line. In a line, the two first values correspond to the limits of the left window and the two last values correspond to the limits of the right window.

Return type

2D array of float

Examples

>>> s = hs.datasets.example_signals.EDS_TEM_Spectrum()
>>> s.add_lines()
>>> bw = s.estimate_background_windows(line_width=[5.0, 2.0])
>>> s.plot(background_windows=bw)
>>> s.get_lines_intensity(background_windows=bw, plot_result=True)
Fe_Ka at 6.4039 keV : Intensity = 2754.00
Pt_La at 9.4421 keV : Intensity = 15090.00
estimate_integration_windows(windows_width=2.0, xray_lines=None)

Estimate a window of integration for each X-ray line.

Parameters
  • windows_width (float) – The width of the integration windows is the ‘windows_width’ times the calculated FWHM of the line.

  • xray_lines (None or list of string) – If None, use ‘metadata.Sample.elements.xray_lines’. Else, provide an iterable containing a list of valid X-ray lines symbols.

Returns

integration_windows – The positions of the windows in energy. Each row corresponds to a X-ray line. Each row contains the left and right value of the window.

Return type

2D array of float

Examples

>>> s = hs.datasets.example_signals.EDS_TEM_Spectrum()
>>> s.add_lines()
>>> iw = s.estimate_integration_windows()
>>> s.plot(integration_windows=iw)
>>> s.get_lines_intensity(integration_windows=iw, plot_result=True)
Fe_Ka at 6.4039 keV : Intensity = 3710.00
Pt_La at 9.4421 keV : Intensity = 15872.00
get_lines_intensity(xray_lines=None, integration_windows=2.0, background_windows=None, plot_result=False, only_one=True, only_lines=('a', ), **kwargs)

Return the intensity map of selected Xray lines.

The intensities, the number of X-ray counts, are computed by suming the spectrum over the different X-ray lines. The sum window width is calculated from the energy resolution of the detector as defined in ‘energy_resolution_MnKa’ of the metadata. Backgrounds average in provided windows can be subtracted from the intensities.

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.

  • integration_windows (Float or array) – If float, the width of the integration windows is the ‘integration_windows_width’ times the calculated FWHM of the line. Else provide an array for which each row corresponds to a X-ray line. Each row contains the left and right value of the window.

  • background_windows (None or 2D array of float) – If None, no background subtraction. Else, the backgrounds average in the windows are subtracted from the return intensities. ‘background_windows’ provides the position of the windows in energy. Each line corresponds to a X-ray line. In a line, the two first values correspond to the limits of the left window and the two last values correspond to the limits of the right window.

  • 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 BaseSignal subclasses.

Return type

list

Examples

>>> s = hs.datasets.example_signals.EDS_SEM_Spectrum()
>>> s.get_lines_intensity(['Mn_Ka'], plot_result=True)
Mn_La at 0.63316 keV : Intensity = 96700.00
>>> s = hs.datasets.example_signals.EDS_SEM_Spectrum()
>>> s.plot(['Mn_Ka'], integration_windows=2.1)
>>> s.get_lines_intensity(['Mn_Ka'],
>>>                       integration_windows=2.1, plot_result=True)
Mn_Ka at 5.8987 keV : Intensity = 53597.00
>>> s = hs.datasets.example_signals.EDS_SEM_Spectrum()
>>> s.set_elements(['Mn'])
>>> s.set_lines(['Mn_Ka'])
>>> bw = s.estimate_background_windows()
>>> s.plot(background_windows=bw)
>>> s.get_lines_intensity(background_windows=bw, plot_result=True)
Mn_Ka at 5.8987 keV : Intensity = 46716.00
get_take_off_angle()

Calculate the take-off-angle (TOA).

TOA is the angle with which the X-rays leave the surface towards the detector. Parameters are read in ‘SEM.Stage.tilt_alpha’, ‘Acquisition_instrument.SEM.Detector.EDS.azimuth_angle’ and ‘SEM.Detector.EDS.elevation_angle’ in ‘metadata’.

Returns

take_off_angle – in Degree

Return type

float

Examples

>>> s = hs.datasets.example_signals.EDS_SEM_Spectrum()
>>> s.get_take_off_angle()
37.0
>>> s.set_microscope_parameters(tilt_stage=20.)
>>> s.get_take_off_angle()
57.0

See also

hs.eds.take_off_angle()

Notes

Defined by M. Schaffer et al., Ultramicroscopy 107(8), pp 587-597 (2007)

plot(xray_lines=False, only_lines=('a', 'b'), only_one=False, background_windows=None, integration_windows=None, **kwargs)

Plot the EDS spectrum. The following markers can be added

  • The position of the X-ray lines and their names.

  • The background windows associated with each X-ray lines. A black line

links the left and right window with the average value in each window.

Parameters
  • xray_lines ({False, True, 'from_elements', list of string}) – If not False, indicate the position and the name of the X-ray lines. If True, if metadata.Sample.elements.xray_lines contains a list of lines use those. If metadata.Sample.elements.xray_lines is undefined or empty or if xray_lines equals ‘from_elements’ and 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.

  • only_lines (None or list of strings) – If not None, use only the given lines (eg. (‘a’,’Kb’)). If None, use all lines.

  • 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).

  • background_windows (None or 2D array of float) – If not None, add markers at the position of the windows in energy. Each line corresponds to a X-ray lines. In a line, the two first value corresponds to the limit of the left window and the two last values corresponds to the limit of the right window.

  • integration_windows (None or 'auto' or float or 2D array of float) – If not None, add markers at the position of the integration windows. If ‘auto’ (or float), the width of the integration windows is 2.0 (or float) times the calculated FWHM of the line. see ‘estimate_integration_windows’. Else provide an array for which each row corresponds to a X-ray line. Each row contains the left and right value of the window.

  • navigator ({"auto", None, "slider", "spectrum", Signal}) – If “auto”, if navigation_dimension > 0, a navigator is provided to explore the data. If navigation_dimension is 1 and the signal is an image the navigator is a spectrum obtained by integrating over the signal axes (the image). If navigation_dimension is 1 and the signal is a spectrum the navigator is an image obtained by stacking horizontally all the spectra in the dataset. If navigation_dimension is > 1, the navigator is an image obtained by integrating the data over the signal axes. Additionaly, if navigation_dimension > 2 a window with one slider per axis is raised to navigate the data. For example, if the dataset consists of 3 navigation axes X, Y, Z and one signal axis, E, the default navigator will be an image obtained by integrating the data over E at the current Z index and a window with sliders for the X, Y and Z axes will be raised. Notice that changing the Z-axis index changes the navigator in this case. If “slider” and the navigation dimension > 0 a window with one slider per axis is raised to navigate the data. If “spectrum” and navigation_dimension > 0 the navigator is always a spectrum obtained by integrating the data over all other axes. If None, no navigator will be provided. Alternatively a Signal instance can be provided. The signal dimension must be 1 (for a spectrum navigator) or 2 (for a image navigator) and navigation_shape must be 0 (for a static navigator) or navigation_shape + signal_shape must be equal to the navigator_shape of the current object (for a dynamic navigator). If the signal dtype is RGB or RGBA this parameters has no effect and is always “slider”.

  • axes_manager ({None, axes_manager}) – If None axes_manager is used.

  • plot_markers (bool, default True) – Plot markers added using s.add_marker(marker, permanent=True). Note, a large number of markers might lead to very slow plotting.

  • norm ({‘auto’, ‘linear’, ‘log’, mpl Normalize instance or subclass},) – default is ‘auto’. Plot the intensity scale on a linear or logarithmic scale. If ‘auto’, plot the intensity on a linear scale except when power_spectrum is True, which can be used only for compatible signal. For Signal2D, a matplotlib Normalize subclass or instance can be provided.

Examples

>>> s = hs.datasets.example_signals.EDS_SEM_Spectrum()
>>> s.plot()
>>> s = hs.datasets.example_signals.EDS_SEM_Spectrum()
>>> s.plot(True)
>>> s = hs.datasets.example_signals.EDS_TEM_Spectrum()
>>> s.add_lines()
>>> bw = s.estimate_background_windows()
>>> s.plot(background_windows=bw)
>>> s = hs.datasets.example_signals.EDS_SEM_Spectrum()
>>> s.plot(['Mn_Ka'], integration_windows='auto')
>>> s = hs.datasets.example_signals.EDS_TEM_Spectrum()
>>> s.add_lines()
>>> bw = s.estimate_background_windows()
>>> s.plot(background_windows=bw, integration_windows=2.1)
rebin(new_shape=None, scale=None, crop=True, out=None)

Rebin array.

Rebin the signal into a smaller or larger shape, based on linear interpolation. Specify either new_shape or scale.

Parameters
  • new_shape (a list of floats or integer, default None) – For each dimension specify the new_shape. This will then be converted into a scale.

  • scale (a list of floats or integer, default None) – For each dimension specify the new:old pixel ratio, e.g. a ratio of 1 is no binning and a ratio of 2 means that each pixel in the new spectrum is twice the size of the pixels in the old spectrum. The length of the list should match the dimension of the numpy array. *Note : Only one of scale or new_shape should be specified otherwise the function will not run*

  • crop (bool, default True) –

    When binning by a non-integer number of pixels it is likely that the final row in each dimension contains less than the full quota to fill one pixel.

    e.g. 5*5 array binned by 2.1 will produce two rows containing 2.1 pixels and one row containing only 0.8 pixels worth. Selection of crop=’True’ or crop=’False’ determines whether or not this ‘black’ line is cropped from the final binned array or not.

    Please note that if crop=False is used, the final row in each dimension may appear black, if a fractional number of pixels are left over. It can be removed but has been left to preserve total counts before and after binning.

  • out (Signal or None) – If None, a new Signal is created with the result of the operation and returned (default). If a Signal is passed, it is used to receive the output of the operation, and nothing is returned.

Returns

s

Return type

Signal subclass

Examples

>>> spectrum = hs.signals.EDSTEMSpectrum(np.ones([4, 4, 10]))
>>> spectrum.data[1, 2, 9] = 5
>>> print(spectrum)
<EDXTEMSpectrum, title: dimensions: (4, 4|10)>
>>> print ('Sum = ', sum(sum(sum(spectrum.data))))
Sum = 164.0
>>> scale = [2, 2, 5]
>>> test = spectrum.rebin(scale)
>>> print(test)
<EDSTEMSpectrum, title: dimensions (2, 2|2)>
>>> print('Sum = ', sum(sum(sum(test.data))))
Sum =  164.0
remove_xray_lines_markers(xray_lines)

Remove marker previosuly added on a spec.plot() with the name of the selected X-ray lines

Parameters

xray_lines (list of string) – A valid list of X-ray lines to remove

set_elements(elements)

Erase all elements and set them.

Parameters

elements (list of strings) – A list of chemical element symbols.

Examples

>>> s = hs.datasets.example_signals.EDS_SEM_Spectrum()
>>> print(s.metadata.Sample.elements)
>>> s.set_elements(['Al'])
>>> print(s.metadata.Sample.elements)
['Al' 'C' 'Cu' 'Mn' 'Zr']
['Al']
set_lines(lines, only_one=True, only_lines=('a', ))

Erase all Xrays lines and set them.

See add_lines for details.

Parameters
  • lines (list of strings) – A list of valid element X-ray lines to add e.g. Fe_Kb. Additionally, if metadata.Sample.elements is defined, add the lines of those elements that where not given in this list.

  • only_one (bool) – If False, add all the lines of each element in metadata.Sample.elements that has not line defined in lines. If True (default), only add the line at the highest energy above an overvoltage of 2 (< beam energy / 2).

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

Examples

>>> s = hs.datasets.example_signals.EDS_SEM_Spectrum()
>>> s.add_lines()
>>> print(s.metadata.Sample.xray_lines)
>>> s.set_lines(['Cu_Ka'])
>>> print(s.metadata.Sample.xray_lines)
['Al_Ka', 'C_Ka', 'Cu_La', 'Mn_La', 'Zr_La']
['Al_Ka', 'C_Ka', 'Cu_Ka', 'Mn_La', 'Zr_La']
sum(axis=None, out=None)

Sum the data over the given axes.

Parameters
  • axis (int, str, axis, tuple of axis or None) – Either one on its own, or many axes in a tuple can be passed. In both cases the axes can be passed directly, or specified using the index in axes_manager or the name of the axis. Any duplicates are removed. If None, the operation is performed over all navigation axes (default).

  • out (Signal or None) – If None, a new Signal is created with the result of the operation and returned (default). If a Signal is passed, it is used to receive the output of the operation, and nothing is returned.

  • rechunk (bool) – Only has effect when operating on lazy signal. If True (default), the data may be automatically rechunked before performing this operation.

Returns

s

Return type

Signal

See also

max(), min(), mean(), std(), var(), indexmax(), valuemax(), amax()

Examples

>>> import numpy as np
>>> s = BaseSignal(np.random.random((64,64,1024)))
>>> s.data.shape
(64,64,1024)
>>> s.sum(-1).data.shape
(64,64)
class hyperspy._signals.eds.LazyEDSSpectrum(*args, **kwards)

Bases: hyperspy._signals.eds.EDSSpectrum, hyperspy._signals.signal1d.LazySignal1D