Calculate a full range spectrumΒΆ

We compute the transmittance of an homogeneous, 1-km atmosphere layer at 300 K and 1 atm, with 2% H2O.

This example makes use of a lot of the RADIS optimization and convenience functions :

  • The database is retrieved from the latest HITRAN data using [HAPI], parsed with RADIS and stored to memory-mapping formats. After the first calls, retrieving the database will be very fast

  • The RADIS algorithm includes a sparse wavenumber implementation, which is activated by default in the following example where the waverange is very large. This behavior can be changed by setting the SPARSE_WAVENUMBER key of the radis.config dictionary, or of the ~/radis.json user file.

  • The wavenumber grid is automatically computed using the wstep='auto' parameter.

  • A linestrength cutoff reduces the initial number of lines.

Eventually, the full-range spectrum (about 4.8M points) is computed within a minute, with about 140k lines resolved, i.e. a performance of about 1e10 gridpoints*lines/s.

Extra optimization could be achieved by cutting the spectrum in small intervals, but requires an a-priori knowledge of the absorption & emission ranges of the spectrum. See the Calculate a large spectrum by part

import astropy.units as u

from radis import calc_spectrum, config

# This next line is needed, because the brodening coefficient of H2O by CO2 is not known.
config["MISSING_BROAD_COEF"] = "air"

s = calc_spectrum(
    wmin=0.5 * u.um,
    wmax=15 * u.um,  # cm-1
    mole_fraction={
        "CO2": 425.48e-6,
        "H2O": 0.02,
    },  # CO2 as of August 2025, see https://gml.noaa.gov/ccgg/trends/
    isotope="1,2,3",
    pressure=1.01325,  # bar
    Tgas=300,  # K
    path_length=1e5,  # 1 km in cm
    verbose=2,
    databank="hitran",
    wstep="auto",
)
--------------------------------------------------------------------------------
CO2 - HITRAN - Downloading database
--------------------------------------------------------------------------------

Download:
- All files already downloaded.

Caching to HDF5/H5 format:
- All files already cached.
HAPI version: 1.3.0.0
HAPI version: 1.3.0.0
HAPI version: 1.3.0.0
... 0.00s - Check line databank
... 0.00s - Reinitialize database
... Scaling equilibrium linestrength
... 0.01s - Scaled equilibrium linestrength
Discarded 80.47% of lines (linestrength<1e-27cm-1/(#.cm-2)) Estimated error: 0.00%
... 0.02s - Applied linestrength cutoff
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/master/radis/misc/warning.py:427: MissingSelfBroadeningTdepWarning: Self-broadening temperature coefficient `Tdpsel` not given in database: used `Tdpair` instead
  warnings.warn(WarningType(message))
... 0.01s - Calculate broadening HWHM
... 0.00s - Calculated lineshift
Sparsity (grid points/lines) = 8.4. Set sparse_ldm to True
... 0.00s - Generated Wavenumber Arrays
... Calculating line broadening (64086 lines)
Estimated time for calculating broadening: 4.80s on 1 CPU
... 0.36s - Calculated line broadening
... 0.02s - Calculated other spectral quantities
... 0.42s - Spectrum calculated (before object generation)
Calculating Equilibrium Spectrum
Physical Conditions
----------------------------------------
   Tgas                 300 K
   isotope              1,2,3
   mole_fraction        0.00042548
   path_length          100000.0 cm
   pressure             1.01325 bar
   self_absorption      True
   species              CO2
   state                X
   wavenum_max          19994.4221 cm-1
   wavenum_min          666.4850 cm-1
Computation Parameters
----------------------------------------
   Tref                 296 K
   add_at_used          numpy
   broadening_method    voigt
   cutoff               1e-27 cm-1/(#.cm-2)
   dbformat             hitran
   dbpath               /home/docs/.radisdb/hitran/CO2.h5
   diluent              air
   folding_thresh       1e-06
   include_neighbouring_lines  True
   isatom               False
   isneutral            None
   lbfunc               None
   memory_mapping_engine  auto
   neighbour_lines      0 cm-1
   optimization         simple
   parsum_mode          full summation
   pfsource             default
   potential_lowering   None
   pseudo_continuum_threshold  0
   sparse_ldm           True
   truncation           50 cm-1
   waveunit             cm-1
   wstep                0.036 cm-1
   zero_padding         536889
Config parameters
----------------------------------------
Information
----------------------------------------
   chunksize            None
   db_use_cached        True
   dxG                  0.1375350788016573
   dxL                  0.20180288881201608
   export_lines         False
   export_populations   None
   export_rovib_fraction  True
   levelsfmt            None
   load_energies        False
   lvl_use_cached       True
   parfuncpath          None
   total_lines          328081
   warning_broadening_threshold  0.01
   warning_linestrength_cutoff  0.01
   wavenum_max_calc     19994.4221 cm-1
   wavenum_min_calc     666.4850 cm-1
----------------------------------------
... 0.00s - Generated Spectrum object
0.43s - Spectrum calculated
--------------------------------------------------------------------------------
H2O - HITRAN - Downloading database
--------------------------------------------------------------------------------

Download:
- Downloading all isotopes for H2O

Downloading isotopes:   0%|          | 0/9 [00:00<?, ?it/s]
Downloading isotopes:  11%|β–ˆ         | 1/9 [00:09<01:13,  9.16s/it]
Downloading isotopes:  22%|β–ˆβ–ˆβ–       | 2/9 [00:10<00:33,  4.79s/it]
Downloading isotopes:  33%|β–ˆβ–ˆβ–ˆβ–Ž      | 3/9 [00:12<00:19,  3.20s/it]
Downloading isotopes:  33%|β–ˆβ–ˆβ–ˆβ–Ž      | 3/9 [00:13<00:27,  4.54s/it]
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/master/radis/io/hitran.py:224: UserWarning: ValueError encountered during download. Retrying (attempt 1/2)...
  ldb.download_and_parse(

Downloading isotopes:   0%|          | 0/9 [00:00<?, ?it/s]File already exist: /home/docs/.radisdb/hitran/downloads__can_be_deleted/H2O/H2O_1.data. Deleting it.`

Downloading isotopes:  11%|β–ˆ         | 1/9 [00:08<01:11,  8.92s/it]File already exist: /home/docs/.radisdb/hitran/downloads__can_be_deleted/H2O/H2O_2.data. Deleting it.`

Downloading isotopes:  22%|β–ˆβ–ˆβ–       | 2/9 [00:10<00:34,  4.88s/it]File already exist: /home/docs/.radisdb/hitran/downloads__can_be_deleted/H2O/H2O_3.data. Deleting it.`

Downloading isotopes:  33%|β–ˆβ–ˆβ–ˆβ–Ž      | 3/9 [00:12<00:20,  3.37s/it]File already exist: /home/docs/.radisdb/hitran/downloads__can_be_deleted/H2O/H2O_4.data. Deleting it.`

Downloading isotopes:  44%|β–ˆβ–ˆβ–ˆβ–ˆβ–     | 4/9 [00:14<00:13,  2.77s/it]
Downloading isotopes:  56%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Œ    | 5/9 [00:15<00:08,  2.03s/it]
Downloading isotopes:  67%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‹   | 6/9 [00:15<00:04,  1.53s/it]
Downloading isotopes:  78%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Š  | 7/9 [00:16<00:02,  1.35s/it]
Downloading isotopes: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 9/9 [00:16<00:00,  1.85s/it]

HITRAN database download complete
Added HITRAN-H2O database in /home/docs/radis.json
HAPI version: 1.3.0.0
HAPI version: 1.3.0.0
HAPI version: 1.3.0.0
... 0.00s - Check line databank
... 0.00s - Reinitialize database
... Scaling equilibrium linestrength
... 0.01s - Scaled equilibrium linestrength
Discarded 73.13% of lines (linestrength<1e-27cm-1/(#.cm-2)) Estimated error: 0.00%
... 0.02s - Applied linestrength cutoff
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/master/radis/misc/warning.py:427: MissingSelfBroadeningTdepWarning: Self-broadening temperature coefficient `Tdpsel` not given in database: used `Tdpair` instead
  warnings.warn(WarningType(message))
... 0.01s - Calculate broadening HWHM
... 0.00s - Calculated lineshift
Sparsity (grid points/lines) = 61.9. Set sparse_ldm to True
... 0.01s - Generated Wavenumber Arrays
... Calculating line broadening (78011 lines)
Estimated time for calculating broadening: 260.28s on 1 CPU
... 35.97s - Calculated line broadening
... 0.15s - Calculated other spectral quantities
... 36.17s - Spectrum calculated (before object generation)
Calculating Equilibrium Spectrum
Physical Conditions
----------------------------------------
   Tgas                 300 K
   isotope              1,2,3
   mole_fraction        0.02
   path_length          100000.0 cm
   pressure             1.01325 bar
   self_absorption      True
   species              H2O
   state                X
   wavenum_max          19994.4221 cm-1
   wavenum_min          666.4850 cm-1
Computation Parameters
----------------------------------------
   Tref                 296 K
   add_at_used          numpy
   broadening_method    voigt
   cutoff               1e-27 cm-1/(#.cm-2)
   dbformat             hitran
   dbpath
   diluent              air
   folding_thresh       1e-06
   include_neighbouring_lines  True
   isatom               False
   isneutral            None
   lbfunc               None
   memory_mapping_engine  auto
   neighbour_lines      0 cm-1
   optimization         simple
   parsum_mode          full summation
   pfsource             default
   potential_lowering   None
   pseudo_continuum_threshold  0
   sparse_ldm           True
   truncation           50 cm-1
   waveunit             cm-1
   wstep                0.004 cm-1
   zero_padding         4831986
Config parameters
----------------------------------------
Information
----------------------------------------
   chunksize            None
   db_use_cached        True
   dxG                  0.1375350788016573
   dxL                  0.20180288881201608
   export_lines         False
   export_populations   None
   export_rovib_fraction  True
   levelsfmt            None
   load_energies        False
   lvl_use_cached       True
   parfuncpath          None
   total_lines          290304
   warning_broadening_threshold  0.01
   warning_linestrength_cutoff  0.01
   wavenum_max_calc     19994.4221 cm-1
   wavenum_min_calc     666.4850 cm-1
----------------------------------------
... 0.04s - Generated Spectrum object
36.21s - Spectrum calculated
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/master/radis/misc/warning.py:427: UnevenWaverangeWarning: When resampling the spectrum, the new waverange had unequal spacing.
  warnings.warn(WarningType(message))
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/master/radis/misc/warning.py:427: UnevenWaverangeWarning: When resampling the spectrum, the new waverange had unequal spacing.
  warnings.warn(WarningType(message))
CO2-hitran-300K-#3728 new quantities added: ['emisscoeff']
H2O-hitran-300K-#2368 new quantities added: ['emisscoeff']

Plot low and high resolution spectra on the same graph :

s.apply_slit(10, "nm")
import matplotlib.pyplot as plt

plt.figure(figsize=(16, 6))
s.plot("transmittance_noslit", wunit="nm", color="k", alpha=0.1, nfig="same")
s.plot("transmittance", wunit="nm", color="k", nfig="same")
plot full range
<matplotlib.lines.Line2D object at 0x72085fce0830>

Print some details about the computed spectrum : We could also simply use print(s)

print("Number of grid points: ", len(s))
print(
    "Number of lines: ", s.c["total_lines"]
)  # some are discarded by linestrength cutoff
print("Number of lines: ", s.c["lines_calculated"])
print("Whether the sparse wavenumber algorithm was activated: ", s.c["sparse_ldm"])
print(f"Lineshape truncation used: {s.c['truncation']:.1f}cm-1")
print(f"Total calculation time: {s.c['calculation_time']:.1f}s")
print(
    f"Gridpoints * lines/s : {len(s)*s.c['lines_calculated']/s.c['calculation_time']:.1e}"
)
Number of grid points:  4831986
Number of lines:  618385
Number of lines:  142097
Whether the sparse wavenumber algorithm was activated:  True
Lineshape truncation used: 50.0cm-1
Total calculation time: 36.6s
Gridpoints * lines/s : 1.9e+10

Total running time of the script: (1 minutes 21.306 seconds)