smif.data_layer.data_handle module¶
Provide an interface to data, parameters and results
A DataHandle
is passed in to a Model
at runtime, to provide
transparent access to the relevant data and parameters for the current
ModelRun
and iteration. It gives read access to parameters and input
data (at any computed or pre-computed timestep) and write access to output data
(at the current timestep).
Summary¶
Exceptions:
DataError |
Raise on attempts at invalid data access (get/set) |
TimestepResolutionError |
Raise when timestep cannot be resolved |
Classes:
DataHandle |
Get/set model parameters and data |
RelativeTimestep |
Specify current, previous or base year timestep |
Functions:
element_before |
Return the element before a given element in a list, or None if the given element is first or not in the list. |
Reference¶
-
class
smif.data_layer.data_handle.
DataHandle
(store, modelrun_name, current_timestep, timesteps, model, modelset_iteration=None, decision_iteration=None)[source]¶ Bases:
object
Get/set model parameters and data
-
derive_for
(model)[source]¶ Derive a new DataHandle configured for the given Model
Parameters: model (Model) – Model which will use this DataHandle
-
current_timestep
¶ Current timestep
-
previous_timestep
¶ Previous timestep
-
base_timestep
¶ Base timestep
-
timesteps
¶ All timesteps (as tuple)
-
get_state
()[source]¶ The current state of the model
Returns: Return type: A list of interventions installed at the current timestep
-
get_data
(input_name, timestep=None)[source]¶ Get data required for model inputs
Parameters: - input_name (str) –
- timestep (RelativeTimestep or int, optional) – defaults to RelativeTimestep.CURRENT
Returns: data – Two-dimensional array with shape (len(regions), len(intervals))
Return type:
-
get_base_timestep_data
(input_name)[source]¶ Get data from the base timestep as required for model inputs
Parameters: input_name (str) – Returns: data – Two-dimensional array with shape (len(regions), len(intervals)) Return type: numpy.ndarray
-
get_previous_timestep_data
(input_name)[source]¶ Get data from the previous timestep as required for model inputs
Parameters: input_name (str) – Returns: data – Two-dimensional array with shape (len(regions), len(intervals)) Return type: numpy.ndarray
-
get_parameter
(parameter_name)[source]¶ Get the value for a parameter
Parameters: parameter_name (str) – Returns: Return type: parameter_value
-
get_parameters
()[source]¶ Get all parameter values
Returns: parameters – Read-only view of parameters (like a read-only dict) Return type: MappingProxyType
-
set_results
(output_name, data)[source]¶ Set results values for model outputs
Parameters: - output_name (str) –
- data (numpy.ndarray) –
-
-
class
smif.data_layer.data_handle.
RelativeTimestep
[source]¶ Bases:
enum.Enum
Specify current, previous or base year timestep
-
CURRENT
= 1¶
-
PREVIOUS
= 2¶
-
BASE
= 3¶
-
ALL
= 4¶
-
-
exception
smif.data_layer.data_handle.
TimestepResolutionError
[source]¶ Bases:
Exception
Raise when timestep cannot be resolved