astropy:docs

BaseSpectrum

class omnifit.spectrum.BaseSpectrum(x, y, dy=None, specname='Unknown spectrum', nondata=[])[source] [edit on github]

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

Represents the data on the “x-axis” of the spectrum. This is stored as an astropy quantity and thus it is recommended that the class constructor is called with such an input. However, the constructor also accepts a numpy ndarray, in which case it will try to guess the units and then convert the input into an appropriate astropy quantity. The autodetection assumes the units are in kayser units (i.e. reciprocal wavenumbers with the unit cm^-1) if the mean of the input array is greater than 1000. Otherwise the autodetection assumes the units are in microns.

y : astropy.units.Quantity or numpy.ndarray

Represents the data on the “x-axis” of the spectrum. This is stored as an astropy quantity and thus it is recommended that the class constructor is called with such an input. However, the constructor also accepts a numpy ndarray, in which case it will assume that the units are in optical depth and then convert the input into this astropy quantity.

dy : float, optional

The uncertainty of y. If given, this is assumed to be the uncertainty of the y axis data in the same units as given (or assumed) with the y input. Otherwise the uncertainty is left as None during initialisation and will be calculated as part of baselining.

specname : string, optional

An optional human-readable name can be given to the spectrum via this input.

nondata : list, optional

If information unrelated to the x and y input data is stored in the class instance, the variable names in which this information is stored can be given here. This causes various internal functions (related to automatic sorting and error-checking) of the class to ignore these variables. It is not usually necessary for the user to use this input during initialisation; it is most often used by children of the BaseSpectrum class.

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

baseline(degree=1,windows=[[0.0,1.0e6]],exclusive=False,usefile=None)[source] [edit on github]

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

Degree of order on the polynomial to fit.

windows : list or string, optional

The windows can be designated in two different ways:

  • as a list of x axis coordinates, e.g. [[200,250],[300,350]] for two windows of 200 to 250, and 300 to 350.
  • in an interactive matplotlib plotting window, by setting windows to ‘manual’

In the former case, no further input is required from the user after calling baseline, but in the latter case the baseliner class is invoked from omnifit.utils.

exclusive : bool, optional

This parameter indicates whether the windows are exclusive or inclusive, i.e. whether the polynomial baseline fitting is done inside (exclusive=False) the range indicated by the windows or outside (exclusive=True) of said range.

usefile : NoneType or string

This parameter indicates whether an interactively designated baseline data is saved into a file, or if the baseline data is read from an already existing file. If the user wishes to use an existing file for a baseline, simply set usefile as the path to the pickle file created in a previous baselining session. To create a new baseline file, set windows to ‘manual’ and set usefile to point to the desired path of the new file.

convert2(newunit, clone=False)[source] [edit on github]

Convert the x axis data to given spectral units. Re-sort the data afterwards.

Parameters:

newunit : astropy.units.core.Unit

Desired (spectral) unit the x axis data should be converted to.

clone : bool, optional

If set to True, returns a modified copy of the spectrum instead of operating on the existing spectrum.

convert2wl(clone=False)[source] [edit on github]

Convert the x axis data to wavelength (in microns) units. Re-sort the data afterwards.

Parameters:

clone : bool, optional

If set to True, returns a modified copy of the spectrum instead of operating on the existing spectrum.

convert2wn(clone=False)[source] [edit on github]

Convert the x axis data to kayser (reciprocal wavenumber) units. Re-sort the data afterwards.

Parameters:

clone : bool, optional

If set to True, returns a modified copy of the spectrum instead of operating on the existing spectrum.

convolve(kernel, clone=False, **kwargs)[source] [edit on github]

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

A convolution kernel to feed into the convolution function.

clone : bool, optional

If set to True, returns a modified copy of the spectrum instead of operating on the existing spectrum.

**kwargs : Arguments, optional

This can be used to pass additional arguments to astropy.convolution.convolve.

gconvolve(fwhm, **kwargs)[source] [edit on github]

Convolve spectrum using a gaussian of given fwhm.

Parameters:

fwhm : float

The desired fwhm of the gaussian, in units of x axis.

**kwargs : Arguments, optional

This can be used to pass additional arguments to convolve.

info()[source] [edit on github]

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(target_spectrum, clone=False)[source] [edit on github]

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

The target spectrum which the x axis resolution of the current spectrum should be made to match.

clone : bool, optional

If set to True, returns a modified copy of the spectrum instead of operating on the existing spectrum.

max(checkrange=None)[source] [edit on github]

Returns maximum y of the spectrum. If checkrange is set, returns maximum inside of that range.

Parameters:

`checkrange` : Nonetype or list

If this is set to a list, the first and second items on the list are taken to indicate the range (in units of x axis) between which the maximum is looked for.

Returns:

Maximum y of either the entire spectrum or, if checkrange is set,

the maximum y inside of the specified range.

min(checkrange=None)[source] [edit on github]

Returns minimum y of the spectrum. If checkrange is set, returns minimum inside of that range.

Parameters:

checkrange : Nonetype or list

If this is set to a list, the first and second items on the list are taken to indicate the range (in units of x axis) between which the minimum is looked for.

Returns:

Minimum y of either the entire spectrum or, if checkrange is set,

the minimum y inside of the specified range.

plot(axis, x='x', y='y', **kwargs)[source] [edit on github]

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

The axis which the plot will be generated in.

x : string, optional

The name of the variable to be plotted on the x axis.

y : string, optional

The name of the variable to be plotted on the x axis.

**kwargs : Arguments, optional

This can be used to pass additional arguments to matplotlib.pyplot.plot, which is used by this method for its plotting.

shift(amount)[source] [edit on github]

Shifts the spectrum by amount specified, in primary x axis units.

Parameters:

x : float

The x axis of the entire spectrum has this number added to it, effectively shifting it.

smooth(window_len=11, window='hanning', clone=False)[source] [edit on github]

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

Desired window size, in increments of x axis.

window : {‘flat’,’hanning’,’hamming’,’bartlett’,’blackman’}, optional

Desired window type.

clone : bool, optional

If set to True, returns a modified copy of the spectrum instead of operating on the existing spectrum.

subspectrum(limit_lower, limit_upper, clone=False)[source] [edit on github]

Cropped the spectrum along along the x axis using the given inclusive limits.

Parameters:

limit_lower : float

The desired minimum x axis of the cropped spectrum, in current units of the spectrum. This limit is inclusive.

limit_upper : float

The desired maximum x axis of the cropped spectrum, in current units of the spectrum. This limit is inclusive.

clone : bool, optional

If set to True, returns a modified copy of the spectrum instead of operating on the existing spectrum.

yat(x)[source] [edit on github]

Return interpolated value of y at requested x.

Parameters:

x : float

The x axis coordinate of interest.

Returns:

The interpolated value of y at the requested x coordinate.

Page Contents