deflex.batch_model_scenario

deflex.batch_model_scenario(path, file_type=None, ignore_errors=True, flat_tuple=False, **kwargs)[source]

Model a single scenario in batch mode. By default errors will be ignored and returned together with the traceback.

Parameters:
  • path (str) – A valid deflex scenario.
  • file_type (str or None) – Type of the input data. Valid values are ‘csv’, ‘xlsx’, None. If the input is non the path should end on ‘csv’, ‘.xlsx’.
  • ignore_errors (bool) – Set True to stop the script if an error occurs for debugging. By default errors are ignored and returned.
  • flat_tuple (bool) – Return a normal tuple instead of a named tuple. This is needed for multi-process use. (default: False)
Other Parameters:
 
  • dump (str or bool) – Path to store the dump file. If True the results will be stored along with the scenarios using the same name and the suffix .dflx. If False no dump will be stored (default: True).
  • results (str or bool) – Path to store the results in an spreadsheet. If True the results will be stored along with the scenarios using the same name and the suffix _results.xlsx. If False no results will be stored (default: False).
  • solver (str) – The solver to use for the optimisation (default: cbc).
Returns:

Return type:

namedtuple

Examples

>>> from deflex import fetch_test_files
>>> fi = fetch_test_files("de02_heat_csv")
>>> r = batch_model_scenario(fi, ignore_errors=False)  # doctest: +ELLIPSIS
Welcome to the CBC MILP ...
>>> r.name
'de02_heat_csv'
>>> my_dump_file = r.dump
>>> os.path.basename(my_dump_file)
'de02_heat_csv.dflx'
>>> r.trace
>>> r.return_value.year > 2019
True
>>> f_wrong = os.path.join("wrong_file.xlsx")
>>> r = batch_model_scenario(f_wrong)
>>> r.name
'wrong_file.xlsx'
>>> repr(r.return_value)
"FileNotFoundError(2, 'No such file or directory')"
>>> r.results
>>> r.trace  # doctest: +ELLIPSIS
'Traceback (most recent call last):...
>>> os.remove(my_dump_file)