rl-institut / offgridders

Models and optimizes capacity & dispatch of electricity supply systems, off-grid or connected to a (weak) central grid
GNU General Public License v3.0
21 stars 9 forks source link

Negative timeseries values terminate simulation #101

Open smartie2076 opened 4 years ago

smartie2076 commented 4 years ago

When a timeseries has negative values for an investment object, the simulation terminates. This is for example the case for PV plants: Some API might generate a negative value at early/late hours of the day... grafik

...which then is not noticed when reading the input files but only in a termination of the simulation. The termination message is very generic:

11:42:00-INFO-Starting simulation of case pv-diesel-storage-mg, project site FID_256753, experiment no. 50/200...
11:42:00-INFO-Added constraint: Stability though actual generation of diesel generators and backup through batteries.
11:42:00-INFO-Simulating...
11:42:00-INFO-Optimization successful...
11:42:01-INFO-Restoring attributes will overwrite existing attributes.
11:42:01-WARNING-Stability criterion is strictly not fullfilled, but deviation is less then e6.
11:42:01-INFO-Simulation of case "pv-diesel-storage-mg" resulted in :
                  3.576 currency/kWh, at a renewable share of 83.61 percent with a reliability of 100.0 percent
11:42:01-INFO-    Initial simulation time (s): 0.24 / Actual evaluation time (s): 1.01
11:42:01-INFO-    Estimated simulation time left: 2.3 minutes.

11:42:01-INFO-Starting simulation of case pv-storage-mg, project site FID_91254, experiment no. 51/200...
11:42:01-INFO-Added constraint: Stability though actual generation of diesel generators and backup through batteries.
11:42:01-INFO-Simulating...
11:42:02-ERROR-Optimization failed with status ok and terminal condition infeasible
ERROR: evaluating expression: No value for uninitialized NumericValue object
    InvestmentFlow.invest[bus_electricity_dc,transformer_inverter_dc_ac]
        (expression: 0.2073418975127565*InvestmentFlow.invest[bus_electricity_
        dc,transformer_inverter_dc_ac] +
        0.2125492347806967*InvestmentFlow.invest[source_pv,bus_electricity_dc]
        + 0.21434363752638408*GenericInvestmentStorageBlock.invest[generic_sto
        rage])
11:42:02-ERROR-evaluating expression: No value for uninitialized NumericValue object InvestmentFlow.invest[bus_electricity_dc,transformer_inverter_dc_ac]
    (expression: 0.2073418975127565*InvestmentFlow.invest[bus_electricity_dc,transformer_inverter_dc_ac] + 0.2125492347806967*InvestmentFlow.invest[source_pv,bus_electricity_dc]
 + 0.21434363752638408*GenericInvestmentStorageBlock.invest[generic_storage])
Traceback (most recent call last):
  File "Offgridders.py", line 275, in <module>
    main()
  File "Offgridders.py", line 185, in main
    sensitivity_experiment_s[experiment], experiment_case_dict
  File "D:\PycharmProjects\offgridders\src\G0_oemof_simulate.py", line 74, in run
    experiment, micro_grid_system, model, file_name
  File "D:\PycharmProjects\offgridders\src\G1_oemof_create_model.py", line 483, in simulate
    micro_grid_system.results["meta"] = outputlib.processing.meta_results(model)
  File "C:\ProgramData\Miniconda3\envs\offgridders_python3-6\lib\site-packages\oemof\outputlib\processing.py", line 189, in meta_results
    meta_res = {'objective': om.objective()}
  File "C:\ProgramData\Miniconda3\envs\offgridders_python3-6\lib\site-packages\pyomo\core\base\expression.py", line 55, in __call__
    return self.expr(exception=exception)
  File "C:\ProgramData\Miniconda3\envs\offgridders_python3-6\lib\site-packages\pyomo\core\kernel\expr_coopr3.py", line 208, in __call__
    exception=exception))
  File "C:\ProgramData\Miniconda3\envs\offgridders_python3-6\lib\site-packages\pyomo\core\kernel\expr_coopr3.py", line 812, in _apply_operation
    return sum(c*next(values) for c in self._coef) + self._const
  File "C:\ProgramData\Miniconda3\envs\offgridders_python3-6\lib\site-packages\pyomo\core\kernel\expr_coopr3.py", line 812, in <genexpr>
    return sum(c*next(values) for c in self._coef) + self._const
  File "C:\ProgramData\Miniconda3\envs\offgridders_python3-6\lib\site-packages\pyomo\core\kernel\expr_coopr3.py", line 217, in _evaluate_arglist
    yield value(arg, exception=exception)
  File "C:\ProgramData\Miniconda3\envs\offgridders_python3-6\lib\site-packages\pyomo\core\kernel\numvalue.py", line 170, in value
    % (obj.name,))
ValueError: No value for uninitialized NumericValue object InvestmentFlow.invest[bus_electricity_dc,transformer_inverter_dc_ac]

This could be fixed by printing a warnining for these cases and clipping everything below 0.

smartie2076 commented 4 years ago

Way to fix input files:

import pandas as pd
import numpy
import os

folder = "2020_07_10_all_sites_value_between_0_1"
files = "data_"
range = numpy.arange(1,28,1)

for number in range:
    file_path = os.path.join(os.path.abspath("."),folder,files+str(number)+".csv")
    data = pd.read_csv(file_path, sep=",")
    data = data.clip(0,1)
    data.to_csv(file_path, index=False)