A class to represent spectroscopic data.
This class is designed to work for spectroscopic data of ices, but may work for other types of spectroscopic data as well. This is the most basic version of the class, concerned solely with the contents of the x and y attributes.
Attributes
x | (astropy.units.Quantity) Represents the data on the “x-axis” of the spectrum, i.e. usually the wavelength or frequency |
y | (astropy.units.Quantity) Represents the data on the “x-axis” of the spectrum, i.e. the flux or optical depth |
dy | (NoneType or float) The uncertainty of y. Can be given during initialisation, or automatically calculated during baselining. (default=None) |
specname | (string) The name of the spectrum (default=’Unknown spectrum’) |
baselined | (bool) Indicates whether the spectrum has been baselined or not |
convolved | (bool) Indicates whether the spectrum has been put through convolution |
Constructor for the BaseSpectrum class. Requires x and y; everything else is optional.
Parameters: | x : astropy.units.Quantity or numpy.ndarray
y : astropy.units.Quantity or numpy.ndarray
dy : float, optional
specname : string, optional
nondata : list, optional
|
---|
Methods Summary
baseline([degree]) | Fit and subtract a polynomial baseline from the spectrum, within the specified windows. |
convert2(newunit,clone=False) | Convert the x axis data to given spectral units. |
convert2wl([clone]) | Convert the x axis data to wavelength (in microns) units. |
convert2wn([clone]) | Convert the x axis data to kayser (reciprocal wavenumber) units. |
convolve(kernel,clone=False,**kwargs) | Use astropy.convolution.convolve to convolve the y axis data of the spectrum with the given kernel. |
gconvolve(fwhm,**kwargs) | Convolve spectrum using a gaussian of given fwhm. |
info() | Prints out a simple human-readable summary of the spectrum, containing the name of the spectrum, the units on its axes, and their limits. |
interpolate(target_spectrum,clone=False) | Interpolate spectrum to match target spectrum resolution. |
max([checkrange]) | Returns maximum y of the spectrum. |
min([checkrange]) | Returns minimum y of the spectrum. |
plot(axis,x=,y=,**kwargs) | Plot the contents of the spectrum into a given matplotlib axis. |
shift(amount) | Shifts the spectrum by amount specified, in primary x axis units. |
smooth([window_len]) | Smooth the spectrum using the given window of requested type and size. |
subspectrum(limit_lower,limit_upper,clone=False) | Cropped the spectrum along along the x axis using the given inclusive limits. |
yat(x) | Return interpolated value of y at requested x. |
Methods Documentation
Fit and subtract a polynomial baseline from the spectrum, within the specified windows. The fitting windows can either be designated as a list of x axis coordinates, or specified interactively within a matplotlib plotting window.
Parameters: | degree : int, optional
windows : list or string, optional
exclusive : bool, optional
usefile : NoneType or string
|
---|
Convert the x axis data to given spectral units. Re-sort the data afterwards.
Parameters: | newunit : astropy.units.core.Unit
clone : bool, optional
|
---|
Convert the x axis data to wavelength (in microns) units. Re-sort the data afterwards.
Parameters: | clone : bool, optional
|
---|
Convert the x axis data to kayser (reciprocal wavenumber) units. Re-sort the data afterwards.
Parameters: | clone : bool, optional
|
---|
Use astropy.convolution.convolve to convolve the y axis data of the spectrum with the given kernel.
Parameters: | kernel : numpy.ndarray or astropy.convolution.Kernel
clone : bool, optional
**kwargs : Arguments, optional
|
---|
Convolve spectrum using a gaussian of given fwhm.
Parameters: | fwhm : float
**kwargs : Arguments, optional
|
---|
Prints out a simple human-readable summary of the spectrum, containing the name of the spectrum, the units on its axes, and their limits. Also shows whether the spectrum has been baselined or convolved yet.
Parameters: | None |
---|---|
Returns: | Nothing, but prints out a summary of the spectrum. |
Interpolate spectrum to match target spectrum resolution. Does not modify current spectrum, but returns a new one, which is a copy of the current spectrum but with the interpolated data on the x and y fields. The target spectrum has to be using the same units on the x and y axes as the current spectrum, or the interpolation will fail.
Parameters: | target_spectrum : BaseSpectrum
clone : bool, optional
|
---|
Returns maximum y of the spectrum. If checkrange is set, returns maximum inside of that range.
Parameters: | `checkrange` : Nonetype or list
|
---|---|
Returns: | Maximum y of either the entire spectrum or, if checkrange is set, the maximum y inside of the specified range. |
Returns minimum y of the spectrum. If checkrange is set, returns minimum inside of that range.
Parameters: | checkrange : Nonetype or list
|
---|---|
Returns: | Minimum y of either the entire spectrum or, if checkrange is set, the minimum y inside of the specified range. |
Plot the contents of the spectrum into a given matplotlib axis. Defaults to the data contained in the x and y attributes, but can also plot other data content if instructed to do so.
Parameters: | axis : matplotlib.axis
x : string, optional
y : string, optional
**kwargs : Arguments, optional
|
---|
Shifts the spectrum by amount specified, in primary x axis units.
Parameters: | x : float
|
---|
Smooth the spectrum using the given window of requested type and size. The supported smoothing functions are: Bartlett, Blackman, Hanning, Hamming, and flat (i.e. moving average). This method has been adapted from http://stackoverflow.com/a/5516430
Parameters: | window_len : int, optional
window : {‘flat’,’hanning’,’hamming’,’bartlett’,’blackman’}, optional
clone : bool, optional
|
---|
Cropped the spectrum along along the x axis using the given inclusive limits.
Parameters: | limit_lower : float
limit_upper : float
clone : bool, optional
|
---|
Return interpolated value of y at requested x.
Parameters: | x : float
|
---|---|
Returns: | The interpolated value of y at the requested x coordinate. |