pypeit.calibrations module
Class for guiding calibration object generation in PypeIt.
- class pypeit.calibrations.Calibrations(fitstbl, par, spectrograph, caldir, calib_ID, frame, det, qadir=None, reuse_calibs=False, show=False, user_slits=None, chk_version=True)[source]
Bases:
objectClass designed to guide the generation of calibration images and objects in PypeIt.
- Parameters:
fitstbl (
PypeItMetaData) – The class holding the metadata for all the frames in this PypeIt run. If None, we are using this class as a glorified dict to hold the objects.par (
CalibrationsPar) – Parameter set defining optional parameters of PypeIt’s algorithms for Calibrationsspectrograph (
Spectrograph) – Spectrograph objectcaldir (
str, Path) – Path for the processed calibration files.qadir (
str, optional) – Path for quality assessment output. If not provided, no QA plots are saved.reuse_calibs (
bool, optional) – Instead of reprocessing them, load existing calibration files from disk if they exist.show (
bool, optional) – Show plots of PypeIt’s results as the code progresses. Requires interaction from the user.user_slits (
dict, optional) – A limited set of slits selected by the user for analysis. Seeuser_mask().chk_version (
bool, optional) – When reading in existing files written by PypeIt, perform strict version checking to ensure a valid file. If False, the code will try to keep going, but this may lead to faults and quiet failures. User beware!
- Variables:
fitstbl (
PypeItMetaData) – See instantiation arguments.par (
CalibrationsPar) – See instantiation arguments.spectrograph (
Spectrograph) – See instantiation arguments.calib_dir (Path) – Path for the processed calibration files.
qa_path (Path) – Path for the QA diagnostics.
reuse_calibs (
bool) – See instantiation arguments.show (
bool) – See instantiation arguments.user_slits (
dict) – See instantiation arguments.det (
int,tuple) – The single detector or set of detectors in a mosaic to process.frame (
int) – The index of a raw file infitstblused to set the calibration group.calib_ID (
int) – The calibration group associated withframe.msarc (
ArcImage) – Arc calibration framemstilt (
TiltImage) – Tilt calibration framealignments (
Alignments) – Alignment calibration framemsbias (
BiasImage) – Bias calibration framemsdark (
DarkImage) – Dark calibration framemsbpm (numpy.ndarray) – Boolean array with the bad-pixel mask (pixels that should masked are set to True).
wv_calib (
WaveCalib) – Wavelength calibration frameslits (
SlitTraceSet) – Slit tracing calibration framewavetilts (
WaveTilts) – Tilts calibration frameflatimages (
FlatImages) – Flat-field calibration framesteps (
list) – A list of strings setting the set of processing steps to be completed (not necessarily those that were successful). See thedefault_stepsfunctions of each subclass.success (
bool) – Flag that the calibrations were all generated successfully.failed_step (
str) – If the calibrations were unsuccessful, this is the step that led to the fault.
- _chk_set(items)[source]
Check whether a needed attribute has previously been set
- Parameters:
items (list) – Attributes to check
- static association_summary(ofile, fitstbl, spectrograph, caldir, subset=None, det=None, overwrite=False)[source]
Write a file listing the associations between the processed calibration frames and their source raw files for every setup and every calibration group.
- Parameters:
fitstbl (
PypeItMetaData) – The class holding the metadata for all the frames to process.spectrograph (
pypeit.spectrographs.spectrograph.Spectrograph) – Spectrograph objectcaldir (
str, Path) – Path for the processed calibration frames.subset (numpy.ndarray, optional) – A boolean array selecting a subset of rows from
fitstblfor output.det (
int,tuple, optional) – The specific detector (or mosaic) to use when constructing the output processed calibration group file names. If None, a placeholder is used.overwrite (
bool, optional) – Overwrite any existing file of the same name.
- check_calibrations(file_list, check_lamps=True)[source]
Check if the input calibration files are consistent with each other. This step is usually needed when combining calibration frames of a given type. This routine currently only prints out warning messages if the calibration files are not consistent.
Note: The exposure times are currently checked in the combine step, so they are not checked here.
- static default_steps()[source]
- This defines the steps for calibrations and their order
Note that the order matters!
- Returns:
Calibration steps, in order of execution
- Return type:
- find_calibrations(frametype, frameclass)[source]
Find calibration files and identifiers.
- Parameters:
frametype (
str) – Calibration frame type. Must be a valid frame type; seevalid_frametype().frameclass (
CalibFrame) – The subclass used to store the processed calibration data.
- Returns:
raw_files (
list) – The list of raw files infitstblwith the provided frametype.cal_file (Path) – The path with/for the processed calibration frame
calib_key (
str) – The calibration identifiersetup (
str) – The setup/configuration identifiercalib_id (
list) – The calibration groupsdetname (
str) – The detector/mosaic identifier
- get_align(force=None)[source]
Load or generate the alignment calibration frame.
- Parameters:
force (
str, optional) – ‘remake’ – Force the frame to be remade. ‘reload’ – Reload the frame if it exists. None – Load the existing frame if it exists and reuse_calibs=True- Returns:
The processed alignment image.
- Return type:
- static get_association(fitstbl, spectrograph, caldir, setup, calib_ID, det, must_exist=True, subset=None, include_science=False, proc_only=False)[source]
Construct a dictionary with the association between raw files and processed calibration frames.
- Parameters:
fitstbl (
PypeItMetaData) – The class holding the metadata for all the frames to process.spectrograph (
pypeit.spectrographs.spectrograph.Spectrograph) – Spectrograph objectcaldir (
str, Path) – Path for the processed calibration frames.setup (
str) – The setup/configuration of the association.calib_ID (
str,int) – The single calibration group of the association.must_exist (
bool, optional) – If True, only existing calibration frames in the association are included. If False, the nominal set of processed calibration frame file names are returned, regardless of whether or not they exist.subset (numpy.ndarray, optional) – A boolean array selecting a subset of rows from
fitstblfor output.include_science (
bool, optional) – Include science and standard frames in the association. This parameter is mutually exclusive withproc_only; if both are true,proc_onlytakes precedence.proc_only (
bool, optional) – If True, only return a dictionary with the names of the processed calibration frames. The dictionary sets the calibration directory toDIR, and the other keys are the capitalized versions of the calibration type keywords; e.g.,asn['ARC']is the processed arc frame. This parameter is mutually exclusive withinclude_science; if both are true,proc_onlytakes precedence.
- Returns:
The set of raw and processed calibration frames associated with the selected calibration group. This only includes the processed frames if
proc_onlyis True, and it includes the science/standard frames ifinclude_scienceis True.- Return type:
- get_bpm(frame=None, force=None)[source]
Load or generate the bad pixel mask.
This is primarily a wrapper for
bpm().- Parameters:
- Returns:
The bad pixel mask, which should match the shape and orientation of a trimmed and PypeIt-oriented science image!
- Return type:
- get_flats(force=None)[source]
Load or generate the flat-field calibration images.
- Parameters:
force (
str, optional) – ‘remake’ – Force the frame to be remade. ‘reload’ – Reload the frame if it exists. None – Load the existing frame if it exists and reuse_calibs=True- Returns:
The processed calibration image.
- Return type:
- static get_instance(fitstbl, par, spectrograph, caldir, calib_ID, frame, det, **kwargs)[source]
Get the instance of the appropriate subclass of
Calibrationsto use for reducing data from the providedspectrograph. For argument descriptions, seeCalibrations.
- get_scattlight(force=None)[source]
Load or generate the scattered light model.
- Parameters:
force (
str, optional) – ‘remake’ – Force the frame to be remade. ‘reload’ – Reload the frame if it exists. None – Load the existing frame if it exists and reuse_calibs=True- Returns:
The processed calibration image including the model.
- Return type:
- get_slits(force=None)[source]
Load or generate the definition of the slit boundaries.
- Returns:
Traces of the slit edges; also kept internally as
slits.- Return type:
- process_load_selection(frame, cal_file, force)[source]
Process how pypeit should use any pre-existing calibration files.
If loading is requested but the calibration file (
cal_file) does not exist,self.successis set to False, and None is returned.- Parameters:
frame (
dict) – A dictionary with two elements:typeis the string defining the frame type andclassis the pypeit class used to load the pre-existing calibration file.force (
str) –Defines how to treat a pre-existing calibration file. Must be one of the following options:
'remake': Force the calibration be remade.'reload': Reload the frame if it exists.None: Load the existing frame if it exists andself.reuse_calibs=True.
- Returns:
Either the loaded calibration object or None.
- Return type:
- class pypeit.calibrations.IFUCalibrations(fitstbl, par, spectrograph, caldir, calib_ID, frame, det, qadir=None, reuse_calibs=False, show=False, user_slits=None, chk_version=True)[source]
Bases:
CalibrationsChild of Calibrations class for performing IFU calibrations. See
Calibrationsfor arguments.
- class pypeit.calibrations.MultiSlitCalibrations(fitstbl, par, spectrograph, caldir, calib_ID, frame, det, qadir=None, reuse_calibs=False, show=False, user_slits=None, chk_version=True)[source]
Bases:
CalibrationsCalibration class for performing multi-slit calibrations (and also long-slit and echelle). See
Calibrationsfor arguments.Note
Calibrations are not sufficiently different yet to warrant a different class for echelle reductions. This may change if a different order is eventually required for the set of processing steps (see
default_steps()).
- pypeit.calibrations.check_for_calibs(par, fitstbl, raise_error=True, cut_cfg=None)[source]
Perform a somewhat quick and dirty check to see if the user has provided all of the calibration frametype’s to reduce the science frames
- Parameters:
par (
PypeItPar)fitstbl (
PypeItMetaData, None) – The class holding the metadata for all the frames in this PypeIt run.raise_error (
bool, optional) – If True, crash outcut_cfg (numpy.ndarray, optional) – Also cut on this restricted configuration (mainly for chk_calibs)
- Returns:
True if we passed all checks
- Return type: