-
Notifications
You must be signed in to change notification settings - Fork 40
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 MATReader when loading one Storage and/or zero DC-lines #363
Conversation
powersimdata/input/scenario_grid.py
Outdated
if isinstance(mpc_iess, int): | ||
n_storage = 1 | ||
else: | ||
n_storage = mpc.iess.shape[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mpc.iess.shape[0]
works for sure. Does mpc_iess.shape[0]
work here, if so, maybe use mpc_iess
instead to be consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, I think that was my original intention.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not not sure I understand the purpose of mpc_iess = mpc.iess
. Am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to separate the potential AttributeError when mpc
doesn't have .iess
(no storage) from the potential AttributeError when mpc.iess
doesn't have .shape
(one storage, so mpc.iess
gets squeezed to an int
). But with the separate int
check before we access .shape
, I think this can be simplified.
From:
try:
# The next line will fail if no iess attribute (index energy storage system)
mpc_iess = mpc.iess
# Since we use the 'squeeze_me' param, 1 storage -> an int, not an array
if isinstance(mpc_iess, int):
n_storage = 1
else:
n_storage = mpc_iess.shape[0]
except AttributeError:
n_storage = 0
To:
try:
# The next line will fail if no iess attribute (index energy storage system)
# Since we use the 'squeeze_me' param, 1 storage -> an int, not an array
if isinstance(mpc.iess, int):
n_storage = 1
else:
n_storage = mpc.iess.shape[0]
except AttributeError:
n_storage = 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or even:
try:
# The next line will fail if no iess attribute (index energy storage system)
# Since we use the 'squeeze_me' param, 1 storage -> an int, not an array
n_storage = 1 if isinstance(mpc.iess, int) else mpc.iess.shape[0]
except AttributeError:
n_storage = 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the changes follow our investigation. Thanks for the verification.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
e46b821
to
718235d
Compare
Purpose
Ensure that grids loaded from matfiles are built just like fresh grids, to aid in grid equality comparisons.
What the code is doing
abstract_grid.py
: add columns tostorage_template
to match what's in the matfiles.scenario_grid.py
:iess
attribute ofmpc
, triggering theAttributeError
if there's no storage, and if it is there then we check whether it is an int (which a 1x1 array for a single storage gets squeezed to) before trying to check its shape. Previously, a single storage would trigger an AttributeError when trying to access.shape
, so we would think there is no storage when there is actually one, so we don't populate the storage table entries as appropriate.genfuel
array as well (could be ignored, but this could let us specify different types of storage in the future)helpers.py
: we expand the columns of the dcline dataframe always, not just when it's nonempty (since now it always has the right column names, even if the rows are empty)Testing
Together with #362, we can successfully reproduce the grid for Scenario 1712 in the create state, and equality comparison returns True:
Time estimate
15-30 minutes. The code changes themselves are minor, but they are part of a complex chain of objects.