Skip to content

Plot overhaul + Auto balance map#1102

Closed
FabianHofmann wants to merge 30 commits intomasterfrom
plotter-integrated-functions
Closed

Plot overhaul + Auto balance map#1102
FabianHofmann wants to merge 30 commits intomasterfrom
plotter-integrated-functions

Conversation

@FabianHofmann
Copy link
Copy Markdown
Contributor

@FabianHofmann FabianHofmann commented Dec 3, 2024

Closes #912

This PR builds on top of #912 and adds

  • an integrated formulation of the NetworkMapPlotter.plot (renamed to .static_map`) function
  • adds a .static_balance_map which
    • calculates dispatch and flow balances
    • scales flows and bus_circles to cover the figure are given in flow_area_fraction/bus_area_fraction
    • auto-detects units for displaying the legend
    • auto-detects representatives for the legend

TODOS:

  • add unit tests
  • fix flow aggregation over one route. I am thinking about enabling the feature that when multiple branches have the same connection the flow in the balance plot should be aggregated. The function is already there but seems to be buggy
  • add release note

Changes proposed in this Pull Request

Checklist

  • Code changes are sufficiently documented; i.e. new functions contain docstrings and further explanations may be given in doc.
  • Unit tests for new features were added (if applicable).
  • A note for the release notes doc/release_notes.rst of the upcoming release is included.
  • I consent to the release of this PR's code under the MIT license.

@lkstrp lkstrp added this to the v0.33 milestone Dec 3, 2024
@lkstrp lkstrp added the feature label Dec 3, 2024
Copy link
Copy Markdown
Member

@lkstrp lkstrp left a comment

Choose a reason for hiding this comment

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

Beautiful! Thanks for reviving #912!
I can't quite remember what I had in mind back in the summer, but this looks pretty good.
I have a few things next to the comments:

return [i[3:] for i in where if i.startswith("bus") and i not in ["bus0", "bus1"]]


def bus_carrier_unit(n: Network, bus_carrier: str | Sequence[str] | None) -> str:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could already be moved to the components class. Maybe a new module components/descriptors.py one level down

@property
def x(self):
if self._x is None:
self.set_layout()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

set_layout is called in __init__, so self._x will never be None?
Same goes for self._y

pypsa/plot.py Outdated
Comment on lines +298 to +299
def add_geomap_features(self, geomap=True, geomap_colors=None):
resolution = "50m" if isinstance(geomap, bool) else geomap
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I still don't like these arguments/variables that can be bool and a string. Let's get rid of them everywhere.
This could just be:

Suggested change
def add_geomap_features(self, geomap=True, geomap_colors=None):
resolution = "50m" if isinstance(geomap, bool) else geomap
def add_geomap_features(self, resolution:str="50m", geomap_colors=None):

and only be called if geomap should be added

color_geomap="geomap_colors",
)
@wraps(NetworkMapPlotter.static_map)
def plot(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why get most arguments via the wrap, but define some still here? Is this a clear cut between kwrags for Plotter init and kwargs needed inside plot()?

@FabianHofmann
Copy link
Copy Markdown
Contributor Author

@lkstrp thanks for the review! the playground is open and all your suggestion should go in. I would be very happy to move things to the component structure, this is something I would like to do anyway.

@FabianHofmann FabianHofmann force-pushed the plotter-integrated-functions branch from 0e59c2c to cbd5032 Compare December 30, 2024 22:38
@FabianHofmann FabianHofmann mentioned this pull request Jan 13, 2025
7 tasks
@lkstrp lkstrp modified the milestones: v0.33, v0.34 Jan 28, 2025
@lkstrp lkstrp removed the feature label Feb 17, 2025
@lkstrp
Copy link
Copy Markdown
Member

lkstrp commented Mar 6, 2025

Closed via #1156

@lkstrp lkstrp closed this Mar 6, 2025
@lkstrp lkstrp mentioned this pull request Mar 6, 2025
21 tasks
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.

2 participants