tracespec¶
- sofia_redux.spectroscopy.tracespec.tracespec(rectimg, positions, orders=None, fwhm=1.0, step=3, sumap=3, winthresh=5, fitorder=2, fitthresh=3, polyfit_kwargs=None, info=None, fast=False, **kwargs)[source]¶
Trace spectral continua in a spatially/spectrally rectified image.
Determines trace coefficients for the center of the aperture via fits to the continuum. Within an order,
sumap
columns are added together to increase the total signal. A Gaussian is then fitted around the guess position. If withinwinthresh
pixels of a guess, the position is stored. The resulting positions are then fitted with a polynomial of degreefitorder
.The
rectimg
value should come from sofia_redux.spectroscopy.rectify.- Parameters:
- rectimgdict
Rectified image data, as returned by
sofia_redux.spectroscopy.rectify
with integer keys. Each order value is a dictionary with keys:"image"
Rectified image array. (ns, nw) array, required.
"wave"
Wave coordinates along image axis=1. (nw,) array, required.
"spatial"
Spatial coordinates along image axis=0. (ns,) array, required.
- positionsdict
List of aperture positions by order, given as arcsec up the slit. Keys are integers, values are lists of floats.
- ordersarray_like of int, optional
Order numbers to process. If not provided, all orders in
positions
will be processed.- stepint, optional
Pixel step size in the dispersion direction used to determine the trace.
- sumapint, optional
Number of columns to add together. Must be odd and less than 2 *
step
.- winthreshfloat, optional
The threshold over which an identified peak is ignored. If the difference between the guess position is larger than
winthresh
, the fitted position is ignored.- fitorderint, optional
Polynomial fit degree used to determine the trace coefficients.
- fitthreshfloat, optional
Sigma threshold used to identify outliers.
- polyfit_kwargsdict, optional
Optional keyword arguments for the polynomial fit to the trace (spatial location of peak vs wavecal). These will be passed to
sofia_redux.toolkit.fitting.polyfit
.- infodict, optional
- If supplied will be updated as follows:
- orderint
- xnumpy.ndarray
(n_apertures, n_steps) array of fitted trace pixel coordinates in x.
- ynumpy.ndarray
(n_apertures, n_steps) array of fitted trace pixel coordinates in y.
- masknumpy.ndarray
(n_apertures, n_steps) array of bool where True indicates that the peak fit on that
step
of columns was included in the final calculation of trace coefficients.- trace_modelnumpy.ndarray
(n_apertures) array containing instances of
astropy.modeling.polynomial.Polynomial1D
models if aperture traces.- fitnumpy.ndarray
(n_apertures, n_steps, n_parameters) array of peak fit coefficients calculated by
mc.fitpeaks1d
at each step.- spatialnumpy.ndarray
(n_apertures, n_steps) array containing the spatial coordinates at each step.
- wavenumpy.ndarray
(n_apertures, n_steps) array containing the wave coordinates at each step.
- peak_model
astropy.modeling.Fittable1DModel
model used to fit peaks via
fitpeaks1d
- fastbool, optional
If set, use
scipy.optimize.curve_fit
to calculate spatial peak coefficients instead of the more flexible optimization insofia_redux.toolkit.fitting.fitpeaks1d
. If NaNs may be present,fast
must be False.- kwargsdict, optional
Keyword arguments for
sofia_redux.toolkit.fitting.fitpeaks1d
. By default this will fit a single 1-D Gaussian peak and a constant background offset to each (median combined +/- sumap/2 @ step interval) column.
- Returns:
- trace_coefficientsdict
Array of polynomial fit coefficients by aperture and order. Coefficients are of the form:
spatial_position = c[0] + c[1].w + c[2].w^2 + … + c[n].w^n
where n ranges from 0 to fit_order and w is the wave value and c are the trace coefficients for a given order and aperture.
- Keys and values are:
- orderint
(n_apertures, n_coeff) array