smif.data_layer.data_interface module¶
This module provides a common data interface to smif
raises: |
|
---|
Reference¶
-
class
smif.data_layer.data_interface.
DataInterface
[source]¶ Bases:
object
Abstract base class to define common data interface
-
read_model_runs
()[source]¶ Read all system-of-system model runs
Returns: A list of model_run dicts Return type: list
-
read_model_run
(model_run_name)[source]¶ Read a system-of-system model run
Parameters: model_run_name (str) – A model_run name Returns: model_run – A model_run dictionary Return type: dict
-
write_model_run
(model_run)[source]¶ Write system-of-system model run
Parameters: model_run (dict) – A model_run dictionary
-
delete_model_run
(model_run_name)[source]¶ Delete a system-of-system model run
Parameters: model_run_name (str) – A 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
(skip_coords=False)[source]¶ Read all sector models
sector_models.yml
Returns: A list of sector_model dicts Return type: list
-
read_sector_model
(sector_model_name, skip_coords=False)[source]¶ Read a sector model
Parameters: sector_model_name (str) – A sector_model name Returns: sector_model – A sector_model dictionary Return type: dict
-
read_sector_model_parameter
(sector_model_name, parameter_name)[source]¶ Read a sector model parameter
Parameters: Returns: parameter – A parameter (spec) dictionary
Return type:
-
read_sector_model_parameter_default
(sector_model_name, parameter_name)[source]¶ Read default data for a sector model parameter
Parameters: Returns: data
Return type:
-
write_sector_model_parameter_default
(sector_model_name, parameter_name, data)[source]¶ Write default data for a sector model parameter
Parameters: - sector_model_name (str) – A sector_model name
- parameter_name (str) – A parameter name
- data (smif.data_layer.data_array.DataArray) –
-
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_strategies
(modelrun_name)[source]¶ Read strategies for a given model_run
Parameters: modelrun_name (str) – Name of the model run for which to read the strategies Returns: List of strategy definition dicts Return type: list
-
write_strategies
(modelrun_name, strategies)[source]¶ Write strategies for a given model_run
Parameters:
-
read_interventions
(sector_model_name)[source]¶ Read interventions data for sector_model_name
Returns: A dict of intervention dictionaries containing intervention attributes keyed by intervention name Return type: dict of dict
-
read_initial_conditions
(sector_model_name)[source]¶ Read historical interventions for sector_model_name
Returns: A list of historical interventions Return type: list
-
read_all_initial_conditions
(model_run_name)[source]¶ A list of all historical interventions
Returns: Return type: list
-
read_state
(modelrun_name, timestep, decision_iteration=None)[source]¶ Read list of (name, build_year) for a given modelrun, timestep, decision
Parameters:
-
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_unit_definitions
()[source]¶ Reads custom unit definitions
Returns: List of str which are valid Pint unit definitions Return type: list
-
read_dimensions
()[source]¶ Read dimensions from project configuration
Returns: A list of dimension dicts Return type: list
-
read_dimension
(dimension_name)[source]¶ Return dimension
Parameters: dimension_name (str) – Name of the dimension Returns: A dimension definition (including elements) Return type: dict
-
write_dimension
(dimension)[source]¶ Write dimension to project configuration
Parameters: dimension (dict) – A dimension dict Notes
Unused
-
delete_dimension
(dimension_name)[source]¶ Delete dimension
Parameters: dimension_name (str) – Name of the (original) entry Notes
Unused
-
read_coefficients
(source_spec, destination_spec)[source]¶ Reads coefficients from the store
Coefficients are uniquely identified by their source/destination specs. This method and write_coefficients implement caching of conversion coefficients between dimensions.
Parameters: - source_spec (smif.metadata.Spec) –
- destination_spec (smif.metadata.Spec) –
Notes
To be called from
Adaptor
implementations.
-
write_coefficients
(source_spec, destination_spec, data)[source]¶ Writes coefficients to the store
Coefficients are uniquely identified by their source/destination specs. This method and read_coefficients implement caching of conversion coefficients between dimensions.
Parameters: - source_spec (smif.metadata.Spec) –
- destination_spec (smif.metadata.Spec) –
- data (numpy.ndarray) –
Notes
To be called from
Adaptor
implementations.
-
read_scenarios
(skip_coords=False)[source]¶ Read scenarios from project configuration
Returns: A list of scenario dicts Return type: list
-
read_scenario
(scenario_name, skip_coords=False)[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
-
update_scenario
(scenario_name, scenario)[source]¶ Update scenario to project configuration
Parameters:
-
delete_scenario
(scenario_name)[source]¶ Delete scenario from project configuration
Parameters: scenario_name (str) – A scenario name
-
read_scenario_variants
(scenario_name)[source]¶ Read scenarios from project configuration
Returns: A list of scenario dicts Return type: list
-
read_scenario_variant
(scenario_name, variant_name)[source]¶ Read a scenario
Parameters: scenario_name (str) – Name of the scenario Returns: A scenario dictionary Return type: dict
-
write_scenario_variant
(scenario_name, variant)[source]¶ Write scenario to project configuration
Parameters: scenario (dict) – A scenario dict
-
update_scenario_variant
(scenario_name, variant_name, variant)[source]¶ Update scenario to project configuration
Parameters:
-
delete_scenario_variant
(scenario_name, variant_name)[source]¶ Delete scenario from project configuration
Parameters: scenario_name (str) – A scenario name
-
read_scenario_variant_data
(scenario_name, variant_name, variable, timestep=None)[source]¶ Read scenario data file
Parameters: Returns: data
Return type: Notes
Called from smif.data_layer.data_handle
-
write_scenario_variant_data
(scenario_name, variant_name, data_array, timestep=None)[source]¶ Write scenario data file
Parameters: - scenario_name (str) – Name of the scenario
- variant_name (str) – Name of the scenario variant
- data_array (smif.data_layer.data_array.DataArray) – Contains the annotated data
- timestep (int (optional)) – If None, read data for all timesteps
Notes
Called from smif.data_layer.data_handle
-
read_narrative_variant_data
(sos_model_name, narrative_name, variant_name, parameter_name, timestep=None)[source]¶ Read narrative data file
Parameters: Returns: Return type:
-
write_narrative_variant_data
(sos_model_name, narrative_name, variant_name, data_array, timestep=None)[source]¶ Read narrative data file
Parameters: - sos_model_name (str) – The name of the sos_model to which the narrative belongs
- narrative_name (str) – Name of the narrative
- data_array (smif.data_layer.data_array.DataArray) – Contains the annotated data to write
- timestep (int (optional)) – Timestep
-
read_results
(modelrun_name, model_name, output_spec, timestep=None, decision_iteration=None)[source]¶ Return results of a model_name in modelrun_name for a given output_name
Parameters: Returns: Return type: Notes
Called from smif.data_layer.data_handle
-
write_results
(data_array, modelrun_name, model_name, timestep=None, decision_iteration=None)[source]¶ Write results of a model_name in modelrun_name for a given output_name
Parameters: - data_array (smif.data_layer.data_array.DataArray) –
- modelrun_id (str) –
- model_name (str) –
- timestep (int, optional) –
- decision_iteration (int, optional) –
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
-
static
ndarray_to_data_list
(data_array, timestep=None)[source]¶ Convert
numpy.ndarray
to list of observationsParameters: - data_array (smif.data_layer.data_array.DataArray) –
- timestep (int, default=None) –
Returns: observations – Each dict has keys: one for the variable name, one for each dimension in spec.dims, and optionally one for the given timestep
Return type: list of dict
-
static
data_list_to_ndarray
(observations, spec)[source]¶ Convert list of observations to a
DataArray
Parameters: - observations (list of dict) – Required keys for each dict are: - one key to match spec.name - one key per dimension in spec.dims
- spec (smif.metadata.Spec) –
Returns: 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_namesSmifDataNotFoundError
– If the observations don’t include data for any dimension combinationSmifDataMismatchError
– If the dimension coordinate ids do not match the observations
-