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

fix: ensure that get_bus_demand works in Create state #422

Merged
merged 3 commits into from
Mar 19, 2021
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
2 changes: 1 addition & 1 deletion powersimdata/input/input_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ def get_bus_demand(scenario_info, grid):
:param powersimdata.input.grid.Grid grid: grid to construct bus demand for.
:return: (*pandas.DataFrame*) -- data frame of demand.
"""
demand = InputData().get_data(scenario_info, "demand")
bus = grid.bus
demand = InputData().get_data(scenario_info, "demand")[bus.zone_id.unique()]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice safeguard

bus["zone_Pd"] = bus.groupby("zone_id")["Pd"].transform("sum")
bus["zone_share"] = bus["Pd"] / bus["zone_Pd"]
zone_bus_shares = pd.DataFrame(
Expand Down
1 change: 1 addition & 0 deletions powersimdata/scenario/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def get_bus_demand(self):

:return: (*pandas.DataFrame*) -- data frame of demand (hour, bus).
"""
self._update_scenario_info()
Copy link
Collaborator

Choose a reason for hiding this comment

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

It makes sense. I am confused to why it was working before without the update.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

get_demand uses get_profile which uses self.builder.demand, but get_bus_demand passes self.scenario_info without updating self.scenario_info with what we're setting in the builder.

Copy link
Collaborator

Choose a reason for hiding this comment

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

When the bug has been introduced because get_bus_demand was working originally.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did we test it in Create state after #388?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably not but I thought this was a feature you were using before creating each scenario. That's why I am surprised you just found the bug now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, this method was not part of my usual scenario setup process. REISE.jl does the same thing within the Julia code though. This feature was mostly being used for scenarios in Analyze state.

grid = self.get_grid()
return get_bus_demand(self._scenario_info, grid)

Expand Down
11 changes: 11 additions & 0 deletions powersimdata/scenario/tests/test_create.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import pytest

from powersimdata.scenario.scenario import Scenario


@pytest.mark.ssh
def test_get_bus_demand():
scenario = Scenario("")
scenario.state.set_builder(interconnect="Texas")
scenario.state.builder.set_base_profile("demand", "vJan2021")
scenario.state.get_bus_demand()