RAPOC : the Rosseland and Planck opacity converter A user-friendly and fast opacity program for Python

RAPOC (Rosseland and Planck Opacity Converter) is a Python 3 code that calculates Rosseland and Planck mean opacities (RPMs) from wavelength-dependent opacities for a given temperature, pressure, and wavelength range. In addition to being user-friendly and rapid, RAPOC can interpolate between discrete data points, making it ﬂexible and widely applicable to the astrophysical and Earth-sciences ﬁelds, as well as in engineering. For the input data, RAPOC can use ExoMol and DACE data, or any user-deﬁned data, provided that it is in a readable format. In this paper, we present the RAPOC code and compare its calculated Rosseland and Planck mean opacities with other values found in the literature. The RAPOC code is open-source and available on Pypi and GitHub.


Introduction
Our understanding of extra-solar planetary systems has grown significantly since the first exoplanet was discovered in 1995 [1].One major aspect of this field, is the analysis, exploration, and modelling of planetary atmospheres; all of which require a careful treatment of opacities.For example, atmospheric spectroscopy makes use of wavelength-dependent opacities to determine the chemical constituents present in the observable part of the atmosphere of exoplanets.Projects such as ExoMol1 [2], HITRAN2 [3], HITEMP3 [4], which are dedicated to generating line-lists for spectroscopy, have facilitated our aim of understanding the atmospheric properties of other worlds [5,6,7,8,9,10,11,12,13].In contrast, when theoretically modelling an exoplanetary atmosphere, opacities are often used to estimate the global temperature profile and the location of the radiative-convective boundary.This approach can work with wavelength-dependent or wavelength-averaged opacities, in which the former is generally accepted to be a more rigorous and accurate representation of real systems than the latter.Although the aforementioned projects primarily focus on line-lists, they can be converted into opacity tables [14] that can be more straightforward to operate with; ExoMol [15] and DACE 4 (Data and Analysis Center for Exoplanets) [16] provide such conversions.Whereas wavelength-dependent opacities can be used in theoretical models, they require computationally-intensive simulations [9,17,18,19]; it is, therefore, common to rely on Rosseland and Planck mean opacities (shortened to RM for the former, PM for the latter, and RPM when referring to both) that only depend on the temperature and pressure of the system.The use of RPMs has several benefits that include (1) their wavelength independence makes them simpler and faster to use, (2) they can be implemented in Grey and semi-Grey models to provide a reasonable estimation of the temperature structure of astrophysical and planetary environments, and (3) such modelling can provide exact solutions.
Whereas we do not explore Grey and semi-Grey approaches in this paper, it is pertinent to discuss them because they are widely used in various academic fields, and they make use of RPMs.Grey and semi-Grey models are approximate analytical solutions to the radiative transfer analyses of gaseous environments, which are defined as using either one (the infrared) or two (the infrared and visible) wavelength-averaged opacities, respectively.In atmospheric sciences, such approaches were popularised by Sir Arthur Eddington [20] and then expanded upon by various others [21,22,23,24,25,26,27,28,29,30,31,32,33].A rigorous comparison of the Grey and semi-Grey models available in the literature has previously been done [34], so it will not be explored in this study.With the recent launch of the JWST [35] on December 24th 2021, and several upcoming astronomical missions like Ariel [36,37] and Twinkle [38], there is a strong motivation for further exploring extra-solar planetary atmospheres.We also recognise that grey and semi-grey approaches may also be used in planetary formation models [39,40,41] and engineering [42,43,44].
Despite the advantages of Grey and semi-Grey approaches, RPM data are not commonly produced.This has motivated some researchers to assume constant values [32], or adopt simple analytic approximations [45].In light of this problem, we present RAPOC, a Python program that converts the readily available wavelength-dependent opacities into RPMs.
Caveat -the RAPOC code is not a replacement for more rigorous radiative transfer approaches [17,18,19,9].Instead, it is built to provide pressure and temperature-dependent RPMs in a spectral range of choice so that Grey and semi-Grey models can include more complex opacity behaviour.This may increase the efficacy of such approaches, assuming that the pressure-temperature models used are appropriate approximations of reality.Whenever and wherever possible, the authors recommend using more rigorous approaches instead of Grey and semi-Grey approximations.
2 What is RAPOC?RAPOC (Rosseland and Planck Opacity converter) is a fast and user-friendly program that is fully written in Python 3 and converts wavelength-dependent opacities into RPMs as a function of the temperature and pressure for the wavelength range of choice.RPMs are usually given as a function of density and temperature (not pressure) [46,47], because opacities are defined as where k ν is the volume opacity (not further referenced in this study), κ ν is the mass opacity, α ν is the extinction coefficient, ρ is the density, and n is the number density.ExoMol and DACE provide opacities as a function of temperature, pressure and wavelength, but not density;this is because their opacities are computed from line lists that are pressure-broadened.More information on the input data can be found in sect.2.3.RAPOC is publicly available on Pypi5 , so it can be installed using the pip command $ p i p i n s t a l l r a p o c or it can be compiled directly from the source, and downloaded from the GitHub repository6 with $ cd Rapoc $ p i p i n s t a l l .
All data generated in this paper used RAPOC version 1.0.5.This version, and all future versions, are available on the GitHub repository.For the complete and extensive RAPOC guide, please refer to the software documentation7 .

Rosseland mean opacity
The Rosseland mean opacity (RM) is defined as [48] where κ ν is the opacity provided by the input data at a given frequency ν, and u(ν, T ) is the Planck black body derivative with respect to the temperature T .Because opacity data is generally not available across the entire electromagnetic spectrum, a shorter range is selected (i.e., multigroup opacities).With RAPOC, the user selects the frequency range of interest (ν 1 , ν 2 ) to compute the mean opacity.Eq. 1 can therefore be rewritten as Due to the definition of RM, if the wavelength-dependent opacity, κ v , were zero at a given wavelength, Eq. 1 would be numerically undefined.This causes an error, so we included a fail-safe correction where the zero is replaced by an arbitrarily small value.This ad-hoc correction keeps the code functional.

Planck mean opacity
The Planck mean opacity (PM) is defined as [48] where B ν (T ) is the Planck black body law computed at temperature T .For the same reasons given previously, Eq. 3 is rewritten as

Inputs
The first step in the code is to load the opacity data to initialise the Model class.This data can be provided as a file or in a custom-made Python dictionary format.The data must contain an opacity table with a corresponding list of pressures, temperatures and wavenumbers (or wavelengths or frequencies) so that the opacities can be sampled.

Input data file
As of the writing of this paper, the RAPOC code only accepts ExoMol crosssections in the TauREx format [49] format, and DACE opacities [16] as input data 8 .
ExoMol cross-section (TauRex format).Raw opacity data is available for a large sample of molecules on the ExoMol website9 [50,51,52,53,15].ExoMol data is structured as a grid of pressures, temperatures, wavenumbers, and cross-sections.By using the units module of the Astropy package [54], RAPOC attaches units to the data so that conversions are straightforward.By default, pressure is expressed in P a and temperature in K; the wavenumber grid (expressed in 1/cm) is converted into wavelengths (µm), and frequencies (Hz).
All previously mentioned information is stored in the Model class.Finally, the cross-sections contained in the ExoMol file are loaded.These are given in units of cm 2 /molecule, so to convert them into opacities, the mass of the molecule is retrieved using the molmass Python package10 and then divide through by the absorption table.After taking into consideration the necessary unit conversions, the opacities expressed in m 2 /kg are obtained.The steps mentioned above lead to a three-dimensional Numpy array [55] table of opacities with indexes corresponding to the pressure, temperature, and wavenumber grids, respectively.These are stored in the Model class under the attribute opacities.
DACE opacities.The DACE database collects line-lists produced by projects like ExoMol, HITRAN, and HITEMP, and converts them into opacities using the HELIOS-K opacity calculator [56].The opacity data can be downloaded from the DACE database in a directory for each molecule containing the binary files.Each of these files contains the opacity as a function of the wavenumber, pressure, and temperature.The downloaded opacities come in units of cm 2 /g.RAPOC accepts the directory address as input and parses the contained files to build a three-dimensional Numpy array of opacities ordered for pressure, temperature, and wavenumber.All units are then converted into SI units and, subsequently, all of the aforementioned information is stored in the Model class.

Input Python dictionary
As previously mentioned, instead of an input file, the user may use a Python dictionary as the required input.The dictionary content must be of the same type as the one described for the input file due to RAPOC handling the contained data in the same way.Therefore, the dictionary must contain the following five entries: (1) mol -a string for the molecule name, (2) pressure -an array for the pressure grid data, (3) temperature -an array for the temperature grid data, (4) wavenumber -an array for the wavenumber grid data, and (5) opacities -a three-dimensional array of the opacities (in units of area over mass) ordered by pressures, temperatures and wavenumbers.Optionally, the dictionary can contain the molecular mass, under (6) 1 for a schematic representation of the dictionary structure or, alternatively, to the RAPOC documentation for a full description.

Rayleigh scattering
RAPOC includes a module for producing Rayleigh scattering RPMs for the atomic species given in table 3 that is found in Appendix A. The Rayleigh scattering wavelength-dependent opacity is given by [57,58], where µ is the atomic mass expressed in SI units and α is the static average electric dipole polarisability of the gaseous species being considered, which is given in Table 3.The resulting k Ray (λ) values are expressed in m 2 /kg and processed in the RPM modules to compute their respective mean opacities.Although the Rayleigh scattering opacity is independent of temperature, RPMs are not due to the black-body equation (or its derivative), as shown in Eq. 1 and 3. Conversely, pressure is not required, so whether or not a pressure is inserted, RAPOC will ignore it.

Estimation algorithms
The RAPOC code offers two estimation methods.For the first method, given the requested pressure P and temperature T input by the user, RAPOC finds the closest pressure and temperature in the data grid, extracts the opacity data, and computes the desired mean opacity in the frequency range (or wavelength or wavenumber) of choice (i.e.ν 1 , ν 2 ).Eq. 2 and Eq. 4 are used to calculate the RMs or PMs respectively.
The second method consists of an interpolation of the estimated RPM values.For this method, RAPOC first produces a map by computing the model mean opacity (RM or PM with Eq. 1 or Eq. 3, respectively) at the indicated frequency band (ν 1 , ν 2 ) for every pressure and temperature available in the data.To make the code faster, once the map is built, the code will not reproduce it, unless the user changes the investigated frequency bands in a successive iteration.This map can be used to interpolate the model opacity values for given pressures and temperatures as long as they are within the bounds of the data grids.The aim of this code is to compute RPMs from given input data in a reliable and efficient manner.Therefore, extrapolation methods are not implemented into RAPOC.Hence, inserting an input pressure or temperature outside the data range will result in an error.Nevertheless, the interpolation is handled by the Scipy griddata module [59] using the linear mode described in the documentation.As input data usually contains a wide range of pressures, RAPOC also contains a loglinear mode, which is the same as linear but the pressure is in a logarithmic form when the interpolation is made.We stress that the Scipy griddata algorithms should be used carefully as the quality of the interpolation is dependent on the local environment as well as the mode requested, so unphysical estimations may occur.Both estimation algorithms allow the user to compute the RPMs for either a single input pressure and temperature, or for a grid, by giving a list of pressures and temperatures as inputs.

Outputs
An example of the possible outputs is shown in Table 2.In the table, estimates are provided for ExoMol 's water [52] and carbon dioxide [60] data using the linear method.In Fig. 1, we show the RPM values estimated by RAPOC compared to the input opacity as a function of wavelength, temperature and pressure.Using RAPOC, one can generate a map of RMs and PMs for each combination of pressure and temperature available in the input data; examples of these maps are shown in Fig. 2 and 3.The two figures demonstrate that opacities usually do not have a monotonic behaviour in their respective pressure and temperature grids.By comparing Fig. 2 with Fig. 3 one sees that the estimated opacities are strongly dependent on the wavelength range considered.

Other Opacity Rosseland & Planck Opacity Sources
There are various resources for RPMs in the literature, but most focus on primordial gas mixtures with different metallicities [61,62,48 [67,45].Alternatively, RAPOC uses precomputed opacities for single molecules to estimate their wavelength-averaged values, which allows for faster and easier computations, and a straightforward integration into other codes.RAPOC, therefore, relies on precomputed data, such as the one provided by ExoMol and DACE, instead of line lists.Furthermore, if the opacities of a gas mixture are required, the user must manually account for the contributions of the individual species calculate by RAPOC.In the following, we compare the estimates obtained by RAPOC with others found in the literature.We compare our RPM opacity estimations for water vapor with those of Hottel [68], Abu-Romia & Tien [69], and Kurosaki et al. [45].Hottel estimated the IR Planck mean opacities from emissivity data, whereas Abu-Romia & Tien found IR RPMs from spectral data using selected bands in the 2.7−20 µm range, which contribute appreciably to the emitted energy.Kurosaki et al., however, produces a monotonic power-law fit (their Eqs.A.5-8) for estimating water RPMs in the visible and thermal wavelengths using HITRAN data.The power-law approximation presented in Kurosaki et al. has been tuned for two wavelength ranges: visible (0.4 − 0.7 µm) and thermal (0.7 − 100 µm).For a comparison with RAPOC, we estimate RPMs with 0.4 − 0.7 µm and 0.7 − 50 µm wavelength ranges for visible and thermal range respectively.Our comparison is found in Fig. 4. Because Abu-Romia & Tien and Hottel only provide results the IR range, we only show Kurosaki et al. for the visible range.We are aware that for simple molecules such as H 2 that are weakly absorbing in the infrared and visible wavelengths, the collisional absorption may be crudely  approximately by a power law as a function of pressure and temperature.However, as soon as a hydrogen gas is slightly enriched by other molecules, the power-law approximation begins to fail [65,66].In addition, for molecules like H 2 O and CO 2 , there are other sources of opacity such as electronic transitions, molecular rotations, and vibrations, meaning that the opacity is not at all monotonic.Because of this, and the different wavelength ranges considered, the model by Kurosaki et al.As previously mentioned, Abu-Romia & Tien and Hottel results are only applicable to the IR range.The data reported in Abu-Romia & Tien [69] are displayed in figures with temperature on the x-axis (in units of Rankine) and opacity (as inverse feet) in the y-axis.We convert their estimates by dividing their opacities by the local gas density, which is estimated using the ideal gas equation where M is the molar mass of the gas (M H2O = 18.01528 g/mol for water), P is the pressure, R is the ideal gas constant, and T is the temperature.Fig. Regarding CO 2 , we compare the Planck opacities calculated by RAPOC with those given in Abu-Romia & Tien [69] and Hottel [68]; the Rosseland opacities are compared to those of Badescu [67].The comparison for the PM is shown in Fig. 5, where the Planck opacities are given for three different temperatures.The opacities from Abu-Romia & Tien [69] were extracted from their graphs, as described previously, but by using the molar mass of carbon dioxide M CO2 = 44.01g/mol.As shown in For the Rosseland mean opacities, Table 6 of Badescu [67] is considered.In their calculation, a wavelength range of 0.5 µm to 100 µm was used, which is beyond the limit provided by ExoMol data [60].Hence, a wavelength range of 0.5 µm to 50 µm will be adopted when making the comparison.The results are shown in the first row of Fig. 6.The figure shows that Badescu's estimates are closer to the median value of the wavelength dependent opacities from ExoMol than what RAPOC calculates.The bottom row of the same figure reports the same estimates performed on the 5 − 10 µm wavelength range.A major advantage of the RAPOC code is that the wavelength range can be specified, whereas using Badescu's values are given for a set wavelength range.
For the water and carbon dioxide cases, there are significant differences between the RPMs given by RAPOC and those available in the literature; the only exception being the Planck mean opacities that are consistent with those of Abu-Romia & Tien [69] and Hottel [68].These differences are the result Fig. 4: Comparison between Kurosaki et al. [45], Abu-Romia & Tien [69], Hottel [68] and RAPOC.The shaded lines in both plots represent the raw data loaded from ExoMol 's water opacities [52] of different wavelength ranges investigated, or the adoption of simple analytic approximations, such as the power-law fit introduced in Kurosaki et al. [45].The major advantage of RAPOC is that it provides a flexible and systematic avenue for calculating RPMs with widely available input data.As shown in the above, this flexibility is coupled with RAPOC's ability to better represent the weighted mean opacity of a gaseous species at a given spectral window, or across a large range than the other approaches in the literature.Despite these advantages, RAPOCis dependent on the input data (excluding the Rayleigh scattering opacities), and it cannot extrapolate outside the given wavelength, temperature, and pressure bounds.

Limitations with Rosseland and Planck Mean Opacities
Whereas RPMs have their uses, they are also limited.For instance, in opticallythin environments, RPMs may overestimate the opacities present as photons could traverse through 'spectral windows', which might be very different from a few strong opacity regions.Furthermore, RM and PM have different functional forms corresponding to the different averages they are providing.The RM opacity uses the derivative of the Planck distribution as the weighting function, which it then uses to find the harmonic mean of the opacity.Consequently, RMs are extremely sensitive to the opacity minima and can provide erroneous values if a molecule is fully transparent at a given wavelength.Conversely, PM opacity uses the Planck function as the weighting function and then finds the arithmetic mean, so it is strongly affected by the more opaque regions of the spectrum.Due to their different averaging prescriptions, RM and PM opacities can differ by over two orders of magnitude which, depending on thermodynamic properties of the system, could lead to substantially different temperature profiles.

Summary and Conclusion
In this paper we present the RAPOC code that is able to convert wavelengthdependent opacity data into Rosseland and Planck mean opacities (RPMs) in an efficient manner.Our code is fully written in Python and publicly available on GitHub and Pypi.RAPOC uses ExoMol and DACE data, but user-defined data can also be used as an input as long as it is within a readable format.By Fig. 6: Comparison between Badescu [67] and RAPOC estimates.The shaded lines in all plots represent the raw data loaded from ExoMol 's carbon dioxide opacities [60].The blue lines are Rosseland Mean Opacities with the filled lines from Badescu and the dashed lines from RAPOC.The red dashed lines are RAPOC's Planck Mean opacities, and the black dotted lines are the median value of the raw wavelength dependent opacities.The left column is for low pressure (567 • 10 −3 bar) and the right column is for high pressure (11.467 bar); both columns use the same temperature (300 K).The wavelength range is different in the two rows as the top row uses 0.5 to 50 µm range, while the bottom row uses 5 to 10 µm.
incorporating the pressure and temperature dependence of RPMs, RAPOC provides a more complex treatment of the mean opacities than what is sometimes used in the literature, notably, assuming constant values or adopting simple analytic formulations.Whereas RPMs should not be used as a replacement for more rigorous opacity analyses, they have certain benefits.For example, RPMs allow one to use Grey or semi-Grey models when analysing gaseous environments, which are simpler and have exact solutions.We note that RAPOC should not be used as an alternative to more thorough approaches such as those using wavelength-dependent opacities.However, for simpler models, RAPOC provides a prescription for evaluating wavelength-dependent opacities, which can be used for exploring a larger parameter space, as well as benchmark testing.
(a) H 2 O mean opacities in the 1 − 50 µm range at P = 0.001 bar and T = 500 K.(b) H 2 O mean opacities in the 1 − 50 µm range at P = 1 bar and T = 1000 K. (c) CO 2 mean opacities in the 1 − 50 µm range at P = 0.001 bar and T = 500 K.(d) CO 2 mean opacities in the 1 − 50 µm range at P = 1 bar and T = 1000 K.

Fig. 1 :
Fig.1: The mean opacities computed by RAPOC for four different cases.In each panel the grey line represents the input data opacities (ExoMol ) with their corresponding pressures and temperatures in the given wavelength range.The blue and red lines are the computed RMs and PMs, respectively.These have been estimated with the closest method.In the top row, the opacities of water are shown, while the bottom row is for methane.The right column reports the results for P = 0.001 bar and T = 500 K, while the left row shows the equivalent for P = 1 bar and T = 1000 K.In all of the panels the wavelength range is 1 − 50 µm.
predicts opacities that differ by up to five orders of magnitude from what is estimated by RAPOC.Fig.4shows how Kurosaki et al. predicts opacities that are significantly greater than the wavelength-dependent values available from ExoMol.

Fig. 2 :
Fig. 2: Opacity map produced with RAPOC for H 2 O[52] (top row) and CO 2 [60] (bottom row) over the 1 − 50 µm range using ExoMol input data.RMs are reported on the left column, while PMs are reported on the right column.

Fig. 3 :
Fig. 3: Opacities map produced with RAPOC for H 2 O[52] over the 0.38 − 1 µm range from ExoMol input data.RMs are reported on the left, while PMs are reported on the right.
Fig 5, the RAPOC Planck opacities are consistent with those of Abu-Romia & Tien and Hottel.
Fig.4: Comparison between Kurosaki et al.[45], Abu-Romia & Tien[69], Hottel[68] and RAPOC.The shaded lines in both plots represent the raw data loaded from ExoMol 's water opacities[52].The blue lines are Rosseland Mean Opacities with the filled lines being from Kurosaki et al., the dash-dotted line from Abu-Romia & Tien, and the dashed lines from RAPOC.The red lines are Planck Mean Opacities with the filled lines being from Kurosaki et al., the dash-dotted line from Abu-Romia & Tien, the dash-dot-dotted line from Hottel, and the dashed lines from RAPOC.The black dotted line is the median value of the raw wavelength dependent opacities.The left panel is for the visible wavelength range (0.3 to 0.7 µm) and right panel is for the IR wavelength range (0.7 to 50 µm).Both panels use the same pressure (1.01325 bar) and temperature (1500 K).

Fig. 5 :
Fig.5: Comparison between Abu-Romia & Tien[69], Hottel[68] and RAPOC.The shaded lines in all plots represent the raw data loaded from ExoMol 's carbon dioxide opacities[60].The blue lines are Rosseland Mean Opacities with the dash-dotted lines being from Abu-Romia & Tien, and the dashed lines from RAPOC .The red lines are Planck Mean Opacities with the dash-dotdotted lines being from Hottel, the dash-dotted lines from Abu-Romia & Tien, and the dashed being from RAPOC.The black dotted line is the median value of the raw wavelength dependent opacities.The three panels refer to different gas temperatures: right is for T = 1500 K, centre is for T = 2000 K, and right is for T = 2500 K.All panels use the same pressure (1.01325 bar).

Table 1 :
mol_mass key.If this key is not present, RAPOC will compute this quantity automatically.We point the Input dictionary structure.A custom made Python dictionary can be used as a RAPOC input if it contains the indicated keywords.
reader to Table

Table 2 :
, 63, 64, 47, 65, 66].Whereas the values of mixtures are useful for modelling planetary formation RPMs estimated by RAPOC for different temperatures and pressures in the 1 − 50 µm wavelength range for water and methane using ExoMol data.This estimation has been performed using the linear method.orstellar interiors, they are not as applicable to planetary atmospheres.We, therefore, focus on papers providing RPMs for individual molecules because they allow for a straightforward comparison with the RPM values provided by RAPOC.Most of the individual molecule RPM values present in the literature are estimated directly from line-lists

Table 3 :
[57]static average electric dipole polarisabilities for ground state atoms used in RAPOC.An analysis of the values with their associated references can be found in the referenced CRC handbook[57].