FitTrace

class specreduce.tracing.FitTrace(image: ~astropy.nddata.nddata.NDData, bins: int | None = None, guess: float | None = None, window: int | None = None, disp_bounds: tuple[float, float] | None = None, trace_model: ~astropy.modeling.core.Model = <Polynomial1D(1, c0=0., c1=0.)>, peak_method: ~typing.Literal['gaussian', 'centroid', 'max'] = 'max', _crossdisp_axis: int = 0, _disp_axis: int = 1, mask_treatment: ~typing.Literal['apply', 'propagate', 'apply_nan_only'] = 'apply', _save_bin_peaks_testing: bool = True)[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]

disp_bounds

The lower and upper bounds of the pixel range along the dispersion axis that is used when fitting the trace model. If None, defaults to the entire range of pixels along the dispersion axis. [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’, generic linear models are fit with the ‘LinearLSQFitter’, while the other models are fit with the ‘LMLSQFitter’. [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]

mask_treatment

Specifies how to handle masked or non-finite values in the input image. The fit cannot handle non-finite values, so only the apply, propagate, apply_nan_only options are supported. The apply option combines the existing mask with the mask derived from non-finite values, propagate expands the mask along the cross-dispersion axis (that is, a masked pixel results in the whole cross-dispersion slice being masked), and apply_nan_only drops the existing mask and replaces it with a mask derived from non-finite values.

Attributes Summary

bins

disp_bounds

guess

image

mask_treatment

peak_method

trace_model

window

Attributes Documentation

bins: int | None = None
disp_bounds: tuple[float, float] | None = None
guess: float | None = None
image: NDData = <dataclasses._MISSING_TYPE object>
mask_treatment: Literal['apply', 'propagate', 'apply_nan_only'] = 'apply'
peak_method: Literal['gaussian', 'centroid', 'max'] = 'max'
trace_model: Model = <Polynomial1D(1, c0=0., c1=0.)>
window: int | None = None