Caching Modules (taurex.cache)

Singleton

Just contains a singleton class. Pretty useful

class Singleton[source]

Bases: object

A singleton for your usage. When inheriting do not implement __init__ instead override init()

init(*args, **kwds)[source]

Override to act as an init

OpacityCache

Contains caching class for Molecular cross section files

class OpacityCache[source]

Bases: taurex.core.Singleton

Implements a lazy load of opacities. A singleton that loads 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 Opacity object 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, molecule_filter=None)[source]

Adds a Opacity object to the cache to then be used by Taurex 3

Parameters
  • opacity (Opacity) – Opacity object to add to the cache

  • molecule_filter (list of 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

clear_cache()[source]

Clears all currently loaded cross-sections

enable_radis(enable)[source]

Enables/Disables use of RADIS to fill 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)

find_list_of_molecules()[source]
force_active(molecules)[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

init()[source]

Override to act as an init

load_opacity(opacities=None, opacity_path=None, molecule_filter=None)[source]

Main function to use when loading molecular opacities. Handles both cross sections and paths. Handles lists of either so lists of Opacity objects or lists of paths can be used to load multiple files/objects

Parameters
  • opacities (Opacity or list of Opacity , optional) – Object(s) to include in cache

  • opacity_path (str or list of str, optional) – search path(s) to look for molecular opacities

  • molecule_filter (list of str , optional) – If provided, the opacity will only be loaded if its molecule is in this list. Mostly used by the __getitem__() for filtering

load_opacity_from_path(path, molecule_filter=None)[source]

Searches path for molecular cross-section files, creates and loads them into the cache .pickle will be loaded as PickleOpacity

Parameters
  • path (str) – Path to search for molecular cross-section files

  • molecule_filter (list of 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)[source]

Sets the interpolation mode for all currently loaded (and future loaded) cross-sections

Can either be linear for linear interpolation of both temeprature and pressure:

>>> OpacityCache().set_interpolation('linear')

or exp for natural exponential interpolation of temperature and linear for pressure

>>> OpacityCache().set_interpolation('exp')
Parameters

interpolation_mode (str) – Either linear for bilinear interpolation or exp for exp-linear interpolation

set_memory_mode(in_memory)[source]

If using the HDF5 opacities, 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)[source]

Set the path(s) that will be searched for opacities. Opacities in this path must be of supported types:

  • HDF5 opacities

  • .pickle opacities

  • ExoTransmit opacities.

Parameters

opacity_path (str or list of str, optional) – search path(s) to look for molecular opacities

set_radis_wavenumber(wn_start, wn_end, wn_points)[source]

CIACache

Contains caching class for Collisionally Induced Absorption files

class CIACache[source]

Bases: taurex.core.Singleton

Implements a lazy load of collisionally induced absorpiton cross-sections Supports pickle files and HITRAN cia files. Functionally behaves the same as OpacityCache except the keys are now cia pairs e.g:

>>> CIACache()['H2-H2']
<taurex.cia.picklecia.PickleCIA at 0x107a60be0>

Pickle .db and HITRAN .cia files are supported and automatically loaded. with priority given to .db files

add_cia(cia, pair_filter=None)[source]

Adds a CIA object to the cache to then be used by Taurex 3

Parameters
  • cia (CIA) – CIA object to add to the cache

  • pair_filter (list of 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

init()[source]

Override to act as an init

load_cia(cia_xsec=None, cia_path=None, pair_filter=None)[source]

Main function to use when loading CIA files. Handles both cross sections and paths. Handles lists of either so lists of CIA objects or lists of paths can be used to load multiple files/objects

Parameters
  • cia_xsec (CIA or list of CIA , optional) – Object(s) to include in cache

  • cia_path (str or list of str, optional) – search path(s) to look for cias

  • pair_filter (list of str , optional) – If provided, the cia will only be loaded if its pair name is in this list. Mostly used by the __getitem__() for filtering

load_cia_from_path(path, pair_filter=None)[source]

Searches path for CIA files, creates and loads them into the cache .db will be loaded as PickleCIA and .cia files will be loaded as HitranCIA

Parameters
  • path (str) – Path to search for CIA files

  • pair_filter (list of str , optional) – If provided, the cia will only be loaded if its pairname is in the list. Mostly used by the __getitem__() for filtering

set_cia_path(cia_path)[source]

Sets the path to search for CIA files

Parameters

cia_path (str or list of str) – Either a single path or a list of paths that contain CIA files