pypeit.pypeit module

Main driver class for PypeIt run

class pypeit.pypeit.PypeIt(pypeit_file, verbosity=2, overwrite=True, reuse_calibs=False, logname=None, show=False, redux_path=None, calib_only=False)[source]

Bases: object

This class runs the primary calibration and extraction in PypeIt


Fill in list of attributes!

  • pypeit_file (str) – PypeIt filename.

  • verbosity (int, optional) –

    Verbosity level of system output. Can be:

    • 0: No output

    • 1: Minimal output (default)

    • 2: All output

  • overwrite (bool, optional) – Flag to overwrite any existing files/directories.

  • reuse_calibs (bool, optional) – Reuse any pre-existing calibration files

  • logname (str, optional) – The name of an ascii log file with the details of the reduction.

  • show – (bool, optional): Show reduction steps via plots (which will block further execution until clicked on) and outputs to ginga. Requires remote control ginga session via ginga --modules=RC,SlitWavelength &

  • redux_path (str, optional) – Over-ride reduction path in PypeIt file (e.g. Notebook usage)

  • calib_only – (bool, optional): Only generate the calibration files that you can


Name of the pypeit file to read. PypeIt files have a specific set of valid formats. A description can be found PypeIt Reduction File.




holds the meta info




Generate QA wrappers


Process all calibration frames.

Provides an avenue to reduce a dataset without (or omitting) any science/standard frames.

calib_one(frames, det)[source]

Run Calibration for a single exposure/detector pair

  • frames (list) – List of frames to extract; stacked if more than one is provided

  • det (int) – Detector number (1-indexed)


caliBrate (pypeit.calibrations.Calibrations)

extract_one(frames, det, sciImg, objFind, initial_sky, sobjs_obj)[source]

Extract Objects in a single exposure/detector pair

sci_ID and det need to have been set internally prior to calling this method

  • frames (list) – List of frames to extract; stacked if more than one is provided

  • det (int) – Detector number (1-indexed)

  • sciImg (PypeItImage) – Data container that holds a single image from a single detector its related images (e.g. ivar, mask)

  • objFindFindObjects Object finding object

  • initial_sky (numpy.ndarray) – Initial global sky model

  • sobjs_obj (pypeit.specobjs.SpecObjs) – List of objects found during run_objfind


Returns six numpy.ndarray objects and a pypeit.specobjs.SpecObjs object with the extracted spectra from this exposure/detector pair. The six numpy.ndarray objects are (1) the science image, (2) its inverse variance, (3) the sky model, (4) the object model, (5) the model inverse variance, and (6) the mask.

Return type:


get_sci_metadata(frame, det)[source]

Grab the meta data for a given science frame and specific detector

  • frame (int) – Frame index

  • det (int) – Detector index


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

static get_spec_file_name(science_path, basename, twod=False)[source]

Return the spec1d file name for a reduced standard to use as a tracing crutch.

The file is either constructed using the provided standard frame indices or it is directly pulled from the FindObjPar parameters in par. The latter takes precedence. If more than one row is provided by standard_frames, the first index is used.


standard_frames (array-like) – Set of rows in fitstbl with standards.


Full path to the standard spec1d output file to use.

Return type:


load_skyregions(initial_slits=False, scifile=None, frame=None, spat_flexure=None)[source]

Generate or load sky regions, if defined by the user.

Sky regions are defined by the internal provided parameters; see user_regions in SkySubPar. If included in the pypeit file like so,

        user_regions = :25,75:

The first and last 25% of all slits are used as sky. If the user has used the pypeit_skysub_regions GUI to generate a sky mask for a given frame, this can be searched for and loaded by setting the parameter to user:

        user_regions = user
  • initial_slits (bool, optional) – Flag to use the initial slits before any tweaking based on the slit-illumination profile; see select_edges().

  • scifile (str, optional) – The file name used to define the user-based sky regions. Only used if user_regions = user.

  • frame (int, optional) – The index of the frame used to construct the calibration key. Only used if user_regions = user.

  • spat_flexure (float, None, optional) – The spatial flexure (measured in pixels) of the science frame relative to the trace frame.


skymask – A boolean array used to select sky pixels; i.e., True is a pixel that corresponds to a sky region. If the user_regions parameter is not set (or an empty string), the returned value is None.

Return type:



Reset the msgs object

objfind_one(frames, det, bg_frames=None, std_outfile=None)[source]

Reduce + Find Objects in a single exposure/detector pair

sci_ID and det need to have been set internally prior to calling this method

  • frames (list) – List of frames to extract; stacked if more than one is provided

  • det (int) – Detector number (1-indexed)

  • bg_frames (list, optional) – List of frames to use as the background. Can be empty.

  • std_outfile (str, optional) – Filename for the standard star spec1d file. Passed directly to get_std_trace().



Check whether the 2D outfile of a given frame already exists


frame (int) – Frame index from fitstbl


True if the 2d file exists, False if it does not exist

Return type:



Print the elapsed time

property qa_path

Return the path to the top-level QA directory.


Main driver of the entire reduction

Calibration and extraction via a series of calls to reduce_exposure().

reduce_exposure(frames, bg_frames=None, std_outfile=None)[source]

Reduce a single exposure

  • frames (list) – List of 0-indexed rows in fitstbl with the frames to reduce.

  • bg_frames (list, optional) – List of frame indices for the background.

  • std_outfile (str, optional) – File with a previously reduced standard spectrum from PypeIt.


The dictionary containing the primary outputs of extraction.

Return type:


refframe_correct(slits, ra, dec, obstime, slitgpm=None, waveimg=None, sobjs=None)[source]

Correct the calibrated wavelength to the user-supplied reference frame

  • slits (SlitTraceSet) – Slit trace set object

  • ra (float, str) – Right Ascension

  • dec (float, str) – Declination

  • obstime (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

save_exposure(frame, all_spec2d, all_specobjs, basename, history=None)[source]

Save the outputs from extraction for a given exposure

  • frame (int) – 0-indexed row in the metadata table with the frame that has been reduced.

  • all_spec2d (pypeit.spec2dobj.AllSpec2DObj) –

  • sci_dict (dict) – Dictionary containing the primary outputs of extraction

  • basename (str) – The root name for the output file.

  • history (pypeit.history.History) – History entries to be added to fits header


All of the objects saved to disk

Return type:

None or SpecObjs

property science_path

Return the path to the science directory.

static select_detectors(spectrograph, detnum, slitspatnum=None)[source]

Get the set of detectors to be reduced.

This is mostly a wrapper for select_detectors(), except that it applies any limitations set by the ReduxPar parameters.

  • spectrograph (Spectrograph) – Spectrograph instance that defines the allowed detectors/mosaics.

  • detnum (int, tuple) – The detectors/mosaics to parse

  • slitspatnum (str, optional) – Used to restrict the reduction to a specified slit. See ReduxPar.


List of unique detectors or detector mosaics to be reduced.

Return type:



Simple print of science frames

spec_output_file(frame, twod=False)[source]

Return the path to the spectral output data file.

  • frame (int) – Frame index from fitstbl.

  • twod (bool) – Name for the 2D output file; 1D file otherwise.


The path for the output file

Return type: