FilterSequence

class speclite.filters.FilterSequence(responses)[source] [edit on github]

Bases: Sequence

Immutable sequence of filter responses.

Sequences should normally be created by calling load_filters(). Objects implement the immutable sequence API, in addition to the methods listed here.

A filter sequence’s get_ab_maggies() and get_ab_magnitudes() methods return their results in a Table and are convenient for calculating convolutions in several bands for multiple spectra. For example, given the following 4 (identical) spectra covering the SDSS filters:

>>> num_spectra, num_pixels = 4, 500
>>> wlen = np.linspace(2000, 12000, num_pixels) * default_wavelength_unit
>>> flux = np.ones((num_spectra, num_pixels)) * 1e-17 * default_flux_unit

We can now calculate their magnitudes in all bands with one function:

>>> sdss = load_filters('sdss2010-*')
>>> mags = sdss.get_ab_magnitudes(flux, wlen)

Refer to the astropy docs for details on working with Tables. For example, to pretty-print the magnitudes with a precision of 0.001:

>>> formats = dict((n, '%.3f') for n in sdss.names)
>>> mags.write(None, format='ascii.fixed_width', formats=formats)
| sdss2010-u | sdss2010-g | sdss2010-r | sdss2010-i | sdss2010-z |
|     22.316 |     21.731 |     21.138 |     20.718 |     20.344 |
|     22.316 |     21.731 |     21.138 |     20.718 |     20.344 |
|     22.316 |     21.731 |     21.138 |     20.718 |     20.344 |
|     22.316 |     21.731 |     21.138 |     20.718 |     20.344 |
Parameters:
responsesiterable

Response objects to include in this sequence. Objects are copied to an internal list.

Attributes:
nameslist of str

List of the filter response names in this sequence, with the format “<group_name>-<band_name>”.

effective_wavelengthsastropy.units.Quantity

List of the effective wavelengths for the filter responses in this sequence, with the default wavelength units.

Attributes Summary

effective_wavelengths

names

Methods Summary

get_ab_maggies(spectrum[, wavelength, axis, ...])

Calculate a spectrum's relative AB flux convolutions.

get_ab_magnitudes(spectrum[, wavelength, ...])

Calculate a spectrum's AB magnitude.

pad_spectrum(spectrum, wavelength[, axis, ...])

Pad a spectrum to cover all filter responses.

Attributes Documentation

effective_wavelengths
names

Methods Documentation

get_ab_maggies(spectrum, wavelength=None, axis=-1, mask_invalid=False)[source] [edit on github]

Calculate a spectrum’s relative AB flux convolutions.

Calls FilterResponse.get_ab_maggies() for each filter in this sequence and returns the results in a structured array.

Use get_ab_magnitudes() for the corresponding AB magnitudes.

Parameters:
spectrumcallable or array or astropy.units.Quantity

See get_ab_maggies() for details.

wavelengtharray or astropy.units.Quantity or None

See get_ab_maggies() for details.

axisint

See get_ab_maggies() for details.

mask_invalidbool

When True, if an error occurs while calculating results for one filter (usually because of insufficient wavelength coverage), the corresponding output column will be filled with missing values. Otherwise, any error raises an exception.

Returns:
astropy.table.Table

A table of results with column names corresponding to canonical filter names of the form “<group_name>-<band_name>”. If the input spectrum data is multidimensional, its first index is mapped to rows of the returned table.

get_ab_magnitudes(spectrum, wavelength=None, axis=-1, mask_invalid=False)[source] [edit on github]

Calculate a spectrum’s AB magnitude.

Calls FilterResponse.get_ab_magnitude() for each filter in this sequence and returns the results in a structured array.

Parameters:
spectrumcallable or array or astropy.units.Quantity

See get_ab_magnitude() for details.

wavelengtharray or astropy.units.Quantity or None

See get_ab_magnitude() for details.

axisint

See get_ab_magnitude() for details.

mask_invalidbool

When True, if an error occurs while calculating results for one filter (usually because of insufficient wavelength coverage), the corresponding output column will be filled with missing values. Otherwise, any error raises an exception.

Returns:
astropy.table.Table

A table of results with column names corresponding to canonical filter names of the form “<group_name>-<band_name>”. If the input spectrum data is multidimensional, its first index is mapped to rows of the returned table.

pad_spectrum(spectrum, wavelength, axis=-1, method='median')[source] [edit on github]

Pad a spectrum to cover all filter responses.

Calls FilterResponse.pad_spectrum() for each filter in this sequence, in order of increasing effective wavelength. Parameters and caveats for this method are the same.

Parameters:
spectrumarray or astropy.units.Quantity

See FilterResponse.pad_spectrum() for details.

wavelengtharray or astropy.units.Quantity or None

See FilterResponse.pad_spectrum() for details.

axisint

See FilterResponse.pad_spectrum() for details.

methodstr

See FilterResponse.pad_spectrum() for details.

Returns:
tuple

A tuple (padded_spectrum, padded_wavelength) that replaces the inputs with padded equivalents.