pyckles.spectral_library module#

Main module.

class pyckles.spectral_library.SpectralLibrary(catalog_name=None, **kwargs)[source]#

Bases: object

A container for a library of spectra.

Holds and returns spectra from various catalogues in various “python-friendly” formats, such as: synphot.SourceSpectrum, astropy.Quantity, numpy.ndarray, and fits.BinTableHDU

Spectra can be accessed by using the attribute syntax

>>> import pyckles
>>> spec_lib = pyckles.SpectralLibrary("pickles")
>>> spec_lib.A0V
<astropy.io.fits.hdu.table.BinTableHDU object at 0x...>

or using the item syntax

>>> spec_lib["A0V"]
<astropy.io.fits.hdu.table.BinTableHDU object at 0x...>

The returned spectrum is formatted according to meta["return_style"] parameter

>>> spec_lib.meta["return_style"] = "fits"
>>> type(spec_lib.A0V)
<class 'astropy.io.fits.hdu.table.BinTableHDU'>
Parameters:
catalog_namestr

The name of the spectral catalogue. See pyckles.catalogs

Attributes:
available_spectra

Return table column containing all spectra name in the library.

Methods

load(catalog_name)

Load the catalogue for a valid string catalog_name.

Examples

List the available spectra

>>> import pyckles
>>> spec_lib = pyckles.SpectralLibrary("pickles", return_style="quantity")
>>> spec_lib.available_spectra
<Column name='name' dtype='str7' length=131>
    A0I
  A0III
   A0IV
    A0V
    A2I
    A2V
  A3III
    A3V
   A4IV
  A5III
    A5V
  A7III
    ...
  F5V_W
  F8V_W
  G0V_W
G5III_W
  G5V_W
G8III_W
K0III_W
K1III_W
K2III_W
K3III_W
K4III_W

Get an A0V spectrum

>>> vega = spec_lib.A0V
>>> vega
(<Quantity [ 1150.,  1155.,  1160., ..., 24990., 24995., 25000.] Angstrom>, <Quantity [0.181751, 0.203323, 0.142062, ..., 0.00699 , 0.006986, 0.006983] erg / (Angstrom s cm2)>)

Return synphot.SourceSpectrum objects instead of a list of Quantity arrays

>>> spec_lib.meta["return_style"] = "synphot"
>>> spec_lib.A0V
<synphot.spectrum.SourceSpectrum object at 0x...>
property available_spectra#

Return table column containing all spectra name in the library.

load(catalog_name)[source]#

Load the catalogue for a valid string catalog_name.

pyckles.spectral_library.spectrum_from_hdu(hdu, return_type='fits')[source]#

Convert a BinTableHDU into the required return_type format.

Parameters:
hduBinTableHDU

A BinTableHDU spectrum with column names: wavelength, flux

return_typestr

The format of the returned spectra - See SpectralLibrary docs

Returns:
specvarious

See above

See also

SpectralLibrary