pypeit.scripts.ql module
Script for quick-look PypeIt reductions.
Use cases:
User inputs N files: arc, flat, science(s)
User inputs 1 or more science files for a fixed-format instrument (e.g. NIRES)
User inputs 1 folder of files
User inputs 1 folder of files including 1 new science frame
User inputs an ASCII file of files
User inputs 2 science files with A-B [and calibs or uses defaults]
User inputs N science files with A and B (only), stacks all files at A and B independently, A-B, add pos+neg
User inputs N science files with an arbitrary set of dither patterns that are encoded in the headers (e.g. MOSFIRE, currently this works for just one dither pattern, and that may be all we need). Total stack is computed
Notes with JFH:
Label B images as “sky” for A-B redux
Write spec2D A images to disk with a minus sign and call B
Consider not writing out but return instead
- class pypeit.scripts.ql.QL[source]
Bases:
ScriptBase
- classmethod get_parser(width=None)[source]
Construct the command-line argument parser.
Derived classes should override this. Ideally they should use this base-class method to instantiate the ArgumentParser object and then fill in the relevant parser arguments
Warning
Any argument that defaults to the string
'current working directory'
will be replaced by the result ofos.getcwd()
when the script is executed. This means help dialogs will include this replacement, and parsing of the command line will useos.getcwd()
as the default. This functionality is largely to allow for PypeIt’s automated documentation of script help dialogs without the “current working” directory being that of the developer that most recently compiled the docs.- Parameters:
description (
str
, optional) – A short description of the purpose of the script.width (
int
, optional) – Restrict the width of the formatted help output to be no longer than this number of characters, if possible given the help formatter. If None, the width is the same as the terminal width.formatter (argparse.HelpFormatter) – Class used to format the help output.
- Returns:
Command-line interpreter.
- Return type:
- pypeit.scripts.ql.calib_manifest(calib_dir, spectrograph)[source]
Collate the list of setups with processed calibrations.
The calibrations must exist within the provided parent directory. The calibration directories must start with the PypeIt-specific name used for the relevant spectrograph (e.g.,
shane_kast_blue
), and the sub-directories must have a pypeit file that provides the instrument configuration (setup). Directories that contain a pypeit file but no calibration subdirectory are ignored.- Parameters:
- Returns:
Dictionary with the list of instruments setups with available calibrations. If no calibrations are found, either because no pypeit files are found or none of the directories with pypeit files include a calibrations directory, None is returned. The dictionary has one item for every setup found. Each item includes all the configuration parameters used to define a unique setup for this instrument, and it also includes the item
'calib_dir'
giving the directory with the processed calibrations.- Return type:
- pypeit.scripts.ql.folder_name_from_scifiles(sci_files: list)[source]
Construct the directory name for QL output.
If one file, use the filename without its suffix (see
remove_suffix()
). If multiple files, use a dash-separated string of the first and last filenames (also without their suffixes).
- pypeit.scripts.ql.generate_sci_pypeitfile(redux_path: str, ref_calib_dir: Path, ps_sci, det: str | None = None, clear: bool = False, slitspatnum: str | None = None, maskID: str | None = None, boxcar_radius: float | None = None, snr_thresh: float | None = None, chk_version: bool = True)[source]
Prepare to reduce the science frames:
Correct the setup and calibration group for the science frames to be the same as the associated calibration files.
Create the path for the science reductions, and including a symlink to the pre-processed (reference) calibration frames.
Write the pypeit file with the requested parameter adjustments.
- Parameters:
redux_path (
str
) – Path to the redux folderref_calib_dir (Path) – Path with the pre-processed calibration frames. A symlink will be created to this directory from within
redux_path
to mimic the location of the calibrations expected byPypeIt
.ps_sci (
PypeItSetup
) – Setup object for the science frame(s) only.det (
str
, optional) – Detector/mosaic identifier. If None, all detectors are reduced.clear (
bool
, optional) – Remove the directory structure for these files; i.e., start a completely clean reduction. If false, any existing directory structure will remain, but any existing science reduction products will still be overwritten.slitspatnum (
str
, optional) – Used to identify the slit that should be reduced; see ReduxPar Keywords. If None, all slits are reduced.maskID (
str
, optional) – Slit identifier from the mask design, used to select a single slit to reduce. If None, all slits are reduced.boxcar_radius (
float
, optional) – Boxcar radius in arcsec used for extraction.
- Returns:
The name of the pypeit file.
- Return type:
- pypeit.scripts.ql.get_files(raw_files, raw_path)[source]
Use the user-provided input to get the files to process.
- pypeit.scripts.ql.get_setup_calib(calib_dir, calib_grp=None)[source]
Using all of the files found in the provided directory, determine the setup and calibration group to use for the quicklook science frame(s).
- Parameters:
- Returns:
The setup name and calibration group.
- Return type:
- pypeit.scripts.ql.match_to_calibs(ps: PypeItSetup, calib_dir: str, calibrated_setups=None)[source]
Match observations to existing calibrations.
The function first builds the list of existing calibration setups; see
calib_manifest()
. Then, each setup for data provided by thePypeItSetup
object is matched to the existing setups.- Parameters:
ps (
PypeItSetup
) – Object providing metadata and parameters necessary to execute PypeIt data reduction. This must contain data from a single setup/configuration; an error is raised if not.calib_dir (
str
) – Parent directory with the calibrations; seecalib_manifest()
. This directory must exist.
- Returns:
A nested dictionary with the matched setups. There is one dictionary key for each setup in
ps
. Each setup dictionary item is itself a dictionary with two items,setup
andcalib_dir
, wheresetup
is setup identifier of the existing calibrations (as opposed to the setups provided inps
) and the Path to the calibrations. If a setup inps
is not matched, the associated dictionary item is None.- Return type:
- pypeit.scripts.ql.merge_setups(calibrated_setups, calib_match, frame_setup)[source]
Merge the setup identifiers for new reductions to those matched to existing reductions.
- Parameters:
calibrated_setups (array-like) – The list of setup identifiers with existing calibrations. This can be the list of keys in the top-level dictionary returned by
calib_manifest()
. This is used to determine the next identifier for new setups to be calibrated. All existing setups and every setup incalib_match
must be included in this list.calib_match (
dict
) – A dictionary that provides, for each new setup to be reduced, the matched set of existing calibrations, if there are any. Seematch_to_calibs()
. The identifier for any matched setup must be included incalibrated_setups
.frame_setup (array-like) – The setups associated with each frame in the new set of reductions.
- Returns:
The list of replacement setups for each frame that consolidates existing calibrations with new ones.
- Return type:
- pypeit.scripts.ql.print_offset_report(fitstbl: Table, platescale: float)[source]
Print the dither pattern for a set of files to the screen.
The files in the provided table must come from a single dither pattern!
- Parameters:
fitstbl (astropy.table.Table) – Table with the file metadata. This should be the table extracted from a
PypeItMetaData
instance, selecting the relevant science frames.platescale (
float
) – The relevant (binned) pixelscale in arcsec/pixel.
- pypeit.scripts.ql.quicklook_regroup(fitstbl)[source]
Regroup frames for quick-look reductions.
Restrictions/Alterations applied are:
Science and standard frames each must be observations of a single target (according to the
'target'
keyword).For metadata tables where the background image are not set, all science and standard frames are each assigned to a single combination group, so that all observations are stacked.
For metadata tables where the background images are set (e.g., for difference-imaging dither sequences), all frames of a given offset are combined (the column
dithoff
must exist). I.e., if there are multiple dither sequences peformed (e.g., ABBA, then ABBA), all with the same offset (e.g., +/- 5 arcsec), the image combination and background IDs are changed so that all the As are combined and all the Bs are combined before calculating the difference.
This function directly alters the input object!
- Parameters:
fitstbl (
PypeItMetaData
) – Metadata table for frames to be processed.