smif.data_layer.data_interface module¶
This module provides a common data interface to smif
raises: |
|
---|
Summary¶
Exceptions:
DataExistsError |
Raise when some data is found unexpectedly |
DataMismatchError |
Raise when some data doesn’t match the context |
DataNotFoundError |
Raise when some data is not found |
Classes:
DataInterface |
Abstract base class to define common data interface |
Reference¶
-
class
smif.data_layer.data_interface.
DataInterface
[source]¶ Bases:
object
Abstract base class to define common data interface
-
read_units_file_name
()[source]¶ Reads the unit definition file name from the store
Returns: Path to the units file Return type: str
-
read_sos_model_runs
()[source]¶ Read all system-of-system model runs
Returns: A list of sos_model_run dicts Return type: list
-
read_sos_model_run
(sos_model_run_name)[source]¶ Read a system-of-system model run
Parameters: sos_model_run_name (str) – A sos_model_run name Returns: sos_model_run – A sos_model_run dictionary Return type: dict
-
write_sos_model_run
(sos_model_run)[source]¶ Write system-of-system model run
Parameters: sos_model_run (dict) – A sos_model_run dictionary
-
update_sos_model_run
(sos_model_run_name, sos_model_run)[source]¶ Update system-of-system model run
Parameters:
-
delete_sos_model_run
(sos_model_run)[source]¶ Delete a system-of-system model run
Parameters: sos_model_run_name (str) – A sos_model_run name
-
read_sos_models
()[source]¶ Read all system-of-system models
Returns: A list of sos_model dicts Return type: list
-
read_sos_model
(sos_model_name)[source]¶ Read a specific system-of-system model
Parameters: sos_model_name (str) – A sos_model name Returns: sos_model – A sos_model dictionary Return type: dict
-
write_sos_model
(sos_model)[source]¶ Write system-of-system model
Parameters: sos_model (dict) – A sos_model dictionary
-
delete_sos_model
(sos_model_name)[source]¶ Delete a system-of-system model
Parameters: sos_model_name (str) – A sos_model name
-
read_sector_models
()[source]¶ Read all sector models
sector_models.yml
Returns: A list of sector_model dicts Return type: list
-
read_sector_model
(sector_model_name)[source]¶ Read a sector model
Parameters: sector_model_name (str) – A sector_model name Returns: sector_model – A sector_model dictionary Return type: dict
-
write_sector_model
(sector_model)[source]¶ Write sector model
Parameters: sector_model (dict) – A sector_model dictionary
-
delete_sector_model
(sector_model_name)[source]¶ Delete a sector model
Parameters: sector_model_name (str) – A sector_model name
-
read_state
(modelrun_name, timestep, decision_iteration=None)[source]¶ Read list of (name, build_year) for a given modelrun, timestep, decision
-
write_state
(state, modelrun_name, timestep, decision_iteration=None)[source]¶ State is a list of decision dicts with name and build_year keys,
State is output from the DecisionManager
Parameters:
-
read_region_definitions
()[source]¶ Read region_definitions from project configuration
Returns: A list of region_definition dicts Return type: list
-
read_region_definition_data
(region_definition_name)[source]¶ Read region_definition data file into a Fiona feature collection
The file format must be possible to parse with GDAL, and must contain an attribute “name” to use as an identifier for the region_definition.
Parameters: region_definition_name (str) – Name of the region_definition Returns: A list of data from the specified file in a fiona formatted dict Return type: list
-
read_region_names
(region_definition_name)[source]¶ Return the set of unique region names in region set region_definition_name
Parameters: region_definition_name (str) – Name of the region_definition Returns: Return type: list
-
write_region_definition
(region_definition)[source]¶ Write region_definition to project configuration
Parameters: region_definition (dict) – A region_definition dict Notes
Unused
-
update_region_definition
(region_definition)[source]¶ Update region_definition to project configuration
Parameters: Notes
Unused
-
read_interval_definitions
()[source]¶ Read interval_definition sets from project configuration
Returns: A list of interval_definition set dicts Return type: list
-
read_interval_definition_data
(interval_definition_name)[source]¶ Read data for an interval definition
Parameters: interval_definition_name (str) – Returns: Interval definition data Return type: dict Notes
Expects headings of id, start, end
-
read_interval_names
(interval_definition_name)[source]¶ Reads the unique set of interval names
Parameters: interval_definition_name (str) – Returns: Return type: list
-
write_interval_definition
(interval_definition)[source]¶ Write interval_definition to project configuration
Parameters: interval_definition (dict) – A interval_definition dict Notes
Unused
-
update_interval_definition
(interval_definition)[source]¶ Update interval_definition to project configuration
Parameters:
-
read_scenario_set_scenario_definitions
(scenario_set_name)[source]¶ Read all scenarios from a certain scenario_set
Parameters: scenario_set_name (str) – Name of the scenario_set Returns: A list of scenarios within the specified scenario_set_name Return type: list Notes
Unused
-
read_scenario_definition
(scenario_name)[source]¶ Read scenario definition data
Parameters: scenario_name (str) – Name of the scenario Returns: The scenario definition Return type: dict
-
read_scenario_sets
()[source]¶ Read scenario sets from project configuration
Returns: A list of scenario set dicts Return type: list
-
read_scenario_set
(scenario_set_name)[source]¶ Read a scenario_set
Parameters: scenario_set_name (str) – Name of the scenario_set Returns: Scenario set definition Return type: dict
-
write_scenario_set
(scenario_set)[source]¶ Write scenario_set to project configuration
Parameters: scenario_set (dict) – A scenario_set dict
-
update_scenario_set
(scenario_set_name, scenario_set)[source]¶ Update scenario_set to project configuration
Parameters:
-
delete_scenario_set
(scenario_set_name)[source]¶ Delete scenario_set from project configuration and all scenarios within scenario_set
Parameters: scenario_set_name (str) – A scenario_set name
-
read_scenarios
()[source]¶ Read scenarios from project configuration
Returns: A list of scenario dicts Return type: list
-
read_scenario
(scenario_name)[source]¶ Read a scenario
Parameters: scenario_name (str) – Name of the scenario Returns: A scenario dictionary Return type: dict
-
write_scenario
(scenario)[source]¶ Write scenario to project configuration
Parameters: scenario (dict) – A scenario dict
-
delete_scenario
(scenario_name)[source]¶ Delete scenario from project configuration
Parameters: scenario_name (str) – A scenario name
-
read_scenario_data
(scenario_name, facet_name, spatial_resolution, temporal_resolution, timestep)[source]¶ Read scenario data file
Parameters: Returns: data
Return type: Notes
Called from smif.data_layer.data_handle
-
read_narrative_sets
()[source]¶ Read narrative sets from project configuration
Returns: A list of narrative set dicts Return type: list
-
read_narrative_set
(narrative_set_name)[source]¶ Read all narratives from a certain narrative_set
Parameters: narrative_set_name (str) – Name of the narrative_set Returns: A narrative_set dictionary Return type: list
-
write_narrative_set
(narrative_set)[source]¶ Write narrative_set to project configuration
Parameters: narrative_set (dict) – A narrative_set dict
-
update_narrative_set
(narrative_set)[source]¶ Update narrative_set to project configuration
Parameters:
-
delete_narrative_set
(narrative_set_name)[source]¶ Delete narrative_set from project configuration
Parameters: narrative_set_name (str) – A narrative_set name
-
read_narratives
()[source]¶ Read narrative sets from project configuration
Returns: A list of narrative set dicts Return type: list
-
read_narrative
(narrative_name)[source]¶ Read all narratives from a certain narrative
Parameters: narrative_name (str) – Name of the narrative Returns: A narrative dictionary Return type: list
-
write_narrative
(narrative)[source]¶ Write narrative to project configuration
Parameters: narrative (dict) – A narrative dict
-
delete_narrative
(narrative_name)[source]¶ Delete narrative from project configuration
Parameters: narrative_name (str) – A narrative name
-
read_narrative_data
(narrative_name)[source]¶ Read narrative data file
Parameters: narrative_name (str) – Name of the narrative Returns: A list with dictionaries containing the contents of ‘narrative_name’ data file Return type: list
-
read_coefficients
(source_name, destination_name)[source]¶ Reads coefficients from the store
Coefficients are uniquely identified by their source/destination names. This method and write_coefficients implement caching of conversion coefficients between dimensions.
Parameters: Notes
Both source_name and destination_name should reference names of elements from the same ResolutionSet (e.g. both spatial or temporal resolutions)
Called from smif.convert.register
-
write_coefficients
(source_name, destination_name, data)[source]¶ Writes coefficients to the store
- Coefficients are uniquely identified by their source/destination names.
This method and read_coefficients implement caching of conversion coefficients between dimensions.
- source_name : str
- The name of a ResolutionSet
- destination_name : str
- The name of a ResolutionSet
data : numpy.ndarray
Both source_name and destination_name should reference names of elements from the same ResolutionSet (e.g. both spatial or temporal resolutions)
Called from smif.convert.register
-
read_results
(modelrun_name, model_name, output_name, spatial_resolution, temporal_resolution, timestep=None, modelset_iteration=None, decision_iteration=None)[source]¶ Return results of a model_name in modelrun_name for a given output_name
Parameters: Returns: data
Return type: Notes
Called from smif.data_layer.data_handle
-
prepare_warm_start
(modelrun_id)[source]¶ Copy the results from the previous modelrun if available
The method allows a previous unsuccessful modelrun to ‘warm start’ a new model run from a later timestep. Model results are recovered from the timestep that the previous modelrun was run until, and the new model run runs from the returned timestep
Parameters: modelrun_id (str) – The name of the modelrun to recover Returns: The timestep to which the data store was recovered Return type: int Notes
Called from smif.controller.execute
-
write_results
(modelrun_name, model_name, output_name, data, spatial_resolution, temporal_resolution, timestep=None, modelset_iteration=None, decision_iteration=None)[source]¶ Write results of a model_name in modelrun_name for a given output_name
Parameters: Notes
Called from smif.data_layer.data_handle
-
read_parameters
(modelrun_name, model_name)[source]¶ Read global and model-specific parameter values for a given modelrun and model.
Notes
Called from smif.data_layer.data_handle
-
static
ndarray_to_data_list
(data, region_names, interval_names, timestep=None)[source]¶ Convert
numpy.ndarray
to list of observationsParameters: - data (numpy.ndarray) –
- region_names (list of str) –
- interval_names (list of str) –
- timestep (int or None) –
Returns: observations – Each dict has keys: ‘region’ (a region name), ‘interval’ (an interval name) and ‘value’.
Return type: list of dict
-
static
data_list_to_ndarray
(observations, region_names, interval_names)[source]¶ Convert list of observations to
numpy.ndarray
Parameters: Returns: data
Return type: Raises: KeyError
– If an observation is missing a required keyValueError
– If an observation region or interval is not in region_names or interval_namesDataNotFoundError
– If the observations don’t include data for any region/interval combinationDataMismatchError
– If the region_names and interval_names do not match the observations
-
-
exception
smif.data_layer.data_interface.
DataNotFoundError
[source]¶ Bases:
Exception
Raise when some data is not found