otoole package

Submodules

otoole.cli module

otoole.exceptions module

exception otoole.exceptions.OtooleException[source]

Bases: Exception

Base class for all otoole exceptions.

exception otoole.exceptions.OtooleRelationError(resource, foreign_resource, message)[source]

Bases: otoole.exceptions.OtooleException

Relations between input data is not correct

Parameters:
  • resource (str) – Name of the resource which is invalid
  • foreign_resource (str) – Name of the resource which is invalid
  • message (str) – Error message
exception otoole.exceptions.OtooleValidationError(resource, message)[source]

Bases: otoole.exceptions.OtooleException

Input data is invalid

Parameters:
  • resource (str) – Name of the resource which is invalid
  • message (str) – Error message

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.check_for_duplicates(codes: Sequence[T_co]) → bool[source]
otoole.validate.compose_expression(schema: List[T]) → str[source]

Generates a regular expression from a schema

Returns:
Return type:str
otoole.validate.compose_multi_expression(resource: List[T]) → str[source]

Concatenates multiple expressions using an OR operator

Use to validate elements using an OR operation e.g. the elements must match this expression OR the expression

otoole.validate.create_schema(config: Dict[str, Dict[KT, VT]] = None) → Dict[KT, VT][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.identify_orphaned_fuels_techs(package) → Dict[str, str][source]

Returns a list of fuels and technologies which are unconnected

Returns:
Return type:dict
otoole.validate.main(file_format: str, filepath: str, config=None)[source]
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_resource(package, resource: str, schemas: List[Dict[KT, VT]])[source]
Parameters:
  • package
  • resource (str) –
  • schemas (List[Dict]) – The schema from which to create a validation expression

Module contents

otoole.read_datapackage(filepath: str, sql: bool = False)[source]

Open an OSeMOSYS datapackage

Parameters:
  • filepath (str) –
  • sql (bool, default=False) –
otoole.read_packaged_file(filename: str, module_name: str = None)[source]