qusp.spectrum module¶
Provides classes to represent functions of wavelength.
Examples
Construct a Spectrum
object from wave
, flux
, and ivar
arrays:
>>> spectrum = qusp.spectrum.Spectrum(wave, flux, ivar)
Get the mean flux between wave_min
and wave_max
:
>>> spectrum.mean_flux(wave_min, wave_max)
Get the median signal to noise between wave_min
and wave_max
:
>>> spectrum.median_signal_to_noise(wave_min, wave_max)
Load the combined spectrum of a qsub.target.Target
object, target
:
filename = 'spPlate-%s-%s.fits' % (target['plate'], target['mjd'])
spplate = fits.open(os.path.join(paths.boss_path, str(target['plate']), filename))
combined = qusp.read_combined_spectrum(spplate, target)
-
class
qusp.spectrum.
BOSSSpectrum
(wavelength, flux, ivar, wavelengths_units=<Mock id='140482188747280'>, flux_units=None, extrapolated_value=None)¶ Bases:
object
Represents a BOSS co-added spectrum.
Parameters: - wavelength (numpy.ndarray) – wavelength pixel centers.
- flux (numpy.ndarray) – flux values.
- ivar (numpy.ndarray) – flux inverse variance values.
-
create_corrected
(correction)¶
-
find_pixel
(wavelength, clip=False)¶ Returns the corresponding pixel index of the specified wavelength.
Parameters: Returns: pixel index
Return type: pixelIndex (int)
-
mean_flux
(min_wavelength, max_wavelength, ivar_weighting=True)¶ Returns the mean flux between the specified wavelengths. Use
ivar_weighting=False
to turn ignore weights.Parameters: Returns: the mean flux between
min_wavelength
andmax_wavelength
.
-
median_signal_to_noise
(min_wavelength, max_wavelength)¶ Returns the median signal to noise ratio between the specified wavelengths.
Parameters: Returns: the median flux between
min_wavelength
andmax_wavelength
.Return type: median (float)
-
trim_range
(wave_min, wave_max, clip=True)¶ Returns a
BOSSSpectrum
object trimmed to the specified range.Parameters: Returns: Raises: ValueError
– if no pixels in specified range
-
class
qusp.spectrum.
SpectralFluxDensity
(wavelength, flux, wavelengths_units=<Mock id='140482189143568'>, flux_units=None, extrapolated_value=None)¶ Bases:
qusp.spectrum.WavelengthFunction
Represents a spectral flux density as a function of wavelength.
Initializes a spectral flux density using tabulated flux values at specified wavelengths. See the documentation of WavelengthFunction for details. The default flux unit is 1e-17 erg/(s*cm^2*Ang), which is available as SpectralFluxDensity.fiducialFluxUnit, but other units can be specified.
Parameters: - wavelength (numpy.ndarray) – tabulated wavelength values
- flux (numpy.ndarray) – tabulated flux values
- wavelengths_units (astropy.units.Quantity) – wavelength value units
- flux_units (astropy.units.Quantity) – flux value units
- extrapolated_value (float, optional) –
-
create_redshifted
(new_z, old_z=0.0, preserve_wavelengths=False)¶ Returns a new SpectralFluxDensity whose wavelengths and fluxes have been rescaled for the transformation from old_z to new_z. If preserve_wavelengths is True and an extrapolated_value has been set, then the rescaled spectrum will be resampled to the original wavelengths. Otherwise, the new spectrum will be tabulated on the redshifted grid.
Parameters: Returns: rescaled spectrum (
qusp.spectrum.SpectralFluxDensity
)Raises: RuntimeError
– if preserve_wavelengths is True and no extrapolated_value has been set
-
create_rescaled
(sdss_band, ab_magnitude)¶ Parameters: Returns: rescaled spectrum (
qusp.spectrum.SpectralFluxDensity
)Raises: RuntimeError
– in case our spectrum does not fully cover the band.
-
fiducialFluxUnit
¶ 1e-17 erg/(s*cm^2*Ang)
-
get_ab_magnitudes
()¶ Returns a dictionary of AB magnitudes calculated in each SDSS filter. Magnitude values of None are returned when our spectrum has no extrapolated_value set and a filter extends beyond our tabulated wavelengths.
-
get_filtered_rates
(filter_curves, wavelength_step=1.0)¶ Returns the counting rates in photons/(s*cm^2) when our spectral flux density is filtered by the specified curves. The curves should be specified as a dictionary of WavelengthFunctions and the results will also be a dictionary of floats using the same keys. Rates of None are returned when our spectrum has no extrapolated_value set and a filter extends beyond our tabulated wavelengths.
Parameters: filter_curves (dict) – dictionary of WavelengthFunctions
-
sdss_filter_curves
= None¶
-
sdss_filter_rates
= None¶
-
class
qusp.spectrum.
Spectrum
(wavelength, flux, ivar)¶ Bases:
object
Represents a BOSS co-added spectrum.
Parameters: - wavelength (numpy.ndarray) – wavelength pixel centers.
- flux (numpy.ndarray) – flux values.
- ivar (numpy.ndarray) – flux inverse variance values.
-
find_pixel
(wavelength)¶ Returns the corresponding pixel index of the specified wavelength.
Parameters: wavelength (float) – value Returns: pixel index Return type: pixelIndex (int)
-
mean_flux
(min_wavelength, max_wavelength, ivar_weighting=True)¶ Returns the mean flux between the specified wavelengths. Use
ivar_weighting=False
to turn ignore weights.Parameters: Returns: the mean flux between
min_wavelength
andmax_wavelength
.
-
median_signal_to_noise
(min_wavelength, max_wavelength)¶ Returns the median signal to noise ratio between the specified wavelengths.
Parameters: Returns: the median flux between
min_wavelength
andmax_wavelength
.Return type: median (float)
-
class
qusp.spectrum.
WavelengthFunction
(wavelength, values, wavelengths_units=<Mock id='140482189143056'>, value_units=None, extrapolated_value=None)¶ Bases:
object
Represents an arbitrary function of wavelength.
Initializes a function of wavelength using tabulated values at specified wavelengths. The default wavelength units are angstroms but other units can be specified. Optional value units can also be specified but are not required. The input wavelengths must be increasing. The input wavelength and value arrays must have the same size. If either is already a numpy array, no internal copy is made (except when conversion to Angstroms is needed) so these are lightweight objects but be aware of possible side effects.
Parameters: - wavelength (np.ndarray) – tabulated wavelength values
- values (np.ndarray) – tabulated values
- wavelengths_units (astropy.units.Quantity) – wavelength value units
- value_units (astropy.units.Quantity, optional) – value units
- extrapolated_value (float, optional) –
-
get_model
()¶ Returns a model for interpolating within our tabulated wavelength function values. If an extrapolated_value was provided to the constructor, the model will use this for any wavelengths outside the tabulated grid.
Returns: model (scipy.interpolate.interp1d)
-
get_resampled_values
(wavelength, wavelengths_units=<Mock id='140482189143184'>)¶ Returns a numpy array of values resampled at the specified wavelengths (which do not need to be sorted). The default wavelength units are angstroms but other units can be specified.
Parameters: - wavelength (numpy.ndarray) – wavelengths to resample at
- wavelengths_units (astropy.Units.Quantity) – wavelength value units
Returns: resampled values (numpy.ndarray)
Raises: RuntimeError
– if resampling would require an extrapolation but no extrapolated_value was provided to the constructor.
-
classmethod
load_from_text_file
(filename, wavelength_column=0, values_column=1, wavelengths_units=<Mock id='140482189143376'>, extrapolated_value=None)¶ Returns a new WavelengthFunction (or subclass of WavelengthFunction) from the specified text file. Any comment lines beginning with ‘#’ are ignored. Uses the specified columns for the wavelength and values. Additional columns are allowed and silently ignored. The default wavelength units are Angstroms but other units can be specified. Refer to the WavelengthFunction constructor for details on extrapolated_value.
Parameters: filename (string) –
-
qusp.spectrum.
load_sdss_filter_curves
(which_column=1)¶ Loads SDSS filter curves from a standard location within this module. The default which_column=1 corresponds to curves of the quantum efficiency on the sky looking through 1.3 airmasses at APO for a point source. Values of 2-4 are also possible but probably not what you want. Consult the filter data file headers for details.
-
qusp.spectrum.
read_combined_spectrum
(spplate, fiber)¶ Returns the combined spectrum of the specified fiber from the provided spPlate.
Parameters: - spplate (astropy.io.fits.HDUList) – spPlate file
- fiber (
qusp.target.Target
) – boss target’s fiberid, or aqusp.target.Target
object.
Returns: a
Spectrum
object offiber
ofspplate
.Return type: spectrum (
Spectrum
)
-
qusp.spectrum.
read_lite_spectrum
(spec)¶ Returns the combined spectrum of the specified fiber from the provided spPlate.
Parameters: fiber ( qusp.target.Target
) – boss target’s fiberid, or aqusp.target.Target
object.Returns: a Spectrum
object offiber
ofspplate
.Return type: spectrum ( Spectrum
)