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.
Features
- 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.
Installation
BaySpec is available on PyPI:
pip install bayspec
Optional: MultiNest sampler
To enable MultiNest for nested
sampling, follow the
pymultinest install
guide.
Optional: astromodels components
To pull components from
astromodels,
install astromodels in your Python environment.
Optional: Xspec components
To pull components from
Xspec:
- Install
HEASoftandXspec v12.12.1+. - After initialising the
HEASoftenvironment, installxspec-models-cxc.
Note:
bayspeccurrently supports onlyAdditiveandMultiplicativeXspecmodels.
BaySpec App
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:
Documentation
Read the full documentation or browse the examples for typical workflows end to end.
Citation
If you use BaySpec in your research, please cite the software version
used in your analysis. Citation metadata are provided in
CITATION.cff, and a reusable BibTeX entry is available in
CITATION.bib. For version 0.4.5:
Yang, J. (2026). BaySpec: Bayesian inference for high-energy astrophysical spectra (Version 0.4.5) [Computer software]. https://github.com/jyangch/bayspec/releases/tag/v0.4.5
@software{bayspec,
author = {Yang, Jun},
title = {{BaySpec}: Bayesian inference for high-energy astrophysical spectra},
version = {0.4.5},
year = {2026},
month = oct,
date = {2026-10-11},
url = {https://github.com/jyangch/bayspec/releases/tag/v0.4.5}
}
Zenodo automatic archiving is enabled for this repository. A DOI for the first archive is pending; until it is available, use the version-specific release URL above. Once archived, cite the DOI for the version used in your analysis.
License
BaySpec is distributed under the
GPL-3.0 license.
Metadata
Release files for bayspec 0.4.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| bayspec-0.4.5.tar.gz | 984.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| bayspec-0.4.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 2.0 MB
Release files / bayspec-0.4.5.tar.gz
| Download URL | bayspec-0.4.5.tar.gz |
|---|---|
| Size | 984.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
924c6a0e5479a4ee225529c66c1aae26566aba32685692506f5f02d4ec14cdde
|
|
BLAKE2b-256 checksum How to use checksums |
cf20d3ce9b8d01803a4bb648db9d6411c6d20f50d44e3186e072209934b60a25
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.8
|
Release files / bayspec-0.4.5-py3-none-any.whl
| Download URL | bayspec-0.4.5-py3-none-any.whl |
|---|---|
| Size | 988.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c44fd1c3cfc902cc6c5ba5ca6a157304b643908798c8751726833e34ba23b93c
|
|
BLAKE2b-256 checksum How to use checksums |
f78ca4df623ecfbb3c099641255d2404b6e21f2dc67f10a0e6f40bc54ee0d8e2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.8
|