pypeit.spec2dobj module
Module for the Spec2DObj class
- class pypeit.spec2dobj.AllSpec2DObj[source]
Bases:
object
Simple object to hold Spec2DObj objects and perform I/O
Anything that goes into self[‘meta’] must be parseable into a FITS Header
Restrict keys to be type int or ‘meta’ and items to be
Spec2DObj
- build_primary_hdr(raw_header, spectrograph, calib_dir=None, redux_path=None, subheader=None, history=None)[source]
Build the primary header for a spec2d file
- Parameters:
raw_header (astropy.io.fits.Header) – Header from the raw FITS file (i.e. original header)
spectrograph (
Spectrograph
) – Spectrograph used to obtain the data.calib_dir (
str
) – Path to the folder with processed calibration framesredux_path (
str
, optional) – Full path to the reduction output files.subheader (
dict
, optional) – Generated bysubheader_for_spec()
.
- Returns:
The primary header for the output fits file.
- Return type:
- property detectors
Return the list of detector/mosaic names, assuming they are the list of all keys except for meta.
- classmethod from_fits(filename, chk_version=True)[source]
- Parameters:
- Returns:
The constructed object.
- Return type:
- hdr_prefix = 'ALLSPEC2D_'
- property keys
Return the list of attributes
- write_to_fits(outfile, pri_hdr=None, update_det=None, slitspatnum=None, overwrite=True)[source]
Write the spec2d FITS file
- Parameters:
pri_hdr (astropy.io.fits.Header, optional) – Header to be used in lieu of default Usually generated by
build_primary_hdr()
slitspatnum (
str
orlist
, optional) – Restricted set of slits for reduction If provided, do not clobber the existing file but only update the indicated slits. Useful for re-running on a subset of slitspri_hdr() – Baseline primary header. If None, initial primary header is empty. Usually generated by
build_primary_hdr()
update_det (
list
, optional) – If the output file already exists, this sets the list of detectors/mosaics to update with the data in this object. If None, a new file is constructed from scratch, if overwrite is True. Otherwise, the existing file is read and any detectors in that file but not in this one are added to this object. I.e., ifupdate_det
is not None, this method can alter the object.overwrite (
bool
, optional) – If true and the output file already exists, overwrite it. The combination of this andupdate_det
may also alter this object based on the existing file.
- class pypeit.spec2dobj.Spec2DObj(sciimg, ivarraw, skymodel, bkg_redux_skymodel, objmodel, ivarmodel, scaleimg, waveimg, bpmmask, detector, sci_spat_flexure, sci_spec_flexure, vel_type, vel_corr, slits, wavesol, tilts, maskdef_designtab)[source]
Bases:
DataContainer
Class to handle 2D spectral image outputs of PypeIt
One generates one of these Objects for each detector in the exposure.
The datamodel attributes are:
Version: 1.1.1
Attribute
Type
Array Type
Description
bkg_redux_skymodel
2D sky model image without the background subtraction (float32)
bpmmask
2D bad-pixel mask for the image
det
int
Detector index
detector
Detector or Mosaic metadata
ivarmodel
2D ivar model image (float32)
ivarraw
2D processed inverse variance image (float32)
maskdef_designtab
Table with slitmask design and object info
med_chis
Median of the chi image for each slit/order
objmodel
2D object model image (float32)
scaleimg
2D multiplicative scale image [or a single scalar as an array] that has been applied to the science image (float32)
sci_spat_flexure
float
Shift, in spatial pixels, between this image and SlitTrace
sci_spec_flexure
Global shift of the spectrum to correct for spectralflexure (pixels). This is based on the sky spectrum atthe center of each slit
sciimg
2D processed science image (float32)
skymodel
2D sky model image (float32)
slits
SlitTraceSet defining the slits
std_chis
std of the chi image for each slit/order
tilts
2D tilts image (float64)
vel_corr
float
Relativistic velocity correction for wavelengths
vel_type
str
Type of reference frame correction (if any). Options are listed in the routine: WavelengthSolutionPar.valid_reference_frames() Current list: observed, heliocentric, barycentric
waveimg
2D wavelength image in vacuum (float64)
wavesol
Table with WaveCalib diagnostic info
Args:
- head0
Primary header if instantiated from a FITS file
- Type:
- _base_header(hdr=None)[source]
Override the base class method to add useful/identifying internals to the header.
- Parameters:
hdr (astropy.io.fits.Header, optional) – Header object to update. The object is modified in-place and also returned. If None, an empty header is instantiated, edited, and returned.
- Returns:
The initialized (or edited) fits header.
- Return type:
- _bundle()[source]
Over-write default _bundle() method to separate the DetectorContainer into its own HDU
- Returns:
A list of dictionaries, each list element is written to its own fits extension. See the description above.
- Return type:
- calc_chi_slit(slitidx: int, pad: int = None, remove_object: bool = True)[source]
Calculate a chi map and run some stats on it for a given slit/order
- datamodel = {'bkg_redux_skymodel': {'atype': <class 'numpy.floating'>, 'descr': '2D sky model image without the background subtraction (float32)', 'otype': <class 'numpy.ndarray'>}, 'bpmmask': {'descr': '2D bad-pixel mask for the image', 'otype': <class 'pypeit.images.imagebitmask.ImageBitMaskArray'>}, 'det': {'descr': 'Detector index', 'otype': <class 'int'>}, 'detector': {'descr': 'Detector or Mosaic metadata', 'otype': (<class 'pypeit.images.detector_container.DetectorContainer'>, <class 'pypeit.images.mosaic.Mosaic'>)}, 'ivarmodel': {'atype': <class 'numpy.floating'>, 'descr': '2D ivar model image (float32)', 'otype': <class 'numpy.ndarray'>}, 'ivarraw': {'atype': <class 'numpy.floating'>, 'descr': '2D processed inverse variance image (float32)', 'otype': <class 'numpy.ndarray'>}, 'maskdef_designtab': {'descr': 'Table with slitmask design and object info', 'otype': <class 'astropy.table.table.Table'>}, 'med_chis': {'atype': <class 'numpy.floating'>, 'descr': 'Median of the chi image for each slit/order', 'otype': <class 'numpy.ndarray'>}, 'objmodel': {'atype': <class 'numpy.floating'>, 'descr': '2D object model image (float32)', 'otype': <class 'numpy.ndarray'>}, 'scaleimg': {'atype': <class 'numpy.floating'>, 'descr': '2D multiplicative scale image [or a single scalar as an array] that has been applied to the science image (float32)', 'otype': <class 'numpy.ndarray'>}, 'sci_spat_flexure': {'descr': 'Shift, in spatial pixels, between this image and SlitTrace', 'otype': <class 'float'>}, 'sci_spec_flexure': {'descr': 'Global shift of the spectrum to correct for spectralflexure (pixels). This is based on the sky spectrum atthe center of each slit', 'otype': <class 'astropy.table.table.Table'>}, 'sciimg': {'atype': <class 'numpy.floating'>, 'descr': '2D processed science image (float32)', 'otype': <class 'numpy.ndarray'>}, 'skymodel': {'atype': <class 'numpy.floating'>, 'descr': '2D sky model image (float32)', 'otype': <class 'numpy.ndarray'>}, 'slits': {'descr': 'SlitTraceSet defining the slits', 'otype': <class 'pypeit.slittrace.SlitTraceSet'>}, 'std_chis': {'atype': <class 'numpy.floating'>, 'descr': 'std of the chi image for each slit/order', 'otype': <class 'numpy.ndarray'>}, 'tilts': {'atype': <class 'numpy.floating'>, 'descr': '2D tilts image (float64)', 'otype': <class 'numpy.ndarray'>}, 'vel_corr': {'descr': 'Relativistic velocity correction for wavelengths', 'otype': <class 'float'>}, 'vel_type': {'descr': 'Type of reference frame correction (if any). Options are listed in the routine: WavelengthSolutionPar.valid_reference_frames() Current list: observed, heliocentric, barycentric', 'otype': <class 'str'>}, 'waveimg': {'atype': <class 'numpy.floating'>, 'descr': '2D wavelength image in vacuum (float64)', 'otype': <class 'numpy.ndarray'>}, 'wavesol': {'descr': 'Table with WaveCalib diagnostic info', 'otype': <class 'astropy.table.table.Table'>}}
Provides the class data model. This is undefined in the abstract class and should be overwritten in the derived classes.
The format of the
datamodel
needed for each implementation of aDataContainer
derived class is as follows.The datamodel itself is a class attribute (i.e., it is a member of the class, not just of an instance of the class). The datamodel is a dictionary of dictionaries: Each key of the datamodel dictionary provides the name of a given datamodel element, and the associated item (dictionary) for the datamodel element provides the type and description information for that datamodel element. For each datamodel element, the dictionary item must provide:
otype
: This is the type of the object for this datamodel item. E.g., for a float or a numpy.ndarray, you would setotype=float
andotype=np.ndarray
, respectively.descr
: This provides a text description of the datamodel element. This is used to construct the datamodel tables in the pypeit documentation.
If the object type is a numpy.ndarray, you should also provide the
atype
keyword that sets the type of the data contained within the array. E.g., for a floating point array containing an image, your datamodel could be simply:datamodel = {'image' : dict(otype=np.ndarray, atype=float, descr='My image')}
More advanced examples are given in the top-level module documentation.
Currently,
datamodel
components are restricted to haveotype
that aretuple
,int
,float
,numpy.integer
,numpy.floating
, numpy.ndarray, or astropy.table.Table objects. E.g.,datamodel
values forotype
cannot bedict
.
- property detname
- classmethod from_file(ifile, detname, chk_version=True)[source]
Instantiate the object from an extension in the specified fits file.
Over-load
from_file()
to specify detector to read.- Parameters:
detname (
str
) – The string identifier for the detector or mosaic used to select the data that is read.chk_version (
bool
, optional) – Passed tofrom_hdu()
.
- classmethod from_hdu(hdu, detname, chk_version=True)[source]
Override base-class
from_hdu()
to specify detector to read.- Parameters:
hdu (astropy.io.fits.HDUList, astropy.io.fits.ImageHDU, astropy.io.fits.BinTableHDU) – The HDU(s) with the data to use for instantiation.
detname (
str
) – The string identifier for the detector or mosaic used to select the data that is read.chk_version (
bool
, optional) – If False, allow a mismatch in datamodel to proceed
- Returns:
2D spectra object.
- Return type:
- property hdu_prefix
Provides for a dynamic hdu_prefix based on our naming model.
- Returns:
Detector/mosaic identifier
- Return type:
- internals = ['calibs', 'process_steps', 'head0']
A list of strings identifying a set of internal attributes that are not part of the datamodel.
- select_flag(flag=None, invert=False)[source]
Return a boolean array that selects pixels masked with the specified bits in
bpmmask
.For example, to create a bad-pixel mask based on which pixels have cosmic-ray detections, run:
cr_bpm = self.select_flag(flag='CR')
Or, to create a good-pixel mask for all pixels that are not flagged for any reason, run:
gpm = self.select_flag(invert=True)
- Parameters:
flag (
str
, array-like, optional) – One or more flags to select when returning the boolean mask. If None, pixels flagged for any reason are returned as True.invert (
bool
, optional) – If False, the return mask is True for masked pixels, False for good pixels (i.e., a bad-pixel mask). If True, invert the sense of the mask (i.e., create a good-pixel mask, True for good pixels, False for bad pixels).
- Returns:
Boolean array where pixels with the selected bits flagged are returned as True (if
invert
is False); i.e., this is a boolean bad-pixel mask (or a good-pixel mask wheninvert
is True). Ifflag
is not provided, pixels flagged for any reason are returned as True.- Return type:
- update_slits(spec2DObj)[source]
Update the object at all good slits in the input object
- Parameters:
spec2DObj (Spec2DObj)
Returns:
- version = '1.1.1'
Provides the string representation of the class version.
This is currently put to minimal use so far, but will used for I/O verification in the future.
Each derived class should provide a version to guard against data model changes during development.