Configuration classes#

Configuration handler.

This script provides the base class to save the metadata for a given ReEDS scenario. It can either read the information directly or throught a cases file.

class r2x.config.Configuration(scenarios=<factory>, scenario_names=<factory>)#

R2X configuration manager that wraps multiple Scenario instances.

This class parses either the cases_*.csv file or reads the inputs from the CLI.

Parameters:
  • scenarios (dict)

  • scenario_names (list)

scenario_list#

List of Scenario instances

scenario_names#

Names of the scenarios in scenario_list

Type:

list

See also

Scenario

classmethod from_cases(cases_fpath, cli_args, user_dict=None)#

Parse the legacy cases file into a list of Scenarios.

Parameters:
  • cases_fpath (str) – fpath of cases file

  • cli_args (dict)

  • user_dict (dict | None)

Raises:

FileNotFoundError – If csv file does not exists

classmethod from_cli(cli_args, user_dict=None, **kwargs)#

Create scenario from the CLI arguments.

It saves the created scenario in the scenario_list` and scenario_names

Parameters:
  • kwargs – Arguments for constructing the scenario.

  • cli_args (dict)

  • user_dict (dict | None)

get(name)#

Return a scenario from the configuration manager.

Parameters:

name (str) – Name of the scenario to get

Return type:

Configuration

Raises:

KeyError – If name is not present on scenario_names

static override(params, cli_args, user_dict=None)#

Override scenario either by user provided dict or cli.

If the user want to override defaults it can be done by passing the user_dict. Currently, we only use the user_dict to override the defaults and the fmap.

Parameters:
  • params (dict) – Parameters to create the scenario

  • user_dict (dict | None) – Dictionary that will override the defaults

  • cli_args (dict) – Arguments passed from the CLI

Return type:

Scenario

class r2x.config.Scenario(name=None, run_folder=None, output_folder=PosixPath('.'), solve_year=None, weather_year=None, input_model=None, output_model=None, cases_flags=<factory>, fmap=<factory>, defaults=<factory>, feature_flags=<factory>, plugins=None, _mkdir=True)#

Scenario class.

The purpose of the scenario class is to provide a way to track the inputs and defaults for a given translation. It serves as an access point to get the defaults, configuration and features flags for different steps (e.g., parser, exporter or validation) since most of the codebase use object composition.

Each scenario can have its own set of flags that will run different parts of the parsers.

A very simple use case for this class:

from r2x.config import Scenario

scenario = Scenario(name="test")
print(scenario)
Parameters:
  • name (str | None) – Name for the scenario

  • run_folder (pathlib.Path | str | None) – Path for the scenario inputs

  • output_folder (pathlib.Path | str) – Path for output exports

  • input_model (str | None) – Model to translate from

  • output_model (str | None) – model to translate to

  • fmap (dict[str, Any]) – Dictionary with files configuration

  • defaults (dict[str, Any]) – Default configuration from the scenario

  • feature_flags (dict[str, Any]) – Dictionary with experimental features

  • plugins (list[Any] | None) – List of plugins enabled

  • solve_year (list[int] | int | None)

  • weather_year (int | None)

  • cases_flags (dict[str, Any])

  • _mkdir (bool)

See also

Configuration

classmethod from_kwargs(**kwargs)#

Create Scenario instance from key arguments.

Return type:

Scenario

info()#

Return table summary of the configuration.

Return type:

None