pypeit.calibrations module

Class for guiding calibration object generation in PypeIt.

class pypeit.calibrations.Calibrations(fitstbl, par, spectrograph, caldir, qadir=None, reuse_calibs=False, show=False, user_slits=None, chk_version=True)[source]

Bases: object

Class 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 Calibrations

  • spectrograph (Spectrograph) – Spectrograph object

  • caldir (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. See user_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!

fitstbl

See instantiation arguments.

Type:

PypeItMetaData

par

See instantiation arguments.

Type:

CalibrationsPar

spectrograph

See instantiation arguments.

Type:

Spectrograph

calib_dir

Path for the processed calibration files.

Type:

Path

qa_path

Path for the QA diagnostics.

Type:

Path

reuse_calibs

See instantiation arguments.

Type:

bool

show

See instantiation arguments.

Type:

bool

user_slits

See instantiation arguments.

Type:

dict

det

The single detector or set of detectors in a mosaic to process.

Type:

int, tuple

frame

The index of a raw file in fitstbl used to set the calibration group.

Type:

int

calib_ID

The calibration group associated with frame.

Type:

int

msarc

Arc calibration frame

Type:

ArcImage

mstilt

Tilt calibration frame

Type:

TiltImage

alignments

Alignment calibration frame

Type:

Alignments

msbias

Bias calibration frame

Type:

BiasImage

msdark

Dark calibration frame

Type:

DarkImage

msbpm

Boolean array with the bad-pixel mask (pixels that should masked are set to True).

Type:

numpy.ndarray

wv_calib

Wavelength calibration frame

Type:

WaveCalib

slits

Slit tracing calibration frame

Type:

SlitTraceSet

wavetilts

Tilts calibration frame

Type:

WaveTilts

flatimages

Flat-field calibration frame

Type:

FlatImages

steps

A list of strings setting the set of processing steps to be completed (not necessarily those that were successful). See the default_steps functions of each subclass.

Type:

list

success

Flag that the calibrations were all generated successfully.

Type:

bool

failed_step

If the calibrations were unsuccessful, this is the step that led to the fault.

Type:

str

_chk_objs(items)[source]

Check that the input items exist internally as attributes

Parameters:

items (list)

Returns:

True if all exist

Return type:

bool

_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:
  • ofile (str, Path) – Full path to the output file.

  • fitstbl (PypeItMetaData) – The class holding the metadata for all the frames to process.

  • spectrograph (pypeit.spectrographs.spectrograph.Spectrograph) – Spectrograph object

  • caldir (str, Path) – Path for the processed calibration frames.

  • subset (numpy.ndarray, optional) – A boolean array selecting a subset of rows from fitstbl for 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.

find_calibrations(frametype, frameclass)[source]

Find calibration files and identifiers.

Parameters:
  • frametype (str) – Calibration frame type. Must be a valid frame type; see valid_frametype().

  • frameclass (CalibFrame) – The subclass used to store the processed calibration data.

Returns:

  • raw_files (list) – The list of raw files in fitstbl with the provided frametype.

  • cal_file (Path) – The path with/for the processed calibration frame

  • calib_key (str) – The calibration identifier

  • setup (str) – The setup/configuration identifier

  • calib_id (list) – The calibration groups

  • detname (str) – The detector/mosaic identifier

get_align()[source]

Load or generate the alignment calibration frame.

Returns:

The processed alignment image.

Return type:

Alignments

get_arc()[source]

Load or generate the arc calibration frame.

Returns:

The processed calibration image.

Return type:

ArcImage

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 object

  • caldir (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.

  • det (int, tuple) – The detector/mosaic 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 fitstbl for output.

  • include_science (bool, optional) – Include science and standard frames in the association. This parameter is mutually exclusive with proc_only; if both are true, proc_only takes 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 to DIR, 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 with include_science; if both are true, proc_only takes precedence.

Returns:

The set of raw and processed calibration frames associated with the selected calibration group. This only includes the processed frames if proc_only is True, and it includes the science/standard frames if include_science is True.

Return type:

dict

get_bias()[source]

Load or generate the bias calibration frame.

Returns:

The processed calibration image.

Return type:

BiasImage

get_bpm(frame=None)[source]

Load or generate the bad pixel mask.

This is primarily a wrapper for bpm().

Returns:

The bad pixel mask, which should match the shape and orientation of a trimmed and PypeIt-oriented science image!

Return type:

numpy.ndarray

get_dark()[source]

Load or generate the dark calibration frame.

Returns:

The processed calibration image.

Return type:

DarkImage

get_flats()[source]

Load or generate the flat-field calibration images.

Returns:

The processed calibration image.

Return type:

FlatImages

static get_instance(fitstbl, par, spectrograph, caldir, **kwargs)[source]

Get the instance of the appropriate subclass of Calibrations to use for reducing data from the provided spectrograph. For argument descriptions, see Calibrations.

get_scattlight()[source]

Load or generate the scattered light model.

Returns:

The processed calibration image including the model.

Return type:

ScatteredLight

get_slits()[source]

Load or generate the definition of the slit boundaries.

Returns:

Traces of the slit edges; also kept internally as slits.

Return type:

SlitTraceSet

get_tiltimg()[source]

Load or generate the tilt calibration frame.

Returns:

The processed calibration image.

Return type:

TiltImage

get_tilts()[source]

Load or generate the wavelength tilts calibration frame

Returns:

Object containing the wavelength tilt calibration.

Return type:

WaveTilts

get_wv_calib()[source]

Load or generate the 1D wavelength calibrations

Returns:

Object containing wavelength calibrations and the updated slit mask array.

Return type:

WaveCalib

run_the_steps()[source]

Run full the full recipe of calibration steps.

set_config(frame, det, par=None)[source]

Specify the critical attributes of the class to perform a set of calibrations.

Operations are:

  • Set the frame

  • Use the frame to find the calibration group

  • Set the detector/mosaic

  • Set the parameters

Parameters:
  • frame (int) – The row index in fitstbl with the frame to calibrate.

  • det (int) – Detector number.

  • par (CalibrationsPar, optional) – Parameters used by the calibration procedures. If None, use par.

class pypeit.calibrations.IFUCalibrations(fitstbl, par, spectrograph, caldir, qadir=None, reuse_calibs=False, show=False, user_slits=None, chk_version=True)[source]

Bases: Calibrations

Child of Calibrations class for performing IFU calibrations. See Calibrations for arguments.

static default_steps()[source]

This defines the steps for calibrations and their order

Returns:

Calibration steps, in order of execution

Return type:

list

class pypeit.calibrations.MultiSlitCalibrations(fitstbl, par, spectrograph, caldir, qadir=None, reuse_calibs=False, show=False, user_slits=None, chk_version=True)[source]

Bases: Calibrations

Calibration class for performing multi-slit calibrations (and also long-slit and echelle). See Calibrations for 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()).

static default_steps()[source]

This defines the calibration steps and their order.

Returns:

Calibration steps, in order of execution.

Return type:

list

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 out

  • cut_cfg (numpy.ndarray, optional) – Also cut on this restricted configuration (mainly for chk_calibs)

Returns:

True if we passed all checks

Return type:

bool