Caching Modules (taurex.cache)¶
Singleton¶
Just contains a singleton class. Pretty useful
OpacityCache¶
Contains caching class for Molecular cross section files.
- class OpacityCache(*args, **kwds)[source]¶
Bases:
SingletonImplements a lazy load of opacities.
A singleton thatloads and caches xsections as they are needed. Calling:
>>> opt = OpacityCache() ... opt2 = OpacityCache()
Reveals that:
>>> opt == opt2 True
Importantly this class will automatically search directories for cross-sections set using the
set_opacity_path()method:>>> opt.set_opacity_path('path/to/crossections')
Multiple paths can be set as well
>>> opt.set_opacity_path( ... ['/path/to/crosssections','/another/path/to/crosssections'])
To get the cross-section object for a particular molecule use the square bracket operator:
>>> opt['H2O'] <taurex.opacity.pickleopacity.PickleOpacity at 0x107a60be0>
This returns a
Opacityobject for you to compute H2O cross sections from. When called for the first time, a directory search is performed and, if found, the appropriate cross-section is loaded. Subsequent calls will immediately return the already loaded object:>>> h2o_a = opt['H2O'] >>> h2o_b = opt['H2O'] >>> h2o_a == h2o_b True
If you have any plugins that include new opacity formats, the cache will automatically detect them.
Lastly you can manually add an opacity directly for a molecule into the cache:
>>> new_h2o = MyNewOpacityFormat() >>> new_h2o.molecule H2O >>> opt.add_opacity(new_h2o) >>> opt['H2O'] <MyNewOpacityFormat at 0x107a60be0>
Now TauREx3 will use it instead in all calculations!
- add_opacity(opacity: object, molecule_filter: List[str] | None = None)[source]¶
Adds a
Opacityobject to the cache.- Parameters:
opacity (
Opacity) – Opacity object to add to the cachemolecule_filter (
listof str , optional) – If provided, the opacity object will only be included if its molecule is in the list. Mostly used by the__getitem__()for filtering
- enable_radis(enable: bool) None[source]¶
Enables/Disables use of RADIS to fill in missing molecules.
RADIS fills in missing molecules using HITRAN.
Warning
This is extremely unstable and crashes frequently. It is also very slow as it requires the computation of the Voigt profile for every temperature. We recommend leaving it as False unless necessary.
- Parameters:
enable (bool) – Whether to enable RADIS functionality (default = False)
- force_active(molecules: List[str])[source]¶
Allows some molecules to be forced as active.
Useful when using other radiative codes to do the calculation
- Parameters:
molecules (obj:list) – List of molecules
- load_opacity(opacities: object | List[object] | None = None, opacity_path: str | List[str] | None = None, molecule_filter: List[str] | None = None)[source]¶
Main function to use when loading molecular opacities. Handles both cross sections and paths. Handles lists of either so lists of
Opacityobjects or lists of paths can be used to load multiple files/objects- Parameters:
opacities (
Opacityor)
:param
listofOpacity: Object(s) to include in cache :param optional: Object(s) to include in cache :param opacity_path: search path(s) to look for molecular opacities :type opacity_path: str orlistof str, optional :param molecule_filter: If provided, the opacity will only be loadedif its molecule is in this list. Mostly used by the
__getitem__()for filtering
- load_opacity_from_path(path: str, molecule_filter: List[str] | None = None)[source]¶
Searches path for molecular cross-section files.
Creates and loads opacities into the cache
.picklewill be loaded asPickleOpacity- Parameters:
path (str) – Path to search for molecular cross-section files
molecule_filter (
listof str , optional) – If provided, the opacity will only be loaded if its molecule is in this list. Mostly used by the__getitem__()for filtering
- set_interpolation(interpolation_mode: Literal['linear', 'exp'])[source]¶
Sets the interpolation mode for cross-sections.
Can either be
linearfor linear interpolation of both temeprature and pressure:>>> OpacityCache().set_interpolation('linear')
or
expfor natural exponential interpolation of temperature and linear for pressure>>> OpacityCache().set_interpolation('exp')
- Parameters:
interpolation_mode (str) – Either
linearfor bilinear interpolation orexpfor exp-linear interpolation.
- set_memory_mode(in_memory: bool) None[source]¶
Sets HDF5 opacity load mode.
For HDF5, whether to stream opacities from file (slower, less memory) or load them into memory (faster, more memory)
- Parameters:
in_memory (bool) – Whether HDF5 files should be streamed (False) or loaded into memory (True, default)
- set_opacity_path(opacity_path: str | List[str]) None[source]¶
Set the path(s) that will be searched for opacities.
Opacities in this path must be of supported types:
HDF5 opacities
.pickleopacitiesExoTransmit opacities.
- Parameters:
opacity_path (str or
listof str, optional) – search path(s) to look for molecular opacities- Raises:
NotADirectoryError – If (any) path does not exist
CIACache¶
Contains caching class for Collisionally Induced Absorption files.
- class CIACache(*args, **kwds)[source]¶
Bases:
SingletonImplements a lazy load of collisionally induced absorpiton cross-sections Supports pickle files and HITRAN cia files. Functionally behaves the same as
OpacityCacheexcept the keys are now cia pairs e.g:>>> CIACache()['H2-H2'] <taurex.cia.picklecia.PickleCIA at 0x107a60be0>
Pickle
.dband HITRAN.ciafiles are supported and automatically loaded. with priority given to.dbfiles- add_cia(cia: CIA, pair_filter: List[str] | None = None)[source]¶
Adds a
CIAobject to the cache to then be used by Taurex 3- Parameters:
cia (
CIA) – CIA object to add to the cachepair_filter (
listof str , optional) – If provided, the cia object will only be included if its pairname is in the list. Mostly used by the__getitem__()for filtering
- load_cia(cia_xsec: CIA | List[CIA] | None = None, cia_path: str | List[str] | None = None, pair_filter: List[str] | None = None)[source]¶
Main function to use when loading CIA files. Handles both cross sections and paths. Handles lists of either so lists of
CIAobjects or lists of paths can be used to load multiple files/objects- Parameters:
cia_xsec (
CIAor)
:param
listofCIA: Object(s) to include in cache :param optional: Object(s) to include in cache :param cia_path: search path(s) to look for cias :type cia_path: str orlistof str, optional :param pair_filter: If provided, the cia will only be loadedif its pair name is in this list. Mostly used by the
__getitem__()for filtering
- load_cia_from_path(path: str, pair_filter: List[str] | None = None)[source]¶
Searches path for CIA files, creates and loads them into the cache
.dbwill be loaded asPickleCIAand.ciafiles will be loaded asHitranCIA- Parameters:
path (str) – Path to search for CIA files
pair_filter (
listof str , optional) – If provided, the cia will only be loaded if its pairname is in the list. Mostly used by the__getitem__()for filtering