lumispy.signals.luminescence_spectrum module

Signal class for luminescence spectral data (1D).

class lumispy.signals.luminescence_spectrum.LazyLumiSpectrum(*args, **kwargs)

Bases: LazySignal, LumiSpectrum

General lazy 1D luminescence signal class.

class lumispy.signals.luminescence_spectrum.LumiSpectrum(*args, **kwargs)

Bases: Signal1D, CommonLumi

General 1D luminescence signal class.

centroid(signal_range=None, **kwargs)

Finds the centroid (center of mass) of a peak in the spectrum from the wavelength (or pixel number) and the intensity at each pixel value. It basically represents a “weighted average” of the peak.

Notes

This function only works for a single peak. If you have multiple peaks, slice the signal beforehand or use the signal_range parameter.

TODO: Implement this function for multiple peaks (with the npeaks parameter) by finding the top 2 peaks from mean spectrum and then returning a signal with 2 com.

Parameters:
  • signal_range (tuple of ints or floats, optional) – A tuple representing the indices of the signal axis (start index, end index) where the peak is located. If the tuple contains int, it slices on index. If the tuple contains float, it slices on signal units (default HyperSpy s.inav[:] functionality).

  • kwargs (dictionary) – For the scipy.interpolate.interp1d function.

Returns:

signal – Signal object containing the center of mass for every pixel. Depending on the dimensionality the type is Signal2D or a BaseSignal (for single spectrum).

Return type:

Signal2D, BaseSignal

px_to_nm_grating_solver(gamma_deg, deviation_angle_deg, focal_length_mm, ccd_width_mm, grating_central_wavelength_nm, grating_density_gr_mm, inplace=False)

Converts signal axis of 1D signal (in pixels) to wavelength, solving the grating equation. See lumispy.axes.solve_grating_equation for more details.

Parameters:
  • gamma_deg (float) – Inclination angle between the focal plane and the centre of the grating (found experimentally from calibration). In degree.

  • deviation_angle_deg (float) – Also known as included angle. It is defined as the difference between angle of diffraction (\(\beta\)) and angle of incidence (\(\alpha\)). Given by manufacturer specsheet. In degree.

  • focal_length_mm (float) – Given by manufacturer specsheet. In mm.

  • ccd_width_mm (float) – The width of the CDD. Given by manufacturer specsheet. In mm.

  • grating_central_wavelength_nm (float) – Wavelength at the centre of the grating, where exit slit is placed. In nm.

  • grating_density_gr_mm (int) – Grating density in gratings per mm.

  • inplace (bool) – If False, it returns a new object with the transformation. If True, the original object is transformed, returning no object.

Returns:

signal – A signal with calibrated wavelength units.

Return type:

LumiSpectrum

Examples

>>> s = LumiSpectrum(np.ones(20),))
>>> s.px_to_nm_grating_solver(*params, inplace=True)
>>> s.axes_manager.signal_axes[0].units == 'nm'
remove_background_from_file(background=None, inplace=False, **kwargs)

Subtract the background to the signal in all navigation axes. If no background file is passed as argument, the remove_background() from HyperSpy is called with the GUI.

Parameters:
  • background (array shape (2, n) or Signal1D) – An array containing the background x-axis and the intensity values [[xs],[ys]] or a Signal1D object. If the x-axis values do not match the signal_axes, then interpolation is done before subtraction. If only the intensity values are provided, [ys], the functions assumes no interpolation needed.

  • inplace (boolean) – If False, it returns a new object with the transformation. If True, the original object is transformed, returning no object.

Returns:

signal – A background subtracted signal.

Return type:

LumiSpectrum

Notes

This function does not work with non-uniform axes.

savetxt(filename, fmt='%.5f', delimiter='\t', axes=True, transpose=False, **kwargs)

Writes luminescence spectrum object to simple text file.

Writes single spectra to a two-column data file with signal axis as X and data as Y. Writes linescan data to file with signal axis as first row and navigation axis as first column (flipped if transpose=True).

Parameters:
  • filename (string)

  • fmt (str or sequence of strs, optional) – A single or sequence of format strings. Default is ‘%.5f’.

  • delimiter (str, optional) – String or character separating columns. Default is ‘,’

  • axes (bool, optional) – If True (default), include axes in saved file. If False, save the data array only.

  • transpose (bool, optional) – If True, transpose data array and exchange axes. Default is false. Ignored for single spectra.

  • **kwargs – Takes any additional arguments of numpy.loadtxt, e.g. newline header, footer, comments, or encoding.

See also

numpy.savetxt

Examples

>>> import lumispy as lum
>>> import numpy as np
...
>>> # Spectrum:
>>> S = lum.signals.LumiSpectrum(np.arange(5))
>>> S.savetxt('spectrum.txt')
0.00000     0.00000
1.00000     1.00000
2.00000     2.00000
3.00000     3.00000
4.00000     4.00000
...
>>> # Linescan:
>>> L = lum.signals.LumiSpectrum(np.arange(25).reshape((5,5)))
>>> L.savetxt('linescan.txt')
0.00000     0.00000 1.00000 2.00000 3.00000 4.00000
0.00000     0.00000 5.00000 10.00000        15.00000        20.00000
1.00000     1.00000 6.00000 11.00000        16.00000        21.00000
2.00000     2.00000 7.00000 12.00000        17.00000        22.00000
3.00000     3.00000 8.00000 13.00000        18.00000        23.00000
4.00000     4.00000 9.00000 14.00000        19.00000        24.00000
to_array(axes=True, transpose=False)
Returns luminescence spectrum object as numpy array (optionally

including the axes).

Returns single spectra as two-column array. Returns linescan data as array with signal axis as first row and navigation axis as first column (flipped if transpose=True).

Parameters:
  • axes (bool, optional) – If True (default), include axes in array. If False, return the data array only.

  • transpose (bool, optional) – If True, transpose data array and exchange axes. Default is false. Ignored for single spectra.

  • **kwargs – Takes any additional arguments of numpy.loadtxt, e.g. newline header, footer, comments, or encoding.

Notes

The output of this function can be used to convert a signal object to a pandas dataframe, e.g. using df = pd.Dataframe(S.to_array()).

Examples

>>> import lumispy as lum
>>> import numpy as np
...
>>> # Spectrum:
>>> S = lum.signals.LumiSpectrum(np.arange(5))
>>> S.to_array()
array([[0., 0.],
      [1., 1.],
      [2., 2.],
      [3., 3.],
      [4., 4.]])
...
>>> # Linescan:
>>> L = lum.signals.LumiSpectrum(np.arange(25).reshape((5,5)))
>>> L.to_array()
array([[ 0.,  0.,  1.,  2.,  3.,  4.],
      [ 0.,  0.,  1.,  2.,  3.,  4.],
      [ 1.,  5.,  6.,  7.,  8.,  9.],
      [ 2., 10., 11., 12., 13., 14.],
      [ 3., 15., 16., 17., 18., 19.],
      [ 4., 20., 21., 22., 23., 24.]])