β¦ same as usually. If None, then the reference value (used to
calculate bands) is used
Other Parameters:
save_rescaled_bands (boolean) β save updated bands. Take some time as it requires rescaling all
bands individually (which is only done on the MergedSlabs usually)
Default False
β¦ same as usually. If None, then the reference value (used to
calculate bands) is used
Other Parameters:
save_rescaled_bands (boolean) β save updated bands. Take some time as it requires rescaling all
bands individually (which is only done on the MergedSlabs usually)
Default False
Notes
Implementation:
Generation of a new spectrum is done by recombination of the precalculated
bands with
A class to put together all functions related to loading CDSD / HITRAN
databases, calculating the broadenings, and summing over all the lines.
Parameters:
wmin, wmax (float or Quantity) β a hybrid parameter which can stand for minimum (maximum) wavenumber or minimum
(maximum) wavelength depending upon the unit accompanying it. If dimensionless,
wunit is considered as the accompanying unit.
wunit ('nm', 'cm-1') β the unit accompanying wmin and wmax. Can only be passed with wmin
and wmax. Default is "cm-1".
wavenum_min, wavenum_max (float(cm^-1) or Quantity) β minimum (maximum) wavenumber to be processed in \(cm^{-1}\).
use astropy.units to specify arbitrary inverse-length units.
wavelength_min, wavelength_max (float(nm) or Quantity) β minimum (maximum) wavelength to be processed in \(nm\). This wavelength
can be in 'air' or 'vacuum' depending on the value of the parameter
medium=.
use astropy.units to specify arbitrary length units.
pressure (float(bar) or Quantity) β partial pressure of gas in bar. Default 1.01325 (1 atm).
use astropy.units to specify arbitrary pressure units.
For example, 1013.25*u.mbar.
mole_fraction (float [ 0 - 1]) β species mole fraction. Default 1. Note that the rest of the gas
is considered to be air for collisional broadening.
path_length (float(cm) or Quantity) β path length in cm. Default 1.
use astropy.units to specify arbitrary length units.
molecule (int, str, or None) β molecule id (HITRAN format) or name. If None, the molecule can be inferred
from the database files being loaded. See the list of supported molecules
in MOLECULES_LIST_EQUILIBRIUM
and MOLECULES_LIST_NONEQUILIBRIUM.
Default None.
isotope (int, list, str of the form '1,2', or 'all') β isotope id (sorted by relative density: (eg: 1: CO2-626, 2: CO2-636 for CO2).
See HITRAN documentation for isotope list for all species. If βallβ,
all isotopes in database are used (this may result in larger computation
times!). Default 'all'
medium ('air', 'vacuum') β propagating medium when giving inputs with 'wavenum_min', 'wavenum_max'.
Does not change anything when giving inputs in wavenumber. Default 'air'
diluent (str or dictionary) β can be a string of a single diluent or a dictionary containing diluent
name as key and its mole_fraction as value. Default air.
Other Parameters:
Tref (K) β Reference temperature for calculations (linestrength temperature
correction). HITRAN database uses 296 Kelvin. Default 296 K
self_absorption (boolean) β Compute self absorption. If False, spectra are optically thin. Default True.
truncation (float (\(cm^{-1}\))) β Half-width over which to compute the lineshape, i.e. lines are truncated
on each side after truncation (\(cm^{-1}\)) from the line center.
If None, use no truncation (lineshapes spread on the full spectral range).
Default is 300\(cm^{-1}\)
Note
Large values (> 50) can induce a performance drop (computation of lineshape
typically scale as \(~truncation ^2\) ). The default 300 was
chosen to maintain a good accuracy, and still exhibit the sub-Lorentzian
behavior of most lines far (few hundreds \(cm^{-1}\)) from the line center.
neighbour_lines (float (\(cm^{-1}\))) β The calculated spectral range is increased (by neighbour_lines cm-1
on each side) to take into account overlaps from out-of-range lines.
Default is 0\(cm^{-1}\).β
wstep (float (cm-1) or 'auto') β Resolution of wavenumber grid. Default 0.01 cm-1.
If 'auto', it is ensured that there
are slightly more points for each linewidth than the value of "GRIDPOINTS_PER_LINEWIDTH_WARN_THRESHOLD"
in radis.config (~/radis.json)
Note
wstep = βautoβ is optimized for performances while ensuring accuracy,
but is still experimental in 0.9.30. Feedback welcome!
cutoff (float (~ unit of Linestrength: cm-1/(#.cm-2))) β discard linestrengths that are lower that this, to reduce calculation
times. 1e-27 is what is generally used to generate databases such as
CDSD. If 0, no cutoff. Default 1e-27.
parsum_mode (βfull summationβ, βtabulationβ) β how to compute partition functions, at nonequilibrium or when partition
function are not already tabulated. 'fullsummation' : sums over all
(potentially millions) of rovibrational levels. 'tabulation' :
builds an on-the-fly tabulation of rovibrational levels (500 - 4000x faster
and usually accurate within 0.1%). Default fullsummation'
Note
parsum_mode= βtabulationβ is new in 0.9.30, and makes nonequilibrium
calculations of small spectra extremely fast. Will become the default
after 0.9.31.
pseudo_continuum_threshold (float) β if not 0, first calculate a rough approximation of the spectrum, then
moves all lines whose linestrength intensity is less than this threshold
of the maximum in a semi-continuum. Values above 0.01 can yield significant
errors, mostly in highly populated areas. 80% of the lines can typically
be moved in a continuum, resulting in 5 times faster spectra. If 0,
no semi-continuum is used. Default 0.
save_memory (boolean) β if True, removes databases calculated by intermediate functions (for
instance, delete the full database once the linestrength cutoff criteria
was applied). This saves some memory but requires to reload the database
& recalculate the linestrength for each new parameter. Default False.
export_populations ('vib', 'rovib', None) β if not None, store populations in Spectrum. Either store vibrational
populations (βvibβ) or rovibrational populations (βrovibβ). Default None
export_lines (boolean) β if True, saves details of all calculated lines in Spectrum. This is
necessary to later use line_survey(),
but can take some space. Default False.
chunksize (int, or None) β Splits the lines database in several chunks during calculation, else
the multiplication of lines over all spectral range takes too much memory
and slows the system down. Chunksize let you change the default chunk
size. If None, all lines are processed directly. Usually faster but
can create memory problems. Default None
optimization ("simple", "min-RMS", None) β If either "simple" or "min-RMS" LDM optimization for lineshape calculation is used:
- "min-RMS" : weights optimized by analytical minimization of the RMS-error (See: [Spectral-Synthesis-Algorithm])
- "simple" : weights equal to their relative position in the grid
If using the LDM optimization, broadening method is automatically set to 'fft'.
If None, no lineshape interpolation is performed and the lineshape of all lines is calculated.
folding_thresh (float) β Folding is a correction procedure that is applied when the lineshape is calculated with
the fft broadening method and the linewidth is comparable to wstep, that prevents
sinc(v) modulation of the lineshape. Folding continues until the lineshape intensity
is below folding_threshold. Setting to 1 or higher effectively disables folding correction.
Range: 0.0 < folding_thresh <= 1.0
Default: 1e-6
zero_padding (int) β Zero padding is used in conjunction with the fft broadening method to prevent circular
convolution at the cost of performance. When set to -1, padding is set equal to the spectrum length,
which guarantees a linear convolution.
broadening_method ("voigt", "convolve", "fft") β Calculates broadening with a direct voigt approximation (βvoigtβ) or
by convoluting independently calculated Doppler and collisional
broadening (βconvolveβ). First is much faster, 2nd can be used to
compare results. This SpectrumFactory parameter can be manually
adjusted a posteriori with:
Fast fourier transform 'fft' is only available if using the LDM lineshape
calculation optimization. Because the LDM convolves all lines at the same time,
and thus operates on large arrays, 'fft' becomes more appropriate than
convolutions in real space ('voigt', 'convolve' )
By default, use "fft" for any optimization, and "voigt" if
optimization is None .
warnings (bool, or one of ['warn','error','ignore'], dict) β If one of ['warn','error','ignore'], set the default behaviour
for all warnings. Can also be a dictionary to set specific warnings only.
Example:
verbose (boolean, or int) β If False, stays quiet. If True, tells what is going on.
If >=2, gives more detailed messages (for instance, details of
calculation times). Default True.
fromradisimportSpectrumFactoryfromastropyimportunitsasusf=SpectrumFactory(wavelength_min=4165*u.nm,wavelength_max=4200*u.nm,isotope='1,2',truncation=10,# cm-1optimization=None,medium='vacuum',verbose=1,# more for more details)sf.load_databank('HITRAN-CO2-TEST')# predefined in ~/radis.jsons=sf.eq_spectrum(Tgas=300*u.K,path_length=1*u.cm)s.rescale_path_length(0.01)# cms.plot('radiance_noslit',Iunit='Β΅W/cm2/sr/nm')
initial line database after loading.
If for any reason, you want to manipulate the line database manually (for instance, keeping only lines emitting
by a particular level), you need to access the df0 attribute of
SpectrumFactory.
Warning
never overwrite the df0 attribute, else some metadata may be lost in the process.
Only use inplace operations. If reducing the number of lines, add
a df0.reset_index()
For instance:
fromradisimportSpectrumFactorysf=SpectrumFactory(wavenum_min=2150.4,wavenum_max=2151.4,pressure=1,isotope=1)sf.load_databank('HITRAN-CO-TEST')sf.df0.drop(sf.df0[sf.df0.vu!=1].index,inplace=True)# keep lines emitted by v'=1 onlysf.eq_spectrum(Tgas=3000,name='vu=1').plot()
df0 contains the lines as they are loaded from the database.
df1 is generated during the spectrum calculation, after the
line database reduction steps, population calculation, and scaling of intensity and broadening parameters
with the calculated conditions.
Generate a spectrum at equilibrium with calculation of lineshapes
and broadening done on the GPU.
Note
This method requires CUDA compatible hardware to execute.
For more information on how to setup your system to run GPU-accelerated methods
using CUDA and Cython, check GPU Spectrum Calculation on RADIS
mole_fraction (float) β database species mole fraction. If None, Factory mole fraction is used.
path_length (float or Quantity) β slab size (cm). If None, the default Factory
path_length is used.
pressure (float or Quantity) β pressure (bar). If None, the default Factory
pressure is used.
name (str) β output Spectrum name (useful in batch)
Other Parameters:
backend (str) β if 'gpu-cuda', set CUDA as backend to run code on Nvidia GPU.
if 'cpu-cuda', execute the GPU code on the CPU (useful for development)
Fit an experimental spectrum with an arbitrary model and an arbitrary
number of fit parameters. This method calls fit_legacy()
which is still functional. However, we recommend using fit_spectrum().
Parameters:
s_exp (Spectrum) β experimental spectrum. Should have only spectral array only. Use
take(), e.g:
sf.fit_legacy(s_exp.take('transmittance'))
model (func -> Spectrum) β a line-of-sight model returning a Spectrum. Example :
Tvib12Tvib3Trot_NonLTEModel()
Calculate emission spectrum in non-equilibrium case. Calculates
absorption with broadened linestrength and emission with broadened
Einstein coefficient.
Parameters:
Tvib (float) β vibrational temperature [K]
can be a tuple of float for the special case of more-than-diatomic
molecules (e.g: CO2)
Trot (float) β rotational temperature [K]
Ttrans (float) β translational temperature [K]. If None, translational temperature is
taken as rotational temperature (valid at 1 atm for times above ~ 2ns
which is the RT characteristic time)
mole_fraction (float) β database species mole fraction. If None, Factory mole fraction is used.
diluent (str or dictionary) β can be a string of a single diluent or a dictionary containing diluent
name as key and its mole_fraction as value
path_length (float or Quantity) β slab size (cm). If None, the default Factory
path_length is used.
pressure (float or Quantity) β pressure (bar). If None, the default Factory
pressure is used.
Other Parameters:
vib_distribution ('boltzmann', 'treanor') β vibrational distribution
rot_distribution ('boltzmann') β rotational distribution
overpopulation (dict, or None) β
add overpopulation factors for given levels:
{level:overpopulation_factor}
name (str) β output Spectrum name (useful in batch)
Multi-vibrational temperature. Below we compare non-LTE spectra of CO2 where all
vibrational temperatures are equal, or where the bending & symmetric modes are in
equilibrium with rotation
fromradisimportSpectrumFactorysf=SpectrumFactory(wavenum_min=2000,wavenum_max=3000,molecule="CO2",isotope="1,2,3",)sf.fetch_databank("hitemp",load_columns='noneq')# nonequilibrium between bending+symmetric and asymmetric modes :s1=sf.non_eq_spectrum(Tvib=(600,600,2000),Trot=600,path_length=1,pressure=1)# all vibrational temperatures are equal :s2=sf.non_eq_spectrum(Tvib=(2000,2000,2000),Trot=600,path_length=1,pressure=1)
Calculate total power emitted in equilibrium or non-equilibrium case
in the optically thin approximation: it sums all emission integral over
the total spectral range.
Warning
this is a fast implementation that doesnt take into account
the contribution of lines outside the given spectral range. It is valid for spectral ranges
surrounded by no lines, and spectral ranges much broadened than the typical
line broadening (~ 1-10 cm-1 in the infrared)
If what youβre looking for is an accurate simulation on a narrow spectral range
you better calculate the spectrum (that does take all of that into account)
and integrate it with get_power()
Parameters:
Tgas (float) β equilibrium temperature [K]
If doing a non equilibrium case it should be None. Use Ttrans for
translational temperature
Tvib (float) β vibrational temperature [K]
Trot (float) β rotational temperature [K]
Ttrans (float) β translational temperature [K]. If None, translational temperature is
taken as rotational temperature (valid at 1 atm for times above ~ 2ns
which is the RT characteristic time)
mole_fraction (float) β database species mole fraction. If None, Factory mole fraction is used.
path_length (float) β slab size (cm). If None, Factory mole fraction is used.
unit (str) β output unit. Default 'mW/cm2/sr'
Returns:
float β see unit=.
Return type:
Returns total power density in mW/cm2/sr (unless different unit is chosen),
predict_time(self) uses the input parameters like Spectral Range, Number of lines, wstep,
truncation to predict the estimated calculation time for the Spectrum
broadening step(bottleneck step) for the current optimization and broadening_method. The formula
for predicting time is based on benchmarks performed on various parameters for different optimization,
broadening_method and deriving its time complexity.
Can automatically download databases (HITRAN/HITEMP) or use manually downloaded
local databases, under equilibrium or non-equilibrium, with or without overpopulation,
using either CPU or GPU.
It is a wrapper to SpectrumFactory class.
For advanced used, please refer to the aforementioned class.
molecule (int, str, list or None) β molecule id (HITRAN format) or name. For multiple molecules, use a list.
The 'isotope', 'mole_fraction', 'databank' and 'overpopulation' parameters must then
be dictionaries.
If None, the molecule can be inferred
from the database files being loaded. See the list of supported molecules
in MOLECULES_LIST_EQUILIBRIUM
and MOLECULES_LIST_NONEQUILIBRIUM.
Default None.β
isotope (int, list, str of the form '1,2', or 'all', or dict) β isotope id (sorted by relative density: (eg: 1: CO2-626, 2: CO2-636 for CO2).
See [HITRAN-2020] documentation for isotope list for all species. If 'all',
all isotopes in database are used (this may result in larger computation
times!). Default 'all'.
For multiple molecules, use a dictionary with molecule names as keys
isotope={'CO2':'1,2' , 'CO':'1,2,3' }β
mole_fraction (float or dict) β database species mole fraction. Default 1.
For multiple molecules, use a dictionary with molecule names as keys
mole_fraction={'CO2': 0.8, 'CO':0.2}β
diluent (str or dictionary) β can be a string of a single diluent or a dictionary containing diluent
name as key and its mole_fraction as value
For single diluent
databank=('hitran','full')# download and cache full database, all isotopesdatabank=('hitran','range')# download and cache required range, required isotope
'hitemp', to fetch the latest HITEMP version
through fetch_hitemp(). Downloads all lines
and all isotopes.
'exomol', to fetch the latest ExoMol database
through fetch_exomol(). To download a specific
database use (more info in fetch_exomol)
databank=('exomol','EBJT')# 'EBJT' is a specific ExoMol database name
'geisa', to fetch the GEISA 2020 database
through fetch_geisa(). Downloads all lines
and all isotopes.
the name of a a valid database file, in which case the format is inferred.
For instance, '.par' is recognized as hitran/hitemp format.
Accepts wildcards '*' to select multiple files
databank='PATH/TO/co_*.par'
the name of a spectral database registered in your ~/radis.jsonconfiguration file
databank='MY_SPECTRAL_DATABASE'
Default 'hitran'. See DatabankLoader for more
information on line databases, and DBFORMAT for
your ~/radis.json file format.
For multiple molecules, use a dictionary with molecule names as keys:
databank='hitran'# automatic download (or 'hitemp')databank='PATH/TO/05_HITEMP2019.par'# path to a filedatabank='*CO2*.par'#to get all the files that have CO2 in their names (case insensitive)databank='HITEMP-2019-CO'# user-defined database in Configuration filedatabank={'CO2':'PATH/TO/05_HITEMP2019.par','CO':'hitran'}# for multiple molecules
Other Parameters:
medium ('air', 'vacuum') β propagating medium when giving inputs with 'wavenum_min', 'wavenum_max'.
Does not change anything when giving inputs in wavenumber. Default ``βairβ``β
wstep (float (\(cm^{-1}\)) or 'auto') β Resolution of wavenumber grid. Default 0.01 cm-1.
If 'auto', it is ensured that there
are slightly more or less than radis.config['GRIDPOINTS_PER_LINEWIDTH_WARN_THRESHOLD']
points for each linewidth.
Note
wstep = βautoβ is optimized for performances while ensuring accuracy,
but is still experimental in 0.9.30. Feedback welcome!
truncation (float (\(cm^{-1}\))) β Half-width over which to compute the lineshape, i.e. lines are truncated
on each side after truncation (\(cm^{-1}\)) from the line center.
If None, use no truncation (lineshapes spread on the full spectral range).
Default is 300\(cm^{-1}\)
Note
Large values (> 50) can induce a performance drop (computation of lineshape
typically scale as \(~truncation ^2\) ). The default 300 was
chosen to maintain a good accuracy, and still exhibit the sub-Lorentzian
behavior of most lines far (few hundreds \(cm^{-1}\)) from the line center.
neighbour_lines (float (\(cm^{-1}\))) β The calculated spectral range is increased (by neighbour_lines cm-1
on each side) to take into account overlaps from out-of-range lines.
Default is 0\(cm^{-1}\).β
cutoff (float (~ unit of Linestrength: \(cm^{-1}/(molec.cm^{-2})\))) β discard linestrengths that are lower that this, to reduce calculation
times. 1e-27 is what is generally used to generate line databases such as
CDSD. If 0, no cutoff. Default 1e-27 .
parsum_mode (βfull summationβ, βtabulationβ) β how to compute partition functions, at nonequilibrium or when partition
function are not already tabulated. 'fullsummation' : sums over all
(potentially millions) of rovibrational levels. 'tabulation' :
builds an on-the-fly tabulation of rovibrational levels (500 - 4000x faster
and usually accurate within 0.1%). Default 'fullsummation'
Note
parsum_mode= βtabulationβ is new in 0.9.30, and makes nonequilibrium
calculations of small spectra extremely fast. Will become the default
after 0.9.31.
optimization ("simple", "min-RMS", None) β If either "simple" or "min-RMS" LDM optimization for lineshape calculation is used:
"simple" : weights equal to their relative position in the grid
If using the LDM optimization, broadening method is automatically set to 'fft'.
If None, no lineshape interpolation is performed and the lineshape of all lines is calculated.
Refer to [Spectral-Synthesis-Algorithm] for more explanation on the LDM method for lineshape interpolation.
Default "simple".
overpopulation (dict) β dictionary of overpopulation compared to the given vibrational temperature.
Default None. Example:
export_lines (boolean) β if True, saves details of all calculated lines in Spectrum. This is
necessary to later use line_survey(),
but can take some space. Default False.
name (str) β name of the output Spectrum. If None, a unique ID is generated.
save_to (str) β save to a spec file which contains absorption & emission features, all
calculation parameters, and can be opened with load_spec().
File can be reloaded and exported to text formats afterwards, see
savetxt().
If file already exists, replace.
use_cached (boolean) β use cached files for line database and energy database. Default True.β
verbose (boolean, or int) β If False, stays quiet. If True, tells what is going on.
If >=2, gives more detailed messages (for instance, details of
calculation times). Default True.β
mode ('cpu', 'gpu', 'emulated_gpu') β if set to 'cpu', computes the spectra purely on the CPU. if set to 'gpu',
offloads the calculations of lineshape and broadening steps to the GPU
making use of parallel computations to speed up the process. Default 'cpu'.
Note that mode='gpu' requires CUDA compatible hardware to execute.
For more information on how to setup your system to run GPU-accelerated
methods using CUDA and Cython, check GPU Spectrum Calculation on RADIS
To try the GPU code without an actual GPU, you can use mode='emulated_gpu'.
This will run the GPU equivalent code on the CPU.
return_factory (bool) β if True, return the SpectrumFactory that
computes the spectrum. Useful to access computational parameters, the line database,
or to start batch-computations from a first spectrum calculation. Ex:
s,sf=calc_spectrum(...,return_factory=True)sf.df1# see the lines calculatedsf.eq_spectrum(...)# new calculation without reloading the database
engine (string) β Vaex or Pandas . Default Pandas, if engine is vaex memory performance is improved
**kwargs (other inputs forwarded to SpectrumFactory) β For instance: warnings.
See SpectrumFactory documentation for more
details on input.
See [1]_ to get an overview of all Spectrum methods
SpectrumFactory β if using return_factory=True, the Factory that generated the spectrum is returned.
if calculating multiple molecules, a dictionary of factories is returned
fromradisimportcalc_spectrums=calc_spectrum(1900,2300,# cm-1molecule='CO',isotope='1,2,3',pressure=1.01325,# barTgas=1000,mole_fraction=0.1,databank='hitran',# or 'hitemp'diluent="air"# or {'CO2': 0.1, 'air':0.8})s.apply_slit(0.5,'nm')s.plot('radiance')
This example uses the eq_spectrum_gpu() method to calculate
the spectrum on the GPU. The databank points to the CDSD-4000 databank that has been
pre-processed and stored in numpy.npy format.
β
Refer to the online Examples for more cases, and to
the Spectrum page for details on post-processing methods.
For more details on how to use the GPU method and process the database, refer to the examples
linked above and the documentation on GPU support for RADIS.
β
Other Examples
βββββ
cite: RADIS is built on the shoulders of many state-of-the-art packages and databases. If using RADIS
to compute spectra, make sure you cite all of them, for proper reproducibility and acknowledgement of
the work ! See How to cite? and the cite()
method.