The following article is Open access

Korg: A Modern 1D LTE Spectral Synthesis Package

, , , and

Published 2023 January 24 © 2023. The Author(s). Published by the American Astronomical Society.
, , Citation Adam J. Wheeler et al 2023 AJ 165 68 DOI 10.3847/1538-3881/acaaad

Download Article PDF
DownloadArticle ePub

You need an eReader or compatible software to experience the benefits of the ePub3 file format.

1538-3881/165/2/68

Abstract

We present Korg, a new package for 1D LTE spectral synthesis of FGK stars, which computes theoretical spectra from the near-ultraviolet to the near-infrared, and implements both plane-parallel and spherical radiative transfer. We outline the inputs and internals of Korg, and compare synthetic spectra from Korg, Moog, Turbospectrum, and SME. The disagreements between Korg and the other codes are no larger than those between the other codes, although disagreement between codes is substantial. We examine the case of a C2 band in detail, finding that uncertainties on physical inputs to spectral synthesis account for a significant fraction of the disagreement. Korg is 1–100 times faster than other codes in typical use, compatible with automatic differentiation libraries, and easily extensible, making it ideal for statistical inference and parameter estimation applied to large data sets. Documentation and installation instructions are available at https://ajwheeler.github.io/Korg.jl/stable/.

Export citation and abstract BibTeX RIS

1. Introduction

Improvements in instrumentation have yielded exponential growth in the amount of spectral data to analyze. Creating pipelines that can keep up with analysis is nontrivial. There are several extant codes for 1D LTE spectral synthesis, including Turbospectrum (Plez et al. 1993; Plez 2012; Gerber et al. 2023), Moog (Sneden 1973; Sneden et al. 2012), SYNTHE (Kurucz 1993; Sbordone et al. 2004), SME (Valenti & Piskunov 1996, 2012; Piskunov & Valenti 2017; Wehrhahn et al. 2022), SPECTRUM (Gray & Corbally 1994), and SYNSPEC (Hubeny & Lanz 2011, 2017; Hubeny et al. 2021). While they have enabled a huge volume of research, these codes can be difficult to use for the uninitiated and require input and output through custom file formats, impeding integration into analysis code. Here we present Korg, a new 1D LTE synthesis package, written in Julia and suitable for easy integration with scripts and use in an interactive environment. As the first such new code in more than two decades, Korg benefits from numerical libraries not available at the time earlier packages were authored, principally modern automatic differentiation packages and optimization libraries.

The two fundamental assumptions made by Korg are that the stellar atmosphere is hydrostatic and 1D and in LTE. Eliminating the former two assumptions means calculating atmospheric structure using the full hydrodynamic equations (e.g., Freytag et al. 2012; Magic et al. 2015; Schultz et al. 2022) or the magnetohydrodynamic equations (e.g., Vögler et al. 2005), if the internal magnetic field is strong. Fortunately, corrections to 1D LTE level populations (e.g., Amarsi et al. 2020, 2022), equivalent widths, or abundances (e.g., Lind et al. 2011; Bergemann et al. 2012; Amarsi et al. 2015; Osorio & Barklem 2016) can be calculated from non-LTE (NLTE) simulations. These can be applied to LTE results or codes to produce approximate NLTE spectra at relatively little computational cost. Additionally, biases from the assumption of LTE will roughly cancel for similar stars, yielding differential abundance estimates with high precision.

The performance of spectral synthesis codes is most important when fitting observational data. Because synthesis must be embedded in an inference loop, the analysis of of a single spectrum may trigger tens or hundreds of syntheses. Even when many parameters may be estimated by interpolating over (or otherwise comparing to) a precomputed grid of spectra (e.g., Recio-Blanco et al. 2006; Smiljanic et al. 2014; Holtzman et al. 2018; Boeche et al. 2021; Buder et al. 2021), individual abundances are best done with targeted syntheses of individual lines. Furthermore, generating a grid from which to interpolate can be computationally expensive. Inference and optimization can also be sped up by fast and accurate derivatives of the function being sampled or minimized, most easily produced via automatic differentiation. Korg is designed to be compatible with automatic differentiation packages (e.g., ForwardDiff), which can provide derivative spectra in roughly the same amount of time required for a single synthesis (as discussed in Section 4; see Figure 1).

Figure 1.

Figure 1. Derivatives of a synthesized solar spectrum with respect to various abundances, $\tfrac{\partial { \mathcal F }}{\partial A(X)}$. Vertical offsets have been applied, but the relative scaling is preserved, which is why some derivative spectra appear flat here (but show fluctuations at a subpercent level).

Standard image High-resolution image

2. Description of Code

To synthesize a spectrum, Korg calculates the number density of each species (e.g., H i, C ii, CO) at each layer in the atmosphere (Section 2.2), then computes the absorption coefficient at each wavelength and atmospheric layer due to continuum (Section 2.3) and line absorption (Section 2.4). Given the total absorption coefficient at each wavelength and atmospheric layer, it then solves the radiative transfer equation to produce the flux at the stellar surface (Section 2.5).

2.1. Inputs

Korg takes as inputs, a model atmosphere, a line list, and abundances for each element in A(X) form, 6 assumed to be constant throughout the atmosphere. Korg includes functions for parsing .mod-format MARCS (Gustafsson et al. 2008) model atmospheres, and line lists in the format supplied by VALD (Piskunov et al. 1995; Kupka et al. 1999, 2000; Ryabchikova et al. 2015; Pakhomov et al. 2019) or Kurucz (Kurucz 2011) or those accepted by Moog. When parsing VALD line lists, Korg will automatically apply corrections to unscaled $\mathrm{log}({gf})$ values for transitions with isotope information using the isotopic abundance values supplied by Berglund & Wieser (2011) for line lists that are not already adjusted for isotopic abundances. Korg detects and uses packed Anstee, Barklem, and O'Mara (ABO; Anstee & O'Mara 1991; Barklem et al. 2000a) if they are provided (as VALD optionally does). It uses vacuum wavelengths internally and will automatically convert air-wavelength VALD line lists to vacuum (Birch & Downs 1994). Users may also construct line lists or model atmospheres using custom code and pass them directly into Korg.

2.2. Chemical Equilibrium

Korg uses the assumption of LTE, i.e., that in a sufficiently small region, baryonic matter is described by thermal distributions, and radiation is only slightly out of detailed balance. The source function (the ratio of the per-volume emission and absorption coefficients) is dominated by collisions of baryonic matter and is Planckian. While NLTE calculations are important for producing the most unbiased possible model spectra, they are prohibitively slow and not yet suitable for applications that require computing many spectra over large wavelength ranges.

In order to compute the absorption coefficient, αλ , at each layer of the atmosphere, Korg must solve for the number density of each species. Treating the number density of each neutral atomic species as the free parameters, Korg uses the NLsolve library (Mogensen et al. 2020) to solve the system of Saha and molecular equilibrium equations with the temperature, total number density, and number density of free electrons set by the model atmosphere, and the total abundance of each element set by the user. By default, Korg uses molecular equilibrium constants from Barklem & Collet (2016; the ionization energies are originally from Haynes 2010), but alternatives can be passed by the user. These are defined only up to 10,000 K, so we treat the molecular partition functions as constant above this temperature. This is unlikely to be problematic as few molecules are present above this threshold. The default atomic partition functions are calculated using energy levels from NIST 7 (Kramida & Ralchenko 2021).

In dense environments, upper energy levels are perturbed or dissolved. This can be crudely accounted for by truncating the terms of the partition function (e.g., Hubeny & Mihalas 2014, Section 4.1) or with the "probability occupation formalism" developed in Hummer & Mihalas (1988) and generalized by Hubeny et al. (1994). This effect is most important for hydrogen, where it strongly impacts the partition function starting above 10,000 K. Based on energy level truncation, the partition functions of lithium and vanadium are affected in the same regime at the 5% and 3% level, respectively, but other elements are unchanged at the 1% level. For FGK stars, these effects are most important for higher-order hydrogen transitions. Figure 2 shows the occupation probability correction factor, w, for several energy levels of hydrogen in the solar atmosphere. For n = 1, 2, and 3, the correction is smaller than 10−3 everywhere. At present, we do not include these effects in Korg because they do not make a large difference for FGK stars and because of disagreement with observational data (see Section 3.2).

Figure 2.

Figure 2. The Hummer & Mihalas (1988) occupation probability correction factor, w, for several values of the primary quantum number, n, in hydrogen, evaluated at each layer in the solar atmosphere (indexed by optical depth at 5000 Å). While the formalism affects transitions involving outer energy levels, those which do not, e.g., Hα , are unaffected. The results are similar for the other atmospheres considered in Section 3.

Standard image High-resolution image

By default, Korg solves the equilibrium equations taking into account all elements up to uranium (as neutral, singly ionized, and doubly ionized species), as well as 247 diatomic molecules. As they exist in extremely small quantities in LTE atmospheres, Korg neglects species that are more than doubly ionized. It also neglects ionic and triatomic molecules, which are present in cool stars, although we plan to address this in a future version.

2.3. Continuum Absorption

Korg computes contributions to the continuum absorption coefficient from a number of sources, listed in Table 1. Continuum absorption mechanisms involving an atom and an electron can be classified as bound–free (bf) or free–free (ff), depending on whether the electron is initially bound to the atom. 8 In addition to bound–free and free–free absorption for H, H i, He ii, and ${{\rm{H}}}_{2}^{+}$ (as well as He and He), Korg includes treatments of bound–free and free–free interactions with metals. Free–-free interactions are treated with the hydrogenic approximation using Gaunt factors from van Hoof et al. (2014), with corrections from Peach (1970) for neutral He, C, Si, and Mg. Bound–-free interactions are treated with cross sections from NORAD, 9 when available, and TOPBase 10 (Seaton et al. 1994) otherwise. Following Gustafsson et al. (2008), we shifted the theoretical energy levels to the empirical values from NIST, leaving out levels for which an empirical counterpart was not present. We considered all species with bound–free interaction included in Gustafsson et al. (2008), but included only those that contribute to the total continuum absorption above the 10−3 level anywhere in any of the atmospheres used in Section 3. Figure 3 shows the contribution of various mechanisms to the continuum absorption coefficient at the solar photosphere. At present, Korg treats all scattering as absorption, which is correct in the LTE regime. In the future we plan to support quasi-LTE radiative transfer with isotropic scattering, which will yield more accurate spectra when Rayleigh scattering dominates or is a significant source of opacity.

Figure 3.

Figure 3. Major sources of opacity at the solar photosphere, defined here at the MARCs model atmosphere layers where the optical depth at 5000 Å is most nearly unity.

Standard image High-resolution image

Table 1. Sources of Continuum Absorption in Korg

Absorption SourceWavelength BoundsTemperature BoundsReference
H bf≥1250 Å McLaughlin et al. (2017)
H ff2604–113, 918 Å2520–10,080 KBell & Berrington (1987)
He ff5063–151,878 Å2520–10,080 KJohn (1994)
H i bf  Karzas & Latter (1961) via Gingerich (1969) via Kurucz (1970)
H i ff100–106 Å100–106 Kvan Hoof et al. (2014)
He ii bf  Karzas & Latter (1961) via Gingerich (1969) via Kurucz (1970)
${{\rm{H}}}_{2}^{+}$ bf and ff700–20,000 Å3150–25,200 KStancil (1994)
He ii ff100–106 Å100– 106 Kvan Hoof et al. (2014) with departure coefficients from Peach (1970)
metals ff100– 106 Å100– 106 Kvan Hoof et al. (2014) with departure coefficients from Peach (1970) for C i, Si i, and Mg i
C i bf500–30000 Å100– 105 KNahar & Pradhan (1991)
Na i bf500–30000 Å100– 105 KSeaton et al. (1994)
Mg i bf500–30000 Å100– 105 KSeaton et al. (1994)
Al i bf500–30000 Å100– 105 KSeaton et al. (1994)
Si i bf500–30000 Å100– 105 KNahar & Pradhan (1993)
S i bf500–30000 Å100– 105 KSeaton et al. (1994)
Ca i bf500–30000 Å100– 105 KSeaton et al. (1994)
Fe i bf500–26088 Å100– 105 KBautista (1997)
H Rayleigh≥1300 Å Lee (2005) via Colgan et al. (2016)
He Rayleigh≥1300 Å Dalgarno & Kingston (1960), Dalgarno (1962), Schwerdtfeger (2006) via Colgan et al. (2016)
H2 Rayleigh≥1300 Å Dalgarno & Williams (1962)
electron scattering  Thomson (1912)

Note. When bounds in temperature or wavelength are missing, the absorption coefficient is defined for all positive values.

Download table as:  ASCIITypeset image

Figure 4 shows the ratio of the continuum absorption according to Korg and the one used by MARCS through the solar atmosphere. Agreement is good, except in the violet and ultraviolet, where Korg uses more recent bound–free metal absorption coefficients with more structure in wavelength, which shows up as vertical bands in the figure. Compounding this, the MARCS values also include the effects on line blanketing, which is handled via the line list in Korg. The agreement between the continua calculated by Korg and other codes is good (see Section 3).

Figure 4.

Figure 4. The ratio of the absorption coefficient per Korg and per MARCS in the solar atmosphere (indexed by Rosseland mean opacity, τros). Agreement is good, except in the blue and ultraviolet where Korg uses more recent metal opacities and the effects of line blanketing (handled separately in Korg) in MARCS become large.

Standard image High-resolution image

2.4. Line Absorption

The contribution of each line to the total absorption coefficient, αline, is

Equation (1)

where the wavelength-integrated cross section, σ, is given by

Equation (2)

Here, n is the number density of the line species, Eup and Elo are the upper and lower energy levels of the transition, β = 1/kT is the thermodynamic beta, ϕ is the normalized line profile, U is the species partition function, T is the temperature, f is the oscillator strength, glo is the degeneracy of the lower level, λ0 is the line center, and me is the electron mass.

For all lines of all species besides hydrogen (including autoionizing lines), ϕ is approximated with a Voigt profile using the numerical approximation from Hunger (1956). The width of the Gaussian component is

Equation (3)

where m is the species mass, and ξ is the microturbulent velocity, a fudge factor used to account for convective Doppler shifts. The width of the Lorentz component (in frequency rather than wavelength units) is given by

Equation (4)

where Γrad is the radiative broadening parameter, γstark the per-electron Stark broadening parameter, γvdW the per-neutral-hydrogen van der Waals broadening parameter, and ne and nH I are the number densities of free electrons and neutral hydrogen, respectively. We neglect pressure broadening of molecular lines, setting γstark and γvdW to zero.

When Γrad is not supplied in the line list, Korg approximates it with

Equation (5)

where m is the mass of the atom or molecule, g is the degeneracy of the lower level of the transition, and f is the transition oscillator strength. This can be obtained by assuming that spontaneous deexitation dominates the transition's energy uncertainty, and that the upper level's degeneracy is unity.

The values of γstark and γvdW at 105 K, ${\gamma }_{0}^{\mathrm{stark}}$ and ${\gamma }_{0}^{\mathrm{vdW}}$, are provided by the line list, then scaled by their temperature dependence according to semiclassical impact theory (e.g., Hubeny & Mihalas 2014, chap. 8.3) to the per-particle broadening parameters:

Equation (6)

Equation (7)

If provided, ABO parameters, which describe a more nuanced temperature dependence in broadening by neutral hydrogen, will be used to calculate γvdW instead. When a Stark broadening parameter is not provided in the line list, the approximation from Cowley (1971) is used. When a van der Waals broadening parameter is provided, a form of the the Unsöld approximation (Unsold 1955; Warner 1967) is used in which the angular momentum quantum number is neglected and the mean square radius, $\overline{{r}^{2}}$, is approximated by

Equation (8)

where neff is the effective principal quantum number and Z is the atomic number. Pressure broadening is neglected for autoionizing lines with no provided parameters.

The absorption coefficient for each line (except those of hydrogen) is calculated over a dynamically determined wavelength range. The maximum detuning (wavelength difference from the line center) is calculated by taking the quadrature sum of the detunings at which a pure Gaussian and pure Lorentzian profile reach the value of αcrit. Korg truncates profiles at αcrit = 10−3 αcntm, where αcntm is the local continuum absorption coefficient. This ratio, αcrit/αcntm, can be set by the user.

The broadening of hydrogen lines is treated separately. We use the tabulated Stark broadening profiles from Stehle & Hutcheon (1999), which are pre-convolved with Doppler profiles. For Hα , Hβ , and Hγ , where self-broadening is important, we add to ϕ a Voigt profile using the p-d approximation for self-broadening from Barklem et al. (2000b).

2.5. Radiative Transfer

Given the absorption coefficient, αλ , at each wavelength and atmospheric layer, the final step is to solve the radiative transfer equation. The radiative transfer equation is

Equation (9)

in a plane-parallel atmosphere, and

Equation (10)

in a spherical atmosphere, where Iλ is the intensity of radiation at wavelength λ, Sλ is the source function, αλ is the absorption coefficient, z is the negative depth into the atmosphere, r is the distance to the center of the star, and μ is the cosine of the angle between the r/z axis and the line of sight. When the thickness of the atmosphere is small relative to the stellar radius, curvature can be neglected and a plane-parallel atmosphere is a good approximation; otherwise, sphericity must be taken into account. By default, Korg does its radiative transfer calculations in the same geometry as the model atmosphere.

What Korg actually returns is the disk-averaged intensity, i.e., the astrophysical flux,

Equation (11)

Here, ${I}_{\lambda }^{\mathrm{top}}(\mu )$ stands for Iλ (z = 0, μ) in the plane-parallel case and Iλ (r = R, μ) in the spherical case, where R is the radius of the outermost atmospheric layer. The total flux from the star is then ${F}_{\lambda }={(R/d)}^{2}{{ \mathcal F }}_{\lambda }$, where d is the distance to the star. Since Korg assumes that the stellar atmosphere is in LTE, Sλ is the blackbody spectrum.

In the plane-parallel case,

Equation (12)

where E2 is the second-order exponential integral, τλ is the optical depth (dτλ = αλ dz), and ${\tau }_{\lambda }^{\prime} $ is the depth at the bottom of the atmosphere. The spherical case admits no further analytic simplifications. When using a spherical model atmosphere, to obtain the astrophysical flux, ${{ \mathcal F }}_{\lambda }$, Korg calculates the intensity, ${I}_{\lambda }^{\mathrm{top}}$, at a discrete grid of μ values, by integrating along rays from the lowest atmospheric layer to the top atmospheric layer for many surface μ values. This is valid since the source function is isotropic under LTE. Rays that do not intersect the lowest atmospheric layer are cast from the far side of the star. The integral over μ (Equation (11)) is performed using Gauss–Legendre quadrature.

Korg has two radiative transfer calculation schemes: a lower-order default and the quadratic Bezier scheme from de la Cruz Rodríguez & Piskunov (2013). They agree at the subpercent level in flux, and complications with the Bezier scheme lead us to make the lower-order scheme the default. The Appendix contains numerical details and an extended discussion of the calculation of transfer integrals.

3. Comparison to Other Codes

To test Korg's correctness, we compare its spectra to those produced by Moog, Turbospectrum, and SME for four sets of the parameters (Teff, $\mathrm{log}g$, and metallicity). The first set of parameters is solar, and we have chosen the others to be similar to three well-studied stars: the red giant branch star Arcturus, HD122563 (an extremely metal-poor red giant), and HD49933 (an F-type main-sequence star), but shifted slightly to the nearest existing MARCS model atmosphere to avoid the need to interpolate the atmospheres. For all stars, the same solar abundance pattern was assumed, which is not problematic since we are comparing synthetic spectra to each other and not to observational data. Figures 58 show these comparisons in six vacuum wavelength regions:

  • 1.  
    3660–3670 Å, near the Balmer jump.
  • 2.  
    3935–3948 Å, in the wing of the Ca i Fraunhofer K line.
  • 3.  
    5160–5175 Å, including two lines of the Fraunhofer b Mg triplet.
  • 4.  
    6540–6580 Å, including .
  • 5.  
    15000–15050 Å, in the near-infrared, part of the APOGEE wavelength region.
  • 6.  
    The continuum across 2000–10000 Å, computed without any lines.

For the first four regions, we used an "extract all" line list from VALD, which includes all known lines within the wavelength bounds. The near-infrared spectrum was synthesized using the APOGEE DR16 line list (Smith et al. 2021). The VALD line lists are preadjusted for isotopic abundances, which eliminates a possible source of disagreement. For the APOGEE line list, Turbospectrum's runtime isotopic adjustment may not be consistent with Korg's or with the preadjustment performed for SME or Moog, but agreement is generally good nevertheless. As Moog has a limit of 2500 lines that can contribute at a given wavelength, we culled the weakest TiO lines from each list, reducing the total number of transitions passed to Moog to be at most 10,000. This is expected to have negligible impact on the spectrum. Since Korg (see Section 2.3) and Moog (excepting the fork presented in Sobeck et al. 2011) do not support true scattering, we set the PURE-LTE flag to true in babsma.par, setting Turbospectrum to turn off this functionality. Scattering cannot be turned off in SME, which presumably explains some of the disagreement between it and other codes.

Figure 5.

Figure 5. Portions of a synthetic solar spectrum generated with Korg, Moog, Turbospectrum, and SME, as well as the continuum generated with an empty line list from 4000 to 10000 Å. All wavelengths are vacuum. We emphasize that the structure in the blue and ultraviolet in the Korg continuum is due to resonances in the metal bound–free cross sections, not lines. The residuals (other–Korg) are shown underneath the rectified flux for each wavelength region. The level of agreement between Korg and the other codes is similar to their agreement with each other. See the text for a discussion of the discrepancies.

Standard image High-resolution image

Disagreement between the codes is substantial, with fluxes disagreeing at the 10% level in many cases, as established by Blanco-Cuaresma (2019). Agreement is strongest in the infrared, where continuum opacities are simpler. We discuss some of the discrepancies in more detail here.

3.1. Continuum Absorption in the Violet and Ultraviolet

Near the Balmer jump and blueward, agreement between the synthetic continua is generally poor. This is the primary cause for the disagreement between the codes in the first two wavelength regions, which are at the shortest wavelengths. The disagreement at the Balmer jump between Turbospectrum and the other codes arises from the fact that it dissolves the outer hydrogen orbitals according to the Hummer & Mihalas (1988) formalism when calculating the H i bf absorption coefficient. The defined structure seen in the Korg continuum is due to resonances in the bf cross sections, not lines. Unfortunately, it is the case that reliable spectral synthesis in the blue and ultraviolet remains out of reach, as metal opacities are theoretically very challenging to predict at the energy resolution required (not to mention the difficult-to-model effects of line blanketing).

Figure 6.

Figure 6. Same as Figure 5, but showing the synthetic spectrum of an Arcturus-like star.

Standard image High-resolution image
Figure 7.

Figure 7. Same as Figure 5, but showing the synthetic spectrum of an HD122563-like star.

Standard image High-resolution image
Figure 8.

Figure 8. Same as Figure 5, but showing the synthetic spectrum of an HD499330-like star.

Standard image High-resolution image

3.2. Balmer Series

There are eight Balmer series lines in the 3660–3670 Å (vacuum) wavelength region (upper levels n = 26 to n = 33), five of which are included in Korg (those up to n = 30). Typically, these have a minimal impact on the observed spectrum, but in the metal-poor giant, Korg predicts that these lines are visible as broad shallow features, in contrast to Turbospectrum (hydrogen lines are omitted from the Moog line list in this region). They are located at 3668.76, 3667.17, 3665.75, 3664.48, and 3663.33 Å (vacuum), and are more clearly visible in the residuals panel. This is because Turbospectrum uses the occupation probability formalism discussed in Section 2.2, which eliminates the relevant hydrogen orbitals throughout most of the stellar atmospheres. In a high-resolution ultraviolet spectrum of HD122563 from the Ultraviolet and Visual Echelle Spectrograph 11 (Dekker et al. 2000), a star with similar parameters, the lines are present. For this reason, we are not confident that the occupation probability formalism offers a significant advantage over unmodified partition functions, and we do not use it in Korg. The top left panel in Figure 9 shows part of this wavelength region in more detail, along with the observational data. SME predicts the strongest absorption by these lines in the metal-poor giant, but it also predicts strong absorption for the other stars, where it is not present in observations. The bottom left panel of Figure 9 demonstrates this for the Sun, using the Wallace et al. (2011) solar atlas.

Figure 9.

Figure 9. Top left: part of the region with high-order Balmer lines for the metal-poor giant, along with the observed spectrum of HD122563. Bottom left: the same at the top left panel, but for solar parameters, alongside the observed solar spectrum. Right: Hα in the metal-poor giant, along with the observed spectrum of HD122563. None of the codes correctly model the hydrogen lines in the metal-poor regime. Though SME is the closest to the observed high-order Balmer lines in the metal-poor regime, it predicts strong high-order Balmer lines in stars where they are not present. All synthetic spectra have been convolved to the observational resolution.

Standard image High-resolution image

There is relatively good agreement between Korg, Turbospectrum, and SME in the Hα wings (Moog lacks special treatment of hydrogen lines and generally disagrees). Turbospectrum and SME both use forms of HLINOP (Barklem & Piskunov 2003), so strong agreement is to be expected (though they presumably have differing treatments of the equation of state). Korg uses roughly the same treatment as HLINOP, with Stark broadening from Stehle & Hutcheon (1999) and self-broadening via the Voigt approximation from Barklem & Piskunov (2003), but Figure 9 indicates that there are differences in implementation. For the metal-poor giant hot dwarf (Figures 7 and 8), Turbospectrum and SME agree with each other almost exactly and disagree with Korg at the ∼1% level in the Hα wings. In contrast, Korg and Turbospectrum agree more closely with each other than they do with SME for the Sun. In the Hα core, disagreement is similarly minor, except for in the metal-poor giant. The right panel in Figure 9 shows this in detail, alongside the observed spectrum of HD122563, a star with similar parameters, from GALAH (Buder et al. 2021). Given that accurate modeling of the Hα core requires techniques beyond 1D LTE (e.g., Barklem 2007; Amarsi et al. 2018), and that the observational data does not match the prediction of any of the codes, we consider this disagreement permissible.

3.3. C2 Band

While tracking down the causes of disagreement between codes for all wavelengths and stars is not feasible, it is instructive to focus on one as a "case study." In the Sun, Korg predicts deeper lines from roughly 5160–5165 Å than the other codes. These are due to absorption by C2, and the disagreement arises from the varying molecular equilibrium constants,

Equation (13)

adopted for the species by the codes. Most of the difference in ${K}_{{{\rm{C}}}_{2}}$ values comes from different values for the dissociation energy, D0, of C2. Molecular dissociation energies are one of the most dominant sources of systematic uncertainty in spectral synthesis (see the discussion in Barklem & Collet 2016). To summarize the treatments of ${K}_{{{\rm{C}}}_{2}}$ in each code:

  • 1.  
    Korg uses the data from Barklem & Collet (2016): D0 = 6.371 eV.
  • 2.  
    Based on logging information, Turbospectrum appears to use the polynomial expansions from Tsuji (1973): estimated D0 = 6.07 eV.
  • 3.  
    The Moog molecular equilibrium constants comes from Kurucz. 12 We were able to extract the polynomial approximation for the C2 molecular equilibrium constant from the source code: D0 = 6.21 eV.
  • 4.  
    For C2, the SME equilibrium constant comes from Sauval & Tatum (1984): D0 = 6.297 eV.

Figure 10 shows the effects of these choices about ${K}_{{{\rm{C}}}_{2}}$. They account for nearly all of the disagreement in the synthesized spectra. While the numerical scheme used to represent the temperature dependence of ${K}_{{{\rm{C}}}_{2}}$ plays some role, the value of D0 adopted is far more important. The differing D0 values result in number densities of C2 differing by up to a factor of 2 at the photosphere and by orders of magnitude at the top of the atmosphere.

Figure 10.

Figure 10. Left: some lines from a C2 band in the Sun synthesized by the four codes and synthesized by Korg using the prescriptions for the chemical equilibrium constant, ${K}_{{{\rm{C}}}_{2}}$, from the other codes. Differences in these prescriptions, primarily arising from differences in the dissociation energy, D0, drive most of the disagreement. Right: the ratio of ${K}_{{{\rm{C}}}_{2}}$ values per Barklem & Collet (2016; Korg's adopted values) and per the treatment used by another code. The dashed lines show the values obtained using the Barklem & Collet (2016) data adjusted for the D0 used by another code. Uncertainty in D0 drives most of the disagreement in the amount of C2 present at the photosphere and most of the disagreement in the synthesized spectra at these wavelengths.

Standard image High-resolution image

4. Benchmarks

The top panel in Figure 11 shows the time taken by each code to produce the spectra in the first four wavelength regions in Section 3. These are relatively small regions with line lists including all transitions in VALD, including many which have essentially no effect on the spectrum. The bottom panel shows the time to compute a spectrum from 15000 to 15500 Å using the APOGEE DR16 line list. This provides a more realistic example of synthesizing a spectrum as part of the analysis for a large survey. All tests are single core and run on the same machine with an AMD Epyc 7702P.

Figure 11.

Figure 11. The time taken by each code for the syntheses in Section 3. Top: average compute time for the optical wavelength regions, which used very dense line lists. Bottom: compute time to synthesize spectra from 15000 to 15500 Å with the APOGEE DR16 line list, a more "realistic" use case. Note that the wavelength regions synthesized were larger than those plotted in Figures 58. SME includes a true scattering treatment that cannot be turned off, increasing its execution times.

Standard image High-resolution image

Korg only needs to load the line list and model atmosphere into memory once, so repeat syntheses that use the same inputs (as would be the case when varying individual abundances) avoid that step. For these comparisons, loading the line list (105–106 transitions) takes 1–4 s, and loading the model atmosphere takes roughly 0.05 ms. As nearly all cases requiring performance involve repeated synthesizing with the same (or nearly the same) line list, we did not optimize input parsing for speed and do not include this time in Korg benchmarks. We note that for the "small wavelength regions," the Moog times are technically lower limits, since the line lists provided to Moog were reduced in size by 1 order of magnitude or more (though the synthesized spectra are essentially unchanged). Figure 11 has separate markers for Turbospectrum with and without hydrogen lines, as we found them to slow down synthesis by a very large factor. In wavelength ranges where hydrogen lines are not present or unimportant, they can be omitted, and Turbospectrum executes much more quickly. The comparison to SME is included for completeness, but is not entirely fair since SME includes the effects of scattering, which is numerically expensive. Scattering is turned off for Turbospectrum to make the comparison as fair as possible.

In the top panel of Figure 12 we plot the time required by Korg to compute the gradient of the solar spectrum, $\tfrac{\partial { \mathcal F }}{\partial A(X)}$, with regard to a varying numbers of element abundances, N. (See Figure 1 for a subset of the derivative spectra.) For this demonstration we used the 15000–15500 Å range and the APOGEE DR16 line list. A dashed horizontal line marks the time required to synthesize the spectrum, just under 1 s. Calculating the N-dimensional gradient spectrum takes roughly 2 + 0.15N s, meaning that the marginal time required for each derivative is 1 order of magnitude smaller than the time required to obtain it via finite differences. As Julia's automatic differentiation ecosystem improves, Korg may benefit from further speedups to the calculation of gradient spectra. Calculating derivative spectra with respect to atmospheric parameters, e.g., Teff, $\mathrm{log}g$, or vmic, requires code to interpolate between model atmospheres, which we plan to add to Korg.

Figure 12.

Figure 12. Time required to compute simultaneous derivative of spectrum with regard to N different element abundances, for varying N.

Standard image High-resolution image

5. Conclusions and Future Development

We have presented a new code, Korg, for 1D LTE spectral synthesis, i.e., computing stellar spectra given a model atmosphere, line list, and element abundances. We note the plots in the paper were generated with Korg version 0.10.0. Korg is both fast faster than all other codes, and autodifferentiable, which yields further speedups when synthesis is embedded in an optimization loop. The code is publicly available at https://github.com/ajwheeler/Korg.jl and installable via the Julia package manager. Detailed documentation, usage examples, and installation instructions are available at https://ajwheeler.github.io/Korg.jl/stable.

In comparing Korg to other codes, we have highlighted that the level of disagreement between them (and thus systematic error) is substantial. Much of this can be attributed to uncertain physical parameters (e.g., the C2 dissociation energy, discussed in Section 3.3) and models of continuum absorption processes, but varying numerical methods also play a role (e.g., the discussion in the Appendix). Unfortunately, similar problems extend to model atmospheres, which require the same physics used for synthesis, and line lists, which include many poorly constrained atomic parameters.

We have shown in this work that Korg produces results for FGK stars that are similar to other codes. We recommend its use for these spectral classes. We plan to soon address the factors limiting Korg's applicability outside this regime, most importantly its lack of polyatomic molecules (present in cool stars) and true scattering (important in hot stars). We also plan to add support for NLTE departure coefficients. There are also limitations affecting ease of use that we plan to address. As mentioned in Section 4, calculating derivative spectra with regard to atmospheric parameters like $\mathrm{log}g$ or Teff requires code to interpolate model atmospheres that is written in Julia. Relatedly, while inferring stellar abundances and parameters with Korg is not overly burdensome, the user must still apply the line spread function to synthesized spectra and calculated goodness of fit themselves, processes we would like to automate.

There are some limitations that apply to all spectroscopic synthesis codes. In the blue and ultraviolet, the poorly constrained continuum results in very uncertain predictions, manifesting in the poor agreement found between codes. Many of the chemical equilibrium constants necessary for spectroscopic synthesis are also poorly constrained, as discussed Barklem & Collet (2016). There are doubtless many features (like the one discussed in Section 3.3) where chemical equilibrium constants are the primary driver of uncertainty. Uncertain atomic parameters in line lists pose a similar problem in all regimes.

Our goal is that Korg will be useful for both inference of stellar parameters and abundances for large survey data, e.g., Gaia (Gaia Collaboration et al. 2016), SDSS-V (Kollmeier et al. 2017), MOONS (Kollmeier et al. 2017), WEAVE Dalton et al. 2012, 4-MOST (de Jong et al. 2019), LAMOST (Deng et al. 2012; Zhao et al. 2012), GALAH (De Silva et al. 2015), and for boutique analyses of individual spectra. We aim to make Korg fast and flexible enough to enable better survey pipelines and novel analyses, such as the propagation of error from synthesis inputs to synthesized spectra, or the joint inference of line parameters with observational data. In addition, we hope that by making Korg as easy to use as possible, more researchers will find it worthwhile to synthesize spectra when the need arises.

A.J.W. would like to thank Chris Sneden for his advice; Samuel Potter, Paul Barklem, Karin Lind, Bengt Edvardsson, and Thomas Nordlander for answers to naive questions; and Rob Rutten, David F. Gray, Ivan Hubeny, Robert Kurucz, and Dimitri Mihalas for writing excellent reference material. He would also like to thank Sergey Koposov for bug-finding, Charlie Conroy for his interest and encouragement, and David Hogg for putting him in touch with Mike O'Neil and Samuel Potter. The authors would like to thank the anonymous reviewer for thoughtful comments and expertize.

A.J.W. is supported by the National Science Foundation Graduate Research Fellowship under grant No. 1644869. M.K.N. is in part supported by a Sloan Research Fellowship. A.R.C. is supported in part by the Australian Research Council through a Discovery Early Career Researcher Award (DE190100656) and through a Monash University Network of Excellence grant (NOE170024). Parts of this research were supported by the Australian Research Council Centre of Excellence for All Sky Astrophysics in 3 Dimensions (ASTRO 3D), through project number CE170100013.

This research has made use of the services of the ESO Science Archive Facility. Based on observations collected at the European Southern Observatory under ESO program 266.D-5655. This work has made use of the VALD database, operated at Uppsala University, the Institute of Astronomy RAS in Moscow, and the University of Vienna. The authors acknowledge support and resources from the Center for High-Performance Computing at the University of Utah.

Appendix: Numerical Details of Radiative Transfer

A.1.  Korg's Default Implementation

To solve the equation of radiative transfer along a ray, Korg approximates the source function, S (λ subscripts dropped for brevity), with linear interpolation over optical depth, τ. Between each adjacent pair of atmospheric layers, we have S(τ) ≈ m τ + b, so the (indefinite) transfer integral has the solution

Equation (A1)

When evaluating Equation (12), Korg uses the same approximation,

Equation (A2)

Calculating the optical depth, τ, requires numerically integrating

Equation (A3)

where α5 is the absorption coefficient at the reference wavelength, 5000 Å, calculated by Korg, and $\alpha {{\prime} }_{5}$ is the absorption coefficient at the reference wavelength supplied by the model atmosphere. Their ratio is the correction factor to αλ that enforces greater consistency between the model atmosphere and spectral synthesis. Korg computes τλ by evaluating the equivalent integral

Equation (A4)

where $\tau {{\prime} }_{5}$ is the optical depth at the reference wavelength per the model atmosphere. This integral is numerically preferable, since atmospheric layers are spaced uniformly in $\mathrm{ln}\tau {{\prime} }_{5}$, and the integrand of (A4) is more nearly linear than that of (A3).

A.2. Comparison to Quadratic Bézier Scheme

Korg has a secondary radiative transfer scheme based on de la Cruz Rodríguez & Piskunov (2013), which approximates the source function with monotonic quadratic Bézier interpolation. They suggest that τλ might be computed using the same scheme, but this causes numerical problems when the absorption coefficient is nonmonotonic in depth. We modified the interpolant by requiring the Bézier control point (Equation (10) in de la Cruz Rodríguez & Piskunov 2013) to be within a reasonable range, which eliminates the issue, but is physically unmotivated. This is the implementation available in Korg. As an alternative, we tried computing τλ by interpolating αλ with a cubic spline. Unfortunately, the relatively sparse sampling of model atmospheres means that this choice has an impact on the synthesized spectrum similar to the difference between the default method and the de la Cruz Rodríguez & Piskunov (2013) method. Figure A1 shows the difference in a portion of the solar spectrum resulting from using Bézier interpolation of the source function compared to the default implementation. The difference in synthesized spectra is at the subpercent level, significantly smaller than the level of disagreement between codes. While we plan to adopt a higher-order scheme as the default in the future, we provide this scheme as a secondary option until we better understand the impact of the choices involved.

Figure A1.

Figure A1. The difference in the rectified spectrum obtained for the Sun using the quadratic Bézier scheme and Korg's default scheme. The purple and brown lines show the result obtained using modified Bézier interpolation and cubic spline interpolation of αλ , respectively. (This is separate from the interpolation of the source function, which uses Bézier curves in both cases.) The difference between all three methods is small compared to the difference in spectra obtained from different codes, but nevertheless larger than is ideal.

Standard image High-resolution image

Footnotes

Please wait… references are loading.
10.3847/1538-3881/acaaad