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 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.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:
- 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 bycollate_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, aSpectrograph
instance with the spectrograph parameters used to take the data, and alist
with the spec1d files read from the command line or.collate1d
file.- Return type:
- pypeit.scripts.collate_1d.coadd(par, coaddfile, source)[source]
coadd the spectra for a given source.
- Parameters:
par (
Collate1DPar
) – Parameters for the coaddingsource (
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
- 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. Likecoadded_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:
- 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 uncollatedSourceObject
objects to filter. There should only be oneSpecObj
perSourceObject
.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 ofSourceObject
with any excluded ones removed.excluded_messages (
list
): A list of messages explaining why some source objects were excluded.
- Return type:
- 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.
- 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.
- 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:
- 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 theArchiveMetadata
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 ofNone
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:.
- Return type:
- pypeit.scripts.collate_1d.read_spec1d_files(par, spec1d_files, failure_msgs)[source]
Read spec1d files.
- Parameters:
- Returns:
The SpecObjs objects that were successfully read. list of str: The spec1d files that were successfully read.
- Return type:
- pypeit.scripts.collate_1d.refframe_correction(par, spectrograph, spec1d_files, spec1d_failure_msgs)[source]