TiltSolution#
- class specreduce.tilt_solution.TiltSolution(solution: Model, disp_axis: int = 1, image_shape: tuple[int, int] | None = None)[source]#
Bases:
objectA solution for 2D spectral tilt correction.
This class encapsulates the polynomial transformation from a tilt-corrected (rectified) coordinate space to detector space. It provides methods for coordinate transformation, flux-conserving resampling, and export to a GWCS object.
- Parameters:
- solution
An Astropy compound model representing the transformation from tilt-corrected space to detector space along the dispersion axis.
- disp_axis
The index of the image’s dispersion axis, by default 1.
- image_shape
The shape of the detector image as
(ny, nx). Used to define the grid extent when computing the numerical inverse transform. If not provided here, it must be passed to_calculate_inversedirectly.
Attributes Summary
Transformation from tilt-corrected to detector space along the dispersion axis.
Dispersion-axis derivative of the tilt-corrected to detector space transformation.
Transformation from detector to tilt-corrected space along the dispersion axis.
GWCS object defining the 2D tilt-corrected-to-detector coordinate mapping.
Methods Summary
corr_to_det(disp, cdisp)Transform coordinates from the 2D tilt-corrected space to 2D detector space.
det_to_corr(disp, cdisp)Transform coordinates from 2D detector space to 2D tilt-corrected space.
from_gwcs(wcs[, disp_axis, image_shape])Create a TiltSolution from a GWCS object.
resample(flux[, nbins, bounds, bin_edges, ...])Resample a 2D spectrum from the detector space to a tilt-corrected space.
Attributes Documentation
- c2d#
Transformation from tilt-corrected to detector space along the dispersion axis.
- c2d_derivative[source]#
Dispersion-axis derivative of the tilt-corrected to detector space transformation.
- gwcs[source]#
GWCS object defining the 2D tilt-corrected-to-detector coordinate mapping.
The forward transform maps
(disp_corrected, cdisp)to(disp_detector, cdisp), where the cross-dispersion coordinate passes through unchanged.
Methods Documentation
- corr_to_det(disp: ndarray, cdisp: ndarray) tuple[ndarray, ndarray][source]#
Transform coordinates from the 2D tilt-corrected space to 2D detector space.
- Parameters:
- disp
The dispersion-axis coordinates to be transformed.
- cdisp
The cross-dispersion coordinates.
- Returns:
- tuple of (ndarray, ndarray)
A tuple containing the transformed dispersion-axis coordinates as the first element and the original cross-dispersion-axis coordinates as the second element.
- det_to_corr(disp: ndarray, cdisp: ndarray) tuple[ndarray, ndarray][source]#
Transform coordinates from 2D detector space to 2D tilt-corrected space.
- Parameters:
- disp
The dispersion-axis coordinates in detector space.
- cdisp
The cross-dispersion coordinates in detector space.
- Returns:
- tuple of (ndarray, ndarray)
A tuple containing the transformed dispersion-axis coordinates in tilt-corrected space and the original cross-dispersion coordinates.
- static from_gwcs(wcs: WCS, disp_axis: int = 1, image_shape: tuple[int, int] | None = None)[source]#
Create a TiltSolution from a GWCS object.
- resample(flux: NDData, nbins: int | None = None, bounds: tuple[float, float] | None = None, bin_edges: None | Sequence[float] = None, mask_treatment: Literal['apply', 'ignore', 'propagate', 'zero_fill', 'nan_fill', 'apply_mask_only', 'apply_nan_only'] = 'apply')[source]#
Resample a 2D spectrum from the detector space to a tilt-corrected space.
Resample a 2D spectrum from the detector space to a tilt-corrected space where the wavelength is constant along the cross-dispersion axis. The grid edges are based on the specified number of bins, bounds, or bin edges. The resampling is exact and conserves flux (as long as the tilt-corrected space covers the whole detector space.)
- Parameters:
- flux
2D spectrum as an NDData instance. The dispersion and cross-dispersion axis alignment should be the same as in the arc frames.
- nbins
Number of bins in the tilt-corrected space. If None, the number of bins will be set to the number of columns in the
fluxinput image.- bounds
Tuple specifying the start and end coordinates for the tilt-corrected space along the x-axis. If None, the bounds default to (0, number of columns in
flux).- bin_edges
Explicitly provided edges of the bins in the tilt-corrected space. If None, bin edges are automatically calculated as a uniform grid based on
nbinsandbounds.- mask_treatment
Specifies how to handle masked or non-finite values in the input image. The accepted values are:
apply: The image remains unchanged, and any existing mask is combined with a maskderived from non-finite values.
ignore: The image remains unchanged, and any existing mask is dropped.propagate: The image remains unchanged, and any masked or non-finite pixelcauses the mask to extend across the entire cross-dispersion axis.
zero_fill: Pixels that are either masked or non-finite are replaced with 0.0,and the mask is dropped.
nan_fill: Pixels that are either masked or non-finite are replaced with nan,and the mask is dropped.
apply_mask_only: The image and mask are left unmodified.apply_nan_only: The image is left unmodified, the old mask is dropped,and a new mask is created based on non-finite values.
- Returns:
- NDData
NDData instance containing the flux values resampled into the uniform grid defined by
nbins,bounds, orbin_edges.