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

Drop duplicate hydrogen ports in add_export.py #1233

Merged
merged 3 commits into from
Dec 12, 2024

Conversation

yerbol-akhmetov
Copy link
Collaborator

@yerbol-akhmetov yerbol-akhmetov commented Dec 10, 2024

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.
image

Checklist

  • I consent to the release of this PR's code under the AGPLv3 license and non-code contributions under CC0-1.0 and CC-BY-4.0.
  • I tested my contribution locally and it seems to work fine.
  • A note for the release notes doc/release_notes.rst is amended in the format of previous release notes, including reference to the requested PR.

@GbotemiB
Copy link
Contributor

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.

@ekatef
Copy link
Member

ekatef commented Dec 10, 2024

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 hydrogen_buses_ports are being formed, it appears that the duplicates correspond to the same GADM index:

ports = ports.set_index("gadm_{}".format(gadm_level))
# Select the hydrogen buses based on nodes with ports
hydrogen_buses_ports = n.buses.loc[ports.index + " H2"]

May it be the case that duplicates in hydrogen_buses_ports are different ports but located in the same GADM region?

@@ -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()
Copy link
Member

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks @davide-f, @ekatef. I have applied the latest changes that were suggested and tested it locally. It worked as intended. Also, the comment about TODO was added too.

Copy link
Member

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 😄

@davide-f davide-f merged commit 2091d38 into pypsa-meets-earth:main Dec 12, 2024
6 checks passed
@davide-f
Copy link
Member

Merged, many thanks @yerbol-akhmetov :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants