smif.data_layer package¶
Submodules¶
smif.data_layer.load module¶
Parse yaml config files, to construct sector models
-
smif.data_layer.load.
dump
(data, file_path)[source]¶ Write plain data to a file as yaml
Parameters: - file_path (str) – The path of the configuration file to write
- data – Data to write (should be lists, dicts and simple values)
-
smif.data_layer.load.
load
(file_path)[source]¶ Parse yaml config file into plain data (lists, dicts and simple values)
Parameters: file_path (str) – The path of the configuration file to parse
smif.data_layer.sector_model_config module¶
Read and parse the config for sector models
-
class
smif.data_layer.sector_model_config.
SectorModelReader
(initial_config=None)[source]¶ Bases:
object
Parses the configuration and input data for a sector model
Parameters: initial_config (dict) – Sector model details, sufficient to read the full config from a set of files. Must contain the following fields:
- “model_name”
- The name of the sector model, for reference within the system-of-systems model
- “model_path”
- The path to the python module file that contains an implementation of SectorModel
- “model_classname”
- The name of the class that implements SectorModel
- “model_config_dir”
- The root path of model config/data to use, which must contain inputs.yaml, outputs.yaml, time_intervals.yaml and regions.shp/regions.geojson
- “initial_conditions”
- List of files containing initial conditions
- “interventions”
- List of files containing interventions
-
data
¶ Expose all loaded config data
Returns: data – Model configuration data, with the following fields: “name”: The name of the sector model, for reference within the system-of-systems model“path”: The path to the python module file that contains an implementation of SectorModel
“classname”: The name of the class that implements SectorModel
“inputs”: A list of the inputs that this model requires
“outputs”: A list of the outputs that this model provides
“time_intervals”: A list of time intervals within a year that are represented by the model, each with reference to the model’s internal identifier for timesteps
“regions”: A list of geographical regions used within the model, as objects with both geography and attributes
“initial_conditions”: A list of initial conditions required to set up the modelled system in the base year
“interventions”: A list of possible interventions that could be made in the modelled system
Return type: dict
-
load_initial_conditions
()[source]¶ Inital conditions are located in yaml files specified in sector model blocks in the sos model config
smif.data_layer.sos_model_config module¶
Read and parse the config files for the system-of-systems model
-
class
smif.data_layer.sos_model_config.
SosModelReader
(config_file_path)[source]¶ Bases:
object
Encapsulates the parsing of the system-of-systems configuration
Parameters: config_file_path (str) – A path to the master config file -
data
¶ Expose all model configuration data
Returns: Returns a dictionary with the following keys: - timesteps
- the sequence of years
- max_iterations
- limit iterations for solving interdependencies
- sector_model_config: list
- The list of sector model configuration data
- scenario_data: dict
- A dictionary of scenario data, with the parameter name as the key and the data as the value
- planning: list
- A list of dicts of planning instructions
- region_sets: dict
- A dictionary of region set data, with the name as the key and the data as the value
- interval_sets: dict
- A dictionary of interval set data, with the name as the key and the data as the value
- resolution_mapping: dict
- The mapping of spatial and temporal resolutions to inputs, outputs and scenarios
Return type: dict
-
load_planning
()[source]¶ Loads the set of build instructions for planning
Returns: A list of planning instructions loaded from the planning file Return type: list
-
load_regions
()[source]¶ Model regions are specified in
data/<sectormodel>/regions.*
The file format must be possible to parse with GDAL, and must contain an attribute “name” to use as an identifier for the region.
-
load_scenario_data
()[source]¶ Load scenario data from list in sos model config
Working assumptions:
scenario data is list of dicts, each like:
{ 'parameter': 'parameter_name', 'file': 'relative file path', 'spatial_resolution': 'national' 'temporal_resolution': 'annual' }
data in file is list of dicts, each like:
{ 'value': 100, 'units': 'kg', # optional, depending on parameter type: 'region': 'UK', 'year': 2015 }
Returns: A dictionary where keys are parameters names and values are the file contents, so a list of dicts Return type: dict
-
load_sector_model_data
()[source]¶ Parse list of sector models to run
Model details include: - model name - model config directory - SectorModel class name to call
-
load_sos_config
()[source]¶ Parse model master config
- configures run mode
- sets max iterations for solving interdependencies
- points to timesteps file
- points to shared data files
- points to sector models and sector model data files
-
load_time_intervals
()[source]¶ Within-year time intervals are specified in
data/<sectormodel>/time_intervals.yaml
These specify the mapping of model timesteps to durations within a year (assume modelling 365 days: no extra day in leap years, no leap seconds)
Each time interval must have - start (period since beginning of year) - end (period since beginning of year) - id (label to use when passing between integration layer and sector model)
use ISO 8601[1]_ duration format to specify periods:
P[n]Y[n]M[n]DT[n]H[n]M[n]S
For example:
P1Y == 1 year P3M == 3 months PT168H == 168 hours
So to specify a period from the beginning of March to the end of May:
start: P2M end: P5M id: spring
References
[1] https://en.wikipedia.org/wiki/ISO_8601#Durations
-
smif.data_layer.validate module¶
Validate the correct format and presence of the config data for the system-of-systems model
-
exception
smif.data_layer.validate.
ValidationError
[source]¶ Bases:
Exception
Custom exception to use for parsing validation.
-
smif.data_layer.validate.
validate_initial_condition
(datum, file_path)[source]¶ Check a single initial condition datum
-
smif.data_layer.validate.
validate_initial_conditions
(data, file_path)[source]¶ Check a list of initial condition observations
-
smif.data_layer.validate.
validate_input_spec
(input_spec, model_name)[source]¶ Check the input specification for a single sector model
-
smif.data_layer.validate.
validate_interventions
(data, path)[source]¶ Validate the loaded data as required for model interventions
-
smif.data_layer.validate.
validate_output_spec
(output_spec, model_name)[source]¶ Check the output specification for a single sector model
-
smif.data_layer.validate.
validate_path_to_timesteps
(timesteps)[source]¶ Check timesteps is a path to timesteps file
-
smif.data_layer.validate.
validate_scenario_data
(data, file_path)[source]¶ Check a list of scenario observations
-
smif.data_layer.validate.
validate_scenario_datum
(datum, file_path)[source]¶ Check a single scenario datum
-
smif.data_layer.validate.
validate_sector_model_initial_config
(sector_model_config)[source]¶ Check a single sector model initial configuration
-
smif.data_layer.validate.
validate_sector_models_initial_config
(sector_models)[source]¶ Check list of sector models initial configuration
-
smif.data_layer.validate.
validate_sos_model_config
(data)[source]¶ Check expected values for data loaded from master config file
Module contents¶
Data access modules for loading system-of-systems model configuration