ncempy.algo.eels module¶
- ncempy.algo.eels.adaptive_background()[source]¶
An adaptive background which sum pixels in a neighborhood of each probe position to improve SNR for the background fit. This should only be used when the sampling is higher than the variation in the background signal.
- ncempy.algo.eels.create_rgb(maps, normalize=True)[source]¶
Create an image that combines the input maps into a color image. Each map will be used as the red, green, and blue channels of the final image.
- Parameters:
maps (ndarray, 3D) – A 3D array of shape (3, M, N) where the first two dimensions are the color maps and the thrid dimension indicates the red, green, and blue channels in that order.
normalize (bool) – Set the maximum pixel of each image to 1 for each channel independently. Default is True.
- Returns:
A 3D array of float values. If you pass this to matplotlib.pyplot.imshow or write it to a PNG file it will be displayed as a color image where the red, green, blue channels are properly mixed.
- Return type:
ndarray, 3D
- ncempy.algo.eels.gaussian_lorentz(x, x0, sigma, w, n, C)[source]¶
Gaussian-Lorentz mixture: n * Gaussian(x0, sigma) + (1-n) * Lorentz(x0, w) + C
- ncempy.algo.eels.map_background(spectra, bgnd_box)[source]¶
Power law background subtraction to a set of spectra.
- Parameters:
spectra (ndarray, 2D or 3D) – Spectra as a 2D array (line scan) with shape (N, energy_loss) or a 3D array (spectrum image) with shape (N, M, energy_loss).
bgnd_box (2-tuple of ints) – The starting and ending point (in pixels) for the powerLaw background subtraction.
- Returns:
The background subtracted spectra.
- Return type:
ndarray, 2D or 3D
- ncempy.algo.eels.map_sum(spectra, sig_box)[source]¶
Sum the signal in the spectrum between two pixel values. This will essentially produce a compositional map of the element of interset.
- Parameters:
spectra (ndarray, 2D or 3D) – Spectra as a 2D array (line scan) with shape (N, energy_loss) or a 3D array (spectrum image) with shape (N, M, energy_loss).
sig_box (2-tuple of ints) – The starting and ending point (in pixels) for the signal summation.
- Returns:
For a line scan the return is a 1D set of points and for a spectrum image the returned 2D array is a map.
- Return type:
ndarray, 1D or 2D
- ncempy.algo.eels.powerFit(sig, box)[source]¶
Fit a power low function to a signal inside a designated range.
- Parameters:
sig (ndarray, 1D) – The signal to fit the power law to. Usually the spectral intensity.
box (2-tuple) – The range to fit of the form (low, high) where low and high are in terms of the lowest and highest pixel number to include in the range to fit.
- Returns:
A tuple is returned. The first element contains the values of the power law background fit for all pixel values above the lowest pixel in the range and the end of the spectrum. The second element are the pixel positions of the fit.
- Return type:
- ncempy.algo.eels.pre_post_fit(energy_axis, spectra, pre, post, initial_parameters=(0, 0.15, 0.15, 0.5, 0), fit_function=None)[source]¶
Fit a Gaussian-Lorentz to pre- and post-edge signals. This is useful for low loss EELS
The function is of the form: GL = n * Gaussian(x0, sigma) + (1-n) * Lorentz(x0, w) + C
- Parameters:
energy_axis (ndarray, 1D) – The energy loss values for each spectral intensity.
spectra (ndarray, 1D) – The values of the spectra at the corresponding energy loss values.
pre (2-tuple) – Start and end pixels for the pre-edge fitting range (start, end)
post (2-tuple) – Start and end pixels for the post-edge fitting range (start, end)
initial_parameters (tuple) – The initial guess for the parameters of the form (x0, sigma, w, n, C) as described in the function definition. All values are in eV except n which is dimensionless but should be [0, 1]. Default initial parameters are for a zero loss peak centered at 0 eV with a width of 0.15 eV, 50% mixing of the gaussian/lorentz and zero offset.
fit_function (callable, optional) – The function to fit to the pre- and post-edge signals. The default is a Gaussian-Lorentz mixture as defined in the function definition. The function must take the energy loss values as the first argument and the parameters to fit as subsequent arguments.
- Returns:
A tuple contains two 1D ndarrays. The first is the energy loss values for the signal and the second is the background subtracted signal.
- Return type:
2-tuple