exo_k.settings

@author: jeremy leconte

A class based on a singleton to store global options only once for every instance.

Module Contents

class exo_k.settings.Settings[source]

Bases: exo_k.util.singleton.Singleton

A class based on a singleton to store global options only once for every instance.

So all the following methods can be called using the following syntax:

>>> exo_k.Settings().method_name(agrs)

In gerneal, they will change internal global attributes that change the global behavior of some routines in the library.

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

Override to act as an init

reset_search_path(path_type='all', no_path=False)[source]

Set default search path.

Parameters:
  • path_type (str) – What type of path to reset. Possibilities are ‘all’ (default), ‘kdata’, ‘cia’, and ‘aerosol’

  • no_path (bool (optional)) – If False (default), the search path is reset to ‘.’. If True, empties the search path.

add_search_path(*search_paths, path_type='kdata')[source]

Add path(s) to the list of paths that will be searched for various files.

Parameters:
  • search_path (string or list of strings) – Search path(s) to look for opacities.

  • path_type (str) –

    What type of path to change. Possibilities are:
    • ’kdata’ (default): global xsec and corr-k search path

    • ’ktable’ : only corr-k files

    • ’xtable’ : only cross section files

    • ’cia’: search path for CIA files

    • ’aerosol’: search path for Aerosol optical property files

Examples

>>> exo_k.Settings().add_search_path('data/xsec','data/corrk')
>>> exo_k.Settings().search_path()
['/your/path/to/exo_k',
 '/your/path/to/exo_k/data/xsec',
 '/your/path/to/exo_k/data/corrk']
add_cia_search_path(*search_paths)[source]

Add path(s) to the list of paths that will be searched for cia files.

Parameters:

search_path (string or list of strings) – Search path(s) to look for opacities.

add_aerosol_search_path(*search_paths)[source]

Add path(s) to the list of paths that will be searched for aerosol files.

Parameters:

search_path (string or list of strings) – Search path(s) to look for opacities.

set_search_path(*search_paths, path_type='kdata')[source]

Like :func:~`exo_k.settings.Settings.add_search_path` except for the fact that the path is reset first.

set_cia_search_path(*search_paths)[source]

Like :func:~`exo_k.settings.Settings.add_cia_search_path` except for the fact that the path is reset first.

set_aerosol_search_path(*search_paths)[source]

Like :func:~`exo_k.settings.Settings.add_aerosol_search_path` except for the fact that the path is reset first.

property search_path
Returns the current value of the global search path (_search_path)
cia_search_path()[source]

Returns the current value of the cia search path (_cia_search_path)

aerosol_search_path()[source]

Returns the current value of the aerosol search path (_aerosol_search_path)

set_delimiter(newdelimiter)[source]

Sets the delimiter string used to separate molecule names in filenames.

Parameters:

newdelimiter (string) – New delimiter to use. Default is ‘_’.

Example

If I have a file named ‘H2O.R10000_xsec.hdf5’ that I want to load in a Kdatabase, the default settings will result in an error:

>>> database=xk.Kdatabase(['H2O'],'R10000')
 No file was found with these filters:
 ('H2O_', 'R1000') in the following directories:
 ['/home/falco/xsec/xsec_sampled_R10000_0.3-15']

Using

>>> xk.Settings().set_delimiter('.')
>>> database=xk.Kdatabase(['H2O'],'R10000')

finds the file.

set_delimiters(newdelimiters)[source]

Sets the delimiter string used to separate molecule names in filenames. If you want to include the ‘-’ character, you must put a ‘' before to avoid it being interpreted as a special character by the re module.

Parameters:

newdelimiters (string) – New delimiters to use. Default is ‘_.-’.

set_log_interp(log_interp)[source]

Sets the default interpolation mode for kdata. Default is Log.

Parameters:

log_interp (boolean) – If True, log interpolation. Linear if False.

set_log_interp_aerosol(log_interp)[source]

Sets the default interpolation mode for aerosols. Default is Linear.

Parameters:

log_interp (boolean) – If True, log interpolation. Linear if False.

set_case_sensitive(case_sensitive)[source]

Set whether name matching is case sensitive. Default is False.

Parameters:

case_sensitive (boolean) – If True, name matching is case sensitive.

set_mks(set_mks)[source]

Forces conversion to mks system.

Parameters:

set_mks (boolean) – If True, all datasets are converted to mks upon loading.

list_files(*str_filters, molecule=None, only_one=False, search_path=None, path_type='kdata')[source]

A routine that provides a list of all filenames containing a set of string filters in one of the global _search_path or a local one.

Whether the search is case sensitive is specified through the Settings.set_case_sensitive() method.

Warning

The pattern matching with the str_filters is done using regular expressions. If you want to match special characters (like a dot in a filename), do not forget to put a backslash in front of it.

Parameters:
  • *str_filters (str) – A set of strings that need to be contained in the name of the file

  • molecule (str) – The name of a molecule to be looked for in the filename. It must be followed by one of the characters in self._delimiters and either at the begining of the name or just after one of the characters in self._delimiters.

  • only_one (boolean, optional) – If true, only one filename is returned (the first one). If false, a list is returned. Default is False.

  • search_path (str, optional) – If search_path is provided, it locally overrides the global _search_path settings and only files in search_path are returned.

Returns:

list of strings

List of filenames corresponding to all the str_filters

list_cia_files(*str_filters, molecule_pair=None, only_one=False, search_path=None)[source]

A routine that provides a list of all filenames containing a set of string filters in the global _search_path or a local one.

Whether the search is case sensitive is specified through the Settings.set_case_sensitive() method.

Warning

The pattern matching with the str_filters is done using regular expressions. If you want to match special characters (like a dot in a filename), do not forget to put a backslash in front of it.

Parameters:
  • *str_filters (str) – A set of strings that need to be contained in the name of the file

  • molecule_pair (list of 2 str) – The name of the 2 molecules in the cia pair.

  • only_one (boolean, optional) – If true, only one filename is returned (the first one). If false, a list is returned. Default is False.

  • search_path (str, optional) – If search_path is provided, it locally overrides the global _search_path settings and only files in search_path are returned.

Returns:

list of strings

List of filenames corresponding to all the str_filters

exception exo_k.settings.NoFileFoundError[source]

Bases: Exception

Error when no file is found

Initialize self. See help(type(self)) for accurate signature.