radis.test.utils module

Tools to test RADIS library.

Summary

Tools to test RADIS library

Examples

Run all tests:

cd radis/test
pytest

Run only “fast” tests (tests that have a “fast” label, and should be a few seconds only):

cd radis/test
pytest -m fast

class EmulateMatlab[source]

Bases: object

TEST_DATABASES = {'HITEMP-CO2-HAMIL-TEST': {}, 'HITEMP-CO2-TEST': {}, 'HITRAN-CO-TEST': {}, 'HITRAN-CO2-TEST': {}}[source]

test databases added in the Configuration file by setup_test_line_databases()

Type:

dict

define_Evib_as_min_of_polyad(levels, keys)[source]

Here we define the vibrational energy as the minimum energy in a polyad. Here, the polyad is defined for each combination of keys Typically, keys=['p', 'c', 'N'] or keys=[‘p’, ‘c’].

Rotational energy is the rest:

Evib = min(E(p,c,j,n) for a given set of (p,c))
Erot = E - Evib

Warning

See Pannier, Dubuet & Laux 2020 for a quantitative comparison of the different possible methods to define vibrational energy.

Parameters:

sf (SpectrumFactory object)

define_Evib_as_sum_of_Evibi(levels)[source]

Note that this is arbitrary for a polyatomic molecule. Lookup Pannier, Dubuet and Laux 2020 for more.

We also update Erot to maintain the sum Evib+Erot = E :

Evib = Evib1 + Evib2 + Evib3
Erot = E - Evib    # to be consistent with equilibrium
discard_lines_with_na_levels(sf)[source]

In the test Levels databases, not all levels are given (to save space). Consequently, in the Line databases, some lines have N/A levels and cannot be calculated at nonequilibrium. This function cleans the line databases from such lines by first running a dummy calculation and removing the lines where levels were N/A.

Warning

results from such a calculation are physically wrong. Only use to test the functions!

Parameters:

sf (SpectrumFactory)

getTestFile(file: ['synth-NH3-1-500-2000cm-P10-mf0.01-p1.spec', 'radis_json_example.json', 'geisa_CO2_fragment.par', 'generate_test_files.py', 'hitran_CO2_fragment.par', 'cdsd_hitemp_09_fragment.txt', 'CO_Tgas1500K_mole_fraction0.01.spec', 'cdsd_hitemp_09_header.txt', 'trimmed_1857_VoigtCO_Minesi.mat', 'geisa_H2O_fragment.par', 'CO2abscoeff_300K_4150_4400nm.txt', 'geisa_O2_fragment.par', 'N2C_specair_380nm.spec', 'geisa_CO_fragment.par', 'CO2_measured_spectrum_4-5um.spec', 'calc_N2C_spectrum_Trot1200_Tvib3000_slit0.1.txt', 'hitran_co_3iso_2000_2300cm.par', 'calc_N2C_spectrum_Trot1200_Tvib3000.txt', 'hitran_co2_626_bandhead_4165_4200nm.par', 'hitran_CO_fragment.par', 'Corentin_0_100cm_DownSampled_20cm_10pctCO2_1-wc-gw450-gr300-sl1500-acc5000-.spec', 'CO_Tgas1500K_mole_fraction0.5.spec', 'slitfunction.txt', 'hitran_2016_H2O_2iso_2000_2100cm.par', 'co2_cdsd_hamiltonian_fragment.levels'], force=False)[source]

Return the full path of a test file, if it exists. Used by test functions not to worry about the project architecture. Using test files is recommended when writing tests.

Parameters:

file (str) – filename. See the list of available test files

Returns:

path – absolute path of file on the local machine. Raises an error if test file not present, unless you use force=True

Return type:

str

Examples

from radis.test.utils import getTestFile
from radis import load_spec
load_spec(getTestFile('CO_Tgas1500K_mole_fraction0.01.spec'))
getValidationCase(file: ['test_compare_torch_CO2.py', 'test_RADIS_vs_HAPI_line_broadening.py', 'test_CO2_3Tvib_vs_klarenaar.py', 'test_validation_vs_specair_noneqCO.py', 'test_compare_torch_CO2_data', 'test_CO2_3Tvib_vs_klarenaar_data', 'test_validation_vs_specair_noneqCO_data'], force=False)[source]

Return the full path of a validation case file, if it exists. Used by test functions not to worry about the project architecture. Using validation test files is recommended when writing validation cases.

Parameters:

file (str) – filename. See the list of available validation files

Returns:

path – absolute path of file on the local machine. Raises an error if validation file not present, unless you use force=True

Return type:

str

Examples

Load the reference case from the [Klarenaar2017] paper

from radis.test.utils import getValidationCase
from radis import Spectrum

s_exp = Spectrum.from_txt(
    getValidationCase(
        join(
            "test_CO2_3Tvib_vs_klarenaar_data", "klarenaar_2017_digitized_data.csv",
        )
    ),
    "transmittance_noslit",
    wunit="cm-1",
    unit="",
    delimiter=",",
    name="Klarenaar 2017",
)

See also

getTestFile()

setup_test_line_databases(verbose=True)[source]

Build TEST_DATABASES and add them in ~/radis.json. Generate the file if it doesnt exist.

In particular:

  • HITRAN-CO2-TEST: CO2, HITRAN 2016, 4165-4200 nm

  • HITRAN-CO-TEST: CO, HITRAN 2016, 2000-2300 cm-1

  • HITEMP-CO2-TEST: CO2, HITEMP-2010, 2283.7-2285.1 cm-1, 3 isotopes

  • HITEMP-CO2-HAMIL-TEST: same as previous, with (some) energy levels computed from Tashkun effective Hamiltonian.

These test databases are used to run the different test routines. They can obviously be used by Users to run simulations, but we suggest Users to download their own line databases files and add them to ~/radis.json so they have more control on it

Examples

Initialize the Line databases:

from radis import setup_test_line_databases
setup_test_line_databases()

Plot a CO2 spectrum at high temperature:

from radis import calc_spectrum
calc_spectrum(2284,
              2285,
              Tgas=2000,
              pressure=1,
              molecule='CO2',
              isotope=1
              databank='HITEMP-CO2-TEST').plot()

Note that ‘HITEMP-CO2-TEST’ is defined on 2283.7-2285.1 cm-1 only, as can be shown by reading the Database information:

from radis.misc.config import printDatabankEntries printDatabankEntries(‘HITEMP-CO2-TEST’)

>>> 'HITEMP-CO2-TEST':
>>> {'info': 'HITEMP-2010, CO2, 3 main isotope (CO2-626, 636, 628), 2283.7-2285.1 cm-1',
>>> 'path': ['/USER/PATH/TO\radis\radis\test\files\cdsd_hitemp_09_fragment.txt'],
>>> 'format': 'cdsd-hitemp'
>>> 'parfuncfmt': 'hapi'
>>> 'levelsfmt': 'radis'
testEqual(a, b, info='')[source]
test_spectrum(**kwargs)[source]

Generate the first example spectrum with

import radis
s = radis.test_spectrum()
s.plot()
Other Parameters:

kwargs (sent to calc_spectrum())