smif.data_layer.data_interface module

Common data interface

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_coefficients(source_name, destination_name)[source]
write_coefficients(source_name, destination_name, data)[source]
read_units_file_name()[source]
read_sos_model_runs()[source]
read_sos_model_run(sos_model_run_name)[source]
write_sos_model_run(sos_model_run)[source]
update_sos_model_run(sos_model_run_name, sos_model_run)[source]
delete_sos_model_run(sos_model_run)[source]
read_sos_models()[source]
write_sos_model(sos_model)[source]
update_sos_model(sos_model_name, sos_model)[source]
read_sector_models()[source]
read_sector_model(sector_model_name)[source]
write_sector_model(sector_model)[source]
update_sector_model(sector_model_name, sector_model)[source]
read_region_definitions()[source]
read_region_definition_data(region_definition_name)[source]
write_region_definition(region_definition)[source]
update_region_definition(region_definition)[source]
read_interval_definitions()[source]
read_interval_definition_data(interval_definition_name)[source]
write_interval_definition(interval_definition)[source]
update_interval_definition(interval_definition)[source]
read_scenario_sets()[source]
read_scenario_set(scenario_set_name)[source]
write_scenario_set(scenario_set)[source]
update_scenario_set(scenario_set)[source]
read_scenario_data(scenario_name, parameter_name, spatial_resolution, temporal_resolution, timestep)[source]
write_scenario(scenario)[source]
update_scenario(scenario)[source]
read_narrative_sets()[source]
read_narrative_set(narrative_set_name)[source]
write_narrative_set(narrative_set)[source]
update_narrative_set(narrative_set)[source]
read_narrative_data(narrative_name)[source]
write_narrative(narrative)[source]
update_narrative(narrative)[source]
read_parameters(modelrun_name, model_name)[source]

Read global and model-specific parameter values for a given modelrun and model.

read_results(modelrun_name, model_name, output_name, spatial_resolution, temporal_resolution, timestep=None, modelset_iteration=None, decision_iteration=None)[source]
write_results(modelrun_name, model_name, output_name, data, spatial_resolution, temporal_resolution, timestep=None, modelset_iteration=None, decision_iteration=None)[source]
static ndarray_to_data_list(region_names, interval_names)[source]

Convert numpy.ndarray to list of observations

Parameters:
  • data (numpy.ndarray) –
  • region_names (list of str) –
  • interval_names (list of str) –
Returns:

observations – Each dict has keys: ‘region’ (a region name), ‘interval’ (an interval name) and ‘value’.

Return type:

list of dict

static ndarray_to_buffer()[source]

Serialize numpy.ndarray and metadata to a byte buffer

Parameters:data (numpy.ndarray) –
Returns:Byte buffer containing the serialized input
Return type:pyarrow.lib.Buffer
static data_list_to_ndarray(region_names, interval_names)[source]

Convert list of observations to numpy.ndarray

Parameters:
  • observations (list of dict) – Required keys for each dict are ‘region’ (a region name), ‘interval’ (an interval name) and ‘value’.
  • region_names (list) – A list of unique region names
  • interval_names (list) – A list of unique interval names
Returns:

data

Return type:

numpy.ndarray

Raises:
  • KeyError – If an observation is missing a required key
  • ValueError – If an observation region or interval is not in region_names or interval_names
  • DataNotFoundError – If the observations don’t include data for any region/interval combination
exception smif.data_layer.data_interface.DataNotFoundError[source]

Bases: Exception

Raise when some data is not found

exception smif.data_layer.data_interface.DataExistsError[source]

Bases: Exception

Raise when some data is found unexpectedly

exception smif.data_layer.data_interface.DataMismatchError[source]

Bases: Exception

Raise when some data doesn’t match the context

E.g. when updating an object by id, the updated object’s id must match the id provided separately.