Parsers#

Concrete class to handler parser models.

This module provides the abstract class to create parser objects.

class r2x.parser.handler.BaseParser(config, data=<factory>)

Class that defines the shared methods of parsers.

Note

This class is meant to be use for developing new parsers. Do not use it directly.

Parameters:
config

Scenario configuration

Type:

Scenario

data

We save each file read in a data dictionary

Type:

dict

get_data(key='load')

Return the parsed data for load.

Parameters:

key (str)

Return type:

Any

read_file(fpath='load.csv')

Read load data.

Parameters:
parse_data()

Read all files from a configuration file map.

Parameters:
Return type:

None

abstract build_system()

Create the infra_sys model.

Return type:

System

get_data(key)

Return data.

Parameters:

key (str)

Return type:

Any

parse_data(*, base_folder, fmap, filter_func=None, **kwargs)

Parse all the data for the given translation.

Parameters:
Return type:

None

read_file(fpath, filter_funcs=None, **kwargs)

Read input model data from the file system.

Currently supported formats:
  • .csv

  • .h5

  • .xml

More to come!

Parameters:
  • fpath (Path, str) – Absolute location of the file in the system

  • filter_func (List) – Filter functions to apply

  • filter_funcs (list[Callable] | None)

class r2x.parser.handler.PCMParser(config, data=<factory>)

Class defining shared methods for PCM (currently plexos and sienna) parsers.

Parameters:
r2x.parser.handler.file_handler(fpath, optional=False, **kwargs)

Return FileHandler based on file extension.

Raises:
Parameters:
Return type:

LazyFrame | Sequence | XMLHandler | None

r2x.parser.handler.get_parser_data(config, parser_class, filter_funcs=None, **kwargs)

Return parsed system.

This function will create the ReEDS DataPortal and populate with the most common set of data needed

Paremters#

config Scenario configuration class parser

Parser to process

filter_func

Functions that will applied to read_data process

param kwargs:
year

For filtering by solve year

year_column

To change the column to apply the filter

column_mapping

For renaming columns

See also

BaseParser, pl_filter_year, pl_lower_case, pl_rename

Parameters:
Return type:

BaseParser

ReEDS#

Functions related to parsers.

class r2x.parser.reeds.ReEDSParser(*args, **kwargs)#

ReEDS parser class.

build_system()#

Create IS system for the ReEDS model.

Return type:

System

get_data(key)#

Return data.

Parameters:

key (str)

Return type:

Any

parse_data(*, base_folder, fmap, filter_func=None, **kwargs)#

Parse all the data for the given translation.

Parameters:
Return type:

None

read_file(fpath, filter_funcs=None, **kwargs)#

Read input model data from the file system.

Currently supported formats:
  • .csv

  • .h5

  • .xml

More to come!

Parameters:
  • fpath (Path, str) – Absolute location of the file in the system

  • filter_func (List) – Filter functions to apply

  • filter_funcs (list[Callable] | None)

r2x.parser.reeds.cli_arguments(parser)#

CLI arguments for the plugin.

Parameters:

parser (ArgumentParser)

Sienna#

Plexos#

Functions related to parsers.

class r2x.parser.plexos.PlexosParser(*args, xml_file=None, **kwargs)#

Plexos parser class.

Parameters:

xml_file (str | None)

build_system()#

Create infrasys system.

Return type:

System

get_data(key)#

Return data.

Parameters:

key (str)

Return type:

Any

parse_data(*, base_folder, fmap, filter_func=None, **kwargs)#

Parse all the data for the given translation.

Parameters:
Return type:

None

read_file(fpath, filter_funcs=None, **kwargs)#

Read input model data from the file system.

Currently supported formats:
  • .csv

  • .h5

  • .xml

More to come!

Parameters:
  • fpath (Path, str) – Absolute location of the file in the system

  • filter_func (List) – Filter functions to apply

  • filter_funcs (list[Callable] | None)

r2x.parser.plexos.cli_arguments(parser)#

CLI arguments for the plugin.

Parameters:

parser (ArgumentParser)