potpyri.primitives.sort_files

File sorting and file-list generation for the main pipeline.

Classifies raw files (science, flat, bias, dark, bad) from header keywords and writes a fixed-width file list used by calibration and reduction. Authors: Owen Eskandari, Kerry Paterson, Charlie Kilpatrick.

Functions

handle_files(file_list, paths, tel[, ...])

Build or read the file list: discover raw files, sort, and write table.

is_bad(hdr, tel)

Return True if the header matches bad_keywords/bad_values or has invalid binning.

is_bias(hdr, tel)

Return True if the header matches bias observation keywords and valid binning.

is_dark(hdr, tel)

Return True if the header matches dark observation keywords and valid binning.

is_flat(hdr, tel)

Return True if the header matches flat-field observation keywords.

is_science(hdr, tel)

Return True if the header matches science observation keywords and min exptime.

is_spec(hdr, tel)

Return True if the header matches spectroscopic observation keywords.

sort_files(files, file_list, tel, paths[, ...])

Classify files by type (science, flat, bias, dark) and write file list table.

potpyri.primitives.sort_files.handle_files(file_list, paths, tel, incl_bad=False, proc=None, no_redo=False, log=None)[source]

Build or read the file list: discover raw files, sort, and write table.

If no_redo and file_list exists, reads existing table. Otherwise globs raw/bad/data, runs sort_files, and writes the fixed-width list.

Parameters:
  • file_list (str) – Path to output (or existing) file list table.

  • paths (dict) – Paths dict with ‘raw’, ‘data’, ‘bad’ keys.

  • tel (Instrument) – Instrument instance.

  • incl_bad (bool, optional) – If True, include bad files in list. Default is False.

  • proc (str, optional) – Processor/run identifier for raw_format glob.

  • no_redo (bool, optional) – If True and file_list exists, read it instead of regenerating.

  • log (ColoredLogger, optional) – Logger for progress.

Returns:

File table with Target, Filter, Type, CalType, File, etc.

Return type:

astropy.table.Table

Raises:

SystemExit – If no files found or no good files after sorting.

potpyri.primitives.sort_files.is_bad(hdr, tel)[source]

Return True if the header matches bad_keywords/bad_values or has invalid binning.

Parameters:
  • hdr (astropy.io.fits.Header) – FITS header to check.

  • tel (Instrument) – Instrument instance (bad_keywords, bad_values, get_binning).

Returns:

True if file should be excluded as bad.

Return type:

bool

potpyri.primitives.sort_files.is_bias(hdr, tel)[source]

Return True if the header matches bias observation keywords and valid binning.

Parameters:
  • hdr (astropy.io.fits.Header) – FITS header to check.

  • tel (Instrument) – Instrument instance (bias_keywords, bias_values, get_binning).

Returns:

True if file is a bias.

Return type:

bool

potpyri.primitives.sort_files.is_dark(hdr, tel)[source]

Return True if the header matches dark observation keywords and valid binning.

Parameters:
  • hdr (astropy.io.fits.Header) – FITS header to check.

  • tel (Instrument) – Instrument instance (dark_keywords, dark_values, get_binning).

Returns:

True if file is a dark.

Return type:

bool

potpyri.primitives.sort_files.is_flat(hdr, tel)[source]

Return True if the header matches flat-field observation keywords.

Parameters:
  • hdr (astropy.io.fits.Header) – FITS header to check.

  • tel (Instrument) – Instrument instance (flat_keywords, flat_values).

Returns:

True if file is a flat.

Return type:

bool

potpyri.primitives.sort_files.is_science(hdr, tel)[source]

Return True if the header matches science observation keywords and min exptime.

Parameters:
  • hdr (astropy.io.fits.Header) – FITS header to check.

  • tel (Instrument) – Instrument instance (science_keywords, science_values, min_exptime, get_exptime).

Returns:

True if file is science.

Return type:

bool

potpyri.primitives.sort_files.is_spec(hdr, tel)[source]

Return True if the header matches spectroscopic observation keywords.

Parameters:
  • hdr (astropy.io.fits.Header) – FITS header to check.

  • tel (Instrument) – Instrument instance (spec_keywords, spec_values).

Returns:

True if file is spectroscopic.

Return type:

bool

potpyri.primitives.sort_files.sort_files(files, file_list, tel, paths, incl_bad=False, log=None)[source]

Classify files by type (science, flat, bias, dark) and write file list table.

Reads headers, applies instrument keyword rules, and writes a fixed-width file list.

Parameters:
  • files (list of str) – Paths to raw FITS files.

  • file_list (str) – Path to write fixed-width file list.

  • tel (Instrument) – Instrument instance.

  • paths (dict) – Paths dict (raw, data, bad, work).

  • incl_bad (bool, optional) – If True, include bad files in table. Default is False.

  • log (ColoredLogger, optional) – Logger for progress.

Returns:

Table with Target, Filter, Type, CalType, File, Exp, Time, etc.

Return type:

astropy.table.Table