pypeit.collate module
This module contains code for collating multiple 1d spectra by source object.
- class pypeit.collate.SourceObject(spec1d_obj, spec1d_header, spec1d_file, spectrograph, match_type)[source]
Bases:
objectA group of reduced spectra from the same source object. This contains the information needed to coadd the spectra and archive the metadata.
An instance is initiated with the first spectra of the group. Additional spectra can be compared with this object to see if it matches using the match method, and are added to it if they do.
- Parameters:
spec1d_obj (
pypeit.specobj.SpecObj) – The initial spectra of the group as a SpecObj.spec1d_header (astropy.io.fits.Header) – The header for the first spec1d file in the group.
spec1d_file (str) – Filename of the first spec1d file in the group.
spectrograph (
pypeit.spectrographs.spectrograph.Spectrograph) – The spectrograph that was used to take the data.match_type (str) – How spectra should be compared. ‘ra/dec’ means the spectra should be compared using the sky coordinates in RA and DEC. ‘pixel’ means the spectra should be compared by the spatial pixel coordinates in the image.
- Variables:
spec_obj_list (list of
pypeit.spectrographs.spectrograph.Spectrograph) – The list of spectra in the group as SpecObj objects.spec1d_file_list (list of str) – The pathnames of the spec1d files in the group.
spec1d_header_list – (list of astropy.io.fits.Header): The headers of the spec1d files in the group
- _config_key_match(header)[source]
Check to see if the configuration keys from a spec1d file match the ones for this SourceObject.
- Parameters:
header (astropy.io.fits.Header) – Header from a spec1d file.
- Returns:
- True if the configuration keys match,
false if they do not.
- Return type:
- classmethod build_source_objects(specobjs_list, spec1d_files, match_type)[source]
Build a list of SourceObjects from a list of spec1d files. There will be one SourceObject per SpecObj in the resulting list (i.e. no combining or collating is done by this method).
- Parameters:
specobjs_list (list of
pypeit.specobjs.SpecObjs) – List of SpecObjs objects to build from.spec1d_files (list of str) – List of spec1d filenames corresponding to each SpecObjs object.
match_type (str) – What type of matching the SourceObjects will be configured for. Must be either ‘ra/dec’ or ‘pixel’
- Returns:
A list of uncollated SourceObjects with one SpecObj per SourceObject.
- Return type:
list of
SourceObject
- combine(other_source_object)[source]
Combine this SourceObject with another. The two objects must be from the same spectrograph and use the same match type.
- Parameters:
other_source_object (
SourceObject) – The other object to combine with.- Returns:
This SourceObject, now combined with other_source_object.
- Return type:
- match(spec_obj, spec1d_header, tolerance, unit=Unit('arcsec'))[source]
Determine if a SpecObj matches this group within the given tolerance. This will also compare the configuration keys to make sure the SpecObj is compatible with the ones in this SourceObject.
- Parameters:
spec_obj (
pypeit.specobj.SpecObj) – The SpecObj to compare with this SourceObject.spec1d_header (astropy.io.fits.Header) – The header from the spec1d that dontains the SpecObj.
tolerance (float) – Maximum distance that two spectra can be from each other to be considered to be from the same source. Measured in floating point pixels or as an angular distance (see
unit1argument).unit (astropy.units.Unit) – Units of
toleranceargument if match_type is ‘ra/dec’. Defaults to arcseconds. Igored if match_type is ‘pixel’.
- Returns:
True if the SpecObj matches this group, False otherwise.
- Return type:
- pypeit.collate.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.collate.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.collate.collate_spectra_by_source(source_list, tolerance, unit=Unit('arcsec'))[source]
Given a list of spec1d files from PypeIt, group the spectra within the files by their source object. The grouping is done by comparing the position of each spectra (using either pixel or RA/DEC) using a given tolerance.
- Parameters:
source_list (list of
SourceObject) – A list of source objects, one SpecObj per object, ready for collation.tolerance (float) – Maximum distance that two spectra can be from each other to be considered to be from the same source. Measured in floating point pixels or as an angular distance (see
unitargument).unit (astropy.units.Unit) – Units of
toleranceargument if match_type is ‘ra/dec’. Defaults to arcseconds. Ignored if match_type is ‘pixel’.
- Returns:
The collated spectra as SourceObjects.
- Return type:
- pypeit.collate.copy_spec1d_to_outdir(spec1d_files, outdir)[source]
Copy the spec1d files to the requested outdir, preserving the originals
- pypeit.collate.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.datcontains metadata to report on the coadded output files from the collate process. Likecoadded_files.datit 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.collate.exclude_source_objects(source_objects, exclude_map, par)[source]
Exclude
SourceObjectobjects based on a slit exclude map and the user’s parameters.- Parameters:
source_objects (
list) – List of uncollatedSourceObjectobjects to filter. There should only be oneSpecObjperSourceObject.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:
- Return type:
- pypeit.collate.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.collate.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.collate.flux(par, spectrograph, spec1d_files, failed_fluxing_log)[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_log (list of str) – Return parameter describing any failures that occurred when fluxing.
- Returns:
The spec1d files that were successfully flux calibrated.
- Return type:
- pypeit.collate.get_report_metadata(object_header_keys, spec_obj_keys, file_info)[source]
Gets the metadata from a
SourceObjectinstance 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 theArchiveMetadataobject. 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 ofNonevalues 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.collate.read_spec1d_files(par, spec1d_files, failure_log)[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: