openairclim.read_config

Reads a config file, assigns values to variables and creates an output directory

openairclim.read_config.add_default_config(config: dict, key_str: str, default_config: dict) dict[source]

Adds default settings to config if not defined by user, but defined in default_config

Parameters:
  • config (dict) – Configuration dictionary

  • key_str (str) – String of sub keys associated to one value, sub keys are separated by blanks.

  • default_config (dict) – Default configuration dictionary

Raises:

KeyError – if required setting from key_str not included in default_config

Returns:

Configuration dictionary, with added default setting

Return type:

dict

openairclim.read_config.check_against_template(config, config_template, default_config)[source]

Checks config dictionary against template: check if config is complete, add default settings if required, check if values have correct data types.

Parameters:
  • config (dict) – Configuration dictionary

  • config_template (dict) – Configuration template dictionary

  • default_config (dict) – Default configuration dictionary

Raises:

TypeError – if value in config has not expected data type

Returns:

Configuration dictionary, possibly with added default settings

Return type:

dict

openairclim.read_config.check_config(config, config_template, default_config)[source]

Checks if configuration is complete and correct

Parameters:

config (dict) – Configuration dictionary

Raises:

KeyError – if no response file defined

Returns:

Configuration dictionary

Return type:

dict

openairclim.read_config.check_config_types(config, types)[source]

Checks config against table of types TODO legacy code, remove this function?

Parameters:
  • config (dict) – Configuration dictionary

  • types (dict) – Table of valid types for config entries

Returns:

True if configuration types correct, False otherwise

Return type:

bool

openairclim.read_config.check_metrics_time(config: dict) bool[source]

Checks if metrics time settings are within the defined time range.

Parameters:

config (dict) – Configuration dictionary

Returns:

True if metrics time settings are within the defined time range,

False otherwise.

Return type:

bool

openairclim.read_config.classify_response_types(config, species_arr)[source]

Classifies species into categories based on their response types defined in the config

Parameters:
  • config (dict) – Configuration dictionary

  • species_arr (list) – A list of strings representing the species

Returns:

A tuple of lists. list (species_rf) contains species with response type ‘rf’,

i.e. a response file must be given comprising the response surface from emissions to RF, list (species_tau) contains species with response type ‘tau’, i.e. a response file must be given comprising the response surface from emissions to inverse species lifetime.

Return type:

tuple

Raises:

KeyError – If no valid response type is defined in the configuration for a species.

openairclim.read_config.classify_species(config)[source]

Classifies species into applied response modelling methods

Parameters:

config (dict) – Configuration dictionary

Raises:
  • KeyError – if no valid response_grid in config

  • KeyError – if no response defined for a spec

Returns:

tuple of lists of strings (species names)

Return type:

tuple

openairclim.read_config.create_output_dir(config)[source]

Check for existing output directory, results file, overwrite and full_run settings. Create new output directory if needed.

Parameters:

config (dict) – Configuration dictionary

Raises:

OSError – if no output directory is created or results file not existing with full_run = false

openairclim.read_config.get_config(file_name)[source]

load_config, check_config and create_output_dir

Parameters:

file_name (str) – Name of config file

Returns:

Configuration dictionary

Return type:

dict

openairclim.read_config.get_keys_values(v, key_arr, val_arr, prefix='')[source]

Gets list of (sub) keys and list of values for (nested) dictionary. Nested hierarchy is converted to a flattened structure.

Parameters:
  • v (dict) – (Nested) dictionary

  • key_arr (list) – List of strings, each string comprises all sub keys associated to one value, sub keys are separated by blanks.

  • val_arr (list) – List of values (any type)

  • prefix (str, optional) – Defaults to ‘’.

openairclim.read_config.load_config(file_name)[source]

Loads config file in toml format.

Parameters:

file_name (str) – Name of config file

Returns:

Configuration dictionary

Return type:

dict