pypeit.pypeit_steps module
Module providing functions that support primary reduction steps.
- pypeit.pypeit_steps.calib_one(spectrograph, fitstbl, par, det, calib_ID, calibrations_path, reuse_calibs=True, qa_path=None, show=False, run_state=None, stop_at_step=None)[source]
Run Calibration for a single detector, calib_ID pair
- Parameters:
spectrograph (
Spectrograph) – The spectrograph instancefitstbl (
PypeItMetaData) – The class holding the metadata for all the frames in this PypeIt run.par (
PypeItPar) – The parameter set for the reduction, including slitmask and object finding parameters.det (
int) – Detector number (1-indexed)calib_ID (
str) – The calibration group IDcalibrations_path (
str) – Path to the calibration filesreuse_calibs (
bool, optional) – If True, reuse existing calibration files if they exist.qa_path (
str, optional) – Path to the QA files; if None, use the default path defined by the parameters.show (
bool, optional) – Show the QA during processingrun_state (
dict, optional) – A dictionary containing the current state of the reduction. If None, a new empty dictionary is created.stop_at_step (
str, optional) – Run only up to this calibration step.
- Returns:
caliBrate (
Calibrations)
- pypeit.pypeit_steps.extract_det(spectrograph, fitstbl, par, frames, det, calib_ID, calibrations_path, sciImg, final_sky, sobjs_obj, calib_slits, bkg_redux_final_sky=None, bkg_redux=False, find_negative=False, show=False)[source]
Extract Objects in a single exposure/detector pair
sci_ID and det need to have been set internally prior to calling this method
- Parameters:
spectrograph (
Spectrograph) – The spectrograph instancefitstbl (
PypeItMetaData) – The class holding the metadata for all the frames in this PypeIt run.par (
PypeItPar) – The parameter set for the reduction, including slitmask and object finding parameters.frames (
list) – List of frames to extract; stacked if more than one is provideddet (
int) – Detector number (1-indexed)calib_ID (
str) – The calibration group IDcalibrations_path (
str) – Path to the calibration filessciImg (
PypeItImage) – Data container that holds a single image from a single detector and its related images (e.g. ivar, mask)final_sky (numpy.ndarray) – Final global sky model
sobjs_obj (
SpecObjs) – List of objects found during run_objfindcalib_slits (
SlitTraceSet) – If provided, use these slits instead of those from the calibrations.bkg_redux_final_sky (numpy.ndarray, optional) – Final global sky model for the background-reduced science image. Default is None.
bkg_redux (
bool, optional) – Indicates whether the reduction involves background subtraction. Default is False.find_negative (
bool, optional) – Indicates whether to find negative objects during the reduction. Default is False.show (
bool, optional) – Show the QA during processing. Default is False.0
- Returns:
- Return type:
- pypeit.pypeit_steps.finalize_sky_det(spectrograph, fitstbl, par, frame, det, objFind, initial_sky, all_specobjs_objfind, bkg_redux_sciimg=None, bkg_redux=False, show=False)[source]
Finalize sky subtraction for a specific detector.
This function performs the final global sky subtraction for a given detector. It also updates the slit mask based on bad sky subtraction flags.
- Parameters:
spectrograph (
Spectrograph) – The spectrograph instance.fitstbl (
PypeItMetaData) – The class holding the metadata for all the frames in this PypeIt run.par (
PypeItPar) – The parameter set for the reduction process.frame (
int) – The index of the frame in the fitstbl.det (
int) – Detector number (1-indexed).objFind (
FindObjects) – The object finding instance for this detector.initial_sky (numpy.ndarray) – The initial sky model for this detector.
all_specobjs_objfind (
SpecObjs) – All spectral objects found during object finding.bkg_redux_sciimg (
PypeItImage, optional) – Background-reduced science image, or None if background reduction is not being performed.bkg_redux (
bool, optional) – Indicates whether background reduction is being performed. Default is False.show (
bool, optional) – Show the QA during processing. Default is False.
- Returns:
- A tuple containing:
final_global_sky (numpy.ndarray): The final global sky model for this detector.
bkg_redux_global_sky (numpy.ndarray or None): The background-reduced global sky model, or None if bkg_redux is False.
- objFind (
FindObjects): The updated object finding class for this detector.
- objFind (
- Return type:
- pypeit.pypeit_steps.findobj_on_det(sciImg, spectrograph, fitstbl, par, frames, calib_ID, det, calibrations_path, std_outfile=None, bkg_redux=False, find_negative=False, show=False)[source]
Perform object finding on a specific detector.
This function is responsible for identifying objects on a given detector during the data reduction process. It utilizes calibration data, metadata, and reduction parameters to locate and characterize objects in the science image.
- Parameters:
sciImg (
PypeItImage) – Data container that holds a single image from a single detector and its related images (e.g. ivar, mask)spectrograph (
Spectrograph) – The spectrograph instancefitstbl (
PypeItMetaData) – The class holding the metadata for all the frames in this PypeIt run.par (
PypeItPar) – The parameter set for the reduction, including slitmask and object finding parameters.frames (
list) – List of indices corresponding to the science frames in the fitstbl to be processed together.calib_ID (
str) – The calibration group IDdet (
int) – Detector number (1-indexed)calibrations_path (
str) – Path to the calibration filesstd_outfile (
str, optional) – The standard star output file, if this is a standard star reduction. Default is None.bkg_redux (
bool, optional) – Indicates whether the reduction involves background subtraction. Default is False.find_negative (
bool, optional) – Indicates whether to find negative objects during the reduction. Default is False.show (
bool, optional) – Show the QA during processing. Default is False.
- Returns:
- A tuple containing:
initial_sky (object): The initial sky model.
sobjs_obj (object): The detected objects.
objFind (object): The object finding instance used for the reduction.
- Return type:
- pypeit.pypeit_steps.get_sci_metadata(spectrograph, fitstbl, frame, det)[source]
Grab the meta data for a given science frame and specific detector
- Parameters:
spectrograph (
Spectrograph) – The spectrograph instancefitstbl (
PypeItMetaData) – The class holding the metadata for all the frames in this PypeIt run.frame (
int) – The index of the frame in the fitstbldet (
int) – The detector number (1-indexed)
- Returns:
- 5 objects are returned::
str: Object type; science or standard
str: Setup/configuration string
astropy.time.Time: Time of observation
str: Basename of the frame
str: Binning of the detector
- pypeit.pypeit_steps.instantiate_objfind(sciImg, spectrograph, fitstbl, par, frames, det, caliBrate, bkg_redux, find_negative, show=False)[source]
Instantiate the FindObjects class for object finding in spectroscopic data.
- Parameters:
sciImg (
PypeItImage) – Data container that holds a single image from a single detector and its related images (e.g. ivar, mask)spectrograph (
Spectrograph) – The spectrograph instancefitstbl (
PypeItMetaData) – The class holding the metadata for all the frames in this PypeIt run.par (
PypeItPar) – The parameter set for the reduction, including slitmask and object finding parameters.frames (
list) – List of indices corresponding to the science frames in the fitstbl to be processed together.det (
int) – Detector number (1-indexed)caliBrate (
Calibrations) – The calibration data for the current frame and detector.bkg_redux (
bool) – Indicates whether the reduction involves background subtraction.find_negative (
bool) – Indicates whether to find negative objects during the reduction.show (
bool, optional) – Show the QA during processing. Default is False.
- Returns:
An instance of the FindObjects class configured for object finding.
- Return type:
Notes
This function handles manual extraction if specified in the FITS table.
It also builds an initial sky mask if user-defined sky regions are provided.
The FindObjects instance is initialized with the relevant parameters for object finding.
- pypeit.pypeit_steps.load_calibrations_for_frame(spectrograph, fitstbl, par, frame, det, calib_ID, calibrations_path)[source]
Load calibrations for a specific frame and detector.
This function initializes the Calibrations class, runs the calibration steps, and ensures that the calibrations are successfully loaded for the given frame and detector.
- Parameters:
spectrograph (
Spectrograph) – The spectrograph instancefitstbl (
PypeItMetaData) – The class holding the metadata for all the frames in this PypeIt run.par (
PypeItPar) – The parameter set for the reduction, including slitmask and object finding parameters.frame (
int) – The index of the frame in the fitstbldet (
int) – Detector number (1-indexed)calib_ID (
str) – The calibration group IDcalibrations_path (
str) – Path to the calibration files
- Returns:
The loaded calibrations for the specified frame and detector.
- Return type:
- Raises:
PypeItError – If the calibrations for the specified detector are unsuccessful.
- pypeit.pypeit_steps.load_skyregions(spectrograph, fitstbl, par, frame, det, caliBrate, calibrations_path, scifile=None, initial_slits=False)[source]
Generate or load sky regions, if defined by the user.
Sky regions are defined by the internal provided parameters; see
user_regionsinSkySubPar. If included in the pypeit file like so,[reduce] [[skysub]] user_regions = :25,75:
The first and last 25% of all slits are used as sky. If the user has used the
pypeit_skysub_regionsGUI to generate a sky mask for a given frame, this can be searched for and loaded by setting the parameter touser:[reduce] [[skysub]] user_regions = user
- Parameters:
initial_slits (
bool, optional) – Flag to use the initial slits before any tweaking based on the slit-illumination profile; seeselect_edges().- Returns:
skymask – A boolean array used to select sky pixels; i.e., True is a pixel that corresponds to a sky region. If the
user_regionsparameter is not set (or an empty string), the returned value is None.- Return type:
- pypeit.pypeit_steps.process_one_det(spectrograph, fitstbl, par, frames, det, calib_ID, calibrations_path, bg_frames=None, sci_outfile=None, bkg_outfile=None)[source]
Process a single detector for a given set of frames.
This function handles the image processing for a specific detector, including loading calibrations, building the science image, and optionally subtracting a background image.
- Parameters:
spectrograph (
Spectrograph) – The spectrograph instancefitstbl (
PypeItMetaData) – The class holding the metadata for all the frames in this PypeIt run.par (
PypeItPar) – The parameter set for the reduction, including slitmask and object finding parameters.frames (
list) – List of indices corresponding to the science frames in the fitstbl to be processed together.det (
int) – Detector number (1-indexed)calib_ID (
str) – The calibration group IDcalibrations_path (
str) – Path to the calibration filesbg_frames (
list, optional) – List of indices corresponding to the background frames in the fitstbl. If None or empty, no A-B background subtraction is performed. Default is None.sci_outfile (
str, optional) – The science output file, if this is a science reduction. Default is None.bkg_outfile (
str, optional) – The background output file, if this is a background subtraction reduction. Default is None.
- Returns:
sciImg (
PypeItImage): The processed science image, with background subtraction applied if bg_frames is provided.bkg_redux_sciimg (
PypeItImageor None): The science image without background subtraction, used to generate a global sky model. This is a dictionary with image and ivar keys if bg_frames is provided, otherwise it is None.
- Return type:
- pypeit.pypeit_steps.refframe_correct(spectrograph, par, slits, ra, dec, obstime, slitgpm=None, waveimg=None, sobjs=None)[source]
Correct the calibrated wavelength to the user-supplied reference frame
- Parameters:
slits (
SlitTraceSet) – Slit trace set objectobstime (astropy.time.Time) – Observation time
slitgpm (numpy.ndarray, None, optional) – 1D boolean array indicating the good slits (True). If None, the gpm will be taken from slits
waveimg (numpy.ndarray, optional) – Two-dimensional image specifying the wavelength of each pixel
sobjs (
SpecObjs, None, optional) – Spectrally extracted objects
- pypeit.pypeit_steps.set_bkg_negative(fitstbl, par, bg_frames)[source]
Determine background subtraction settings for a reduction.
- Parameters:
fitstbl (
PypeItMetaData) – The class holding the metadata for all the frames in this PypeIt run.par (
PypeItPar) – The parameter set for the reduction process, including slitmask and object finding parameters.bg_frames (
list) – list A list of indices corresponding to the background frames in the fitstbl. If empty or None, no background subtraction is performed.
- Returns:
- Returns three objects:
- has_bg (
bool): True if background frames are provided and non-empty, False otherwise.
- bkg_redux (
bool): True if the reduction involves background subtraction, False otherwise.
- find_negative (
bool): Indicates whether to find negative objects during the reduction. The default behavior depends on the type of the background frames (‘science’ or ‘sky’) unless explicitly overridden by the parameter par[‘reduce’][‘findobj’][‘find_negative’].
- has_bg (
- Return type: