EDIT: As I finally found out in an earlier post further up this thread, the naive-mpc-optim
has a hard coded limitation to 24 hour of forecast. Hence my error. I will try to reconsider how I use the optimization.
See if you can help me out here. Again trying to get a frequent naive-mpc-optim
working that extends a bit further than 24 hours so I can make full use of nordpool
prices when they are released. As Nordpool release hourly energy prices at 13:00 every day and the prices always extend to the end of the next day, I can make a more predictable optimization where I can opt for a certain SOC at midnight.
But. I get some errors when I send more than 24 hours of data to naive-mpc-optim
. This is my REST JSON:
{ "prediction_horizon": 30,
"soc_init": 1.0,
"soc_target": 0.5,
"def_total_hours": [],
"load_cost_forecast": [3.52, 4.29, 3.51, 2.75, 2.76, 0.86, 0.86, 0.84, 0.82, 0.8, 0.79, 0.82, 0.85, 0.89, 2.47, 2.32, 2.14, 2.05, 1.92, 0.87, 0.85, 1.41, 1.91, 2.21, 2.5, 2.78, 2.64, 1.98, 0.79, 0.76],
"prod_price_forecast": [3.21, 3.98, 3.2, 2.44, 2.45, 0.55, 0.55, 0.53, 0.51, 0.49, 0.48, 0.51, 0.54, 0.58, 2.16, 2.01, 1.83, 1.74, 1.61, 0.56, 0.54, 1.1, 1.6, 1.9, 2.19, 2.47, 2.33, 1.67, 0.48, 0.45],
"pv_power_forecast": [875, 221, 6, 0, 0, 0, 0, 0, 0, 0, 0, 10, 149, 497, 965, 1397, 1689, 1914, 2028, 2011, 1886, 1662, 1373, 982, 446, 112, 3, 0, 0, 0]
}
And this is the error I get:
2023-08-24 17:52:49,565 - web_server - INFO - Setting up needed data
2023-08-24 17:52:49,568 - web_server - INFO - Retrieve hass get data method initiated...
2023-08-24 17:52:51,568 - web_server - INFO - Retrieving weather forecast data using method = list
2023-08-24 17:52:51,570 - web_server - INFO - Retrieving data from hass for load forecast using method = naive
2023-08-24 17:52:51,571 - web_server - INFO - Retrieve hass get data method initiated...
2023-08-24 17:52:56,482 - web_server - ERROR - Exception on /action/naive-mpc-optim [POST]
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 2190, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1486, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1484, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1469, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
File "src/emhass/web_server.py", line 174, in action_call
input_data_dict = set_input_data_dict(config_path, str(data_path), costfun,
File "/usr/local/lib/python3.8/site-packages/emhass-0.4.14-py3.8.egg/emhass/command_line.py", line 127, in set_input_data_dict
df_input_data_dayahead = copy.deepcopy(df_input_data_dayahead)[df_input_data_dayahead.index[0]:df_input_data_dayahead.index[prediction_horizon-1]]
File "/usr/local/lib/python3.8/site-packages/pandas/core/indexes/base.py", line 5039, in __getitem__
return getitem(key)
File "/usr/local/lib/python3.8/site-packages/pandas/core/arrays/datetimelike.py", line 341, in __getitem__
"Union[DatetimeLikeArrayT, DTScalarOrNaT]", super().__getitem__(key)
File "/usr/local/lib/python3.8/site-packages/pandas/core/arrays/_mixins.py", line 272, in __getitem__
result = self._ndarray[key]
IndexError: index 29 is out of bounds for axis 0 with size 24
What’s with that 24 size error? All three arrays I send in are 30 element sizes.
The call works well if I set "prediction_horizon": 24
. Although I currently get “Infeasible” result, which I have to try to resolve, but that’s another story.
EDIT: See edit at top of post.