Configuration#

Configuration models#

pydantic settings r2x.config_models.BaseModelConfig#

Configuration of the Model.

fmap#

Dictionary with file to be parse

defaults#

Default configuration for the model

Raises:

AttributeError

Fields:
field defaults: dict[str, Any] [Optional]#
field fmap: dict[str, Any] [Optional]#
classmethod get_field_mapping()#

Return a dict of {target_class: {target_field: source_field}}.

Return type:

dict[type[BaseModel], dict[str, str]]

to_class(target_class, base_instance=None)#

Transform this model instance to another Pydantic model.

Parameters:
  • target_class (type[BaseModelConfigType])

  • base_instance (BaseModel | None)

Return type:

BaseModelConfigType

transform_field(field_name, target_class)#

Define custom field transformations.

Parameters:
  • field_name (str)

  • target_class (type[BaseModel])

Return type:

Any

pydantic settings r2x.config_models.InfrasysConfig#

Infrasys specific configuration.

Fields:
field reference_year: int | None = None#
classmethod get_field_mapping()#

Return a dict of {target_class: {target_field: source_field}}.

Return type:

dict[type[BaseModel], dict[str, str]]

pydantic settings r2x.config_models.ReEDSConfig#

ReEDs specific configuration.

Fields:
field solve_year: list[int] | int | None = None#
field weather_year: int | None = None#
classmethod get_field_mapping()#

Return a dict of {target_class: {target_field: source_field}}.

Return type:

dict[type[BaseModel], dict[str, str]]

pydantic settings r2x.config_models.PlexosConfig#

Plexos specific configuration.

Fields:
field horizon_year: int | None = None#
field master_file: str | None = None#
field model_name: str | None = None#
field model_year: int | None = None#
pydantic settings r2x.config_models.SiennaConfig#

Sienna specific configuration.

Fields:
field model_year: int | None = None#

Scenario models#

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_scenario.Configuration(scenarios=<factory>)#

Configuration manager that wraps multiple Scenario instances.

Parameters:

scenarios (dict[str, Scenario])

scenarios#

Dictionary of scenarios to be translated.

Type:

dict[str, r2x.config_scenario.Scenario]

See also

Scenario

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

Create a Scenario from the CLI arguments.

It saves the created scenario using CLI input. It can also be overwrited if an user_dict is passed.

Parameters:
  • cli_args (dict[str, Any]) – Arguments for constructing the scenario.

  • user_dict (dict[str, Any] | None) – Configuration for the translation.

  • kwargs – Arguments for constructing the scenario.

classmethod from_scenarios(cli_args, user_dict)#

Create scenario from scenarios on the config file.

This method takes the `user_dict[‘scenarios’] key which is a list of dicts to create the different scenarios for translation. The order of override is CLI -> Global Keys -> Scenario Keys

Parameters:
  • cli_args (dict) – Arguments for constructing the scenario.

  • user_dict (dict) – Configuration for the translation.

list_scenarios()#

Return a list of scenarios in the configuration.

class r2x.config_scenario.Scenario(name=None, run_folder=None, output_folder=PosixPath('.'), input_model=None, output_model=None, input_config=None, output_config=None, feature_flags=<factory>, plugins=None, user_dict=None)#

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_scenario import Scenario

scenario = Scenario(name=”test”) print(scenario)

Parameters:
name#

Name of the translation scenario

Type:

str | None

run_folder#

Path to input model files

Type:

pathlib.Path | str | None

output_folder#

Path for placing the output translation files

Type:

pathlib.Path | str

input_model#

Model to translate from

Type:

str | None

output_model#

model to translate to

Type:

str | None

feature_flags#

Dictionary with experimental features

Type:

dict[str, Any]

plugins#

List of plugins enabled

Type:

list[Any] | None

user_dict#

Dictionary with user configuration.

Type:

dict[str, Any] | collections.ChainMap | None

See also

Configuration

classmethod from_kwargs(input_model, output_model, user_dict=None, **kwargs)#

Create Scenario instance from key arguments.

Parameters:
Return type:

Scenario

info()#

Return table summary of the configuration.

Return type:

None

r2x.config_scenario.get_scenario_configuration(cli_args, user_dict=None)#

Create configuration class using CLI arguments.

Parameters:
  • cli_args (dict)

  • user_dict (dict | None)

Return type:

Configuration