# lumispy.signals.luminescence_spectrum module¶

Signal class for Luminescence spectral data (1D).

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

General lazy 1D luminescence signal class.

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

General 1D luminescence signal class.

_convert_data(newaxis, factor, inplace, jacobian, data2, var2)

Utility function to perform the data and variance conversion for signal unit transformations.

_reset_variance_linear_model()

Resets the variance linear model parameters to their default values, as they are not applicable any longer after a Jacobian transformation.

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 – A BaseSignal with signal dimension of 0, where at each navigation index there is a scalar value containing the center of mass for each navigation pixel.

Return type:

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.

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.

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

to_eV(inplace=True, jacobian=True)

Converts signal axis of 1D signal to non-linear energy axis (eV) using wavelength dependent refractive index of air. Assumes wavelength in units of nm unless the axis units are specifically set to µm.

The intensity is converted from counts/nm (counts/µm) to counts/meV by doing a Jacobian transformation, see e.g. Mooney and Kambhampati, J. Phys. Chem. Lett. 4, 3316 (2013), doi:10.1021/jz401508t, which ensures that integrated signals are correct also in the energy domain. If the variance of the signal is known, i.e. metadata.Signal.Noise_properties.variance is a signal representing the variance, a squared renormalization of the variance is performed. Note that if the variance is a number (not a signal instance), it is converted to a signal if the Jacobian transformation is performed

Parameters:
• inplace (boolean) – If False, a new signal object is created and returned. Otherwise (default) the operation is performed on the existing signal object.

• jacobian (boolean) – The default is to do the Jacobian transformation (recommended at least for luminescence signals), but the transformation can be suppressed by setting this option to False.

Examples

>>> import numpy as np
>>> from lumispy import LumiSpectrum
>>> S1 = LumiSpectrum(np.ones(20), DataAxis(axis = np.arange(200,400,10)), ))
>>> S1.to_eV()

to_invcm(inplace=True, jacobian=True)

Converts signal axis of 1D signal to non-linear wavenumber axis (cm^-1). Assumes wavelength in units of nm unless the axis units are specifically set to µm.

The intensity is converted from counts/nm (counts/µm) to counts/cm^-1 by doing a Jacobian transformation, see e.g. Mooney and Kambhampati, J. Phys. Chem. Lett. 4, 3316 (2013), doi:10.1021/jz401508t, which ensures that integrated signals are correct also in the wavenumber domain. If the variance of the signal is known, i.e. metadata.Signal.Noise_properties.variance is a signal representing the variance, a squared renormalization of the variance is performed. Note that if the variance is a number (not a signal instance), it is converted to a signal if the Jacobian transformation is performed

Parameters:
• inplace (boolean) – If False, a new signal object is created and returned. Otherwise (default) the operation is performed on the existing signal object.

• jacobian (boolean) – The default is to do the Jacobian transformation (recommended at least for luminescence signals), but the transformation can be suppressed by setting this option to False.

Examples

>>> import numpy as np
>>> from lumispy import LumiSpectrum
>>> S1 = LumiSpectrum(np.ones(20), DataAxis(axis = np.arange(200,400,10)), ))
>>> S1.to_invcm()

to_invcm_relative(laser=None, inplace=True, jacobian=False)

Converts signal axis of 1D signal to non-linear wavenumber axis (cm^-1) relative to the exciting laser wavelength (Raman/Stokes shift). Assumes wavelength in units of nm unless the axis units are specifically set to µm.

The intensity is converted from counts/nm (counts/µm) to counts/cm^-1 by doing a Jacobian transformation, see e.g. Mooney and Kambhampati, J. Phys. Chem. Lett. 4, 3316 (2013), doi:10.1021/jz401508t, which ensures that integrated signals are correct also in the wavenumber domain. If the variance of the signal is known, i.e. metadata.Signal.Noise_properties.variance is a signal representing the variance, a squared renormalization of the variance is performed. Note that if the variance is a number (not a signal instance), it is converted to a signal if the Jacobian transformation is performed

Parameters:
• inplace (boolean) – If False, a new signal object is created and returned. Otherwise (default) the operation is performed on the existing signal object.

• laser (float or None) – Laser wavelength in the same units as the signal axis. If None (default), checks if it is stored in metadata.Acquisition_instrument.Laser.wavelength.

• jacobian (boolean) – The default is not to do the Jacobian transformation for Raman shifts, but the transformation can be activated by setting this option to True.

Examples

>>> import numpy as np
>>> from lumispy import LumiSpectrum
>>> S1 = LumiSpectrum(np.ones(20), DataAxis(axis = np.arange(200,400,10)), ))
>>> S1.to_invcm(laser=325)

to_raman_shift(laser=None, inplace=True, jacobian=False)

Converts signal axis of 1D signal to non-linear wavenumber axis (cm^-1) relative to the exciting laser wavelength (Raman/Stokes shift). Assumes wavelength in units of nm unless the axis units are specifically set to µm.

The intensity is converted from counts/nm (counts/µm) to counts/cm^-1 by doing a Jacobian transformation, see e.g. Mooney and Kambhampati, J. Phys. Chem. Lett. 4, 3316 (2013), doi:10.1021/jz401508t, which ensures that integrated signals are correct also in the wavenumber domain. If the variance of the signal is known, i.e. metadata.Signal.Noise_properties.variance is a signal representing the variance, a squared renormalization of the variance is performed. Note that if the variance is a number (not a signal instance), it is converted to a signal if the Jacobian transformation is performed

Parameters:
• inplace (boolean) – If False, a new signal object is created and returned. Otherwise (default) the operation is performed on the existing signal object.

• laser (float or None) – Laser wavelength in the same units as the signal axis. If None (default), checks if it is stored in metadata.Acquisition_instrument.Laser.wavelength.

• jacobian (boolean) – The default is not to do the Jacobian transformation for Raman shifts, but the transformation can be activated by setting this option to True.

Examples

>>> import numpy as np
>>> from lumispy import LumiSpectrum
>>> S1 = LumiSpectrum(np.ones(20), DataAxis(axis = np.arange(200,400,10)), ))
>>> S1.to_invcm(laser=325)