mangadap.proc.templatelibrary module¶
Class that reads and prepares template libraries for use in fitting the
stellar-continuum of a spectrum. See
available_template_libraries()
for the list of default template
libraries.
The “raw” template libraries are expected to consist of 1D fits files.
The wavelength sampling can be either linear or logarithmic in
wavelength. The reference frame of the template wavelengths must be
defined as either vacuum or air. It is expected that the object spectra
to be fit are calibrated to vacuum wavelengths. When preparing the
template spectra for analysis, this class will use
pydl.goddard.astro.airtovac to convert the template wavelengths to
vacuum. Finally, one can specify that the template library is only
valid within a certain wavelength range and above a certian flux limit;
see TemplateLibraryDef
.
Preparation of the template library for use in stellar-continuum fitting
consists of a number of steps as described in the documentation of
TemplateLibrary.process_template_library()
.
A template library that has been prepared for analysis is automatically written to disk for later recovery.
Two support classes are also provided. One is a derived
mangadap.par.parset.KeywordParSet
instance that provides the
defining parameters of a DAP template library. The second is a
derived mangadap.util.bitmask.BitMask
instance that defines
the bitmasks for the template library spectra.
Class usage examples¶
TODO: Update this for new datacube usage
Assuming you have the default directory structure setup, you can do:
# Imports
from mangadap.drpfits import DRPFits
from mangadap.proc.templatelibrary import TemplateLibrary
from matplotlib import pyplot
# Define the DRP file
drpf = DRPFits(7495, 12703, 'CUBE')
# Build the template library
tpl_lib = TemplateLibrary('M11MILES', drpf=drpf, directory_path='.')
# Writes: ./manga-7495-12703-LOGCUBE_M11-MILES.fits
# Plot one of the spectra
pyplot.plot(tpl_lib.hdu['WAVE'].data, tpl_lib.hdu['FLUX'].data[0,:])
pyplot.show()
As part of the instantiation of the TemplateLibrary
object
in the above call, the template library is prepared for use in
fitting the specified DRP file. If the required processing has
already been done, the instantiation of the TemplateLibrary
object simply reads the existing file. If you do not have the
default directory structure setup, you’ll need to define the paths
to, e.g., the DRP file; see mangadap.util.drpfits.DRPFits
.
If you do not want to process the template (match the spectral
resolution and sampling to that of the DRP data), you can force the
TemplateLibrary
object to only provide the “raw” spectra:
# Imports
from mangadap.proc.templatelibrary import TemplateLibrary
from matplotlib import pyplot
# Read the raw template library
tpl_lib = TemplateLibrary('M11MILES', process=False)
# Nothing should be written to disk
# Plot one of the spectra
pyplot.plot(tpl_lib.hdu['WAVE'].data[0,:], tpl_lib.hdu['FLUX'].data[0,:])
pyplot.show()
Note that in the previous example, the wavelength data was already one-dimensional, whereas for the raw library, the wavelength vector can be spectrum-dependent.
In the above examples, the user has not provided a list of template
libraries, meaning that the default set available to the DAP is
used. The default set is defined in
available_template_libraries()
. If you want to use your own
template library, you have to define its parameters using
TemplateLibraryDef
. Currently, the template library
spectra are expected to be 1D fits files with WCS header keywords
defining the wavelength solution; see above. Using an existing DAP
library as an example:
# Imports
import os
from mangadap.proc.templatelibrary import TemplateLibraryDef
from mangadap.proc.templatelibrary import TemplateLibrary
from mangadap.config.defaults import dap_data_root
from matplotlib import pyplot
# Define the search string for the library
search_str = os.path.join(dap_data_root(), 'stellar_templates/miles/*.fits')
# Define the template library parameters
tpl_par = TemplateLibraryDef(key='MILES', # Unique keyword for the library
file_search=search_str, # Search string
fwhm=2.50, # FWHM of resolution element (assumed const)
in_vacuum=False, # Wavelength in vacuum?
wave_limit=numpy.array([ 3575., 7400. ]), # Range of valid lambda
lower_flux_limit=0.0) # Lower limit for valid flux
# Read the raw template library
tpl_lib = TemplateLibrary('MILES', tpllib_list=tpl_par, process=False)
# Nothing should be written to disk
# Plot one of the spectra
pyplot.plot(tpl_lib.hdu['WAVE'].data[0,:], tpl_lib.hdu['FLUX'].data[0,:])
pyplot.show()
Note that the keyword you use must be provided both to the parameter
set and when instantiating the TemplateLibrary
object. In
the example above, I have not processed the library, but you can by
following a similar approach to the first example.
You can also process the spectra to a user-provided resolution and
pixel sampling, toggle on/off the renormalization of the library to
a mean flux of unity and define various paths if you’re not working
within the nominal DAP directory structure. See the optional
instantiation arguments for TemplateLibrary
.
Revision history¶
23 Apr 2015: Implementation begun by K. Westfall (KBW)26 May 2015: (KBW) Added some Sphinx documentation.17 Jun 2015: (KBW) Added flexibility in definition of template libraries from which to choose using the newTemplateLibraryDef
class.23 Jun 2015: (KBW) Allow user to provided non-DRP input spectra, meaning they need to provide the velocity scale and the wavelength and spectral resolution vectors. They must also directly set the name of the output processed file.01 Feb 2016: (KBW) Propagated changes toTemplateLibraryDef
and changed procedure for reading raw template library.04 Feb 2016: (KBW) Converted frommangadap.util.instrument.log_rebin()
tomangadap.util.instrument.resample_vector()
. Allows input library to be logarithmically sampled and provides a different approach to subsampling spectra. Implemented other convenience operations, such as selecting a certain wavelength range for the processed library.19 May 2016: (KBW) Added loggers and quiet keyword arguments toTemplateLibrary
22 Jun 2016: (KBW) Included MILESHC library in documentation. Allow to specify how the resolution and sampling are matched to the DRP data. TheTemplateLibrary
class should be generalized to make this more transparent (and unnecessary).03 Apr 2017: (KBW) Include arguments formangadap.util.instrument.match_spectral_resolution()
that specify the minimum sigma in pixels for the convolution kernel and any offset in the resolution required in the call for the template library. Check that the resampling of the spectrum does not reach the two-pixel resolution limit; flag the spectrum in those regions that do and change the resolution to the two pixel limit.30 Aug 2017: (KBW) Switch from usingmangadap.util.instrument.resample_vector()
tomangadap.util.instrument.resample1d()
30 Aug 2018: (KBW) Switch from using resample1d tomangadap.util.sampling.Resample
.
Copyright © 2019, SDSS-IV/MaNGA Pipeline Group
-
class
mangadap.proc.templatelibrary.
TemplateLibrary
(library_key, tpllib_list=None, cube=None, match_resolution=True, velscale_ratio=None, sres=None, velocity_offset=0.0, min_sig_pix=0.0, no_offset=True, spectral_step=None, log=True, wavelength_range=None, renormalize=True, dapver=None, analysis_path=None, directory_path=None, processed_file=None, read=True, process=True, hardcopy=True, symlink_dir=None, clobber=False, checksum=False, loggers=None, quiet=False)[source]¶ Bases:
object
TODO: Revisit these docs.
Object used to read, store, and prepare template libraries for use in analyzing object spectra.
The default list of available libraries provided by the MaNGA DAP defined in
available_template_libraries()
. The user can provide their own library for use with this class provided they are contained in 1D fits spectra, sampled linearly in wavelength with the wavelength coordinates available via the WCS keywords (CRPIX1
,CRVAL1
,CDELT1
), and they have an appropriately defined spectral resolution. SeeTemplateLibraryDef
and_build_raw_hdu()
.The class is optimized for use in analyzing MaNGA DRP files; however, one can provide the necessary information so that the class can be used with a non-DRP spectrum. In the latter case, the user must supply the velocity scale of the pixel for the logarithmically resampled template library, and a
mangadap.util.resolution.SpectralResolution
object the defines the instrumental resolution of the spectrum/spectra to be analyzed.Todo
Docs are out of date.
Update the list of attributes.
Allow for velocity scale input instead of spectral_step?
Only works with DRP files that have log-linear wavelength binning!
Allow to process, where process is just to change the sampling or the resolution (not necessarily both).
Need to make this more general, removing all dependence on DRPFits object. This would simplify the functionality to change how the resolution and sampling matching is specified.
On initialization, if the datacube object is not provided (is None), the default behavior is to read the raw template library if read=True. If the datacube is provided, the routine will check for the resolution matched fits file; if it doesn’t exist and read is
True
, it will prepare the template library for use in analyzing the datacube and write the prepared library file (if hardcopy is True). If clobber=True, the preparation and writing of the template library will be done even if the library already exists.Todo
Change sres to be a standard input object?
- Parameters
library_key (
str
) – Keyword selecting the library to use.tpllib_list (
list
, optional) – List ofTemplateLibraryDef
objects that define the parameters required to read and interpret a template library. Thelibrary_key
must select one of the objects in this list.cube (
mangadap.datacube.datacube.DataCube
, optional) – The datacube to be analyzed using the template library.match_resolution (
bool
, optional) – Match the spectral resolution of the template library to the resolution provided by thecube
; the latter must be provided for this argument to have any use.velscale_ratio (
int
, optional) – Resample the template spectra such that the ratio of the pixel scale in the providedcube
is this many times larger than the pixels in the resampled template spectrum.sres (
mangadap.util.resolution.SpectralResolution
, optional) – The object is used simply to access the spectral resolution and associated wavelength coordinate vector needed when matching the spectral resolution of the template library; this is used in lieu of a datacube.velocity_offset (
float
, optional) – Velocity offset to use when matching the spectral resolution between the template library and the galaxy spectra.min_sig_pix (
float
, optional) – Minimum value of the LSF standard deviation in pixels allowed before assuming the kernel is a Delta function. Seemangadap.util.resolution.match_spectral_resolution()
.no_offset (
bool
, optional) – Prohibit the spectral resolution matching to introduce an offset in spectral resolution required to match the relative shape of the resolution vectors. Seemangadap.util.resolution.match_spectral_resolution()
andmangadap.util.resolution.SpectralResolution.GaussianKernelDifference()
.spectral_step (
float
, optional) – Logarithmic (log=True
) or linear (log=False
) step in wavelength for the template library.log (
bool
, optional) – Flag to force the library to be logarithmically sampled in wavelength.wavelength_range (array-like, optional) – Force the template library to cover this spectral range. Unobserved spectral regions will be masked.
renormalize (
bool
, optional) – After processing, renormalize the flux of the full library to unity. The relative fluxes of the templates are maintained.dapver (
str
, optional) – DAP version, which is used to define the default DAP analysis path. Default is defined bymangadap.config.defaults.dap_version()
analysis_path (
str
, optional) – The path to the top-level directory for the DAP output files. Default is defined bymangadap.config.defaults.dap_analysis_path()
.directory_path (
str
, optional) – The exact path to the processed template library file. Default is defined bymangadap.config.defaults.dap_common_path()
.processed_file (
str
, optional) – The name of the file containing the prepared template library output file. The file should be found atdirectory_path
/processed_file
. Default is defined bymangadap.config.defaults.dap_file_name()
.read (
bool
, optional) – Flag to read the template library data.process (
bool
, optional) – Process (spectral resolution and sampling operations) the template library in preparation for use in fitting the provided datacube.hardcopy (
bool
, optional) – Flag to keep a hardcopy of the processed template library.symlink_dir (
str
, optional) – Create a symlink to the file in this directory. If None, no symbolic link is created.clobber (
bool
, optional) – Overwrite any saved, processed template library file.checksum (
bool
, optional) – Use the checksum in the fits header to confirm that the data has not been corrupted. The checksum is always written to the fits header when the file is created.loggers (
list
, optional) – List of logging.Logger objects to log progress; ignored if quiet=True. Logging is done usingmangadap.util.log.log_output()
. If None, no logging is performed and output is just written tostdout
.quiet (
bool
, optional) – Suppress all terminal and logging output.
-
bitmask (class
mangadap.util.bitmask.BitMask): Object used to toggle mask values; see
TemplateLibraryBitMask()
.
-
library
¶ Parameter set required to read and prepare the library.
- Type
-
ntpl
¶ Number of template spectra in the library
- Type
int
-
cube
¶ The datacube to be analyzed using the template library.
-
sres
¶ The object is used simply to access the spectral resolution and associated wavelength coordinate vector needed when matching the spectral resolution of the template library; this is used in place of the attributes in any provided DRP file object.
-
velocity_offset
¶ Velocity offset to use when matching the spectral resolution between the template library and the galaxy spectra.
- Type
float
-
spectral_step
¶ Target logarithmic (
log10_sampling=True
) or linear (log10_sampling=False
) step in wavelength for the template library.- Type
float
-
log10_sampling
¶ Flag that the processed template library is logarithmically sampled in wavelength.
- Type
bool
-
directory_path
¶ The exact path to the processed template library file.
- Type
str
-
processed_file
¶ The name of the file containing (to contain) the prepared template library output file. The file should be found at
directory_path
/processed_file
.- Type
str
-
processed
¶ Flag that the template library has been prepared for use in the DAP.
- Type
bool
-
hardcopy
¶ Flag to keep a hardcopy of the processed template library.
- Type
bool
-
symlink_dir
¶ Symlink created to the file in this directory
- Type
str
-
hdu
¶ HDUList read from the DAP file
-
_build_raw_hdu
(npix)[source]¶ Build the “raw” template library arrays.
This simply reads the provided list of fits files and puts them into arrays of size \(N_{\rm tpl} \times N_{\rm pix}\).
This will force reading of the data, even if the
hdu
is already initialized.The
hdu
will contain the appropriate extensions, but it is important to note that the wavelength vectors will not necessarily be the same. That is, reading of the raw template spectra can accommodate spectra that have different wavelength coordinates. Any pixels that have no data are masked using the ‘NO_DATA’ bitmask flag; seeTemplateLibraryBitMask()
.The spectral resolution is set using the
fwhm
orsres_ext
values in the library parameters.Warning
Currently no errors are saved because none are expected for the template libraries.
- Parameters
npix (
int
) – Number of spectral channels for the output arrays
-
_can_set_paths
(directory_path, cube, processed_file, quiet=False)[source]¶ Determine if the paths are fully defined.
- Parameters
directory_path (
str
) – The exact path to the processed template library file.cube (
mangadap.datacube.datacube.DataCube
) – The datacube to be analyzed using the template library.processed_file (
str
) – The name of the file containing (to contain) the prepared template library output file. The file should be found atdirectory_path/processed_file
.quiet (
bool
, optional) – Suppress terminal output.
- Returns
True if the paths can be set.
- Return type
bool
-
_get_file_list
()[source]¶ Use the search string to find the template library fits files.
The file list read by the search key is sorted for consistency.
- Returns
The sorted list of files found with glob.glob.
- Return type
list
- Raises
ValueError – Raised if no files are found.
-
_get_nchannels
()[source]¶ Get the maximum number of wavelength channels needed to store all the template spectra in a single array.
Todo
What happens if the spectrum has an empty primary extension?
- Returns
Maximum number of pixels used by the listed spectra.
- Return type
int
- Raises
ValueError – Raised if the input template spectra are not one-dimensional.
-
_minimum_sampling
()[source]¶ Return the minimum sampling of the available wavelength vectors.
- Returns
Minimum sampling of all (will just be one if the library has been processed) wavelength vectors.
- Return type
float
-
_modify_spectral_resolution
()[source]¶ Modify the spectral resolution to match the provided
sres
.- Returns
Redshift used when matching the spectral resolution.
- Return type
float
-
_process_library
(wavelength_range=None, renormalize=True)[source]¶ Process the template library for use in analyzing object spectra. See
process_template_library()
.Todo
Add wavelength coordinate WCS information to the appropriate extension headers.
Include ‘step’ as an argument
Include limit on covering fraction used to mask data as an argument
- Parameters
wavelength_range (array-like, optional) – A two-element object with the lower and upper limits for the wavelength range of the library.
renormalize (
bool
, optional) – Renormalize the flux of the full library to unity. Relative fluxes of spectra in the library are maintained.
-
_read_raw
()[source]¶ Read the ‘raw’ versions of the template library.
The “raw” library is the data before its sampling or resolution have been altered.
This is a simple wrapper for
_get_file_list()
,_get_channels()
and_build_raw_hdu()
.
-
_rebin_masked
(i, flag, fullRange, rmsk_lim=0.5)[source]¶ Determine the mask value to adopt for a rebinned spectrum by rebinning the mask pixels, setting a masked pixel to unity, and an unmasked pixel to zero. After rebinning, any pixel with a value of larger than
rmsk_lim
is masked; otherwise it is left unmasked.Although the function can be used with multiple flags, its intended use is to determine which pixels should be masked with a specific flag.
- Parameters
i (
int
) – Index of the spectrum to be rebinned.flag (
str
,list
) – Flags to consider when determining which pixels to mask; seemangadap.util.bitmasks.BitMask.flagged()
.fullRange (numpy.ndarray) – Two-element array with the wavelength range for the rebinned spectrum.
rmsk_lim (
float
) – Limit of the rebinned mask value that is allowed before considering the pixel as masked.
- Returns
Boolean array indicating which pixels in the rebinned spectrum should be masked.
- Return type
-
_reset_hdu
(wave, flux, mask, sres, soff)[source]¶ (Re)Set
hdu
to a new HDUList object using the input arrays. Also sets the header items indicating the version of the template reader and the keyword for the library.Warning
No checking is done concerning the size of each array!
- Parameters
wave (numpy.ndarray) – Array with the wavelengths of each pixel.
flux (numpy.ndarray) – Array with the flux in each pixel.
mask (numpy.ndarray) – Bitmask values for each pixel.
sres (numpy.ndarray) – Spectral resolution, \(R=\lambda/\delta\lambda\), at each pixel.
soff (numpy.ndarray) – The spectral resolution offset for each spectrum (see
mangadap.util.resolution.GaussianKernelDifference()
).
-
_set_paths
(directory_path, dapver, analysis_path, cube, processed_file)[source]¶ Set the I/O path to the processed template library.
Used to set
directory_path
andprocessed_file
. If not provided, the defaults are set using, respectively,mangadap.config.defaults.dap_common_path()
andmangadap.config.defaults.dap_file_name()
.- Parameters
directory_path (
str
) – The exact path to the DAP template library file. Seedirectory_path
.dapver (
str
) – DAP version.analysis_path (
str
) – The path to the top-level directory containing the DAP output files for a given DRP and DAP version.cube (
mangadap.datacube.datacube.DataCube
) – The datacube to be analyzed using the template library.processed_file (
str
) – The name of the file containing (to contain) the prepared template library output file. The file should be found atdirectory_path/processed_file
.
-
_wavelength_range
(flag=None)[source]¶ Return the valid wavelength range for each spectrum based on the first and last unmasked pixel; interspersed masked regions are not considered.
- Parameters
flag (
str
,list
, optional) – Flags to consider when determining the wavelength range; seemangadap.util.bitmasks.BitMask.flagged()
.- Returns
Two-element vector with wavelengths of the first and last valid pixels.
- Return type
-
static
define_library
(library_key, tpllib_list=None)[source]¶ Select the library from the provided list. Used to set
library
; seemangadap.proc.util.select_proc_method()
.- Parameters
library_key (
str
) – Keyword of the selected library. Available libraries are proved byavailable__template_libraries()
tpllib_list (
list
, optional) – List ofTemplateLibraryDef
objects that define the parameters required to read and interpret a template library.
-
process_template_library
(library_key=None, tpllib_list=None, cube=None, match_resolution=True, velscale_ratio=None, sres=None, velocity_offset=0.0, min_sig_pix=0.0, no_offset=True, spectral_step=None, log=True, wavelength_range=None, renormalize=True, dapver=None, analysis_path=None, directory_path=None, processed_file=None, hardcopy=True, symlink_dir=None, clobber=False, loggers=None, quiet=False)[source]¶ Process the template library for use in analyzing spectra.
Todo
Docs need to be updated
type checking
If a DRP file is provided, the processing to a logarithmic binning is done by default (log=True). But linearly sampled DRP data are available, so need to have
mangadap.util.drpfits.DRPFits
return the spectral sampling type.Documentation needs updating!
Primary steps are to:
Read the raw 1D fits files; see
_read_raw()
.Convert the wavelengths to vacuum, if necessary; see pydl.goddard.astro.airtovac.
Mask wavelengths outside the rest wavelength range of the datacube spectra, due to need to extrapolate these values; see
mangadap.util.bitmasks.HDUList_mask_wavelengths()
.Match the spectral resolution of the template to that of the datacube (if
match_resolution
is True); seemangadap.util.resolution.match_spectral_resolution()
.Mask the template pixels where the spectral resolution was too low to match to datacube; see
mangadap.util.bitmasks.BitMask.turn_on()
.Force a common wavelength range and sampling for all templates, where the sampling is forced to match the sampling of the DRP spectra; see
mangadap.util.sampling.resample_vector_pix()
. The masks are appropriately resampled as well; see_rebin_masked()
.
Warning
The routine does not check that that an existing processed file or the existing object has been processed using the same datacube, velocity_offset, velscale, or sres input. If unsure, use clobber=True.
- Parameters
library_key (
str
) – Keyword selecting the library to use.tpllib_list (
list
, optional) – List ofTemplateLibraryDef
objects that define the parameters required to read and interpret a template library. Thelibrary_key
must select one of the objects in this list.cube (
mangadap.datacube.datacube.DataCube
, optional) – The datacube to be analyzed using the template library.match_resolution (
bool
, optional) – Match the spectral resolution of the template library to the resolution provided by thecube
; the latter must be provided for this argument to have any use.velscale_ratio (
int
, optional) – Resample the template spectra such that the ratio of the pixel scale in the providedcube
is this many times larger than the pixels in the resampled template spectrum.sres (
mangadap.util.resolution.SpectralResolution
, optional) – The object is used simply to access the spectral resolution and associated wavelength coordinate vector needed when matching the spectral resolution of the template library; this is used in lieu of a datacube.velocity_offset (
float
, optional) – Velocity offset to use when matching the spectral resolution between the template library and the galaxy spectra.min_sig_pix (
float
, optional) – Minimum value of the LSF standard deviation in pixels allowed before assuming the kernel is a Delta function. Seemangadap.util.resolution.match_spectral_resolution()
.no_offset (
bool
, optional) – Prohibit the spectral resolution matching to introduce an offset in spectral resolution required to match the relative shape of the resolution vectors. Seemangadap.util.resolution.match_spectral_resolution()
andmangadap.util.resolution.SpectralResolution.GaussianKernelDifference()
.spectral_step (
float
, optional) – Logarithmic (log=True
) or linear (log=False
) step in wavelength for the template library.log (
bool
, optional) – Flag to force the library to be logarithmically sampled in wavelength.wavelength_range (array-like, optional) – Force the template library to cover this spectral range. Unobserved spectral regions will be masked.
renormalize (
bool
, optional) – After processing, renormalize the flux of the full library to unity. The relative fluxes of the templates are maintained.dapver (
str
, optional) – DAP version, which is used to define the default DAP analysis path. Default is defined bymangadap.config.defaults.dap_version()
analysis_path (
str
, optional) – The path to the top-level directory for the DAP output files. Default is defined bymangadap.config.defaults.dap_analysis_path()
.directory_path (
str
, optional) – The exact path to the processed template library file. Default is defined bymangadap.config.defaults.dap_common_path()
.processed_file (
str
, optional) – The name of the file containing the prepared template library output file. The file should be found atdirectory_path
/processed_file
. Default is defined bymangadap.config.defaults.dap_file_name()
.hardcopy (
bool
, optional) – Flag to keep a hardcopy of the processed template library.symlink_dir (
str
, optional) – Create a symlink to the file in this directory. If None, no symbolic link is created.clobber (
bool
, optional) – Overwrite any saved, processed template library file.loggers (
list
, optional) – List of logging.Logger objects to log progress; ignored if quiet=True. Logging is done usingmangadap.util.log.log_output()
. If None, no logging is performed and output is just written tostdout
.quiet (
bool
, optional) – Suppress all terminal and logging output.
- Raises
ValueError – If the sampling is undefined, or if a hardcopy is requested but the output file could not be defined.
-
read_raw_template_library
(library_key=None, tpllib_list=None)[source]¶ Read the identified template library. If all the arguments are the default, the preset attributes from the initialization of the object are used.
- Parameters
library_key (
str
, optional) – Keyword selecting the library to use.tpllib_list (
list
, optional) – List ofTemplateLibraryDef
objects that define the parameters required to read and interpret a template library.
-
single_spec_to_fits
(i, ofile, clobber=True)[source]¶ Write one of the template spectra to a 1D fits file.
Output is a one-dimensional fits file with a single extension containing the flux measurements and header keywords needed to determine the wavelength of each pixel.
- Parameters
i (
int
) – Index of the spectrum in the avaiable list to output.ofile (
str
) – Name of the file to writeclobber (
bool
, optional) – Overwrite any existing file.
- Raises
ValueError – Raised if the selected index is not available.
-
supported_libraries
= ['BC03', 'BPASS', 'M11ELODIE', 'M11MARCS', 'M11MILES', 'M11STELIB', 'M11STELIBZSOL', 'MASTARHC', 'MASTARHC2', 'MILES', 'MILESAVG', 'MILESHC', 'MILESTHIN', 'MIUSCAT', 'MIUSCATTHIN', 'STELIB']¶ Provides the keywords of the supported libraries.
-
class
mangadap.proc.templatelibrary.
TemplateLibraryBitMask
[source]¶ Bases:
mangadap.util.dapbitmask.DAPBitMask
Derived class that specifies the mask bits for the template library data. The maskbits defined are:
Key
Bit
Description
NO_DATA
0
Pixel has no data
WAVE_INVALID
1
Used to designate pixels in the 1D spectra that are outside the valid wavelength range defined by default_template_libraries().
FLUX_INVALID
2
Used to designate pixels in the 1D spectra that are below the valid flux limit defined by default_template_libraries().
SPECRES_EXTRAP
3
The spectral resolution has been matched to a value that was an extrapolation of the target spectral resolution samples.
SPECRES_LOW
4
The spectral resolution was not matched to the target value because the target value was higher than the existing spectral resolution.
SPECRES_2PIXEL
5
Resampling has lead to the resolution being below the two pixel limit. The spectral resolution has been changed to be exactly the two pixel limit for these pixels.
SPECRES_NOFLUX
6
Resolution matching has lead a template flux <= 0.
-
cfg_root
= 'spectral_template_bits'¶
-
-
class
mangadap.proc.templatelibrary.
TemplateLibraryDef
(key=None, file_search=None, fwhm=None, sres_ext=None, in_vacuum=False, wave_limit=None, lower_flux_limit=None, log10=False)[source]¶ Bases:
mangadap.par.parset.KeywordParSet
Class with parameters used to define the template library. See
mangadap.par.parset.ParSet
for attributes.The defined parameters are:
Key
Type
Options
Default
Description
key
str
Keyword to distinguish the template library.
file_search
str
Search string used by glob to find the 1D fits spectra to include in the template library.
fwhm
int, float
FWHM of the resolution element in angstroms.
sres_ext
str
Extension in the fits files with measurements of the spectral resolution as a function of wavelength.
in_vacuum
bool
Flag that the wavelengths of the spectra are in vacuum, not air.
wave_limit
ndarray
Two-element array with the starting and ending wavelengths for the valid spectral range of the templates.
lower_flux_limit
int, float
Minimum valid flux in the template spectra.
log10
bool
Flag that the template spectra have been binned logarithmically in wavelength.
-
mangadap.proc.templatelibrary.
available_template_libraries
()[source]¶ Return the list of available template libraries.
The available libraries are construced by looking for configuration files in the relevant DAP configuration directory.
Todo
Point to where the library format is described.
Somehow add a python call that reads the databases and constructs the table for presentation in sphinx so that the text above doesn’t have to be edited with changes in the available databases.
- Returns
A list of
mangadap.proc.templatelibrary.TemplateLibraryDef()
objects, each defining a separate template library.- Return type
list
- Raises
IOError – Raised if no template configuration files could be found.
KeyError – Raised if the template-library keywords are not all unique.
ValueError – Raised if the configuration file provides an invalid set of wavelength limits.
-
mangadap.proc.templatelibrary.
validate_spectral_template_config
(cnfg)[source]¶ Validate the
mangadap.util.parser.DefaultConfig
object with the template library parameters.- Parameters
cnfg (
mangadap.util.parser.DefaultConfig
) – Object with the template library parameters to validate.- Raises
KeyError – Raised if required keyword does not exist.
ValueError – Raised if key has unacceptable value.