pypeit.extraction module
Main driver class for skysubtraction and extraction
- class pypeit.extraction.EchelleExtract(sciImg, slits, sobjs_obj, spectrograph, par, objtype, **kwargs)[source]
Bases:
Extract
Child of Reduce for Echelle reductions
See parent doc string for Args and Attributes
- local_skysub_extract(global_sky, sobjs, spat_pix=None, model_noise=True, min_snr=2.0, fit_fwhm=False, show_profile=False, show_resids=False, show_fwhm=False, show=False)[source]
Perform local sky subtraction, profile fitting, and optimal extraction slit by slit
Wrapper to
local_skysub_extract()
.- Parameters
global_sky (numpy.ndarray) – Global sky model
sobjs (
SpecObjs
) – Class containing the information about the objects foundspat_pix (numpy.ndarray, optional) – Image containing the spatial location of pixels. If not input, it will be computed from
spat_img = np.outer(np.ones(nspec), np.arange(nspat))
.model_noise (
bool
, optional) – If True, construct and iteratively update a model inverse variance image usingvariance_model()
. If False, a variance model will not be created and instead the input sciivar will always be taken to be the inverse variance. See ~pypeit.core.skysub.local_skysub_extract for more info.show_resids (
bool
, optional) – Show the model fits and residuals.show_profile (
bool
, optional) – Show QA for the object profile fitting to the screen. Note that this will show interactive matplotlib plots which will block the execution of the code until the window is closed.show (
bool
, optional) – Show debugging plots
- Returns
Return the model sky flux, object flux, inverse variance, and mask as numpy.ndarray objects, and returns a
SpecObjs
: instance c containing the information about the objects found.- Return type
- class pypeit.extraction.Extract(sciImg, slits, sobjs_obj, spectrograph, par, objtype, global_sky=None, waveTilts=None, tilts=None, wv_calib=None, waveimg=None, bkg_redux=False, return_negative=False, std_redux=False, show=False, basename=None)[source]
Bases:
object
This class will organize and run actions relatedt to sky subtraction, and extraction for a Science or Standard star exposure
- ivarmodel
Model of inverse variance
- Type
- objimage
Model of object
- Type
- skyimage
Final model of sky
- Type
- global_sky
Fit to global sky
- Type
- outmask
Final output mask
- Type
- extractmask
Extraction mask
- Type
- slits
- sobjs_obj
Only object finding but no extraction
- sobjs
Final extracted object list with trace corrections applied
- tilts
WaveTilts images generated on-the-spot
- Type
- waveimg
WaveImage image generated on-the-spot
- Type
- slitshift
Global spectral flexure correction for each slit (in pixels)
- Type
- vel_corr
Relativistic reference frame velocity correction (e.g. heliocentyric/barycentric/topocentric)
- Type
- extract_bpm
Bad pixel mask for extraction
- Type
- extract(global_sky, model_noise=None, spat_pix=None)[source]
Main method to extract spectra from the ScienceImage
- Parameters
global_sky (numpy.ndarray) – Sky estimate
sobjs_obj (
pypeit.specobjs.SpecObjs
) – List of SpecObj that have been found and tracedmodel_noise (bool) – If True, construct and iteratively update a model inverse variance image using
variance_model()
. If False, a variance model will not be created and instead the input sciivar will always be taken to be the inverse variance. Seelocal_skysub_extract()
for more info. Default is None, which is to say pypeit will use the bkg_redux attribute to decide whether or not to model the noise.spat_pix (numpy.ndarray) – Image containing the spatial coordinates. This option is used for 2d coadds where the spat_pix image is generated as a coadd of images. For normal reductions spat_pix is not required as it is trivially created from the image itself. Default is None.
- classmethod get_instance(sciImg, slits, sobjs_obj, spectrograph, par, objtype, global_sky=None, waveTilts=None, tilts=None, wv_calib=None, waveimg=None, bkg_redux=False, return_negative=False, std_redux=False, show=False, basename=None)[source]
Instantiate the Reduce subclass appropriate for the provided spectrograph.
The class must be subclassed from Reduce. See
Reduce
for the description of the valid keyword arguments.- Parameters
sciImg (
ScienceImage
) – Image to reduce.slits (
SlitTraceSet
) – Slit trace set objectsobjs_obj (
SpecObjs
) – Objects found but not yet extractedspectrograph (
Spectrograph
) –par (
PypeItPar
) – Parameter set for Extractobjtype (
str
) – Specifies object being reduced ‘science’, ‘standard’, or ‘science_coadd2d’. This is used only to determine the spat_flexure_shift and ech_order for coadd2d.global_sky (numpy.ndarray, optional) – Fit to global sky. If None, an array of zeroes is generated the same size as
sciImg
.waveTilts (
WaveTilts
, optional) – This is waveTilts object which is optional, but either waveTilts or tilts must be provided.tilts (numpy.ndarray, optional) – Tilts image. Either a tilts image or waveTilts object (above) must be provided.
wv_calib (
WaveCalib
, optional) – This is the waveCalib object which is optional, but either wv_calib or waveimg must be provided.waveimg (numpy.ndarray, optional) – Wave image. Either a wave image or wv_calib object (above) must be provided
bkg_redux (
bool
, optional) – If True, the sciImg has been subtracted by a background image (e.g. standard treatment in the IR)return_negative (
bool
, optional) – If True, negative objects from difference imaging will also be extracted and returned. Default=False. This option only applies to the case where bkg_redux=True, i.e. typically a near-IR reduction where difference imaging has been employed to perform a first-pass at sky-subtraction. The default behavior is to not extract these objects, although they are masked in global sky-subtraction (performed in the find_objects class), and modeled in local sky-subtraction (performed by this class).std_redux (
bool
, optional) – If True the object being extracted is a standards star so that the reduction parameters can be adjusted accordingly.basename (str, optional) – Output filename used for spectral flexure QA
show (
bool
, optional) – Show plots along the way?
- Returns
Extraction object.
- Return type
- initialise_slits(slits, initial=False)[source]
Gather all the
SlitTraceSet
attributes that we’ll use here inExtract
- Args
- slits (
SlitTraceSet
): SlitTraceSet object containing the slit boundaries that will be initialized.
- initial (
bool
, optional): Use the initial definition of the slits. If False, tweaked slits are used.
- slits (
- local_skysub_extract(global_sky, sobjs, model_noise=True, spat_pix=None, show_profile=False, show_resids=False, show=False)[source]
Dummy method for local sky-subtraction and extraction.
Overloaded by class specific skysub and extraction.
- property nsobj_to_extract
Number of sobj objects in sobjs_obj taking into account whether or not we are returning negative traces
Returns:
- refframe_correct(ra, dec, obstime, sobjs=None)[source]
Correct the calibrated wavelength to the user-supplied reference frame
- Parameters
radec (astropy.coordiantes.SkyCoord) – Sky Coordinate of the observation
obstime (
astropy.time.Time
) – Observation timesobjs (
pypeit.specobjs.Specobjs
, None) – Spectrally extracted objects
- run(model_noise=None, spat_pix=None)[source]
Primary code flow for PypeIt reductions
- Parameters
model_noise (bool) – If True, construct and iteratively update a model inverse variance image using
variance_model()
. If False, a variance model will not be created and instead the input sciivar will always be taken to be the inverse variance. Seelocal_skysub_extract()
for more info. Default is None, which is to say pypeit will use the bkg_redux attribute to decide whether or not to model the noise.spat_pix (numpy.ndarray) – Image containing the spatial coordinates. This option is used for 2d coadds where the spat_pix image is generated as a coadd of images. For normal reductions spat_pix is not required as it is trivially created from the image itself. Default is None.
- Returns
- skymodel (ndarray), objmodel (ndarray), ivarmodel (ndarray),
outmask (ndarray), sobjs (SpecObjs), waveimg (numpy.ndarray), tilts (numpy.ndarray). See main doc string for description
- Return type
- show(attr, image=None, showmask=False, sobjs=None, chname=None, slits=False, clear=False)[source]
Show one of the internal images
Todo
Should probably put some of these in ProcessImages
- Parameters
attr (str) – global – Sky model (global) sci – Processed science image rawvar – Raw variance image modelvar – Model variance image crmasked – Science image with CRs set to 0 skysub – Science image with global sky subtracted image – Input image
display (str, optional) –
image (ndarray, optional) – User supplied image to display
- spec_flexure_correct(mode='local', sobjs=None)[source]
Correct for spectral flexure
Spectra are modified in place (wavelengths are shifted)
- Parameters
mode (str) – “local” - Use sobjs to determine flexure correction “global” - Use waveimg and global_sky to determine flexure correction at the centre of the slit
sobjs (
pypeit.specobjs.SpecObjs
, None) – Spectrally extracted objects
- class pypeit.extraction.IFUExtract(sciImg, slits, sobjs_obj, spectrograph, par, objtype, **kwargs)[source]
Bases:
MultiSlitExtract
Child of Reduce for IFU reductions
See parent doc string for Args and Attributes
- class pypeit.extraction.MultiSlitExtract(sciImg, slits, sobjs_obj, spectrograph, par, objtype, **kwargs)[source]
Bases:
Extract
Child of Reduce for Multislit and Longslit reductions
See parent doc string for Args and Attributes
- local_skysub_extract(global_sky, sobjs, spat_pix=None, model_noise=True, show_resids=False, show_profile=False, show=False)[source]
Perform local sky subtraction, profile fitting, and optimal extraction slit by slit.
Wrapper to
local_skysub_extract()
.- Parameters
global_sky (numpy.ndarray) – Global sky model
sobjs (
SpecObjs
) – Class containing the information about the objects foundspat_pix (numpy.ndarray, optional) – Image containing the spatial location of pixels. If not input, it will be computed from
spat_img = np.outer(np.ones(nspec), np.arange(nspat))
.model_noise (
bool
, optional) – If True, construct and iteratively update a model inverse variance image usingvariance_model()
. If False, a variance model will not be created and instead the input sciivar will always be taken to be the inverse variance. Seelocal_skysub_extract()
for more info.show_resids (
bool
, optional) – Show the model fits and residuals.show_profile (
bool
, optional) – Show QA for the object profile fitting to the screen. Note that this will show interactive matplotlib plots which will block the execution of the code until the window is closed.show (
bool
, optional) – Show debugging plots
- Returns
Return the model sky flux, object flux, inverse variance, and mask as numpy.ndarray objects, and returns a
SpecObjs
: instance c containing the information about the objects found.- Return type