smif.data_layer.memory_interface module

Memory-backed data interface

Summary

Classes:

MemoryInterface Read and write interface to main memory

Reference

class smif.data_layer.memory_interface.MemoryInterface[source]

Bases: smif.data_layer.data_interface.DataInterface

Read and write interface to main memory

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
update_model_run(model_run_name, model_run)[source]

Update system-of-system model run

Parameters:
  • model_run_name (str) – A model_run name
  • 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
update_sos_model(sos_model_name, sos_model)[source]

Update system-of-system model

Parameters:
  • sos_model_name (str) – A sos_model name
  • 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:
  • sector_model_name (str) – A sector_model name
  • parameter_name (str) – A parameter name
Returns:

parameter – A parameter (spec) dictionary

Return type:

dict

read_sector_model_parameter_default(sector_model_name, parameter_name)[source]

Read default data for a sector model parameter

Parameters:
  • sector_model_name (str) – A sector_model name
  • parameter_name (str) – A parameter name
Returns:

data

Return type:

smif.data_layer.data_array.DataArray

write_sector_model_parameter_default(sector_model_name, parameter_name, data)[source]

Write default data for a sector model parameter

Parameters:
write_sector_model(sector_model)[source]

Write sector model

Parameters:sector_model (dict) – A sector_model dictionary
update_sector_model(sector_model_name, sector_model)[source]

Update sector model

Parameters:
  • sector_model_name (str) – A sector_model name
  • 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_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_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:
  • modelrun_name (str) – Name of the model run for which to read the strategies
  • strategies (list[dict]) – List of strategy definitions
read_initial_conditions(sector_model_name)[source]

Read historical interventions for sector_model_name

Returns:A list of historical interventions
Return type:list
read_state(modelrun_name, timestep=None, decision_iteration=None)[source]

Read list of (name, build_year) for a given modelrun, timestep, decision

Parameters:
  • modelrun_name (str) –
  • timestep (int) –
  • decision_iteration (int, default=None) –
write_state(state, modelrun_name, timestep=None, decision_iteration=None)[source]

State is a list of decision dicts with name and build_year keys,

State is output from the DecisionManager

Parameters:
  • state (list) –
  • modelrun_name (str) –
  • timestep (int) –
  • decision_iteration (int, default=None) –
write_unit_definitions(units)[source]
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

update_dimension(dimension_name, dimension)[source]

Update dimension

Parameters:
  • dimension_name (str) – Name of the (original) entry
  • dimension (dict) – The updated 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:
  • scenario_name (str) – Name of the (original) entry
  • scenario (dict) – The updated scenario dict
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:
  • scenario_name (str) – Name of the (original) entry
  • scenario (dict) – The updated scenario dict
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:
  • scenario_name (str) – Name of the scenario
  • variant_name (str) – Name of the scenario variant
  • variable (str) – Name of the variable (facet)
  • timestep (int (optional)) – If None, read data for all timesteps
Returns:

data

Return type:

numpy.ndarray

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:
  • sos_model_name (str) – The name of the sos_model to which the narrative belongs
  • narrative_name (str) – Name of the narrative
  • variant_name (str) – Narrative variant to use
  • parameter_name (str) – Variable (parameter) to read
  • timestep (int (optional)) – Timestep
Returns:

Return type:

smif.data_layer.data_array.DataArray

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:
  • modelrun_id (str) –
  • model_name (str) –
  • output_spec (smif.metadata.Spec) –
  • timestep (int, default=None) –
  • decision_iteration (int, default=None) –
Returns:

Return type:

smif.data_layer.data_array.DataArray

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:

Notes

Called from smif.data_layer.data_handle

prepare_warm_start(modelrun_name)[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