Skip to main content

SPECIES v4

SPECtroscopic Inference of stEllar parameterS

A modern stellar spectroscopy pipeline for determining atmospheric parameters, chemical abundances, and broadening from high-resolution echelle spectra.

Originally created by Maritza Soto & James Jenkins (Soto & Jenkins 2018). Modernized and maintained by Jose Vines.

What it does

Given a high-resolution stellar spectrum, SPECIES determines:

  • Atmospheric parameters: Teff, log g, [Fe/H], microturbulence
  • Chemical abundances: Na, Mg, Al, Si, Ca, Ti, Cr, Mn, Fe, Ni, Cu, Zn (14 ions)
  • Broadening: vsini (rotational velocity) and vmac (macroturbulence)

It works by measuring equivalent widths of iron lines, then iteratively solving for the atmospheric parameters that produce excitation balance, ionization balance, and abundance consistency using MOOG (Sneden 1973) under the assumption of local thermodynamic equilibrium (LTE). Atmosphere models are interpolated from ATLAS9 grids (Castelli & Kurucz 2004).

Installation

pip install astro-species
species install-moog
species check

install-moog downloads and compiles MOOG from source. You need gfortran installed:

Platform Command
Ubuntu/Debian sudo apt install gfortran
Fedora/RHEL sudo dnf install gcc-gfortran
macOS brew install gcc
Conda conda install -c conda-forge gfortran

You also need ATLAS9 atmosphere model grids (~3.3 GB). These are not bundled with the package. Set SPECIES_ATLAS9_DIR to point to your local copy, or they will be downloaded on first use (TBD).

Docker

For zero-setup usage:

docker build -t species .
docker run -v ./spectra:/data species analyze /data/my_star.fits

Quick start

Python API

from species import Spectrum, Analyzer

# Load a spectrum (auto-detects instrument from FITS header)
spectrum = Spectrum.from_fits("my_star_feros.fits")

# Or from arrays (e.g. from your own reduction pipeline)
spectrum = Spectrum.from_arrays(wavelength, flux, snr=120, instrument="FEROS")

# Run the full analysis
result = Analyzer(spectrum).run()

# Results are structured Python objects
print(result.params.teff)           # 5822.0
print(result.params.logg)           # 4.52
print(result.params.feh)            # -0.003
print(result.abundances["SiI"])     # ElementAbundance(abundance=+0.068, n_lines=20)
print(result.broadening.vsini)      # 2.1 km/s

# Serialize
result.to_fits("results.fits")
result.to_dict()  # for databases, JSON, etc.

Batch processing

from pathlib import Path
from species import Spectrum, Analyzer

# Load multiple spectra
spectra = [Spectrum.from_fits(f) for f in Path("spectra/").glob("*.fits")]

# Analyze in parallel (4 cores)
results = Analyzer.batch(spectra, output_dir="./results", n_cores=4)

for result in results:
    print(f"{result.star_name}: T={result.params.teff:.0f}  [Fe/H]={result.params.feh:.3f}")

Command line

# Single star
species analyze my_star.fits --output ./results

# Multiple stars
species analyze star1.fits star2.fits star3.fits --output ./results

# Glob pattern + parallel
species analyze spectra/*.fits --ncores 4

# Skip broadening (faster)
species analyze my_star.fits --no-broadening

# Giant star
species analyze my_star.fits --giant

# EW measurement only
species ew-only my_star.fits

# Check installation
species check

Configuration

All settings can be overridden via environment variables or constructor arguments:

from species import Analyzer, Spectrum, Settings

config = Settings(
    atlas9_dir="/path/to/grids",
    moog_binary="/usr/local/bin/MOOGSILENT",
    is_giant=True,
)

result = Analyzer(spectrum, config=config).run()

Environment variables use the SPECIES_ prefix: SPECIES_ATLAS9_DIR, SPECIES_MOOG_BINARY, etc.

Supported instruments

SPECIES reads spectra from:

  • HARPS (ESO 3.6m)
  • FEROS (ESO/MPG 2.2m)
  • MAROON-X (Gemini-N, *.hd5; needs the maroonx extra). Blaze: pass the DRS response file (response= / MAROONX_RESPONSE) or a masterflat blaze store (blaze= / MAROONX_BLAZE); without either, orders are flattened by a polynomial envelope.
  • UVES (ESO VLT)
  • HIRES (Keck)
  • CORALIE (Euler 1.2m)
  • PFS (Magellan)
  • AAT
  • LCO NRES
  • Generic FITS (auto-detected from WCS keywords or 2D data layout)

Instrument is auto-detected from the FITS header INSTRUME keyword or the filename convention (starname_instrument.fits). You can also pass instrument="FEROS" explicitly.

Changes from the original SPECIES

Algorithmic improvements

Broyden's method replaces per-parameter bisection. The original adjusted one parameter at a time (metallicity, then temperature, then gravity, then microturbulence) via bisection, cycling until all four diagnostics converged. This required 600-900 MOOG calls per star and had convergence issues when porting from Python 2 to 3 due to float comparison semantics. The new default uses Broyden's quasi-Newton method, which solves the 4-equation system simultaneously in 10-16 MOOG calls. The residual norm is typically 250x smaller. The old bisection method is still available via method="per_parameter".

Broadening uses MOOG 5x instead of 75x. The original ran a separate MOOG synthesis for each vsini grid point (15 values x 5 lines = 75 calls). But the unbroadened spectrum is identical regardless of vsini — rotational broadening is applied afterward. The new code synthesizes once per diagnostic line and applies pyasl.rotBroad() in numpy.

Error propagation unified. The original had two nearly identical files (CalcErrors_new.py for dwarfs, CalcErrorsGiant_new.py for giants) differing only in polynomial coefficients. Now a single parameterized module.

Architecture

Aspect Original (v3) v4
Python version 2.7/3.x compatible 3.12+
Packaging None (clone and run) pip install astro-species
API CLI only (python SPECIES.py -starlist ...) Python library + CLI
Configuration 80+ global variables, 40+ CLI flags Pydantic Settings + env vars
MOOG interface os.system("MOOGSILENT") subprocess.run() with timeout, error handling
Type hints None Full coverage
Tests None 17 integration tests
Output Text files at hardcoded paths Structured dataclasses, FITS, ASCII
Parallelism Per-star (multiprocessing.Pool) Per-star + MOOGSession for per-call efficiency
Lines of code ~9,800 ~5,800

What was removed

  • Isochrone fitting (FindIsochrones.py): Mass, age, and radius determination is now handled by downstream tools. SPECIES focuses on spectroscopy.
  • Python 2 compatibility: from __future__ imports, past.utils.old_div, builtins shims.
  • MultiNest/emcee dependencies: These were only used by the isochrone module.
  • mwdust dependency: Extinction correction is handled elsewhere.
  • Full PhotometricRelations_class.py: Replaced with a lightweight Vizier lookup for initial parameter guesses. With Broyden's method, initial guesses matter less.

Performance

Metric Original v4
MOOG calls per star 600-900 15-25
Wall-clock time 10-20 min ~1 min
Convergence residual ~0.05 ~0.0002

Package structure

src/species/
    __init__.py          # Public API: Spectrum, Analyzer, Settings
    config.py            # Pydantic Settings (replaces global variables)
    cli.py               # Command-line interface
    analyzer.py          # Main orchestrator
    spectrum.py          # Spectrum loading + instrument readers
    ccf.py               # Cross-correlation for RV / rest-frame correction
    ew.py                # Equivalent width measurement
    atmosphere.py        # Atmospheric parameter fitting (Broyden + bisection)
    errors.py            # Error propagation (unified dwarf/giant)
    abundances.py        # Chemical abundance determination
    broadening.py        # vsini / vmac measurement
    photometry.py        # Vizier initial parameter estimation
    moog/
        wrapper.py       # MOOG subprocess interface + MOOGSession
        parser.py        # MOOG output parsing
        par_file.py      # Parameter file generation
        atmosphere_grid.py  # ATLAS9 grid interpolation
    io/
        results.py       # Result dataclasses + serialization
        plots.py         # Diagnostic plots
    data/
        linelists/       # Bundled iron + abundance line lists
        masks/           # Binary masks for CCF
        solar.py         # Asplund 2009 solar abundances

Citation

If you use SPECIES in your work, please cite:

  • Soto & Jenkins 2018, A&A 615, A76 (ADS)
  • Soto et al. 2021, MNRAS 508, 1

License

MIT

Reusing preprocessing and choosing EW workers

Equivalent widths are measured in line-list order with independent processes. measure_equivalent_widths(..., n_workers=None) uses the CPU count capped at 8; n_workers=1 uses sequential measurement. Per-line Monte Carlo seeds make all numerical results independent of worker count. In the pipeline, set Settings(ew_workers=1) to control both Fe and abundance measurements, for example when running a parallel batch over stars. The environment equivalent is SPECIES_EW_WORKERS=1.

Precomputed Fe-line EWs and radial velocities can be supplied directly:

result = analyzer.run(ew_results=measured_fe_lines, rv=known_rv_kms)

The supplied EWs must correspond to the configured Fe line list and the rest-frame spectrum. Abundance lines are a separate measurement. A supplied RV skips CCF measurement and Doppler-corrects an observed spectrum. If Spectrum.rv is already set, the spectrum is treated as corrected and its RV must match. The input spectrum is not mutated. An empty EW list explicitly skips measurement and returns an analysis without fitted parameters.

Disk caching is off by default. Enable it with Settings(use_cache=True) or species analyze star.fits --cache / species ew-only star.fits --cache. The default directory is <output_dir>/cache; Settings(cache_dir=...) selects a shared root with a separate directory per star. --cache --recompute forces fresh measurements, while --no-cache disables reads and writes. Environment settings such as SPECIES_USE_CACHE=true are honoured unless the command line explicitly selects --cache or --no-cache.

Rest-frame entries hash the spectrum and mask. EW entries hash the rest-frame wavelengths, flux, S/N, line-list contents, broadening settings, and measurement code. Changing solver initial values, held parameters, convergence tolerances, or worker count does not invalidate preprocessing. Cache files contain Python pickle data and should only be read from a trusted local cache directory.

Metadata

Release files for astro-species 4.6.0

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

Source distribution (sdist)

Source distribution for astro-species 4.6.0
File Size Uploaded Provenance Actions
astro_species-4.6.0.tar.gz 13.4 MB Without provenance Details for astro_species-4.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for astro-species 4.6.0
File Interpreter ABI Platform Actions
astro_species-4.6.0-py3-none-any.whl Python 3 none any Details for astro_species-4.6.0-py3-none-any.whl

Total release size: 26.9 MB

Release files / astro_species-4.6.0.tar.gz

Download URL astro_species-4.6.0.tar.gz
Size 13.4 MB
Tags Source
SHA-256 checksum
How to use checksums
2e3a3a327a257717b737911a2ca1c13f32bdc5c63f7bfc0ab606a9579d5dbaa3
BLAKE2b-256 checksum
How to use checksums
50267179d12e94d172fd2325e950563e4d0fd897c040a597abce97c813aa40d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.16

Release files / astro_species-4.6.0-py3-none-any.whl

Download URL astro_species-4.6.0-py3-none-any.whl
Size 13.4 MB
Tags Python 3
SHA-256 checksum
How to use checksums
f1ec60cf289902bea0ac63c09cc2c607c73df9847ae14052198a944aa02b974b
BLAKE2b-256 checksum
How to use checksums
d5370ddf793afca6c0262ed56fc1cdf3314240d7e40bd2a1a03bfb73a036bb17
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.16

Security for astro-species 4.6.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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