Bayesian inference-based spectral fitting for high-energy astrophysical data.
BaySpec is a Python library for Bayesian inference on high-energy
astrophysical spectra. It pairs MCMC and nested-sampling backends with
multi-spectrum, multi-model fitting machinery, reads OGIP FITS data out
of the box, and bridges to local, astromodels,
and Xspec
model libraries.
- Inference backends. Posterior sampling via MCMC
(
emcee) or nested sampling (MultiNestviapymultinest); maximum-likelihood fits vialmfitoriminuitfor quick checks. - OGIP Type I & II FITS. Source and background
PHA/PHA2spectra, plusRMF,RSP/RSP2, andARF/ARF2responses — multi-extension archives are row-indexed so individual spectra plug in directly. - Multi-dimensional. Time-evolving spectra fit with time-involved physical models.
- Multi-wavelength. Joint fitting across spectra at different wavelengths.
- Multi-spectrum, multi-model. Simultaneously fit any number of
(data, model)pairs; combine, freeze, or link parameters across pairs. - Pluggable model libraries. A local set plus optional
astromodelsandXspecbridges. Register your own Python functions as new components. - Browser workbench (optional). BaySpec App is a FastAPI + HTMX front-end that exposes the same fitting machinery through a web UI.
BaySpec is available on PyPI:
pip install bayspecTo enable MultiNest for nested
sampling, follow the
pymultinest install
guide.
To pull components from
astromodels,
install astromodels in your Python environment.
To pull components from
Xspec:
- Install
HEASoftandXspec v12.12.1+. - After initialising the
HEASoftenvironment, installxspec-models-cxc.
Note:
bayspeccurrently supports onlyAdditiveandMultiplicativeXspecmodels.
BaySpec App is the
browser front-end for bayspec — a FastAPI + HTMX workbench that loads
OGIP spectra, composes models, and runs inference without notebook glue.
A public, hosted deployment runs on Hugging Face Spaces:
Read the full documentation or browse the examples for typical workflows end to end.
BaySpec is distributed under the
GPL-3.0 license.