pypeit.specobj module
Module for the SpecObj classes
- class pypeit.specobj.SpecObj(PYPELINE, DET, OBJTYPE='unknown', SLITID=None, ECH_ORDER=None, ECH_ORDERINDX=None)[source]
Bases:
DataContainer
Class to handle single spectra from a single exposure.
One generates one of these objects for each spectrum in the exposure. They are instantiated by the object finding routine, and then all spectral extraction information for the object are assigned as attributes
The datamodel attributes are:
Version: 1.1.10
Attribute
Type
Array Type
Description
BOX_CHI2
float
Reduced chi2 of the model fit for this spectral pixel
BOX_COUNTS
float
Boxcar flux (counts)
BOX_COUNTS_IVAR
float
Inverse variance of optimally extracted flux using modelivar image (counts^2)
BOX_COUNTS_NIVAR
float
Boxcar extracted noise variance, sky+read noise only (counts^2)
BOX_COUNTS_SIG
float
Boxcar extracted noise from IVAR (counts)
BOX_COUNTS_SIG_DET
float
Boxcar extracted detector noise (counts)
BOX_COUNTS_SKY
float
Boxcar extracted sky (counts)
BOX_FLAM
float
Boxcar flux (erg/s/cm^2/Ang)
BOX_FLAM_IVAR
float
Boxcar flux inverse variance (1e-17 erg/s/cm^2/Ang)^-2
BOX_FLAM_SIG
float
Boxcar flux uncertainty (1e-17 erg/s/cm^2/Ang)
BOX_FRAC_USE
float
Fraction of pixels in the object profile subimage used for this extraction
BOX_FWHM
float
Spectral FWHM (in Angstroms) at every pixel of the boxcar extracted flux.
BOX_MASK
Mask for boxcar extracted flux. True=good
BOX_NPIX
float
Number of pixels used for the boxcar extraction; can be fractional
BOX_RADIUS
float
Size of boxcar radius (pixels)
BOX_WAVE
float
Boxcar Wavelengths in vacuum (Angstroms)
DEC
float
Declination (J2000) decimal degree
DET
str
A string identifier for the reduced detector or mosaic.
DETECTOR
Object with the detector or mosaic metadata
ECH_FRACPOS
float, numpy.floating
Synced echelle fractional location of the object on the slit
ECH_NAME
str
Name of the object for echelle data. Same as NAME above but order numbers are omitted giving a unique name per object.
ECH_OBJID
int, numpy.integer
Object ID for echelle data. Each object is given an index in the order it appears increasing from from left to right. These are one based.
ECH_ORDER
int, numpy.integer
Physical echelle order
ECH_ORDERINDX
int, numpy.integer
Order indx, analogous to SLITID for echelle. Zero based.
FLEX_SHIFT_GLOBAL
float
Global shift of the spectrum to correct for spectralflexure (pixels). This is based on the sky spectrum atthe center of the slit
FLEX_SHIFT_LOCAL
float
Local shift of the spectrum to correct for spectralflexure (pixels). This should be a small correction tothe global value, and is based on the sky spectrumextracted near the object
FLEX_SHIFT_TOTAL
float
Total shift of the spectrum to correct for spectralflexure (pixels). This is the sum of the global andlocal FLEX_SHIFT
FWHM
float
Spatial FWHM of the object (pixels)
FWHMFIT
float
Spatial FWHM across the detector (pixels)
MASKDEF_EXTRACT
bool
Boolean indicating if this is a forced extraction at the expected location from slitmask design.
MASKDEF_ID
int, numpy.integer
Slitmask definition ID
MASKDEF_OBJMAG
float
Magnitude of the object from the slitmask definition
MASKDEF_OBJMAG_BAND
str
Magnitude band of the object from the slitmask definition
MASKDEF_OBJNAME
str
Name of the object from the slitmask definition
NAME
str
Name of the object following the naming model
OBJID
int, numpy.integer
Object ID for multislit data. Each object is given an index for the slit it appears increasing from from left to right. These are one based.
OBJTYPE
str
Object type (e.g., standard, science)
OPT_CHI2
float
Reduced chi2 of the model fit for this spectral pixel
OPT_COUNTS
float
Optimal flux (counts)
OPT_COUNTS_IVAR
float
Inverse variance of optimally extracted flux using modelivar image (counts^2)
OPT_COUNTS_NIVAR
float
Optimally extracted noise variance, sky+read noise only (counts^2)
OPT_COUNTS_SIG
float
Optimally extracted noise from IVAR (counts)
OPT_COUNTS_SIG_DET
float
Optimally extracted detector noise (counts)
OPT_COUNTS_SKY
float
Optimally extracted sky (counts)
OPT_FLAM
float
Optimal flux (1e-17 erg/s/cm^2/Ang)
OPT_FLAM_IVAR
float
Optimal flux inverse variance (1e-17 erg/s/cm^2/Ang)^-2
OPT_FLAM_SIG
float
Optimal flux uncertainty (1e-17 erg/s/cm^2/Ang)
OPT_FRAC_USE
float
Fraction of pixels in the object profile subimage used for this extraction
OPT_FWHM
float
Spectral FWHM (in Angstroms) at every pixel of the optimally extracted flux.
OPT_MASK
Mask for optimally extracted flux. True=good
OPT_WAVE
float
Optimal Wavelengths in vacuum (Angstroms)
PYPELINE
str
Name of the PypeIt pipeline mode
RA
float
Right Ascension (J2000) decimal degree
S2N
float
Median signal to noise ratio of the extracted spectrum(OPT if available, otherwise BOX)
SLITID
int, numpy.integer
PypeIt slit ID (aka SPAT_ID).
SPAT_FRACPOS
float, numpy.floating
Fractional location of the object on the slit
SPAT_FWHM
float
Spatial FWHM of the object (arcsec)
SPAT_PIXPOS
float, numpy.floating
Spatial location of the trace on detector (pixel) at half-way
TRACE_SPAT
float
Object trace along the spec (spatial pixel)
VEL_CORR
float
Relativistic velocity correction for wavelengths
VEL_TYPE
str
Type of heliocentric correction (if any)
WAVE_RMS
float, numpy.floating
RMS (pix) for the wavelength solution for this slit.
hand_extract_flag
bool
Boolean indicating if this is a forced extraction at the location provided by the user.
maskwidth
float, numpy.floating
Size (in units of spatial fwhm) of the region used for local sky subtraction
smash_peakflux
float
Peak value of the spectral direction collapsed spatial profile
smash_snr
float
Peak S/N ratio of the spectral direction collapsed patial profile
trace_spec
int, numpy.integer
Array of pixels along the spectral direction
- Parameters:
PYPELINE (
str
) – Name of thePypeIt
pipeline method. Allowed options are MultiSlit, Echelle, or SlicerIFU.DET (
str
) – The name of the detector or mosaic from which the spectrum was extracted. For example, DET01.OBJTYPE (
str
, optional) – Object type. For example: ‘unknown’, ‘standard’, ‘science’.SLITID (
int
, optional) – For multislit and SlicerIFU reductions, this is an identifier for the slit (max=9999).ECH_ORDER (
int
, optional) – Physical order number.ECH_ORDERINDX (
int
, optional) – Running index for the order.
- __repr__()[source]
Over-ride print representation
- Returns:
Basics of the Data Container
- Return type:
- _bundle(**kwargs)[source]
Override base class to handle inclusion of
DetectorContainer
orMosaic
objects for each spectrum.
- apply_flux_calib(wave_zp, zeropoint, exptime, tellmodel=None, extinct_correct=False, airmass=None, longitude=None, latitude=None, extinctfilepar=None, extrap_sens=False)[source]
Apply a sensitivity function to our spectrum
FLAM, FLAM_SIG, and FLAM_IVAR are generated
- Parameters:
wave_zp (numpy.ndarray) – Zeropoint wavelength array
zeropoint (numpy.ndarray) – zeropoint array
exptime (float) – Exposure time
tellmodel – Telluric correction
extinct_correct – If True, extinction correct
airmass (float, optional) – Airmass
longitude (float, optional) – longitude in degree for observatory
latitude (float, optional) – latitude in degree for observatory Used for extinction correction
extinctfilepar (str, optional) – [sensfunc][UVIS][extinct_file] parameter Used for extinction correction
extrap_sens (bool, optional) – Extrapolate the sensitivity function (instead of crashing out)
- apply_helio(vel_corr, refframe)[source]
Apply a heliocentric correction
Wavelength arrays are modified in place
- apply_spectral_flexure(shift, sky_spec)[source]
Apply interpolation with the flexure dict
- Parameters:
shift (float) – additive spectral flexure in pixels
sky_spec (linetools.spectra.xspectrum1d.XSpectrum1D) – Sky Spectrum
- Returns:
New sky spectrum (mainly for QA)
- Return type:
- best_ext_match(extract=None, fluxed=True)[source]
Determine the extraction and calibration type that best matches a user request.
Precedence is given to the requested extraction and calibration types. Beyond that, optimal extraction takes precedence over boxcar extraction, and flux-calibrated data take precedence over uncalibrated counts.
- Parameters:
extract (
str
, optional) – The extraction used to produce the spectrum. Must be either None,'BOX'
(for a boxcar extraction), or'OPT'
for optimal extraction. If None, the optimal extraction will be returned, if it exists, otherwise the boxcar extraction will be returned.fluxed (
bool
, optional) – If True, return the flux calibrated spectrum, if it exists. If the flux calibration hasn’t been performed orfluxed=False
, the spectrum is returned in counts.
- Returns:
The adjusted extraction type (
'BOX'
or'OPT'
) and the adjusted calibration type (True for flux-calibrated, False for uncalibrated counts).- Return type:
- datamodel = {'BOX_CHI2': {'atype': <class 'float'>, 'descr': 'Reduced chi2 of the model fit for this spectral pixel', 'otype': <class 'numpy.ndarray'>}, 'BOX_COUNTS': {'atype': <class 'float'>, 'descr': 'Boxcar flux (counts)', 'otype': <class 'numpy.ndarray'>}, 'BOX_COUNTS_IVAR': {'atype': <class 'float'>, 'descr': 'Inverse variance of optimally extracted flux using modelivar image (counts^2)', 'otype': <class 'numpy.ndarray'>}, 'BOX_COUNTS_NIVAR': {'atype': <class 'float'>, 'descr': 'Boxcar extracted noise variance, sky+read noise only (counts^2)', 'otype': <class 'numpy.ndarray'>}, 'BOX_COUNTS_SIG': {'atype': <class 'float'>, 'descr': 'Boxcar extracted noise from IVAR (counts)', 'otype': <class 'numpy.ndarray'>}, 'BOX_COUNTS_SIG_DET': {'atype': <class 'float'>, 'descr': 'Boxcar extracted detector noise (counts)', 'otype': <class 'numpy.ndarray'>}, 'BOX_COUNTS_SKY': {'atype': <class 'float'>, 'descr': 'Boxcar extracted sky (counts)', 'otype': <class 'numpy.ndarray'>}, 'BOX_FLAM': {'atype': <class 'float'>, 'descr': 'Boxcar flux (erg/s/cm^2/Ang)', 'otype': <class 'numpy.ndarray'>}, 'BOX_FLAM_IVAR': {'atype': <class 'float'>, 'descr': 'Boxcar flux inverse variance (1e-17 erg/s/cm^2/Ang)^-2', 'otype': <class 'numpy.ndarray'>}, 'BOX_FLAM_SIG': {'atype': <class 'float'>, 'descr': 'Boxcar flux uncertainty (1e-17 erg/s/cm^2/Ang)', 'otype': <class 'numpy.ndarray'>}, 'BOX_FRAC_USE': {'atype': <class 'float'>, 'descr': 'Fraction of pixels in the object profile subimage used for this extraction', 'otype': <class 'numpy.ndarray'>}, 'BOX_FWHM': {'atype': <class 'float'>, 'descr': 'Spectral FWHM (in Angstroms) at every pixel of the boxcar extracted flux.', 'otype': <class 'numpy.ndarray'>}, 'BOX_MASK': {'atype': <class 'numpy.bool_'>, 'descr': 'Mask for boxcar extracted flux. True=good', 'otype': <class 'numpy.ndarray'>}, 'BOX_NPIX': {'atype': <class 'float'>, 'descr': 'Number of pixels used for the boxcar extraction; can be fractional', 'otype': <class 'numpy.ndarray'>}, 'BOX_RADIUS': {'descr': 'Size of boxcar radius (pixels)', 'otype': <class 'float'>}, 'BOX_WAVE': {'atype': <class 'float'>, 'descr': 'Boxcar Wavelengths in vacuum (Angstroms)', 'otype': <class 'numpy.ndarray'>}, 'DEC': {'descr': 'Declination (J2000) decimal degree', 'otype': <class 'float'>}, 'DET': {'descr': 'A string identifier for the reduced detector or mosaic.', 'otype': <class 'str'>}, 'DETECTOR': {'descr': 'Object with the detector or mosaic metadata', 'otype': (<class 'pypeit.images.detector_container.DetectorContainer'>, <class 'pypeit.images.mosaic.Mosaic'>)}, 'ECH_FRACPOS': {'descr': 'Synced echelle fractional location of the object on the slit', 'otype': (<class 'float'>, <class 'numpy.floating'>)}, 'ECH_NAME': {'descr': 'Name of the object for echelle data. Same as NAME above but order numbers are omitted giving a unique name per object.', 'otype': <class 'str'>}, 'ECH_OBJID': {'descr': 'Object ID for echelle data. Each object is given an index in the order it appears increasing from from left to right. These are one based.', 'otype': (<class 'int'>, <class 'numpy.integer'>)}, 'ECH_ORDER': {'descr': 'Physical echelle order', 'otype': (<class 'int'>, <class 'numpy.integer'>)}, 'ECH_ORDERINDX': {'descr': 'Order indx, analogous to SLITID for echelle. Zero based.', 'otype': (<class 'int'>, <class 'numpy.integer'>)}, 'FLEX_SHIFT_GLOBAL': {'descr': 'Global shift of the spectrum to correct for spectralflexure (pixels). This is based on the sky spectrum atthe center of the slit', 'otype': <class 'float'>}, 'FLEX_SHIFT_LOCAL': {'descr': 'Local shift of the spectrum to correct for spectralflexure (pixels). This should be a small correction tothe global value, and is based on the sky spectrumextracted near the object', 'otype': <class 'float'>}, 'FLEX_SHIFT_TOTAL': {'descr': 'Total shift of the spectrum to correct for spectralflexure (pixels). This is the sum of the global andlocal FLEX_SHIFT', 'otype': <class 'float'>}, 'FWHM': {'descr': 'Spatial FWHM of the object (pixels)', 'otype': <class 'float'>}, 'FWHMFIT': {'atype': <class 'float'>, 'descr': 'Spatial FWHM across the detector (pixels)', 'otype': <class 'numpy.ndarray'>}, 'MASKDEF_EXTRACT': {'descr': 'Boolean indicating if this is a forced extraction at the expected location from slitmask design. ', 'otype': <class 'bool'>}, 'MASKDEF_ID': {'descr': 'Slitmask definition ID', 'otype': (<class 'int'>, <class 'numpy.integer'>)}, 'MASKDEF_OBJMAG': {'descr': 'Magnitude of the object from the slitmask definition', 'otype': <class 'float'>}, 'MASKDEF_OBJMAG_BAND': {'descr': 'Magnitude band of the object from the slitmask definition', 'otype': <class 'str'>}, 'MASKDEF_OBJNAME': {'descr': 'Name of the object from the slitmask definition', 'otype': <class 'str'>}, 'NAME': {'descr': 'Name of the object following the naming model', 'otype': <class 'str'>}, 'OBJID': {'descr': 'Object ID for multislit data. Each object is given an index for the slit it appears increasing from from left to right. These are one based.', 'otype': (<class 'int'>, <class 'numpy.integer'>)}, 'OBJTYPE': {'descr': 'Object type (e.g., standard, science)', 'otype': <class 'str'>}, 'OPT_CHI2': {'atype': <class 'float'>, 'descr': 'Reduced chi2 of the model fit for this spectral pixel', 'otype': <class 'numpy.ndarray'>}, 'OPT_COUNTS': {'atype': <class 'float'>, 'descr': 'Optimal flux (counts)', 'otype': <class 'numpy.ndarray'>}, 'OPT_COUNTS_IVAR': {'atype': <class 'float'>, 'descr': 'Inverse variance of optimally extracted flux using modelivar image (counts^2)', 'otype': <class 'numpy.ndarray'>}, 'OPT_COUNTS_NIVAR': {'atype': <class 'float'>, 'descr': 'Optimally extracted noise variance, sky+read noise only (counts^2)', 'otype': <class 'numpy.ndarray'>}, 'OPT_COUNTS_SIG': {'atype': <class 'float'>, 'descr': 'Optimally extracted noise from IVAR (counts)', 'otype': <class 'numpy.ndarray'>}, 'OPT_COUNTS_SIG_DET': {'atype': <class 'float'>, 'descr': 'Optimally extracted detector noise (counts)', 'otype': <class 'numpy.ndarray'>}, 'OPT_COUNTS_SKY': {'atype': <class 'float'>, 'descr': 'Optimally extracted sky (counts)', 'otype': <class 'numpy.ndarray'>}, 'OPT_FLAM': {'atype': <class 'float'>, 'descr': 'Optimal flux (1e-17 erg/s/cm^2/Ang)', 'otype': <class 'numpy.ndarray'>}, 'OPT_FLAM_IVAR': {'atype': <class 'float'>, 'descr': 'Optimal flux inverse variance (1e-17 erg/s/cm^2/Ang)^-2', 'otype': <class 'numpy.ndarray'>}, 'OPT_FLAM_SIG': {'atype': <class 'float'>, 'descr': 'Optimal flux uncertainty (1e-17 erg/s/cm^2/Ang)', 'otype': <class 'numpy.ndarray'>}, 'OPT_FRAC_USE': {'atype': <class 'float'>, 'descr': 'Fraction of pixels in the object profile subimage used for this extraction', 'otype': <class 'numpy.ndarray'>}, 'OPT_FWHM': {'atype': <class 'float'>, 'descr': 'Spectral FWHM (in Angstroms) at every pixel of the optimally extracted flux.', 'otype': <class 'numpy.ndarray'>}, 'OPT_MASK': {'atype': <class 'numpy.bool_'>, 'descr': 'Mask for optimally extracted flux. True=good', 'otype': <class 'numpy.ndarray'>}, 'OPT_WAVE': {'atype': <class 'float'>, 'descr': 'Optimal Wavelengths in vacuum (Angstroms)', 'otype': <class 'numpy.ndarray'>}, 'PYPELINE': {'descr': 'Name of the PypeIt pipeline mode', 'otype': <class 'str'>}, 'RA': {'descr': 'Right Ascension (J2000) decimal degree', 'otype': <class 'float'>}, 'S2N': {'descr': 'Median signal to noise ratio of the extracted spectrum(OPT if available, otherwise BOX)', 'otype': <class 'float'>}, 'SLITID': {'descr': 'PypeIt slit ID (aka SPAT_ID).', 'otype': (<class 'int'>, <class 'numpy.integer'>)}, 'SPAT_FRACPOS': {'descr': 'Fractional location of the object on the slit', 'otype': (<class 'float'>, <class 'numpy.floating'>)}, 'SPAT_FWHM': {'descr': 'Spatial FWHM of the object (arcsec)', 'otype': <class 'float'>}, 'SPAT_PIXPOS': {'descr': 'Spatial location of the trace on detector (pixel) at half-way', 'otype': (<class 'float'>, <class 'numpy.floating'>)}, 'TRACE_SPAT': {'atype': <class 'float'>, 'descr': 'Object trace along the spec (spatial pixel)', 'otype': <class 'numpy.ndarray'>}, 'VEL_CORR': {'descr': 'Relativistic velocity correction for wavelengths', 'otype': <class 'float'>}, 'VEL_TYPE': {'descr': 'Type of heliocentric correction (if any)', 'otype': <class 'str'>}, 'WAVE_RMS': {'descr': 'RMS (pix) for the wavelength solution for this slit.', 'otype': (<class 'float'>, <class 'numpy.floating'>)}, 'hand_extract_flag': {'descr': 'Boolean indicating if this is a forced extraction at the location provided by the user. ', 'otype': <class 'bool'>}, 'maskwidth': {'descr': 'Size (in units of spatial fwhm) of the region used for local sky subtraction', 'otype': (<class 'float'>, <class 'numpy.floating'>)}, 'smash_peakflux': {'descr': 'Peak value of the spectral direction collapsed spatial profile', 'otype': <class 'float'>}, 'smash_snr': {'descr': 'Peak S/N ratio of the spectral direction collapsed patial profile', 'otype': <class 'float'>}, 'trace_spec': {'atype': (<class 'int'>, <class 'numpy.integer'>), 'descr': 'Array of pixels along the spectral direction', 'otype': <class 'numpy.ndarray'>}}
Defines the current datmodel.
- classmethod from_arrays(PYPELINE: str, wave: ndarray, counts: ndarray, ivar: ndarray, mode='OPT', DET='DET01', SLITID=0, **kwargs)[source]
- internals = ['smash_peakflux', 'smash_snr', 'hand_extract_flag', 'hand_extract_spec', 'hand_extract_spat', 'hand_extract_det', 'hand_extract_fwhm', 'prof_nsigma', 'sign', 'min_spat', 'max_spat', 'ech_frac_was_fit', 'ech_snr']
A list of strings identifying a set of internal attributes that are not part of the datamodel.
- med_s2n()[source]
Return median S/N of the spectrum Uses OPT_COUNTS if present and then BOX_COUNTS
- Returns:
float
- property mnx_wave
Return min, max wavelength of the spectrum Uses OPT_WAVE if present and then BOX_WAVE
- Returns:
min, max (float)
- Return type:
- ready_for_extraction()[source]
Simple method to check all the items are filled and ready for skysub and extraction.
- Returns:
True if all checks have passed
- Return type:
- set_name()[source]
Construct the
PypeIt
name for this object.The
PypeIt
name depends on the type of data being processed:For multislit and SlicerIFU data, the name is
SPATnnnn-SLITmmmm-{DET}
, wherennnn
is the nearest integer pixel in the spatial direction (at the spectral midpoint) where the object was extracted,mmmm
is the slit identification number, and{DET}
is the string identifier for the detector or mosaic.For echelle data, the name is
OBJnnnn-{DET}-ORDERoooo
, wherennnn
is 1000 times the fractional position along the spatial direction rounded to the nearest integer,{DET}
is the string identifier for the detector or mosaic, andoooo
is the echelle order.
For echelle data, this modifies both
ECH_NAME
andNAME
; otherwise, only the latter is set.
- property slit_order
- property slit_orderindx
- to_hdu(**kwargs)[source]
Override the base class function to force the main datamodel attributes to be written to an astropy.io.fits.BinTableHDU object. This is identical to the base class method except
force_to_bintbl
is always set to True.
- to_xspec1d(masked=True, extraction='OPT', fluxed=True)[source]
Create an XSpectrum1D using this spectrum.
- Parameters:
- Returns:
Spectrum object
- Return type:
- update_flex_shift(shift, flex_type='local')[source]
Store the total spectral flexure shift in pixels
- Parameters:
shift (float) – additive spectral flexure in pixels
- version = '1.1.10'
Current datamodel version number.