Config

class Config(conf_filename='./config.json', custom_config=None)[source]

Bases: object

Initialize and load the configuration used by cases and exporters.

The config reads a json from a file or in-line which contains paths to the case to load, the plots directory, and the logs directory. It is passed later directly to different other modules to use its information.

You can modify the paths in runtime by using the dedicated setter methods.

If custom_config is provided, it overrides any file-based configuration and conf_filename is ignored.

A config must always be a dictionary with the following format and fields: {

“case_path”: “path/to/the/input/case/directory/or/file”, “plot_path”: “path/to/the/output/plot/directory”, “log_path”: “path/to/the/output/logs/directory”

}

Parameters:
  • conf_filename (str) – Path to the JSON configuration file to load.

  • custom_config (Optional[dict]) – A configuration dictionary provided inline. If set, no file is read and this dictionary becomes the active config.

Returns:

None

set_other_field(field, value)[source]

Set a custom field in the configuration dictionary.

Parameters:
  • field (str) – The name of the field to set.

  • value – The value to assign to the field.

Returns:

None

set_case_path(new_path)[source]

Set the case path in the configuration.

Parameters:

new_path (str) – The new path to the case directory.

Returns:

None

set_plot_path(new_path)[source]

Set the directory where plots should be written.

Parameters:

new_path (str) – The new path to the plots directory.

Returns:

None

set_log_path(new_path)[source]

Set the directory where logs should be stored.

Parameters:

new_path (str) – The new path to the logs directory.

Returns:

None

get_config()[source]

Get the full configuration dictionary.

Return dict:

The active configuration as a Python dictionary.

Return type:

dict

get_other_field(field)[source]

Get the value of a custom configuration field, if it exists.

Parameters:

field (str) – The name of the field to retrieve.

Returns:

The value of the field if present, otherwise None.

get_case_path()[source]

Get the configured case path.

Return str:

The path to the case directory.

Return type:

str

get_plot_path()[source]

Get the directory where plots are stored.

Return str:

The path to the plots directory.

Return type:

str

get_log_path()[source]

Get the directory where logs are stored.

Return str:

The path to the logs directory.

Return type:

str

log_path_is_set()[source]

Check whether a logs directory is defined in the configuration.

Return bool:

True if a logs directory is set, otherwise False.

Return type:

bool

get_filename()[source]

Get the filename of the loaded configuration file.

Return str:

The configuration file name.

Return type:

str