Base class to handle spectra¶
- class qmostetc.Spectrum(wavelength, flux)¶
Spectrum representing a flux or a transmission.
This class is somewhat generic. It may represent any flux quantity, like enery flux, photon flux, CCD photoelectron flux etc, but also throughput spectra, like atmospheric throughput, detector throughputs etc.
To a Spectrum, another Spectrum can be added, as long as the units are compatible. Both spectra need to have the same wavelength bins.
A Spectrum may be multiplied with either an array of the correct shape, or with a Spectrum, which needs to have the same wavelength bins.
- Attributes:
- wavelength
astropy.units.Quantity Wavelength array [nm]
- flux
astropy.units.Quantity Flux, in any convenient unit
- wavelength
- to(unit)¶
Create a new spectrum with the flux values converted
This also allows to convert between energy flux and photon flux.
- Parameters:
- unit
astropy.units.Unitorstr The unit to convert the flux to.
- unit
- Returns:
SpectrumConverted flux spectrum.
Examples
Convert a constant photon flux into an energy flux:
>>> import numpy as np >>> import astropy.units as u >>> from qmostetc import Spectrum >>> wavelength = np.linspace(600., 650., 4) * u.nm >>> flux = np.ones(wavelength.shape) * u.photon/(u.m**2*u.s*u.nm) >>> spec = Spectrum(wavelength, flux) >>> print(spec.to('erg/(nm m² s)').flux) [3.31074310e-12 3.22126355e-12 3.13649346e-12 3.05607055e-12] erg / (nm s m2)
- subspectrum(lower, upper)¶
Extract a subspectrum with given limits
- Parameters:
- lower
astropy.units.Quantity Lower wavelength limit [nm]
- upper
astropy.units.Quantity Upper wavelength limit [nm]
- lower
- Returns:
SpectrumNew flux spectrum within the given limits
- __call__(wavelength)¶
Return the (interpolated) flux value(s) for given wavelength(s)
The interpolation is done linearly.
- Parameters:
- wavelength
astropy.units.Quantity Wavelength or wavelength array to retrieve the values [nm]
- wavelength
- Returns:
astropy.units.QuantityValue or Value array corresponding to the given wavelength(s).
- get_mag(magunit, flt)¶
Get the magnitude for this spectrum.
- Parameters:
- magunit
astropy.units.MagUnit Star magnitude unit (
astropy.units.ABmagorqmostetc.VEGAmag)- flt
strorpathlib.PathorSpectrum Filter to apply, given by name, file path, or as a spectrum
- magunit
- Returns:
astropy.units.QuantityEstimated magnitude when applying the filter, with the given unit.
Examples
Retrieve the VEGA magnitude for a scaled template:
>>> from qmostetc import SEDTemplate, VEGAmag >>> import astropy.units as u >>> pck = SEDTemplate('Pickles_G0V') >>> spectrum = pck(15*u.ABmag, 'GAIA_GAIA2r.G') >>> spectrum.get_mag(u.ABmag, 'GAIA_GAIA2r.G') <Magnitude 15. mag(AB)> >>> spectrum.get_mag(VEGAmag, 'GAIA_GAIA2r.G') <Magnitude 14.87880973 mag(VEGA)>
- check_coverage(flt)¶
Check the wavelength range coverage
Ensure that the wavelength range of the spectrum covers the range of the given filter.
- Parameters:
- flt
strorpathlib.PathorSpectrum Filter to apply, given by name, file path, or as a spectrum
- flt
- Raises:
ValueErrorIf the wavelength range does not cover the wavelength range of the filter
Examples
Raise an exception for a really small wavelength range:
>>> import numpy as np >>> import astropy.units as u >>> from qmostetc import Spectrum >>> wavelength = np.arange(300., 310.) * u.nm >>> spec = Spectrum(wavelength, np.zeros(wavelength.shape)) >>> spec.check_coverage('GAIA_GAIA2r.G') Traceback (most recent call last): ... ValueError: Insufficient wavelength coverage (300…309 nm) for filter (300…1098 nm)
- static read(table)¶
Read a template spectrum from a table
The table needs to have the following columns:
WAVELENGTH, LAMBDA, LAMB, WAVE, or LAM for the wavelength column,
FLAM, FLUX_DENSITY, FLUXDENSITY, F, FLUX, or TRANS for the flux column.
The method tries to fix some glitches in the file; however it is best to have the units stored correctly, for FITS files according to the FITS standard.
- Parameters:
- table
pathlib.Pathorastropy.table.QTable File name or table
- table
- Returns:
SpectrumSpectrum stored in the table