multi-vector-simulator
multi-vector-simulator copied to clipboard
Changes in B0_data_input_json.py cause a simulation termination
Changes in B0_data_input_json.py line 29:
KPI,
KPI_COST_MATRIX,
KPI_SCALAR_MATRIX,
LABEL,
line 343:
for kpi in (KPI_COST_MATRIX, KPI_SCALAR_MATRIX):
if not isinstance(dict_values[KPI][kpi], pd.DataFrame):
dict_values[KPI][kpi] = pd.DataFrame.from_records(dict_values[KPI][kpi])
if LABEL not in dict_values[KPI][kpi].columns:
dict_values[KPI][kpi][LABEL] = dict_values[KPI][kpi].index
These changes result in a simulation termination:
(MVS) C:\Andra\MVS_GitHub>python mvs_tool.py -i C:\Andra\RLI\Master_Thesis\Data\MVS\Input_templates\Greenfield_sector_coupling -ext csv -o C:\Andra\RLI\Master_Thesis\Data\MVS\Simulations\Greenfield\210205_sector_coupled_syst\random_test -f -pdf
12:13:28-INFO-Path for logging: C:\Andra\RLI\Master_Thesis\Data\MVS\Simulations\Greenfield\210205_sector_coupled_syst\random_test\mvs_logfile.log
12:13:28-INFO-
Multi-Vector Simulation Tool (MVS) V0.5.5dev
Version: 2020-12-18
Part of the toolbox of H2020 project "E-LAND", Integrated multi-vector management system for Energy isLANDs
Coded at: Reiner Lemoine Institute (Berlin)
Contributors: Martha M. Hoffmann
12:13:28-INFO-loading and converting all csv's from C:\Andra\RLI\Master_Thesis\Data\MVS\Input_templates\Greenfield_sector_coupling\csv_elements into one json
c:\andra\mvs_github\src\multi_vector_simulator\A1_csv_to_json.py:283: WrongParameterWarning:
The parameter minimal_degree_of_autonomy in the fileC:\Andra\RLI\Master_Thesis\Data\MVS\Input_templates\Greenfield_sector_coupling\csv_elements\constraints.csv is not expected.
Expected parameters are ['minimal_renewable_factor', 'maximum_emissions']
12:13:28-INFO-Json file created successfully from csv's and stored into C:\Andra\RLI\Master_Thesis\Data\MVS\Input_templates\Greenfield_sector_coupling\csv_elements\mvs_csv_config.json
Traceback (most recent call last):
File "mvs_tool.py", line 4, in <module>
main()
File "c:\andra\mvs_github\src\multi_vector_simulator\cli.py", line 149, in main
set_default_values=True,
File "c:\andra\mvs_github\src\multi_vector_simulator\B0_data_input_json.py", line 345, in load_json
if not isinstance(dict_values[KPI][kpi], pd.DataFrame):
KeyError: 'kpi'
The log stops at:
2021-03-02 12:13:28,949 - INFO - A1_csv_to_json - Json file created successfully from csv's and stored into C:\Andra\RLI\Master_Thesis\Data\MVS\Input_templates\Greenfield_sector_coupling\csv_elements\mvs_csv_config.json
2021-03-02 12:13:28,955 - DEBUG - A1_csv_to_json - Json created successfully from csv.
2021-03-02 12:13:28,955 - DEBUG - cli - Accessing script: B0_data_input_json
And indeed in mvs_csv_config.json there is no KPI.
Would the solution be to add an exception when loading mvs_csv_config.json ?
A solution would be to ignore if the key KPI is not in the dict_values
--> add an if statement before if not isinstance(dict_values[KPI][kpi], pd.DataFrame):
if KPI in dict_values:
if not isinstance(dict_values[KPI][kpi], pd.DataFrame):
# of course indent accordingly