pyspeckit 0.1 documentation

Baseline Fitting

There are a number of cool features in baselining that aren’t well-described below, partly due to Sphinx errors as of 12/22/2011.

exclude and include allow you to specify which parts of the spectrum to use for baseline fitting. Enter values as pairs of coordinates.

Excludefit makes use of an existing fit and excludes all points with signal above a (very low) threshold when fitting the baseline. Going back and forth between baseline(excludefit=True) and specfit() is a nice way to iteratively measure the baseline & emission/absorption line components.

API

class pyspeckit.spectrum.baseline.Baseline(Spectrum)

Class to measure and subtract baselines from spectra.

While the term ‘baseline’ is generally used in the radio to refer to broad-band features in a spectrum not necessarily associated with a source, in this package it refers to general continuum fitting. In principle, there’s no reason to separate ‘continuum’ and ‘spectral feature’ fitting into different categories (both require some model, data, and optional weights when fitting). In practice, however, ‘continuum’ is frequently something to be removed and ignored, while spectral features are the desired measurable quantity. In order to accurately measure spectral features, it is necessary to allow baselines of varying complexity.

The Baseline class has both interactive and command-based data selection features. It can be used to fit both polynomial and power-law continua. Blackbody fitting is not yet implemented [12/21/2011]. Baseline fitting is a necessary prerequisite for Equivalent Width measurement.

As you may observe in the comments on this code, this has been one of the buggiest and least adequately tested components of pyspeckit. Bug reports are welcome. (as of 1/15/2012, a major change has probably fixed most of the bugs, and the code base is much simpler)

__call__(*args, **kwargs)

Fit and remove a polynomial from the spectrum. It will be saved in the variable “self.basespec” and the fit parameters will be saved in “self.order”

function baseline(spectrum,xarr=None,xmin=None,xmax=None,order=1,quiet=True,exclude=None): Subtract a baseline from a spectrum If xmin,xmax are not specified, defaults to ignoring first and last 10% of spectrum

exclude is a set of start/end indices to ignore when baseline fitting (ignored by setting error to infinite in fitting procedure)

excludefit creates a mask based on the fitted gaussian model (assuming that it has a zero-height) using an exclusion level of (exclusionlevel) * the smallest gaussian peak that was fit

fit_plotted_area means that a fit will only be attempted on the region currently shown in the plot. Overridden by interactive=True or exclude=’interactive’

if fit_original is set, “basespec” is added back to the spectrum before fitting so you can run this procedure multiple times without losing information

__init__(Spectrum)
__module__ = 'pyspeckit.spectrum.baseline'
annotate(loc='upper left')
button2action(event=None, debug=False, subtract=True, fit_original=False, powerlaw=False, baseline_fit_color='orange', exclude=None, **kwargs)

Do the baseline fitting and save and plot the results.

Can specify a region to exclude using velocity units or pixel units

button3action(event=None, debug=False, subtract=True, fit_original=False, powerlaw=False, baseline_fit_color='orange', exclude=None, **kwargs)

Do the baseline fitting and save and plot the results.

Can specify a region to exclude using velocity units or pixel units

clearlegend()
copy(parent=None)

Create a copy of the baseline fit

[ parent ]
A spectroscopic axis instance that is the parent of the specfit instance. This needs to be specified at some point, but defaults to None to prevent overwriting a previous plot.
crop(x1pix, x2pix)

When spectrum.crop is called, this must be too

downsample(factor)
plot_baseline(annotate=True, baseline_fit_color='orange', **kwargs)

Overplot the baseline fit

savefit()
unsubtract()