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

Bugfix/dingo annual demand nans #402

Merged
merged 7 commits into from
Jul 11, 2024
Merged
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
6 changes: 6 additions & 0 deletions edisgo/network/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -1448,6 +1448,12 @@ def predefined_conventional_loads_by_sector(
load_names = self._check_if_components_exist(edisgo_object, load_names, "loads")
loads_df = edisgo_object.topology.loads_df.loc[load_names, :]

# check if loads contain annual demand
if not all(loads_df.annual_consumption.notnull()):
raise AttributeError(
"The annual consumption of some loads is missing. Please provide"
)

# scale time series by annual consumption
ts_scaled = loads_df.apply(
lambda x: ts_loads[x.sector] * x.annual_consumption,
Expand Down
20 changes: 20 additions & 0 deletions tests/network/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -1794,6 +1794,26 @@ def test_predefined_conventional_loads_by_sector(self, caplog):
).values,
).all()

# test Error if 'annual_consumption' is missing
# Save the original 'annual_consumption' values
original_annual_consumption = self.edisgo.topology.loads_df[
"annual_consumption"
].copy()
# Set 'annual_consumption' to None for the test
self.edisgo.topology.loads_df["annual_consumption"] = None
with pytest.raises(AttributeError) as exc_info:
self.edisgo.timeseries.predefined_conventional_loads_by_sector(
self.edisgo, "demandlib"
)
assert (
exc_info.value.args[0]
== "The annual consumption of some loads is missing. Please provide"
)
# Restore the original 'annual_consumption' values
self.edisgo.topology.loads_df[
"annual_consumption"
] = original_annual_consumption

def test_predefined_charging_points_by_use_case(self, caplog):
index = pd.date_range("1/1/2018", periods=3, freq="H")
self.edisgo.timeseries.timeindex = index
Expand Down
Loading