sheap’s Overview
Overview
sheap is a Python library for modeling, fitting, and sampling astronomical spectra. Leveraging modern JAX-based numerical routines and probabilistic inference via NumPyro, sheap provides a flexible, high-performance framework for:
Pre-processing: automated Galactic extinction and redshift corrections
Region definition: build spectral moodel with emission‐line regions (e.g. broad, narrow, outflow) Fe II templates, Balmer continuum, and more
Deterministic fitting: gradient-based optimization of continuum and multi-component line profiles (Gaussian, Lorentzian, linear, broken-powerlaw)
Uncertainty estimation: Monte Carlo sampling using per-pixel spectral uncertainties.
Bayesian sampling: posterior sampling of line and continuum parameters using Hamiltonian Monte Carlo (NUTS)
Key Features
High performance: JIT-compiled flux modeling and optimization (via JAX & Optax)
Modular API: separate stages for region building, fitting, plotting, and sampling
Flexible templates: define custom line lists via YAML or Python dicts
Extensible: add new profile shapes, priors/constraints, and sampling strategies
Quickstart
Install sheap
pip install sheap
Load a spectrum
from sheap import Sheapectral spec = Sheapectral("my_spectrum.txt", z=0.5, ebv=0.02)
Build a fitting region
Fit
spec.fitmodel()
Inspect results
fig = spec.plotter.plot(0) params = spec.result.params
Obtain the extra products
spec.estimate_posteriors(sampling_method="montecarlo") spec.result.posterior[1]
Documentation
See the following modules for detailed API reference:
Sheapectral: core entry point, I/O, extinction & redshift correctionSheapModelBuilder: construct line‐fitting templates from YAML & rulesSheapModelFitting: perform JAX/Optax minimization with constraintsMinimizer: low‐level optimizer wrapperMasterSampler: Posterior samplingSheaProducts: sheap extra products.