pypeit.scripts.collate_1d module

This script collates multiple 1d spectra in multiple files by object, runs flux calibration on them, and then coadds them.

class pypeit.scripts.collate_1d.Collate1D[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 of os.getcwd() when the script is executed. This means help dialogs will include this replacement, and parsing of the command line will use os.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:

argparse.ArgumentParser

static main(args)[source]

Execute the script.

pypeit.scripts.collate_1d.build_coadd_file_name(source_object)[source]

Build the output file name for coadding. The filename convention is J<hmsdms+dms>_<instrument name>_<YYYYMMDD>.fits when matching by RA/DEC and SPAT_<spatial position>_<instrument name>_<YYYYMMDD>.fits when matching by pixel position. The date portion may be <YYYYMMDD-YYYMMDD> if the files coadded span more than one date.

Currently instrument_name is taken from spectrograph.camera

Returns:

The name of the coadd output file.

Return type:

str

pypeit.scripts.collate_1d.build_parameters(args)[source]

Read the command-line arguments and the input .collate1d file (if any), to build the parameters needed by collate_1d.

Parameters:

args (argparse.Namespace) – The parsed command line as returned by the argparse module.

Returns:

Returns three objects: a PypeItPar instance with the parameters for collate_1d, a Spectrograph instance with the spectrograph parameters used to take the data, and a list with the spec1d files read from the command line or .collate1d file.

Return type:

tuple

pypeit.scripts.collate_1d.coadd(par, coaddfile, source)[source]

coadd the spectra for a given source.

Parameters:
  • par (Collate1DPar) – Parameters for the coadding

  • source (SourceObject) – The SourceObject with information on which files and spectra to coadd.

pypeit.scripts.collate_1d.copy_spec1d_to_outdir(spec1d_files, outdir)[source]

Copy the spec1d files to the requested outdir, preserving the originals

Parameters:
  • spec1d_files (list of str) – List of spec1d files generated by PypeIt.

  • outdir (str) – Directory to copy the spec1d files.

Returns:

The pathnames of the newly copied files.

Return type:

list of str

pypeit.scripts.collate_1d.create_report_archive(par)[source]

Create an report archive with the desired metadata information.

Metadata is written to three files in the ipac format:

  • collate_report.dat contains metadata to report on the coadded output files from the collate process. Like coadded_files.dat it may have more than one row per output file. This file is always written to the current directory.

Returns:

Object for archiving files and/or metadata.

Return type:

ArchiveDir

pypeit.scripts.collate_1d.exclude_source_objects(source_objects, exclude_map, par)[source]

Exclude SourceObject objects based on a slit exclude map and the user’s parameters.

Parameters:
  • source_objects (list) – List of uncollated SourceObject objects to filter. There should only be one SpecObj per SourceObject.

  • exclude_map (dict) – Mapping of excluded slit ids to the reasons they should be excluded.

  • par (PypeItPar) – Configuration parameters from the command line or a configuration file.

Returns:

Tuple containing two lists:

  • filtered_objects (list): A list of SourceObject with any excluded ones removed.

  • excluded_messages (list): A list of messages explaining why some source objects were excluded.

Return type:

tuple

pypeit.scripts.collate_1d.find_slits_to_exclude(spec2d_files, par)[source]

Find slits that should be excluded according to the input parameters.

The slit mask ids are returned in a map alongside the text labels for the flags that caused the slit to be excluded.

Parameters:
  • spec2d_files (list) – List of spec2d files to build the map from.

  • par (PypeItPar) – Parameters from a .collate1d file

Returns:

Mapping of slit mask ids to the flags that caused the slit to be excluded.

Return type:

dict

pypeit.scripts.collate_1d.find_spec2d_from_spec1d(spec1d_files)[source]

Find the spec2d files corresponding to the given list of spec1d files. This looks for the spec2d files in the same directory as the spec1d files. It will exit with an error if a spec2d file cannot be found.

Parameters:

spec1d_files (list of str) – List of spec1d files generated by PypeIt.

Returns:

List of the matching spec2d files.

Return type:

list of str

pypeit.scripts.collate_1d.flux(par, spectrograph, spec1d_files, failed_fluxing_msgs)[source]

Flux calibrate spec1d files using archived sens func files.

Parameters:
  • par (PypeItPar) – Parameters for collating, fluxing, and coadding.

  • spectrograph (Spectrograph) – Spectrograph for the files to flux.

  • spec1d_files (list of str) – List of spec1d files to flux calibrate.

  • failed_fluxing_msgs (list of str) – Return parameter describing any failures that occurred when fluxing.

Returns:

The spec1d files that were successfully flux calibrated.

Return type:

list of str

pypeit.scripts.collate_1d.get_report_metadata(object_header_keys, spec_obj_keys, file_info)[source]

Gets the metadata from a SourceObject instance used building a report on the results of collation. It is intended to be wrapped in by functools partial object that passes in object_header_keys and spec_obj_keys. file_info is then passed as in by the ArchiveMetadata object. Unlike the other get_*_metadata functions, this is not used for archiving; it is used for reporting on the results of collating.

If another type of file is added to the ArchiveMetadata object, the file_info argument will not be a SourceObject, In this case, a list of None values are returned.

Parameters:
  • object_header_keys (list of str) – The keys to read fom the spec1d headers from the SourceObject.

  • spec_obj_keys (list of str) – The keys to read from the (SpecObj) objects in the SourceObject.

  • file_info (SourceObject) – The source object containing the headers, filenames and SpecObj information for a coadd output file.

Returns:

A tuple of two lists:.

  • data_rows (list of list): The metadata rows built from the source object.

  • files_to_copy (iterable): An list of tuples of files to copy. Because this function is not used for archving data, this is always None.

Return type:

tuple

pypeit.scripts.collate_1d.read_spec1d_files(par, spec1d_files, failure_msgs)[source]

Read spec1d files.

Parameters:
  • (obj (par) – pypeit.par.pypeitpar.PypeItPar): Parameters for collating, fluxing, and coadding.

  • spec1d_files (list of str) – List of spec1d files to read.

  • failure_msgs (list of str) – Return parameter describing any failures that occurred when reading.

Returns:

The SpecObjs objects that were successfully read. list of str: The spec1d files that were successfully read.

Return type:

list of str

pypeit.scripts.collate_1d.refframe_correction(par, spectrograph, spec1d_files, spec1d_failure_msgs)[source]
pypeit.scripts.collate_1d.write_warnings(par, excluded_obj_msgs, failed_source_msgs, spec1d_failure_msgs, start_time, total_time)[source]

Write gathered warning messages to a collate_warnings.txt file.

Parameters:
  • excluded_obj_msgs (list of str) – Messages about which objects were excluded from collating and why.

  • failed_source_msgs (list of str) – Messages about which objects failed coadding and why.

  • spec1d_failure_msgs (list of str) – Messages about failures with spec1d files and why.