HorneExtract¶
- class specreduce.extract.HorneExtract(image: NDData, trace_object: Trace, bkgrd_prof: None | Model = None, spatial_profile: str | dict = 'gaussian', variance: ndarray = None, mask: ndarray = None, unit: ndarray = None, disp_axis: int = 1, crossdisp_axis: int = 0)[source]¶
 Bases:
SpecreduceOperationPerform a Horne (a.k.a. optimal) extraction on a two-dimensional spectrum.
There are two options for fitting the spatial profile used for extraction - by default, a 1D gaussian is fit and as a uniform profile across the spectrum. Alternativley, the
self profileoption may be chosen - when this option is chosen, the spatial profile will be sampled (using a default of 10 sample bins, but can be modified withspatial_profile) and interpolated between to produce a smoothly varying spatial profile across the spectrum.If using the Gaussian option for the spatial profile, a background profile may be fit (but not subtracted) simultaneously to the data. By default, this is done with a 2nd degree polynomial. If using the
interpolated_profileoption, the background model must be set to None.- Parameters:
 - image
NDData-like or array-like, required The input 2D spectrum from which to extract a source. An NDData object must specify uncertainty and a mask. An array requires use of the
variance,mask, &unitarguments.- trace_object
Trace, required The associated 1D trace object created for the 2D image.
- disp_axisint, optional
 The index of the image’s dispersion axis. [default: 1]
- crossdisp_axisint, optional
 The index of the image’s cross-dispersion axis. [default: 0]
- bkgrd_prof
Modelor None, optional A model for the image’s background flux when using the
gaussianspatial profile. Ifspatial_profileis set togaussian, it defaults tomodels.Polynomial1D(2). Note that theinterpolated_profileoption does not support a background model, sobkgrd_profmust be left asNone.- spatial_profilestr or dict, optional
 The shape of the object profile. The first option is ‘gaussian’ to fit a uniform 1D gaussian to the average of pixels in the cross-dispersion direction. The other option is ‘interpolated_profile’ - when this option is used, the profile is sampled in bins and these samples are interpolated between to construct a continuously varying, empirical spatial profile for extraction. For this option, if passed in as a string (i.e spatial_profile=’interpolated_profile’) the default values for the number of bins used (10) and degree of interpolation (linear in x and y, by default) will be used. To set these parameters, pass in a dictionary with the keys ‘n_bins_interpolated_profile’ (which accepts an integer number of bins) and ‘interp_degree’ (which accepts an int, or tuple of ints for x and y degree, respectively). [default: gaussian]
- variance
ndarray, optional (Only used if
imageis not an NDData object.) The associated variances for each pixel in the image. Must have the same dimensions asimage. If all zeros, the variance will be ignored and treated as all ones. If any zeros, those elements will be excluded via masking. If any negative values, an error will be raised. [default: None]- mask
ndarray, optional (Only used if
imageis not an NDData object.) Whether to mask each pixel in the image. Must have the same dimensions asimage. If blank, all non-NaN pixels are unmasked. [default: None]- unit
Unitor str, optional (Only used if
imageis not an NDData object.) The associated unit for the data inimage. If blank, fluxes are interpreted in DN. [default: None]
- image
 
Attributes Summary
Methods Summary
__call__([image, trace_object, disp_axis, ...])Run the Horne calculation on a region of an image and extract a 1D spectrum.
Attributes Documentation
- spectrum¶
 
Methods Documentation
- __call__(image=None, trace_object=None, disp_axis=None, crossdisp_axis=None, bkgrd_prof=None, spatial_profile=None, n_bins_interpolated_profile=None, interp_degree_interpolated_profile=None, variance=None, mask=None, unit=None)[source]¶
 Run the Horne calculation on a region of an image and extract a 1D spectrum.
- Parameters:
 - image
NDData-like or array-like, required The input 2D spectrum from which to extract a source. An NDData object must specify uncertainty and a mask. An array requires use of the
variance,mask, &unitarguments.- trace_object
Trace, required The associated 1D trace object created for the 2D image.
- disp_axisint, optional
 The index of the image’s dispersion axis.
- crossdisp_axisint, optional
 The index of the image’s cross-dispersion axis.
- bkgrd_prof
Model, optional A model for the image’s background flux when using the
gaussianspatial profile. Ifspatial_profileis set togaussian, it defaults tomodels.Polynomial1D(2). Note that theinterpolated_profileoption does not support a background model, sobkgrd_profmust be left asNone.- spatial_profilestr or dict, optional
 The shape of the object profile. The first option is ‘gaussian’ to fit a uniform 1D gaussian to the average of pixels in the cross-dispersion direction. The other option is ‘interpolated_profile’ - when this option is used, the profile is sampled in bins and these samples are interpolated between to construct a continuously varying, empirical spatial profile for extraction. For this option, if passed in as a string (i.e spatial_profile=’interpolated_profile’) the default values for the number of bins used (10) and degree of interpolation (linear in x and y, by default) will be used. To set these parameters, pass in a dictionary with the keys ‘n_bins_interpolated_profile’ (which accepts an integer number of bins) and ‘interp_degree’ (which accepts an int, or tuple of ints for x and y degree, respectively). [default: gaussian]
- variance
ndarray, optional (Only used if
imageis not an NDData object.) The associated variances for each pixel in the image. Must have the same dimensions asimage. If all zeros, the variance will be ignored and treated as all ones. If any zeros, those elements will be excluded via masking. If any negative values, an error will be raised.- mask
ndarray, optional (Only used if
imageis not an NDData object.) Whether to mask each pixel in the image. Must have the same dimensions asimage. If blank, all non-NaN pixels are unmasked.- unit
Unitor str, optional (Only used if
imageis not an NDData object.) The associated unit for the data inimage. If blank, fluxes are interpreted in DN.
- image
 - Returns:
 - spec_1d
Spectrum1D The final, Horne extracted 1D spectrum.
- spec_1d