Tools for working with stellar spectral libraries.
speclib provides a lightweight Python interface for loading, manipulating, and analyzing stellar spectra and model grids. It includes utilities for photometric synthesis, spectral resampling, and SED construction using libraries such as PHOENIX.
Read the complete user guide, runnable tutorials, model library notes, and API reference at speclib.readthedocs.io.
With Poetry (recommended):
git clone https://github.com/brackham/speclib.git
cd speclib
poetry installOr with pip:
pip install git+https://github.com/brackham/speclib.gitIf you use speclib in published work, please cite both:
- the archived Zenodo release corresponding to the version of
speclibused in your work (doi:10.5281/zenodo.7868049), and - Rackham & de Wit (2024), doi:10.3847/1538-3881/ad5833.
The Zenodo citation provides a persistent software DOI, while Rackham & de Wit (2024) describes the scientific motivation and methodology. The contribution-credit policy is described in CONTRIBUTING.md.
import astropy.units as u
import numpy as np
from speclib import Spectrum
wavelength = np.linspace(5000, 5100, 1001) * u.AA
flux = np.ones(wavelength.size) * u.erg / (u.s * u.cm**2 * u.AA)
spectrum = Spectrum(spectral_axis=wavelength, flux=flux)
sampled = spectrum.resample(np.linspace(5010, 5090, 81) * u.AA)This example is entirely local. Loading a stellar-model spectrum may download external data; see the Quickstart and model library guide before starting a large grid download.
Downloaded spectral libraries are stored in ~/.speclib/libraries by default.
Set the SPECLIB_LIBRARY_PATH environment variable or call
speclib.utils.set_library_root("/path/to/cache") to use a different location.
Download, extraction, storage, and interpolation behavior for PHOENIX, MPS-ATLAS, SPHINX, and NewEra are documented in the model library reference.
MIT © 2021–2026 Benjamin V. Rackham