smif.data_layer.results module

Results provides a common interface to access results from model runs.

Summary

Data:

Results Common interface to access results from model runs.

Reference

class smif.data_layer.results.Results(store: Union[smif.data_layer.store.Store, dict])[source]

Bases: object

Common interface to access results from model runs.

Parameters:store (Store or dict) – pre-created Store object or dictionary of the form {‘interface’: <interface>, ‘dir’: <dir>} where <interface> is either ‘local_csv’ or ‘local_parquet’, and <dir> is the model base directory
list_model_runs()[source]

Return a list of model run names.

Returns:
Return type:List of model run names
list_sector_models(model_run_name: str)[source]

Return a list of sector models for given model run.

Parameters:model_run_name (str the requested model run) –
Returns:
Return type:List of sector models for the given model run
list_scenarios(model_run_name: str)[source]

Return a dictionary of scenarios for given model run.

Parameters:model_run_name (str the requested model run) –
Returns:
Return type:Dictionary of (scenario name, variant) for the given model run.
list_scenario_outputs(scenario_name: str)[source]

Return a list of outputs of a given scenario.

Parameters:scenario_name (str the requested scenario) –
Returns:
Return type:List of outputs for the requested scenario
list_outputs(sector_model_name: str)[source]

Return a list of model run names.

Parameters:sector_model_name (str the requested sector model) –
Returns:
Return type:List of outputs for the given sector model
available_results(model_run_name)[source]

Return the results available for a given model run.

Parameters:model_run_name (str the requested model run) –
Returns:
Return type:A nested dictionary data structure of the results available for the given model run
read_results(model_run_names: list, model_names: list, output_names: list, timesteps: list = None, decisions: list = None, time_decision_tuples: list = None)[source]

Return results from the store as a formatted pandas data frame. There are a number of ways of requesting specific timesteps/decisions. You can specify either:

a list of (timestep, decision) tuples
in which case data for all of those tuples matching the available results will be returned
or:
a list of timesteps
in which case data for all of those timesteps (and any decision iterations) matching the available results will be returned
or:
a list of decision iterations
in which case data for all of those decision iterations (and any timesteps) matching the available results will be returned
or:
a list of timesteps and a list of decision iterations
in which case data for the Cartesian product of those timesteps and those decision iterations matching the available results will be returned
or:
nothing
in which case all available results will be returned
Parameters:
  • model_run_names (list) – the requested model run names
  • model_names (list) – the requested sector model names (exactly one required)
  • output_names (list) – the requested output names (output specs must all match)
  • timesteps (list) – the requested timesteps
  • decisions (list) – the requested decision iterations
  • time_decision_tuples (list) – a list of requested (timestep, decision) tuples
Raises:
  • SmifDataNotFoundError – If data cannot be found in the store when try to read from the store
  • SmifDataMismatchError – Data presented to read, write and update methods is in the incorrect format or of wrong dimensions to that expected
  • SmifDataReadError – When unable to read data e.g. unable to handle file type or connect to database
Returns:

Return type:

pandas.DataFrame

read_scenario_data(scenario_name: str, variant_name: str, variable_name: str, timesteps: list) → <MagicMock id='139764769550240'>[source]

Return scenario variant data from the store as a formatted pandas data frame.

Parameters:
  • scenario_name (str) – the requested scenario name
  • variant_name (str) – the requested scenario variant name
  • variable_name (str) – the requested output variable name that the requested scenario provides
  • timesteps (list) – the requested timesteps
Raises:
  • SmifDataNotFoundError – If data cannot be found in the store when try to read from the store
  • SmifDataMismatchError – Data presented to read, write and update methods is in the incorrect format or of wrong dimensions to that expected
  • SmifDataReadError – When unable to read data e.g. unable to handle file type or connect to database
Returns:

Return type:

pandas.DataFrame

get_units(output_name: str)[source]

Return the units of a given output.

Parameters:output_name (str) –
Returns:
Return type:str
validate_names(model_run_names, sec_model_names, output_names)[source]