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

inflexible devices power unit conversion #968

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions flexmeasures/data/models/planning/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from flexmeasures.data.schemas.scheduling import FlexContextSchema
from flexmeasures.utils.time_utils import get_max_planning_horizon
from flexmeasures.utils.coding_utils import deprecated
from flexmeasures.utils.unit_utils import ur, convert_units
from flexmeasures.utils.unit_utils import ur


def check_and_convert_power_capacity(
Expand Down Expand Up @@ -210,12 +210,12 @@ def _prepare(self, skip_validation: bool = False) -> tuple: # noqa: C901
) * get_continuous_series_sensor_or_quantity(
quantity_or_sensor=production_capacity,
actuator=sensor,
unit=sensor.unit,
unit="MW",
query_window=(start, end),
resolution=resolution,
beliefs_before=belief_time,
fallback_attribute="production_capacity",
max_value=convert_units(power_capacity_in_mw, "MW", sensor.unit),
max_value=power_capacity_in_mw,
)
if sensor.get_attribute("is_strictly_non_negative"):
device_constraints[0]["derivative max"] = 0
Expand All @@ -225,12 +225,12 @@ def _prepare(self, skip_validation: bool = False) -> tuple: # noqa: C901
] = get_continuous_series_sensor_or_quantity(
quantity_or_sensor=consumption_capacity,
actuator=sensor,
unit=sensor.unit,
unit="MW",
query_window=(start, end),
resolution=resolution,
beliefs_before=belief_time,
fallback_attribute="consumption_capacity",
max_value=convert_units(power_capacity_in_mw, "MW", sensor.unit),
max_value=power_capacity_in_mw,
)

soc_gain = self.flex_model.get("soc_gain", [])
Expand Down
4 changes: 2 additions & 2 deletions flexmeasures/data/models/planning/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,15 @@ def add_inflexible_device_forecasts(
# PV (8 hours at zero capacity, 8 hours at 90% capacity, and again 8 hours at zero capacity)
headroom = 0.1 # 90% of nominal capacity
pv_sensor = inflexible_devices["PV power sensor"]
capacity = pv_sensor.get_attribute("capacity_in_mw")
capacity = pv_sensor.get_attribute("capacity_in_mw") * 1000 # MW -> kW
pv_values = (
[0] * (8 * 4) + [(1 - headroom) * capacity] * (8 * 4) + [0] * (8 * 4)
) * (len(time_slots) // (24 * 4))
add_as_beliefs(db, pv_sensor, pv_values, time_slots, setup_sources["Seita"])

# Residual demand (1 MW continuously)
residual_demand_sensor = inflexible_devices["residual demand power sensor"]
residual_demand_values = [-1] * len(time_slots)
residual_demand_values = [-1000] * len(time_slots)
add_as_beliefs(
db,
residual_demand_sensor,
Expand Down
1 change: 1 addition & 0 deletions flexmeasures/data/models/planning/tests/test_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ def test_building_solver_day_2(
).tail(
-4 * 24
) # remove first 96 quarter-hours (the schedule is about the 2nd day)
capacity = capacity * 0.001 # kW -> MW
capacity["max"] = building.get_attribute("capacity_in_mw")
capacity["min"] = -building.get_attribute("capacity_in_mw")
capacity["production headroom"] = capacity["max"] - capacity["inflexible"]
Expand Down
3 changes: 3 additions & 0 deletions flexmeasures/data/models/planning/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ def get_power_values(
resolution: timedelta,
beliefs_before: Optional[datetime],
sensor: Sensor,
to_unit="MW",
) -> np.ndarray:
"""Get measurements or forecasts of an inflexible device represented by a power sensor.

Expand Down Expand Up @@ -208,6 +209,8 @@ def get_power_values(
)
df = df.fillna(0)

df *= convert_units(1, sensor.unit, to_unit)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if you pass df instead of 1 this method may even allow converting from kWh to kW using the sensor's resolution.


if sensor.get_attribute(
"consumption_is_positive", False
): # FlexMeasures default is to store consumption as negative power values
Expand Down
Loading