radis.api.hitempapi module¶
Created on Tue Jan 26 22:40:51 2021
@author: erwan
https://stackoverflow.com/questions/55610891/numpy-load-from-io-bytesio-stream https://stupidpythonideas.blogspot.com/2014/07/three-ways-to-read-files.html
- class HITEMPDatabaseManager(name, molecule, local_databases, engine='default', verbose=True, chunksize=100000, parallel=True, database='most_recent')[source]¶
Bases:
DatabaseManager- fetch_url_Nlines_wmin_wmax(session=None, hitemp_url='https://hitran.org')[source]¶
requires connexion
- keep_only_relevant(inputfiles, wavenum_min=None, wavenum_max=None, verbose=True) list[source]¶
For H2O, return only relevant files for given wavenumber range.
If other molecule, return the file anyway. see
radis.api.hitempapi.keep_only_relevant()
- parse_to_local_file(opener, urlname, local_file, pbar_active=True, pbar_t0=0, pbar_Ntot_estimate_factor=None, pbar_Nlines_already=0, pbar_last=True)[source]¶
Uncompress
urlnameintolocal_file. Also add metadata- Parameters:
opener (an opener with an .open() command)
gfile (file handler. Filename: for info)
- download_and_decompress_CO2_into_df(local_databases=None, load_wavenum_min=None, load_wavenum_max=None, isotope=None, columns=None, verbose=True, engine='pytables', output='pandas')[source]¶
This function handles downloading the HITEMP CO2 database. The full 2024 database is downloaded in smaller files of approximately 50-70 MB (500 MB decompressed chunks in h5 format), locating the appropriate data chunk based on the provided wavenumber range and reading the relevant data into a DataFrame.
- Parameters:
load_wavenum_min (float or None, optional) – Minimum wavenumber to load from the database. If None, loads from the beginning.
load_wavenum_max (float or None, optional) – Maximum wavenumber to load from the database. If None, loads to the end.
verbose (bool, default True) – If True, prints progress and status messages.
isotope (str, int or None) – load only certain isotopes :
'2','1,2', etc. IfNone, loads everything. DefaultNone.columns (list of str or None) – List of columns to load from the database. If None, loads all columns. Default
None.engine (str, default “pytables”) – Engine to use for reading and writing data. Options may include “pytables”.
output (str, default “pandas”) – Output format for the data. Default is “pandas” DataFrame.
local_databases (str or None, optional) – Directory to store/read local database files. If None, uses the default directory.
- Returns:
The loaded data in the specified output format (default: pandas DataFrame).
- Return type:
DataFrame or object
Notes
Requires the HITEMP CO2 database to be accessible or downloadable.
- get_recent_hitemp_database_year(molecule)[source]¶
Retrieve the most recent available database year from the hitran website.
- Parameters:
molecule (str)
- Returns:
The year of the latest available database.
- Return type:
str
Examples
Get the latest database year for CO2 from HITEMP :
year = get_recent_hitemp_database_year("CO2") >>> "2024"
- keep_only_relevant(inputfiles, wavenum_min=None, wavenum_max=None, verbose=True) list | float[source]¶
Parser file names for
wavenum_format(min and max) and only keep relevant files if the requested range is[wavenum_min, wavenum_max]- Returns:
relevant (list of relevant files)
files_wmin, files_wmax ((float, float) : wavenum min & max of relevant range)
- login_to_hitran(verbose=False)[source]¶
Login to HITRAN using stored credentials from radis.json or prompt if not available
- parse_one_CO2_block(fname, cache=True, verbose=True, columns=None, engine='pytables', output='pandas', parse_quanta=True, wav_range=None)[source]¶
Parse a CO2 .par file block into a DataFrame with caching support.
- Parameters:
fname (str) – Path to the .par file
cache (bool) – Whether to use/save cached version. Setting
cache = Truewill convert and save the .par file to a .h5 or .hdf5 cache file (default True).verbose (bool) – Print progress messages (default True)
engine (str) – Cache format: ‘pytables’ (.h5) or ‘vaex’ (.hdf5) (default ‘pytables’)
output (str) – Output format: ‘pandas’ or ‘vaex’ (default ‘pandas’)
parse_quanta (bool) – Parse quantum numbers for non-LTE calculations (default True)
- Returns:
Parsed spectroscopic data
- Return type:
DataFrame
- read_and_write_chunked_for_CO2(load_wavenum_max, load_wavenum_min, columns=None, isotope=None, engine='pytables', output='pandas', verbose=True, local_databases=None)[source]¶
Download, parse and cache CO2 data chunks for specified wavenumber range. :Parameters: * load_wavenum_min, load_wavenum_max (float) – Wavenumber range to load (cm-1)
columns (list, optional) – Columns to include in output
isotope (str, optional) – Isotope filter (e.g., “1”, “2”, “1,2”)
engine (str) – Cache format: ‘pytables’ or ‘vaex’ (default ‘pytables’)
output (str) – Output format: ‘pandas’ or ‘vaex’ (default ‘pandas’)
verbose (bool) – Print progress messages (default True)
local_databases (str, optional) – Custom cache directory
- Returns:
(DataFrame, list of local file paths)
- Return type:
tuple
- read_config()[source]¶
Load the RADIS configuration from the JSON file.
- Returns:
The configuration dictionary loaded from CONFIG_PATH_JSON, or an empty dictionary if the file does not exist.
- Return type:
dict