calliope.util.schema
¶
Load, update, and access attributes in the Calliope pre-defined YAML schemas.
MODEL_SCHEMA = load_config('model_def_schema.yaml')
module-attribute
¶
extract_from_schema(schema, keyword, subset_top_level=None)
¶
Extract a keyword for each leaf property in the schema.
This currently only reliably works for "default". Other keywords exist at branch properties, which confuses the extraction process.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
schema
|
dict
|
Schema to extract keyword from |
required |
keyword
|
str
|
property key to extract |
required |
subset_top_level
|
Literal['nodes', 'techs', 'parameters'] | None
|
Include only those properties that are leaves along a specific top-level property branch. Defaults to None (all property branches are included). |
None
|
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
Flat dictionary of property name : keyword value. Property trees are discarded since property names must be unique. |
Source code in src/calliope/util/schema.py
reset()
¶
update_model_schema(top_level_property, new_entries, allow_override=True)
¶
Update existing entries in the model schema or add a new parameter to the model schema.
Available attributes:
- title (str): Short description of the parameter.
- description (str): Long description of the parameter.
- type (str): expected type of entry. Pre-defined entries tend to use "\(ref: "#/\)defs/TechParamNullNumber" instead, to allow type to be either numeric or an indexed parameter.
- default (str): default value. This will be used in generating the optimisation problem.
- x-type (str): type of the non-NaN array entries in the internal calliope representation of the parameter.
- x-unit (str): Unit of the parameter to use in documentation.
- x-operate-param (bool): If True, this parameter's schema data will only be loaded into the optimisation problem if running in "operate" mode.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
top_level_property
|
Literal['nodes', 'techs', 'parameters']
|
Top-level key under which parameters are to be updated/added. |
required |
new_entries
|
dict
|
Data to update the schema with. |
required |
allow_override
|
bool
|
If True, allow existing entries in the schema to be overwritten. Defaults to True. |
True
|
Source code in src/calliope/util/schema.py
validate_dict(to_validate, schema, dict_descriptor)
¶
Validate a dictionary under a given schema.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
to_validate
|
dict
|
Dictionary to validate. |
required |
schema
|
dict
|
Schema to validate with. |
required |
dict_descriptor
|
str
|
Description of the dictionary to validate, to use if an error is raised. |
required |
Raises:
Type | Description |
---|---|
SchemaError
|
If the schema itself is malformed, a SchemaError will be raised at the first issue. Other issues than that raised may still exist. |
ModelError
|
If the dictionary is not valid according to the schema, a list of the issues found will be collated and raised. |