Skip to main content

spice logo

SPICE: SPectral Integration Compiled Engine

A comprehensive Python library for modeling and analyzing stellar spectra with inhomogeneous surfaces, supporting rotation, pulsations, spots, and binary star systems.

The paper is submitted and available as a preprint.

Installation

Use Python 3.11 or newer. The current dependency constraints require JAX/JAXlib ≥0.10 and NumPy ≥2.0,<3. Install from PyPI:

pip install stellar-spice

For PHOEBE integration support:

pip install "stellar-spice[phoebe]"

For zarr-backed model-atmosphere grid interpolation (LazyZarrInterpolator and friends):

pip install "stellar-spice[grid]"

For neural-network emulator bundles (aemu), such as the paper's mjablonska/TPayne-spice-harps-interp:

pip install "stellar-spice[aemu]"

TransformerPayne bundles need 64-bit JAX: set JAX_ENABLE_X64=1 (or call jax.config.update("jax_enable_x64", True)) before importing SPICE.

Documentation

📖 Read the full documentation for detailed API reference and tutorials.

The grids and model outputs behind the paper are in the Hugging Face dataset mjablonska/spice-paper-data; python tutorial/paper_results/fetch_paper_data.py downloads them (see the Paper data page of the documentation).

Key Features

🌟 Stellar Surface Modeling

  • Mesh-based stellar surfaces using icosphere discretization
  • Inhomogeneous temperature distributions across stellar surfaces
  • Surface gravity variations accounting for rotation and shape distortions
  • Line-of-sight velocity calculations for Doppler shift effects

🔄 Stellar Rotation

  • Solid-body (rigid) rotation with a configurable axis and equatorial velocity
  • Rotational broadening effects on spectral lines
  • Surface velocity field calculations
  • Time-dependent spectral variations due to rotation

🌊 Stellar Pulsations

  • Spherical harmonic pulsation modes (l, m modes)
  • Fourier series parameterization for complex pulsation patterns
  • Multi-mode pulsations with different periods and amplitudes
  • Surface displacement and velocity calculations

🌑 Stellar Spots

  • Spherical harmonic spot modeling for complex spot distributions
  • Temperature contrast between spots and photosphere
  • Spots that rotate with the surface
  • Spot-induced spectral variations

⭐ Binary Star Systems

  • Full orbital dynamics with Keplerian orbits
  • Mutual eclipses and occultations resolved on the projected meshes
  • PHOEBE integration — import Roche-lobe geometry and tidally distorted binary meshes computed by PHOEBE

📊 Spectral Synthesis

  • Blackbody radiation for basic stellar modeling
  • Model-atmosphere grid interpolation from precomputed, zarr-backed grids
  • Analytic line-profile emulators (Gaussian and physical)
  • Neural-network emulator (aemu) bundles for ML-based spectral synthesis
  • Custom spectral models via the SpectrumEmulator interface

🔍 Synthetic Photometry

  • Multiple passband support (Johnson, Stromgren, Gaia, etc.)
  • AB, ST and Vega magnitude systems
  • Bolometric luminosity computations
  • Time-series photometry for variable stars

🎯 Advanced Features

  • JAX-based computations for fast, differentiable calculations
  • GPU acceleration support
  • 3D visualization of stellar surfaces and binary systems
  • Animation capabilities for time-evolving systems
  • Occlusion handling for complex geometries

Quick Start

Basic Stellar Model

import numpy as np
from spice.models import IcosphereModel
from spice.models.mesh_transform import add_rotation, evaluate_rotation
from spice.spectrum import simulate_observed_flux, Blackbody

bb = Blackbody()

# Create a solar-like star
star = IcosphereModel.construct(
    n_vertices=1000,                 # Resolution request; rounded to a refinement level
    radius=1.0,                      # Solar radii
    mass=1.0,                        # Solar masses
    parameters=bb.solar_parameters,
    parameter_names=bb.parameter_names,
)

# Add solid-body rotation (equatorial velocity in km/s) and evaluate it at t = 0 s
star = evaluate_rotation(add_rotation(star, rotation_velocity=2.0), 0.)

# Generate the disc-integrated spectrum. simulate_observed_flux expects *log10*
# wavelengths and returns an (n_wavelengths, 2) array whose columns are the
# disc-integrated emulator channels (flux and continuum; column 0 is the flux).
wavelengths = np.logspace(3, 4, 1000)            # 1000-10000 Å
flux = simulate_observed_flux(bb.intensity, star, np.log10(wavelengths))

The flux is in erg/s/cm²/Å at the default distance of 10 pc. Pass linear wavelengths in Å and flux[:, 0] directly to the AB, ST, or Vega magnitude functions; no spectral-density conversion is needed. See the photometry guide.

For a custom viewing direction, call get_mesh_view before add_rotation to choose an equator-on default axis. Changing the view of an already rotating model preserves its physical axis; looking along that axis gives zero projected rotational velocity.

Binary Star System

import numpy as np
import jax.numpy as jnp
from spice.models import IcosphereModel, Binary
from spice.models.binary import add_orbit, evaluate_orbit_at_times
from spice.models.mesh_view import get_mesh_view
from spice.spectrum import simulate_observed_flux, Blackbody, AB_passband_luminosity
from spice.spectrum.filter import GaiaG

bb = Blackbody()
los = jnp.array([0.0, 0.0, -1.0])  # line of sight (observer -> star); orbit inclination is measured from +z

# Create binary components. Meshes already use the default line of sight above;
# get_mesh_view only matters for a different one, which both components must share.
primary = get_mesh_view(
    IcosphereModel.construct(1000, 1.0, 1.0, bb.solar_parameters, bb.parameter_names), los)
secondary = get_mesh_view(
    IcosphereModel.construct(1000, 0.8, 0.8, bb.solar_parameters, bb.parameter_names), los)

# Assemble the system
binary = Binary.from_bodies(primary, secondary)

# A close, edge-on orbit (P ~ 3.65 days) so the components eclipse
binary = add_orbit(
    binary,
    P=0.01,                   # orbital period [years]
    ecc=0.0,                  # eccentricity
    T=0.0,                    # time of periastron passage [years]
    i=np.pi / 2,              # inclination [rad], edge-on
    omega=0.0,                # argument of periastron [rad]
    Omega=0.0,                # longitude of the ascending node [rad]
    mean_anomaly=0.0,         # additive phase offset from periastron timing [rad]
    reference_time=0.0,       # reference time [years]
    vgamma=0.0,               # systemic velocity [km/s]
    orbit_resolution_points=20,
)

# Evaluate the orbit across one period (eclipses/occlusions resolved internally).
# Each step resolves occlusions between two 1280-face meshes; on a laptop CPU
# the 20 steps take under a minute or two.
times = jnp.linspace(0.0, 0.01, 20)
primaries, secondaries = evaluate_orbit_at_times(binary, times)

# Combined Gaia G-band light curve
wavelengths = np.linspace(900, 40000, 1000)
gaia_g = GaiaG()
light_curve = [
    AB_passband_luminosity(
        gaia_g,
        wavelengths,
        simulate_observed_flux(bb.intensity, p1, np.log10(wavelengths))[:, 0]
        + simulate_observed_flux(bb.intensity, p2, np.log10(wavelengths))[:, 0],
    )
    for p1, p2 in zip(primaries, secondaries)
]

PHOEBE Integration

import numpy as np
import phoebe
from phoebe.parameters.dataset import _mesh_columns
from spice.models import PhoebeBinary
from spice.models.binary import evaluate_orbit
from spice.models.phoebe_utils import PhoebeConfig
from spice.spectrum import simulate_observed_flux, Blackbody

bb = Blackbody()

# Build a PHOEBE binary and compute a mesh dataset (standard PHOEBE workflow)
b = phoebe.default_binary()
times = np.linspace(0, 1, 10)
b.add_dataset('mesh', compute_times=times, columns=_mesh_columns, dataset='mesh01')
b.add_dataset('orb', compute_times=times, dataset='orb01')
b.run_compute(coordinates='uvw', overwrite=True)

# Wrap the PHOEBE meshes for SPICE (PHOEBE models are read-only inside SPICE)
config = PhoebeConfig(b, 'mesh01')
pb = PhoebeBinary.construct(config, ['teff', 'logg', 'abun'])

# Evaluate the components at a snapshot time, then synthesise the spectrum
# (t = 0 is the primary eclipse of the default binary, so pick a later time)
primary, secondary = evaluate_orbit(pb, config.times[2])
wavelengths = np.logspace(3, 4, 1000)
flux = simulate_observed_flux(bb.intensity, primary, np.log10(wavelengths))

Performance

  • JAX-powered computations for fast, vectorized operations
  • GPU acceleration support for large-scale calculations
  • Efficient mesh operations with optimized occlusion algorithms
  • Memory-efficient spectral synthesis for time-series data

Known internals caveat

Mesh area conventions (slated for cleanup)

MeshModel currently exposes two area arrays that follow different unit conventions:

Property Convention Sum over the mesh
m.areas / m.base_areas divided by the reference radius squared ≈ 4π for an undeformed sphere
m.cast_areas / m.visible_cast_areas physical R⊙² ≈ 2π R² / ≈ π R²

The sums above describe undeformed, uneclipsed spheres. Pulsations change m.areas and the projected areas; the normalization still uses the reference radius. With multiple modes, SPICE combines vertex displacements before calculating the area change. Zero displacement preserves the original geometry.

Any code that integrates over the stellar surface must apply the matching cgs prefactor:

  • simulate_observed_flux integrates m.visible_cast_areas (already in R⊙²) and applies only the dimensionless dilution (R⊙ / pc)² / d_pc².
  • simulate_monochromatic_luminosity integrates m.areas (unit-sphere) and applies R² × R⊙²[cm²] to convert to cgs.

If you add a new integrator over either array, mirror the matching pattern. This convention asymmetry is a known maintainability hazard and is slated for future cleanup: once m.areas is normalised the same way as m.visible_cast_areas, the cgs prefactor in simulate_monochromatic_luminosity should be reduced to R⊙²[cm²] only, matching the structure of simulate_observed_flux.

Citation

If you use stellar-spice in your research, please cite:

@misc{spice,
      title={SPICE -- modelling synthetic spectra of stars with non-homogeneous surfaces}, 
      author={M. Jabłońska, T. Różański, L. Casagrande, H. Shah, P. A. Kołaczek-Szymański, M. Rychlicki and Yuan-Sen Ting},
      year={2025},
      eprint={2511.10998},
      archivePrefix={arXiv},
      primaryClass={astro-ph.SR},
      url={https://arxiv.org/abs/2511.10998}, 
}

Contributing

We welcome contributions! Please see our contributing guidelines for details.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Built with JAX for fast, differentiable computations
  • Integrates with PHOEBE for binary star modeling
  • Uses astro-emulators-toolkit bundles for ML-based spectral synthesis

A preprint describing SPICE is available on arXiv. See Citation if you use it in your work.

Metadata

Release files for stellar-spice 1.9.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for stellar-spice 1.9.1
File Size Uploaded Provenance Actions
stellar_spice-1.9.1.tar.gz 704.6 kB With provenance Details for stellar_spice-1.9.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for stellar-spice 1.9.1
File Interpreter ABI Platform Actions
stellar_spice-1.9.1-py3-none-any.whl Python 3 none any Details for stellar_spice-1.9.1-py3-none-any.whl

Total release size: 1.4 MB

Release files / stellar_spice-1.9.1.tar.gz

Download URL stellar_spice-1.9.1.tar.gz
Size 704.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a17c43b71028179f37fc8981988bc11fcad9c70f159ad2655dbbbb9f0fbee957
BLAKE2b-256 checksum
How to use checksums
30d35d2781eac5626a1d60bebdc9aad12a0d28726bdd818ddb1f275ed358d760
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

Release files / stellar_spice-1.9.1-py3-none-any.whl

Download URL stellar_spice-1.9.1-py3-none-any.whl
Size 653.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e897752d00bef881d804a4e429474e52d45ee3e52aa08ab3bf73a4bfdec9a61f
BLAKE2b-256 checksum
How to use checksums
132aab8497c616d4ac8f88b374cd3ac8ea06eb6d01d3ece0e8093142cdde2b67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

Security for stellar-spice 1.9.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for stellar_spice-1.9.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page