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.
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.
from speclib import Spectrum, Filter, apply_filter
spec = Spectrum.from_grid(teff=4000, logg=4.5, feh=0.0)
filt = Filter("2MASS J")
flux = apply_filter(spec, filt)
print(f"J-band flux: {flux:.2e}")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.
NewEra grid downloads now keep the tarball cached without unpacking by default.
When a specific metallicity file is needed, it is extracted on demand from the
cached archive. To explicitly extract the full grid (for offline usage or bulk
access), use the extract="all" option:
from speclib.utils import download_newera_grid
# Cache the tarball only (default behavior)
download_newera_grid("newera_jwst")
# Extract all members from the tarball
download_newera_grid("newera_jwst", extract="all")MIT © 2025 Benjamin V. Rackham