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 an error in simplify_network when to_substations simplification flag is on #708

Merged
merged 4 commits into from
May 9, 2023

Conversation

ekatef
Copy link
Collaborator

@ekatef ekatef commented May 3, 2023

Closes #646

Changes proposed in this Pull Request

Checklist

  • I consent to the release of this PR's code under the GPLv3 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.
  • Code and workflow changes are sufficiently documented.
  • Newly introduced dependencies are added to envs/environment.yaml and envs/environment.docs.yaml.
  • Changes in configuration options are added in all of config.default.yaml and config.tutorial.yaml.
  • Add a test config or line additions to test/ (note tests are changing the config.tutorial.yaml)
  • Changes in configuration options are also documented in doc/configtables/*.csv and line references are adjusted in doc/configuration.rst and doc/tutorial.rst.
  • 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.

@ekatef ekatef marked this pull request as ready for review May 4, 2023 11:16
@ekatef
Copy link
Collaborator Author

ekatef commented May 4, 2023

@davide-f, I think that is ready for the review
I'd omit release node as it's just a part of general bug-fixing

@ekatef
Copy link
Collaborator Author

ekatef commented May 4, 2023

As a comment, a reason for the issue was referring to n.buses.bus_id column which can be not there. It has been resolved by adding a supplementary column to keep a bus index value

Copy link
Member

@davide-f davide-f left a comment

Choose a reason for hiding this comment

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

Nice PR and basically ready for merging after a simple comment :)

Comment on lines 662 to 666
n.buses.assign(bus_index=n.buses.index.get_level_values(0))
.loc[i_suffic_load]
.groupby("country")["bus_index"]
.first()
.to_dict()
Copy link
Member

Choose a reason for hiding this comment

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

For consistency, I'd use "bus_id" instead of bus_index.
Is there a specific reason for this naming?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agree, revised

No rational reason, just a habit to keep the original data :)

@ekatef
Copy link
Collaborator Author

ekatef commented May 8, 2023

Nice PR and basically ready for merging after a simple comment :)

Thank you! Fixed :)

@@ -658,7 +659,11 @@ def merge_isolated_nodes(n, threshold, aggregation_strategies=dict()):

# all the nodes to be merged should be mapped into a single node
map_isolated_node_by_country = (
n.buses.loc[i_suffic_load].groupby("country")["bus_id"].first().to_dict()
n.buses.assign(bus_id=n.buses.index.get_level_values(0))
Copy link
Member

Choose a reason for hiding this comment

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

Sorry a comment: why get_level_values here? isn't buses.index enough?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Our data structure seem to be quite flexible, while multi-indexing is a usual pythonic practice. So, I thought it could be natural to use a general approach

However, looking into the code, it seems that we assume everywhere that n.buses always only one index. So, get_level_values(0) looks like over-complication. Removed

Copy link
Member

@davide-f davide-f left a comment

Choose a reason for hiding this comment

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

A comment

@ekatef
Copy link
Collaborator Author

ekatef commented May 8, 2023

A comment

Have removed over-complication :)
Thanks for double-checking!

@davide-f
Copy link
Member

davide-f commented May 9, 2023

Super! Merging:)

@davide-f davide-f merged commit 1989668 into pypsa-meets-earth:main May 9, 2023
@ekatef ekatef deleted the fix_to_subs_clustering branch November 14, 2023 22:19
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.

KeyError in simplify_network when to_substations simplification flag is on
2 participants