pypeit.outputfiles module

Module for constructing output file names and paths for PypeIt reductions.

pypeit.outputfiles.construct_basename(filename, target, camera, mjd, allowed_extensions)[source]

Construct the root name primarily for PypeIt file output.

Parameters:
  • filename (str, Path) – The name of the raw file. The extension is stripped based on allowed_extensions before constructing the basename. If no extension in allowed_extensions matches, a warning is issued and the full input name is used unmodified.

  • target (str) – The name of the target/object observed.

  • camera (str) – The camera name; see camera.

  • mjd (float) – The MJD of the observation.

  • allowed_extensions (list) – List of recognized raw-file extensions for the relevant spectrograph, used to correctly strip the extension from filename; see allowed_extensions.

Returns:

The root name for file output.

Return type:

str

pypeit.outputfiles.existing_spec2d_files(pypeit_file, target, science_dir, spectrograph)[source]

Find the current reduced spec2d products expected for a target.

Parameters:
Returns:

  • files (list) – Paths to the reduced spec2d files found for the target, one per combination group.

  • missing (list) – Raw-file stems (see group_science_rows()) for combination groups whose spec2d product has not yet been reduced.

  • target_name (str) – The literal target name as recorded in the PypeIt file’s data block.

pypeit.outputfiles.find_reduced_spec2d(science_dir, row, spectrograph)[source]

Find the existing spec2d product for a science-frame row.

Tries an exact match first, reconstructing the spec2d basename from the row’s own metadata via construct_basename(); a hit is target-correct by construction, since the row’s own target was used to build the name, so no header read is needed. Falls back to matching by raw-file stem and verifying the target recorded in each candidate’s header, for cases where the exact name can’t be reconstructed (e.g. no mjd column, or a corrupt/missing mjd value) or doesn’t match an existing file (e.g. an older .pypeit file, or different metadata precision).

Parameters:
Returns:

Path to the matching spec2d file. If more than one candidate matches in the fallback search, the first (alphabetically sorted) is used and a warning is logged. Returns None if no candidate matches.

Return type:

Path

pypeit.outputfiles.get_std_outfile(fitstbl, par, standard_frames)[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.

Parameters:
Returns:

Full path to the standard spec1d output file to use.

Return type:

str

pypeit.outputfiles.intermediate_filename(itype, basename, det_name, inter_path='Intermediate')[source]

Construct the intermediate file name for a given type and detector

Parameters:
  • itype (str) – Type of intermediate file Standard options are: sciImg, bkgImg, initSky, spec1d

  • basename (str) – Basename of the file

  • det_name (str) – Name of the detector

  • inter_path (str, optional) – Path to the intermediate files

Returns:

The full path to the intermediate file

Return type:

str

pypeit.outputfiles.science_path(par)[source]

Constructs the path to the science directory based on the provided parameters.

Parameters:

par (PypeItPar) – The parameter set for the reduction, including slitmask and object finding parameters.

Returns:

The full path to the science directory as a Path object.

Return type:

Path

pypeit.outputfiles.spec2d_target(spec2d_file)[source]

Read the target name from a spec2d primary header.

Parameters:

spec2d_file (str, Path) – Path to a spec2d FITS file.

Returns:

The first non-empty value found among the TARGET, TARGNAME, and OBJECT header keywords, in that order. Returns None if none of those keywords are present or non-empty.

Return type:

str

pypeit.outputfiles.spec_output_file(fitstbl, par, frame, twod=False, ext='.fits', sci_path=None)[source]

Return the path to the spectral output data file.

Parameters:
  • fitstbl (pypeit.metadata.PypeItMetaData) – The metadata table for the current reduction.

  • par (pypeit.par.pypeitpar.PypeItPar) – The parameter set for the current reduction.

  • frame (int) – Frame index from fitstbl.

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

  • ext (str, optional) – Extension for the output file. Default is ‘.fits’.

Returns:

The path for the output file

Return type:

Path

pypeit.outputfiles.strip_raw_extension(filename, allowed_extensions)[source]

Strip the raw-file extension from a filename.

Parameters:
  • filename (str, Path) – The name of the raw file. Only the file name is used; see Path.name.

  • allowed_extensions (list) – List of recognized raw-file extensions for the relevant spectrograph, used to correctly strip the extension from filename; see allowed_extensions.

Returns:

The file name with the extension removed. If no extension in allowed_extensions matches, a warning is issued and the full input name is returned unmodified.

Return type:

str