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

  1. Install sheap

    pip install sheap
    
  2. Load a spectrum

    from sheap import Sheapectral
    spec = Sheapectral("my_spectrum.txt", z=0.5, ebv=0.02)
    
  3. Build a fitting region

  4. Fit

    spec.fitmodel()
    
  5. Inspect results

    fig    = spec.plotter.plot(0)
    params = spec.result.params
    
  6. Obtain the extra products

    spec.estimate_posteriors(sampling_method="montecarlo")
    spec.result.posterior[1]
    

Documentation

See the following modules for detailed API reference: