Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various scheduler improvements #524

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 11 additions & 5 deletions flexmeasures/data/models/planning/battery.py
Expand Up @@ -127,7 +127,7 @@ def schedule_battery(
beliefs_before=belief_time,
sensor=inflexible_sensor,
)
if soc_targets is not None:
if soc_targets is not None and not soc_targets.empty:
device_constraints[0]["equals"] = soc_targets.shift(
-1, freq=resolution
).values * (timedelta(hours=1) / resolution) - soc_at_start * (
Expand All @@ -141,10 +141,16 @@ def schedule_battery(
device_constraints[0]["max"] = (soc_max - soc_at_start) * (
timedelta(hours=1) / resolution
)
device_constraints[0]["derivative min"] = (
sensor.get_attribute("capacity_in_mw") * -1
)
device_constraints[0]["derivative max"] = sensor.get_attribute("capacity_in_mw")
if sensor.get_attribute("is_strictly_non_positive"):
device_constraints[0]["derivative min"] = 0
else:
device_constraints[0]["derivative min"] = (
sensor.get_attribute("capacity_in_mw") * -1
)
if sensor.get_attribute("is_strictly_non_negative"):
device_constraints[0]["derivative max"] = 0
else:
device_constraints[0]["derivative max"] = sensor.get_attribute("capacity_in_mw")

# Apply round-trip efficiency evenly to charging and discharging
device_constraints[0]["derivative down efficiency"] = roundtrip_efficiency**0.5
Expand Down
11 changes: 8 additions & 3 deletions flexmeasures/data/models/planning/utils.py
Expand Up @@ -9,7 +9,6 @@

from flexmeasures.data.models.time_series import Sensor, TimedBelief
from flexmeasures.data.models.planning.exceptions import (
UnknownForecastException,
UnknownMarketException,
UnknownPricesException,
)
Expand Down Expand Up @@ -150,11 +149,17 @@ def get_power_values(
one_deterministic_belief_per_event=True,
) # consumption is negative, production is positive
df = simplify_index(bdf)
df = df.reindex(initialize_index(query_window[0], query_window[1], resolution))
nan_values = df.isnull().values
if nan_values.any() or df.empty:
raise UnknownForecastException(
f"Forecasts unknown for planning window. (sensor {sensor.id})"
current_app.logger.warning(
f"Assuming zero power values for (partially) unknown power values for planning window. (sensor {sensor.id})"
)
df = df.fillna(0)
if sensor.get_attribute(
"consumption_is_positive", False
): # FlexMeasures default is to store consumption as negative power values
return df.values
return -df.values


Expand Down
2 changes: 2 additions & 0 deletions flexmeasures/utils/config_utils.py
Expand Up @@ -8,6 +8,7 @@

from flask import Flask
from inflection import camelize
import pandas as pd

from flexmeasures.utils.config_defaults import (
Config as DefaultConfig,
Expand Down Expand Up @@ -45,6 +46,7 @@

def configure_logging():
"""Configure and register logging"""
pd.options.display.expand_frame_repr = False # Don't wrap DataFrame representations
loggingDictConfig(flexmeasures_logging_config)


Expand Down