SPEX: High-Resolution Spectral Modeling and Fitting for X-ray Astronomy
Jelle de Plaa, Jelle S. Kaastra, Liyi Gu, Junjie Mao, Ton Raassen
aa r X i v : . [ a s t r o - ph . I M ] D ec SPEX: High-Resolution Spectral Modelingand Fitting for X-ray Astronomy
Jelle de Plaa, Jelle S. Kaastra, , Liyi Gu, Junjie Mao, and Ton Raassen SRON Netherlands Institute for Space Research, Utrecht, The Netherlands; [email protected] Leiden University, Leiden, The Netherlands RIKEN High Energy Astrophysics Laboratory, Wako, Saitama, Japan University of Strathclyde, Glasgow, UK
Abstract.
We present the SPEX software package for modeling and fitting X-rayspectra. Our group has developed spectral models, atomic data and code for X-rayapplications since the 1970’s. Since the 1990’s these are further developed in the pub-lic SPEX package. In the last decades, X-ray spectroscopy has been revolutionizedby the high-resolution grating spectrometers aboard XMM-Newton and Chandra. Cur-rently, new high-resolution detectors aboard the Hitomi mission, and future missions,like XRISM and Athena, will provide another major step forward in spectral resolution.This poses challenges for us to increase the atomic database substantially, while keep-ing model calculation times short. In this paper, we summarize our e ff orts to preparethe SPEX package for the next generation of X-ray observatories.
1. Introduction
Plasmas, gases and dust in the Universe can show distinct spectral features in the X-rayband. With the advance of space-based X-ray observatories that started in the 1970’s,there has been an increasing demand for spectral models that can be used to fit theobserved spectra. What started with a code to model the solar X-ray spectrum (Mewe1972) grew over a few decades into a multi-purpose spectral fitting code called SPEX (Kaastra et al. 1996). The package contains models for, for example, optically thinplasmas in collisional ionization equilibrium, plasmas in photo-ionization equilibrium,and charge-exchange emission. These models are all using the same atomic database,which is built-up in parallel with the software package.SPEX has a similar purpose as the other well known X-ray spectral fitting packagecalled Xspec (Arnaud 1996). The main di ff erence is that Xspec acts as a spectral fittingplatform with community provided models, while SPEX favors a more self-consistentapproach. Most of the models that require atomic data in SPEX use the same atomicdatabase and the same routines calculating the physical processes. and ATHENA , there will be much higher requirements on the accuracy ofthe spectral models.
2. Development Challenges
The increasing spectral resolution of observed X-ray spectra poses a number of chal-lenges. Not only do we need to increase the size of the atomic database, also the ac-curacy of the calculations needs to be improved. In addition, the new microcalorimeterinstruments have much larger response matrices. These matrices are used to convolvethe model spectrum with the instrument characteristics to make a direct comparisonwith observed spectra possible. Finally, there is an increasing demand to make the codebetter scriptable using languages like Python. At the same time, the code should remainlight enough to run smoothly on a typical workstation.
To illustrate the progress of the atomic database, we compare the number of lines usedin the original SPEX version 2 models (before 2016) and the current version 3 database.In version 2 models, the number of lines is of the order of 5000, while the currentdatabase contains about 2 million lines. Figure 1 shows the di ff erence between thesemodels around the silicon and sulfur lines around 2 keV. The bottleneck of calculatingall these lines is to solve the line strengths (transition rates) per ion. Currently, this isdone by solving a large set of rate equations using CPU accelerated LAPACK routines(Intel Math Kernel Library or OpenBLAS). An attempt to accelerate the calculationeven more using graphical processors (GPU) did not result in faster execution times.Another trick to speed up the calculations is to approximate computationally in-tensive physics relations with a simpler parametrization. It turns out that some of theseapproximations in the SPEX version 2 models are not accurate enough for the highquality data we can expect from future X-ray missions. Therefore, we are in the pro-cess of replacing the old functions with more accurate versions, if applicable also withmore (recent) atomic data. Although model calculations are the most computationally intensive, we can also expectlonger execution times when fitting high-resolution data. In X-ray astrophysics, it iscustomary to convolve the model spectrum with the instrumental response (e ff ectivearea and redistribution matrix) to calculate what the model spectrum looks like when it http://xrism.isas.jaxa.jp/en/ PEX 3
Figure 1. Here we compare a thermal spectrum (with a temperature of kT = is observed by the instrument. This way, the spectral model can be fitted to the observedspectrum.With the increased spectral resolution of the new spectrometers, the redistribu-tion matrices will become much larger. In the current standard OGIP format , theseresponse matrices can grow to about 4 GB, while currently the largest matrices are ofthe order of 100 MB. To reduce this size, and speed up the convolution, new responsefile structures and binning algorithms have been developed (Kaastra & Bleeker 2016)to reduce the size of these matrices. In addition, the matrices can be re-ordered to makeit easier to do the convolution in parallel using OpenMP. These features should help tokeep the execution times for spectral fitting within reasonable limits. Currently, SPEX is an interactive program operated by giving commands on a commandprompt in a terminal window. Although the interface can be quite e ffi cient, once youlearn the commands, there is an increasing demand from users to be able to scriptSPEX. Especially Python has grown very popular as a scripting language and togetherwith Jupyter Notebook this provides very nice features to do a documented interactiveanalysis of spectra. We are currently developing a Python wrapper for SPEX that allowsusers to include SPEX into their Python program without using the command prompt. Ifsuccessful, this may appear as an experimental feature in the release of SPEX 3.06.00.In preparation for the Python interface, we released a package with Python ver-sions of a few auxiliary tools (de Plaa 2019). This package is mainly focused on https://heasarc.gsfc.nasa.gov/docs/heasarc/ofwg/docs/spectra/ogip_92_007/ogip_92_007.html https://github.com/spex-xray/pyspextools de Plaa,Kaastra, Gu,Maoand Raassenmanipulating spectrum and response files in SPEX and OGIP format and contains atemplate to build user defined models for SPEX in Python.
3. Code Distribution
SPEX is written mostly in FORTRAN 90 and runs on UNIX systems like Linux andMacOS. Historically, SPEX has been distributed with statically compiled binaries in-cluded. Since SPEX version 3.05.00 the source code of SPEX is available under theGPLv3 license following the new Open Science policy in the Netherlands. This allowsusers to compile the code on their own machine, which solves issues with binary com-patibility and library dependencies that sometimes occur at the cost of a slightly morecomplicated install procedure. In addition to the binaries and source code, a Dockerimage is available to be able to run SPEX in a controlled environment. Since 2018, allSPEX versions above version 2.0 are available on Zenodo (Kaastra et al. 2018).
4. Discussion and Future Prospects
Although a lot of work has been done to prepare SPEX for the Hitomi mission, there arestill challenges left on multiple aspects of the package. We intent to improve the atomicdata, expand and make the spectral models more accurate, improve the e ffi ciency ofthe spectral fitting, make the interfaces more flexible and user friendly, and expand theavailable documentation with more examples and analysis threads.The high-resolution spectra that will be obtained after the Japanese XRISM mis-sion is launched early 2022 will provide thorough tests for the improvements made tothe SPEX package. This will help preparing SPEX and other spectral codes for the nextgeneration of high-resolution spectrometers provided by ATHENA in the 2030’s. References
Arnaud, K. A. 1996, in Astronomical Data Analysis Software and Systems V, edited by G. H.Jacoby, & J. Barnes, vol. 101 of Astronomical Society of the Pacific Conference Series,17de Plaa, J. 2019, Pyspextools. URL https://doi.org/10.5281/zenodo.3245804 den Herder, J. W., et al. 2001, A&A, 365, L7Kaastra, J. S., & Bleeker, J. A. M. 2016, A&A, 587, A151.
Kaastra, J. S., Mewe, R., & Nieuwenhuijzen, H. 1996, in UV and X-ray Spectroscopy of Astro-physical and Laboratory Plasmas, 411Kaastra, J. S., Raassen, A. J. J., de Plaa, J., & Gu, L. 2018, Spex x-ray spectral fitting package.URL https://doi.org/10.5281/zenodo.2419563
Mewe, R. 1972, Solar Phys., 22, 459Takahashi, T., et al. 2016, in Space Telescopes and Instrumentation 2016: Ultraviolet to GammaRay, vol. 9905 of SPIE Proc., 99050UWeisskopf, M. C., Tananbaum, H. D., Van Speybroeck, L. P., & O’Dell, S. L. 2000, in SPIEProc., edited by J. E. Truemper, & B. Aschenbach, vol. 4012 of Society of Photo-OpticalInstrumentation Engineers (SPIE) Conference Series, 2. astro-ph/00041276