-
Notifications
You must be signed in to change notification settings - Fork 173
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 runoff in case runoff data are missed for some hydropower plants #757
Conversation
Hello @ekatef :) This PR sounds to me straightforward and thanks! Is it complete in your opinion? |
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 have a comment to add: we shall make sure the order is guaranteed when using plant and name.
when doing the assignment that may be lost and hence the correspondance between plant and its corresponding inflow may be lost
As far as I understand, correspondence between pypsa-earth/scripts/add_electricity.py Lines 468 to 470 in 20e5061
So, an order of elements in @davide-f could you please double-check if this does make sense for you? :) |
A couple of additional points that should be checked in context of this PR.
|
Update by both the points above:
|
@davide-f my feeling is that this PR is ready. Would be grateful if you could look into it :) |
scripts/add_electricity.py
Outdated
idxs_to_keep = inflow_buses[ | ||
inflow_buses.isin(intersection_plants) | ||
].index | ||
idxs_to_keep = inflow_buses[inflow_buses.isin(plants_with_data)].index |
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 think we need to improve the readability of the code because it is easy to get lost with indices.
Something that Irealize now is that this code seems a duplication and we may need to debug it together.
Initially is defined as the values of a subset of inflow_buses, whose index are idxs_to_keep.
I think that to improve the readability, we may avoid defining idx_to_keep inside the if but outside.
plants with data may be the view: inflow_buses[inflow_buses.isin(inflow.indexes["plant"])]
where its index is idxs_to_leep and its values are '''plants'''.
We may revise the code in that way so that it may be easier to understand.
What do you think? Let me know if the above is clear
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.
@davide-f agree that this change look very natural. However, I needed about an hour to understand it, so I absolutely aligned with your idea to make this fragment a bit more readable! :D
Have implemented a possible approach. Along with revision of idxs_to_keep
definition, there were following changes:
- move reading PHS
phs = ppl.query('technology == "Pumped Storage"')
to a less over-crowded part; - revise the names of the data frames
ror
andhydro
to make it clear that both were derived fromppl
and contain run-of-river and reservoir data, respectively; - change
inflow_idx
tohydro_ppl_idx
to avoid an association withinflow
indices which can be a bit misleading.
Not sure if all these changes are really necessary. I'd suggest to select only those which are really needed. Could you please check if these changes do really allow to decrease reading time? :)
Tested on "CD" and proved to resolve a problem which has previously arisen when What I'm not sure about is updating of plants_with_data = inflow_buses[inflow_buses.isin(plants_to_keep)]
network_buses_to_keep = plants_with_data.index |
For the sake of avoiding problems, that's a good point, you could add a row below to update the value of plants_to_keep. |
Great! Thank you :) Then let's try this way. To me, that looks also a bit more consistent to keep updates of both Sorry for the mess in commits. Actually, I can squash them after the final revision ;) |
if not intersection_plants.empty: | ||
# if there are any plants for which runoff data are available | ||
if not plants_with_data.empty: | ||
network_buses_to_keep = plants_with_data.index |
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.
Hello :)
I saw that you removed here the plants_to_keep = plants_with_data.to_numpy()
, maybe we misunderstood.
I understood your proposal was to add its definition also there, without moving it from below.
Having the two definitions of the entries here ensures an easy understanding that the two values are of equal length and are consistent: plants_with_data represents indeed a mapping and with that, it is clear.
Having the definitions across the previous 20 lines unfortunately is not so clear.
I see two options:
- keep it was before
- or having it both here and above
What do you think?
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.
Hello :)
I saw that you removed here the
plants_to_keep = plants_with_data.to_numpy()
, maybe we misunderstood. I understood your proposal was to add its definition also there, without moving it from below.Having the two definitions of the entries here ensures an easy understanding that the two values are of equal length and are consistent: plants_with_data represents indeed a mapping and with that, it is clear. Having the definitions across the previous 20 lines unfortunately is not so clear.
I see two options:
- keep it was before
- or having it both here and above
What do you think?
I have tired to avoid duplicating of plants_to_keep
definition. But agree that it might be not so obvious to have a definition twenty lines above... :)
My personal preferences is to have plants_to_keep
in both fragments, but also happy to keep the original version if you feel it more 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.
@ekatef for me it's good to go :)
Let me know if you want to squash the last two commits or go as-is ;)
Super! Squash done ;) |
Merged :D |
Thank you so much ;) |
PR fixes an issue appeared in a workflow for India with gadm clustering on. The problem is caused by a case when there are hydropower plants on islands, namely Kalpong hydro power plant for India, for which ERA5 can miss the data:
Changes proposed in this Pull Request
Hydropower indices are matched with plants names.
Checklist
envs/environment.yaml
anddoc/requirements.txt
.config.default.yaml
andconfig.tutorial.yaml
.test/
(note tests are changing the config.tutorial.yaml)doc/configtables/*.csv
and line references are adjusted indoc/configuration.rst
anddoc/tutorial.rst
.doc/release_notes.rst
is amended in the format of previous release notes, including reference to the requested PR.