FitTrace

class specreduce.tracing.FitTrace(image: ~astropy.nddata.nddata.NDData, bins: int = None, guess: float = None, window: int = None, trace_model: ~astropy.modeling.core.Model = <Polynomial1D(1, c0=0., c1=0.)>, peak_method: str = 'max')[source]

Bases: Trace, _ImageParser

Trace the spectrum aperture in an image.

Bins along the image’s dispersion (wavelength) direction, finds each bin’s peak cross-dispersion (spatial) pixel, and uses a model to interpolate the function fitted to the peaks as a final trace. The number of bins, peak finding algorithm, and model used for fitting are customizable by the user.

Example:

trace = FitTrace(image, peak_method='gaussian', guess=trace_pos)
Parameters:
imageNDData-like or array-like, required

The image over which to run the trace. Assumes cross-dispersion (spatial) direction is axis 0 and dispersion (wavelength) direction is axis 1.

binsint, optional

The number of bins in the dispersion (wavelength) direction into which to divide the image. If not set, defaults to one bin per dispersion (wavelength) pixel in the given image. If set, requires at least 4 or N bins for a degree N trace_model, whichever is greater. [default: None]

guessint, optional

A guess at the trace’s location in the cross-dispersion (spatial) direction. If set, overrides the normal max peak finder. Good for tracing a fainter source if multiple traces are present. [default: None]

windowint, optional

Fit the trace to a region with size window * 2 around the guess position. Useful for tracing faint sources if multiple traces are present, but potentially bad if the trace is substantially bent or warped. [default: None]

trace_modelone of Chebyshev1D, Legendre1D, Polynomial1D, or Spline1D, optional

The 1-D polynomial model used to fit the trace to the bins’ peak pixels. Spline1D models are fit with Astropy’s ‘SplineSmoothingFitter’, while the other models are fit with the ‘LevMarLSQFitter’. [default: models.Polynomial1D(degree=1)]

peak_methodstring, optional

One of gaussian, centroid, or max. gaussian: Fits a gaussian to the window within each bin and adopts the central value as the peak. May work best with fewer bins on faint targets. (Based on the “kosmos” algorithm from James Davenport’s same-named repository.) centroid: Takes the centroid of the window within in bin. max: Saves the position with the maximum flux in each bin. [default: max]

Attributes Summary

bins

guess

peak_method

trace_model

window

Attributes Documentation

bins: int = None
guess: float = None
peak_method: str = 'max'
trace_model: Model = <Polynomial1D(1, c0=0., c1=0.)>
window: int = None