Skip to content

Conversation

@nader-00
Copy link
Collaborator

Description

This PR adds Plotly-based “voltage over distance” comparison plots to eDisGo.

It introduces two new methods on EDisGo:

  • plot_voltage_over_dist(mv_id, lv_id, other, save_as=False, split_branches=False)
    LV voltage (p.u.) vs. shortest-path distance to the MV/LV transformer; compares two EDisGo objects and visualizes load/feed-in worst cases. Includes LV tolerance band (0.90–1.10 p.u.).

  • plot_voltage_over_dist_mv(mv_id, other, save_as=False)
    MV voltage (p.u.) vs. shortest-path distance to the HV/MV transformer; compares two EDisGo objects and visualizes load/feed-in worst cases. Includes MV tolerance band (0.96–1.06 p.u.).

Distances are computed using Dijkstra shortest paths on the grid graph. Export to HTML/PNG is supported via save_as. Core logic is implemented in edisgo/tools/voltage_over_distance.py with thin wrappers in edisgo/edisgo.py. Tests are added (skipped when results.v_res is empty in the default fixture).

Fixes #565

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist:

  • New and adjusted code is formatted using the pre-commit hooks
  • New and adjusted code includes type hinting now
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • The Read the Docs documentation is compiling correctly
  • If new packages are needed, I added them the setup/env files
  • I have added new features to the corresponding whatsnew file

return s


def _shortest_distances_km(G, source_bus: str, weight: Optional[str] = "length") -> pd.Series:
Copy link
Collaborator

Choose a reason for hiding this comment

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

We allready have the function edisgo.tools.tools.get_path_length_to_station

title = None
plots.histogram(data=data, title=title, timeindex=timestep, **kwargs)

def plot_voltage_over_dist(self, mv_id, lv_id, other, save_as=False, split_branches=False):
Copy link
Collaborator

Choose a reason for hiding this comment

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

The other parameter should be obsolete. The comparison between two grids should also be optional (sorry, I didn’t describe this correctly before). You shouldn’t need this parameter, since the reinforcement results are already stored in the edisgo object.

Have a look at the plot_plotly function here. In that function, the reinforcement results are taken directly from the object itself, which allows you to compare both versions.


# Distances (Dijkstra)
# Edge weight attribute commonly is 'length' in eDisGo graphs; adjust if your graph uses 'length_km'
dist_a = _shortest_distances_km(lv_grid_a.graph, source_bus=source_a, weight="length")
Copy link
Collaborator

Choose a reason for hiding this comment

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

v_b_feed = _series_at_t(v_b, t_feed_b)

# Buses to plot: intersection
buses = pd.Index([str(b) for b in lv_grid_a.buses_df.index]).intersection(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use all buses. As explained above, you don’t need to take the intersection, since both grids are identical.

# needs analysis results
self.edisgo.analyze()
v_res = self.edisgo.results.v_res() if callable(self.edisgo.results.v_res) else self.edisgo.results.v_res
if getattr(v_res, "empty", True):
Copy link
Collaborator

Choose a reason for hiding this comment

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

don't build a skip function in a test since you want to see the test failing.

def test_plot_voltage_over_dist_mv(self):
self.edisgo.analyze()
v_res = self.edisgo.results.v_res() if callable(self.edisgo.results.v_res) else self.edisgo.results.v_res
if getattr(v_res, "empty", True):
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as above

Comment on lines +1441 to +1443
if getattr(v_res, "empty", True):
import pytest
pytest.skip("No voltage results (v_res empty) in this test fixture; skipping voltage-over-distance plot test.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as above

import pytest
pytest.skip("No voltage results (v_res empty) in this test fixture; skipping voltage-over-distance plot test.")
fig = self.edisgo.plot_voltage_over_dist_mv(mv_id=None, other=other)
assert fig is not None
Copy link
Collaborator

Choose a reason for hiding this comment

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

This test only checks whether a figure is created, not whether the results are the expected ones. To test that, you would probably need the new functions to return the DataFrames, so you can verify that the DataFrames contain the expected values.

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.

[Feature] Add plotting methods for voltage vs. distance analysis with comparison functionality

3 participants