pyEELSMODEL.operators package

Subpackages

Submodules

pyEELSMODEL.operators.areaselection module

class pyEELSMODEL.operators.areaselection.AreaSelection(multispectrum, input_map=None, max_points=4, other_spectra=[])

Bases: Operator

Class which uses user input to return an average area of a multispectrum. This only will not work for a line scan since chosing an area out of this is a bit easier.

calculate_mask_from_coords()

Calculates the mask used from the points selected. This mask can be accessed via the attribute self.mask.

determine_input_area()

Shows an image (or plot) which is given by input map. By right clicking on the image, an area can be selected where the number of corners is defined by the max_points parameter. This function sets the proper values for self.xcoords and self.ycoords.

get_mean_from_area()

Uses the user input area to calculate the average EEL spectrum. This function uses the self.xcoords and self.ycoords to calculate the area. Therefore, it is necessary to have some values for these attributes. User input on these coordinates can be obtained via the self.determine_input_area() function. The average spectra of the self.other_spectra attribute can be accessed via the self.other_avg_spec attribute.

Returns:

s – The average spectrum from the area.

Return type:

Spectrum

property input_map
property mask
property max_points
show_area(**kwargs)

Shows the area which is selected.

pyEELSMODEL.operators.backgroundremoval module

Created on Thu Dec 9 20:46:09 2021

@author: joverbee

class pyEELSMODEL.operators.backgroundremoval.BackgroundRemoval(spectrum, signal_range, model_type='Powerlaw', linear_fitting=False, order=2, non_linear_fitter='LSQ', r_values=(2, 3))

Bases: Operator

BackgroundRemoval is a class which needs a spectrum and signal range. This class provides a workflow on going extracting the elemental map of one edge.

calculate()

Returns the background subtracted spectrum. The exclude of the spectrum will be set the same as it was before this function was called. A least squares approach is used to fit the background.

Returns:

self.results – The background subtracted spectrum

Return type:

Spectrum

calculate_multi()

Returns the background subtracted multispectrum. The exclude of the spectrum will be set the same as it was before this function was called.

Returns:

self.results – The background subtracted multispectrum

Return type:

MultiSpectrum

determine_fast_fit_parameters()

Performs the autofit over one spectrum, if the parameters need to be determined for a Multispectrum then the determine_multi_fast_fit_parameters() should be used. This is used as starting parameter for the more advanced fitting. Fast fitting only works for the powerlaw and exponential background models

determine_multi_fast_fit_parameters()

Performs the autofit over the entire multispectrum. This is used as starting parameter for the more advanced fitting. Fast fitting only works for the powerlaw and exponential background models

property do_linear_fitting
fast_calculate_multi()

Uses the parameters estimated from the autofit to remove the background this only works if the model_type is Powerlaw or Exponential

Returns:

self.fast_result – The background subtracted multispectrum using the fast fitting parameters.

Return type:

MultiSpectrum

property fast_fit
property fitter
get_background_model()
get_fitting_parameters()

Returns the fitting parameters :return:

getprogress()
include_areas()

Sets the exlude of the spectrum such that only the integration range is taken into account. It depends on the type of integration, it can be two area or just one area before the edge onset.

Parameters:

None

Return type:

None

make_background_model()

Creates a model for the background, this depends on which model_type is chosen when creating the background object. The model will be set and given as an attribute to this object.

Parameters:

None

Return type:

None

property model
property model_type
property multi_fast_fit
property non_linear_fitter
property order
quantify_from_edge(integration_range, element, edge, E0, alpha, beta, ll=None)

Calculates the abundance of the element using the background removed edge. The integration window should be added together with information on which element, and the experimental parameters. A low loss could be provided to get a more accurate result.

Parameters:
  • integration_range (tuple) – Input the expected integration range to get the elemental abundance. Just used for visualization purpose.

  • element (string) – The element of interest

  • edge (string) – The edge being used

  • E0 (float) – acceleration voltage [V]

  • alpha (float) – convergence angle [rad]

  • beta (float) – collection angle [rad]

  • ll (Spectrum or MultiSpectrum) – The low loss of the used core-loss spectrum which is used to convolve the theoretical core-loss edges and have a more accurate result.

Returns:

abundance – The calculated abundance using the background removal method. A float is returned for a spectrum and a 2d numpy array when a multispectrum is used. None is returned when this function is called before any background removal has been applied.

Return type:

float, numpy 2d array, None

set_fit_type()

Set the fitter type for the background subtraction

set_indices()

Calculates the indices used which are excluded in the fit. These indices are also used to determine a first guess of the background model. :param None:

Return type:

None

show_fit_result(index=(0, 0), integration_range=None, use_mean=False)

Shows the background fitting result. Is usefull for showing the result of the procedure to identify problems or being able to optimize the signal_range.

Parameters:
  • index (tuple) – If a multispectrum is used, then the index inputted will be used for the visualization

  • integration_range (tuple) – Input the expected integration range to get the elemental abundance. Just used for visualization purpose.

  • use_mean (boolean) – If a multispectrum is used, the average results can be shown which could be useful when wanting to decrease the noise level in the individual spectrum.

Returns:

fig – The created figure

Return type:

Figure

property signal_range
stop()

pyEELSMODEL.operators.calibratespectrum module

Created on Thu Dec 9 20:46:09 2021

@author: joverbee

class pyEELSMODEL.operators.calibratespectrum.CalibrateSpectrum(spectrum, element_list, edge_list, other_spectra=[])

Bases: Operator

The CalibrateSpectrum class provides a workflow to change the energy axis which is sometimes wrong. It does this by performing a linear fit between the measured onset energies (defined by user) and values obtained from literature.

calibrate_energy_axis()

Calibrates the energy axis using the input energies.

determine_edge_positions()

Use user input by using right mouse click to select the edge energy. After the click is performed, it is shown which edge you had selected and you can verify if this is correct.

Returns:

set_onset_edge_energies()

Calculates the list of tabulated onset energies of the edges.

show_calibration_fit()
show_real_energies()

Show the real energies from the tabulated data on the spectrum

pyEELSMODEL.operators.estimate_thickness module

class pyEELSMODEL.operators.estimate_thickness.ThicknessEstimator(spectrum, model_type='Lorentzian', signal_range=None)

Bases: Operator

Calculates the thickness of the material.

extract_vacuum(threshold, show_inelastic=True)

It can happen that vacuum is present and this can be used to estimate the thickness. The vacuum spectrum is stored as the .vacuum attribute

Parameters:
  • threshold (0 < float < 1) – The number of times the spectrum needs to be upsampled

  • show_inelastic (boolean) – Indicates whether the inelastic signal used for vacuum determination is used.

log_ratio_method()

Calculates the inelastic mean free path by esitmating the zero loss peak. The estimated zlp is stored in the .zlp attribute. The inelastic mean free path is stored in the .tlambda attribute

pyEELSMODEL.operators.multispectrumvisualizer module

class pyEELSMODEL.operators.multispectrumvisualizer.MultiSpectrumVisualizer(multispectra, input_map=None, labels=None, logscale=False)

Bases: Operator

Class which visualizes the multspectrum.

connect()

Connect to all the events we need.

disconnect()

Disconnect all callbacks.

get_indextitle(x0, y0, w, h)
on_key_press(event)
on_motion(event)

Move the rectangle if the mouse is over us.

on_press(event)

Check whether mouse is over us; if so, store some data.

on_release(event)

Clear button press information.

plot(**kwargs)
plotrect()
update_eels()
updaterect()

pyEELSMODEL.operators.splice module

class pyEELSMODEL.operators.splice.Splice(spectra, acq_times=None)

Bases: Operator

This class splines multiple spectra into each other. At this point the spectra should still overlap. The splicing first calculates a new energy axis which conveys each spectrum added to the spectra list. Then each spectrum is interpolated to the new axis and the weighted average is calcualted with the information on the acquisition time. This assumes that each spectrum is acquired with the same current. It is not needed for the dispersion to be the same. When this happens it uses the highest dispersion (lowest value) for the interpolation.

check_multispectra_validity(spectra)
get_new_energy_axis()

Determines the lowest energy, highest energy and highest dispersion from the list of spectra provided. From this information it calculates a new energy axis E

Returns:

E – The new energy axis on which each spectrum will be interpolated.

Return type:

1d numpy array

splice_multispectra()
splice_spectra()

Multiple spectra can be spliced together. This only works for spectra and not multispectra

property weights

pyEELSMODEL.operators.zlpremoval module

class pyEELSMODEL.operators.zlpremoval.ZLPRemoval(spectrum, signal_range=None, model_type='Gaussian')

Bases: Operator

Removes the ZLP from the spectrum by fitting the appropriate function to it

estimate_start_param()
estimate_start_param_multi()

Estimates the starting value of the fitting for a multispectrum when having a gaussian or lorentzian model to fit.

fit_zlp()
property fitter

The fitter used in the spectrum (now it is the LSQ since it fast and stable)

include_areas()

Sets the exlude of the spectrum such that only the integration range is taken into account.

make_zeroloss_model()

Creates a model for the zero loss peak, this depends on which model_type is chosen when creating the background object. The model is stored in the model attribute

mirrored_zlp()
property model

The model used for the fitting

property model_type
set_indices()

Calculates the indices used which are excluded in the fit. These indices are also used to determine a first guess of the background model. The result is stored in the indices attribute

set_start_parameters()
show_fit_result()
show_mirror_result()
property signal_range
property spectrum

Module contents