-
Notifications
You must be signed in to change notification settings - Fork 207
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
Drop duplicate hydrogen ports in add_export.py
#1233
Drop duplicate hydrogen ports in add_export.py
#1233
Conversation
I have also tested this and it works properly. Before this, the US model was not feasible, but with this solution the model is now feasible. |
Thank you @yerbol-akhmetov! Great to hear that the fix works, and a great investigation of the reasons #1231. Just to be sure, I wonder if we could drop some available shipping capacity when dropping duplicated buses in the current implementation? From the way how the pypsa-earth/scripts/add_export.py Lines 63 to 66 in 5d02b29
May it be the case that duplicates in |
scripts/add_export.py
Outdated
@@ -66,6 +66,9 @@ def select_ports(n): | |||
hydrogen_buses_ports = n.buses.loc[ports.index + " H2"] | |||
hydrogen_buses_ports.index.name = "Bus" | |||
|
|||
# drop duplicate ports if exists | |||
hydrogen_buses_ports = hydrogen_buses_ports.drop_duplicates() |
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.
Thanks a lot @yerbol-akhmetov for this great proposal; I'd propose just a minor revision that may make the code more robust.
If I get the issue right, the problem in the current workflow is that the column "gadm_{}".format(gadm_level) used as index may contain duplicates.
For your case, however, drop_duplicates works.
The function drop_duplicates() by default drops only duplicated rows, if rows have the same index but different content they are not dropped.
To ensure robustness and keep the proposed formulation, a possible proposal would be to move the drop_duplicates few lines up with something like:
gcol = "gadm_{}".format(gadm_level)
ports_sel = ports.loc[~ports[gcol].duplicated(keep='first')].set_index(gcol)
May that work? Feel free to revise and improve as you feel best
I'd also recommend to add a comment like "TODO: revise if ports quantity and property by shape become relevant" just to keep track of this approximation
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.
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.
Ahh, true!! The check for duplicates relate to the whole lines, not only indices. Agree then that data loss is highly unlikely.
I think the implementation looks great, and if @davide-f doesn't have further comments, happy to merge 😄
Merged, many thanks @yerbol-akhmetov :D |
Changes proposed in this Pull Request
Good day. This PR aims to minor a bug related to duplicate entries of H2 export ports which prevents addition of links that connect
H2 export bus
and H2 buses. This issue happens particularly for US, where multiple ports are available. The PR is linked to issue #1231. Dropping the duplicates solve the issue.Checklist
doc/release_notes.rst
is amended in the format of previous release notes, including reference to the requested PR.