otoole package

Submodules

otoole.cli module

Provides a command line interface to the otoole package

The key functions are convert, cplex and viz.

The convert command allows convertion of multiple different OSeMOSYS input formats including from/to csv, an AMPL format datafile, a Tabular Data Package, a folder of CSVs, an Excel workbook with one tab per parameter, an SQLite database

The cplex command provides access to scripts which transform and process a CPLEX solution file into a format which is more readily processed - either to CBC or CSV format.

The viz command allows you to produce a Reference Energy System diagram from a Tabular Data Package.

Example

Ask for help on the command line:

>>> $ otoole --help
usage: otoole [-h] [--verbose] [--version] {convert,cplex,viz} ...

otoole: Python toolkit of OSeMOSYS users

positional arguments:
{convert,cplex,viz}
    convert            Convert from one input format to another
    cplex              Process a CPLEX solution file
    viz                Visualise the model

optional arguments:
-h, --help           show this help message and exit
--verbose, -v        Enable debug mode
--version, -V        The version of otoole
otoole.cli.conversion_matrix(args)[source]

from o ex cs dp sq df excel – yy csv nn – yy nn nn datapackage nn ?? – yy yy sql nn – yy datafile nn ?? yy –

otoole.cli.cplex2cbc(args)[source]
otoole.cli.datapackage2res(args)[source]
otoole.cli.get_parser()[source]
otoole.cli.main()[source]

otoole.validate module

Ensures that technology and fuel names match the convention

For example, to validate the following list of names, you would use the config shown below:

theseUNIQUE_ENTRY1
are__UNIQUE_ENTRY2
all__UNIQUE_ENTRY1
validUNIQUE_ENTRY2
entryUNIQUE_ENTRY1
in__UNIQUE_ENTRY2
a____UNIQUE_ENTRY1
list_UNIQUE_ENTRY2

Create a yaml validation config with the following format:

codes:
  some_valid_codes:
    UNIQUE_ENTRY1: Description of unique entry 1
    UNIQUE_ENTRY2: Description of unique entry 2
schema:
  schema_name:
  - name: first_entry_in_schema
    valid: ['these', 'are__', 'all__', 'valid', 'entry', 'in__', 'a____', 'list_']
    position: (1, 5) # a tuple representing the start and end position
  - name: second_entry_in_schema
    valid: some_valid_codes  # references an entry in the codes section of the config
    position: (6, 19) # a tuple representing the start and end position
otoole.validate.compose_expression(schema: List[T]) → str[source]

Generates a regular expression from a schema

Returns:
Return type:str
otoole.validate.create_schema(config: Dict[KT, VT] = None)[source]

Populate the dict of schema with codes from the validation config

Parameters:config (dict, default=None) – A configuration dictionary containing codes and schema keys
otoole.validate.read_validation_config()[source]
otoole.validate.validate(expression: str, name: str) → bool[source]

Determine if name matches the expression

Parameters:
  • expression (str) –
  • name (str) –
Returns:

Return type:

bool

otoole.validate.validate_fuel_name(name: str) → bool[source]

Validate a fuel name

Parameters:
  • name (str) –
  • country_codes (list) –
  • fuel_codes (list) –
Returns:

  • True if name is valid according to country_codes and fuel_codes
  • otherwise False

Module contents

otoole.read_packaged_file(filename: str, module_name: str = None)[source]