SPEX: X-ray Spectral Modeling Tool
- SPEX is a comprehensive X-ray spectroscopy toolkit that combines an extensive atomic database with self-consistent plasma models for high-resolution astrophysical analysis.
- It employs a robust Fortran 90 architecture with CPU-accelerated libraries and OpenMP threading to efficiently handle millions of atomic transitions and complex instrument responses.
- Its integrated approach, merging calibration-aware fitting and internally consistent models, enables rapid, accurate interpretation of data from missions like XMM-Newton, Chandra, Hitomi, XRISM, and Athena.
SPEX is a software package for modeling and fitting X-ray spectra, developed for X-ray applications through the combined evolution of spectral models, atomic data, and code since the 1970s, and made public as a package from the 1990s onward. It is designed for high-resolution X-ray spectroscopy, particularly in the observational regime established by the grating spectrometers aboard XMM-Newton and Chandra and extended by microcalorimeter-class missions such as Hitomi, XRISM, and Athena. Within this framework, SPEX combines a large atomic database, internally consistent plasma models, and a fitting engine intended to keep model calculation times short despite rapidly expanding spectral complexity (Plaa et al., 2019).
1. Historical development and software identity
SPEX traces its roots to R. Mewe’s early work on solar X-ray spectra in 1972. As grating and crystal-spectrometer data began to accumulate from early X-ray missions, the need for flexible plasma-emission codes increased. In 1996, Kaastra, Mewe, and Nieuwenhuijzen released SPEX v1 as a multi-purpose fitting platform for optically thin plasmas in collisional ionization equilibrium, photo-ionized plasmas, charge exchange, and related applications. The package has since been continuously developed at SRON in Utrecht, with public releases including v2 before 2016 and v3 from 2016 onward under a GPLv3 license (Plaa et al., 2019).
A central distinction drawn in the literature is between SPEX and XSPEC. XSPEC is characterized as a fitting platform with contributed models, whereas SPEX provides a coherent suite of internally consistent plasma models driven by the same atomic database. This design choice places atomic consistency and cross-model compatibility at the center of the package rather than treating models as loosely coupled additions. This suggests that SPEX is intended not only as a front end for fitting, but as an integrated physical environment for X-ray plasma spectroscopy.
2. Software architecture and major components
SPEX is written primarily in Fortran 90 and runs on Linux and macOS. Its architecture is organized around three main layers: an atomic database, model libraries, and a fitting engine (Plaa et al., 2019).
The atomic database contains energy levels, radiative transition rates, collisional excitation and ionization cross sections, dielectronic recombination rates, and charge-exchange rates. Its scale increased substantially between versions: v2 had approximately 5,000 lines, whereas v3 grew to approximately 2 million lines for elements from C to Ni. The stated driver for this expansion is the requirement imposed by high-resolution missions.
The model libraries include collisional equilibrium, photo-ionization equilibrium, charge exchange, recombining and ionizing non-equilibrium plasmas, dust and molecular absorption, and both thermal and non-thermal continua. The fitting engine implements and C-statistic minimization, parameter error searches, contour plots, and MCMC walkers described as in development. Model spectra are convolved with instrumental responses using ARF and RMF products through CPU-optimized routines and OpenMP threading. Taken together, these components define SPEX as a tightly coupled system in which atomic data, physical models, and statistical fitting are treated as parts of one computational pipeline rather than as separable utilities.
3. Physical modeling and mathematical formulation
SPEX models several principal physical processes relevant to astrophysical X-ray spectra. For collisional ionization equilibrium, it solves a system of rate equations for ion populations ,
where includes collisional ionization, recombination, and charge-exchange rates (Plaa et al., 2019).
For photo-ionization equilibrium, SPEX balances photo-ionization rates against radiative and dielectronic recombination. The code uses either user-supplied spectral energy distributions or built-in continuum shapes. This provides a common framework for modeling both collisionally ionized and externally irradiated plasmas.
Line emission is treated explicitly. For an electric-dipole transition , the emissivity is computed as
where is the electron density, the upper-level population, the collisional excitation rate coefficient, and the photon energy. Continuum processes include free–free emission, free–bound emission, two-photon emission, non-thermal inverse-Compton emission, and synchrotron emission. The free–free contribution is expressed as
0
These equations define the formal core of the package: ionization balance, emissivity formation, and continuum production are all embedded in a shared computational environment. A plausible implication is that SPEX is optimized for analyses in which line-rich plasmas, multiple ionization channels, and instrument response convolution must be treated simultaneously.
4. Atomic data expansion, line blending, and calibration
The SPEX atomic database draws on NIST, Chianti, ADAS, FAC, and R-matrix calculations. Regular updates improve energy levels, oscillator strengths, and collision strengths (Plaa et al., 2019). The enlargement from thousands to millions of transitions is directly tied to the transition from earlier X-ray spectroscopy to the high-resolution regime.
Line blending is handled through caching of all lines within a user-settable tolerance, with an example tolerance of 1, followed by application of instrument-specific line-spread functions. This treatment is essential in crowded spectral regions where observed features may represent unresolved or partially resolved multiplets rather than isolated transitions.
SPEX also includes pre-computed energy shifts and cross-calibration corrections for XMM-Newton/RGS, Chandra/HETG-LETG, Hitomi/SXS, XRISM/Resolve, and Athena/X-IFU. In practice, this ties the physical model layer to mission-specific calibration behavior. This suggests that SPEX is intended not merely for generic theoretical spectra, but for folded, calibration-aware inference from concrete observatory products.
5. Computational strategies and fitting workflow
The package adopts several explicit optimization strategies to control runtime as the atomic database and response models increase in size. Its rate-equation solver uses CPU-accelerated LAPACK through Intel MKL or OpenBLAS to invert large collisional–radiative matrices. GPU attempts are reported to have shown no net gain because of memory overhead (Plaa et al., 2019).
Response convolution implements “optimal binning” of the RMF, following Kaastra and Bleeker (2016), to reduce matrix sizes from approximately 4 GB to at most about 100 MB, together with OpenMP-parallel kernels for matrix-vector operations. Where detailed integrals such as Gaunt factors are too slow, carefully validated analytic fits are used, although these are being re-examined for future microcalorimeter accuracy. A forthcoming Python/C-API wrapper, pyspextools, is intended to support embedding SPEX in Python scripts and Jupyter notebooks.
A minimal fitting session for a collisional-equilibrium plasma observed with XMM-Newton RGS is given as follows:
3
The example identifies the best-fit 2 and normalization with the electron temperature and emission measure. It also notes that line fluxes for individual ions, such as the Si XIII triplet, can be extracted with show line cie, or that narrow delta models may be added to test for velocity shifts or turbulence. The same workflow is presented in Python pseudocode using Session, load_spectrum, load_response, add_model("cie"), set_param, fit, and plot_fit. This illustrates the package’s dual orientation toward command-line spectroscopy and scriptable analysis.
6. Scientific role in high-resolution X-ray astronomy
The scientific motivation for SPEX is closely linked to successive increases in spectral resolution in X-ray astronomy. The high-resolution grating spectrometers aboard XMM-Newton and Chandra transformed X-ray spectroscopy, and the arrival of high-resolution detectors aboard Hitomi, together with future missions such as XRISM and Athena, introduces a further step in resolution. The principal challenge identified for SPEX is therefore twofold: the atomic database must be substantially enlarged, and model calculation times must remain short (Plaa et al., 2019).
Within this trajectory, Hitomi is reported to have yielded the first microcalorimeter spectra and to have validated SPEX line libraries. XRISM and Athena are described as requiring further expansion of atomic data, including L-shell iron lines, sub-eV energy accuracy, and even more efficient convolution algorithms. Planned enhancements include MCMC samplers, automated line identification tools, improved charge-exchange models, and full Python integration.
The broader significance of SPEX lies in its attempt to maintain physical self-consistency across the entire inference chain: atomic data, plasma state, spectral formation, instrument response, and fitting statistics are all treated as parts of a single system. In the context of next-generation observatories, this suggests a model of spectroscopy in which the limiting factors are increasingly atomic completeness, calibration fidelity, and computational efficiency rather than only detector sensitivity.