-
Notifications
You must be signed in to change notification settings - Fork 0
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
map-viewer widget #13
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
24a733a
adds a map-viewer widget based on the network-map-viewer component (f…
CBiasuzzi c915f67
Merge branch 'main' into mapviewer_widget
CBiasuzzi 4b5e898
adds the VL picker and the VL nominal voltage filter to the map widge…
CBiasuzzi e17bab9
adds a map tab to the network explorer; map widget can also use the l…
CBiasuzzi db3707e
Merge branch 'main' into mapviewer_widget
CBiasuzzi 4f3171b
adds parameters for displaying ids or names, and filter the top n nom…
CBiasuzzi 1d83530
fixes size of the voltage filter
CBiasuzzi f8785b9
fixes the case when the network line extensions are used and coordina…
CBiasuzzi dd26a3d
aligns to the latest main (use_name feature)
CBiasuzzi 086ad7d
updates docs
CBiasuzzi 69fd6c0
Merge branch 'main' into mapviewer_widget
flo-dup 7851615
fixes typos and missing copyright headers
CBiasuzzi d27e428
renames parameters for better clarity; adds the optional use_line_geo…
CBiasuzzi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Network map widget | ||
|
||
Network map is an interactive widget that displays a network's substations and lines on a map. | ||
If the network does not contain geo data (in its substation's and line's IIDM extensions), the map will be empty. | ||
The widget allows you to pan and zoom the map. A filter on the network's nominal voltages list can be used to improve the readability of the map, in case of a large network. | ||
|
||
The following code, to be run in a notebook, first creates a network, then displays the Network map widget on it. | ||
|
||
```python | ||
import pypowsybl.network as pn | ||
from pypowsybl_jupyter import NetworkMapWidget | ||
|
||
# load a CGMES file containing a GL profile (Graphical Layout) and run a LF | ||
network1 = pn.load('./data/MicroGridTestConfiguration_T4_BE_BB_Complete_v2.zip', {'iidm.import.cgmes.post-processors': 'cgmesGLImport'}) | ||
|
||
NetworkMapWidget(network1) | ||
``` | ||
|
||
![Network map widget 1](/_static/img/networkmap_1.png) | ||
|
||
|
||
A click on a substation pops up a list of its VL. | ||
|
||
![Network map widget 2](/_static/img/networkmap_2.png) | ||
|
||
|
||
## Widget API | ||
```python | ||
NetworkMapWidget(network:Network, sub_id:str = None, use_name:bool = True, display_lines:bool = True, use_line_geodata:bool = False, nominal_voltages_top_tiers_filter = -1) -> NetworkMapWidget | ||
``` | ||
|
||
- network: the input network. | ||
- sub_id: if not None, centers the network on the substation with the given substation id. Default is None. | ||
- use_name: When True (default) the widget displays network's elements names (if available, otherwise their ids); When False, the widget displays network's elements ids. | ||
- display_lines: When True (default) the network lines are displayed on the map. When false, the widget displays only the substations. | ||
- use_line_geodata: When False (default) the widget does not use the network's line geodata extensions; Each line is drawn as a straight line connecting two substations. | ||
- nominal_voltages_top_tiers_filter: filters the elements in the map based on the network's top nominal voltages. N displays the top n nominal voltages; -1 (default) displays all. | ||
|
||
|
||
## Customize widget's interactions | ||
It is possible to customize the widget's behaviour when one entry is clicked in a substation's voltage levels popup. This feature could be used to create more complex interactions (e.g., by integrating other widgets). | ||
|
||
Use these widget's method to register a callback on a specific event: | ||
|
||
- on_selectvl | ||
|
||
The [network explorer](/user_guide/network_explorer.md) demonstrates the approach. | ||
|
||
Example: the code below activate a callback when a VL entry is clicked in the VL list popup. This example just prints the voltage level. | ||
|
||
```python | ||
|
||
map_widget = NetworkMapWidget(network) | ||
map_widget.on_selectvl(lambda event : print_infos('Selected VL : ' + event.selected_vl)) | ||
``` |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<iidm:network xmlns:iidm="http://www.powsybl.org/schema/iidm/1_12" xmlns:lp="http://www.powsybl.org/schema/iidm/ext/line_position/1_0" xmlns:sp="http://www.powsybl.org/schema/iidm/ext/substation_position/1_0" id="sim1" caseDate="2022-04-06T13:43:05.020+02:00" forecastDistance="0" sourceFormat="test" minimumValidationLevel="STEADY_STATE_HYPOTHESIS"> | ||
<iidm:substation id="P1" country="FR" tso="RTE" geographicalTags="A"> | ||
<iidm:voltageLevel id="VLGEN" nominalV="24.0" topologyKind="BUS_BREAKER"> | ||
<iidm:busBreakerTopology> | ||
<iidm:bus id="NGEN"/> | ||
</iidm:busBreakerTopology> | ||
<iidm:generator id="GEN" energySource="OTHER" minP="-9999.99" maxP="9999.99" voltageRegulatorOn="true" targetP="607.0" targetV="24.5" targetQ="301.0" bus="NGEN" connectableBus="NGEN"> | ||
<iidm:minMaxReactiveLimits minQ="-9999.99" maxQ="9999.99"/> | ||
</iidm:generator> | ||
</iidm:voltageLevel> | ||
<iidm:voltageLevel id="VLHV1" nominalV="380.0" topologyKind="BUS_BREAKER"> | ||
<iidm:busBreakerTopology> | ||
<iidm:bus id="NHV1"/> | ||
</iidm:busBreakerTopology> | ||
</iidm:voltageLevel> | ||
<iidm:twoWindingsTransformer id="NGEN_NHV1" r="0.26658461538461536" x="11.104492831516762" g="0.0" b="0.0" ratedU1="24.0" ratedU2="400.0" bus1="NGEN" connectableBus1="NGEN" voltageLevelId1="VLGEN" bus2="NHV1" connectableBus2="NHV1" voltageLevelId2="VLHV1"/> | ||
</iidm:substation> | ||
<iidm:substation id="P2" country="FR" tso="RTE" geographicalTags="B"> | ||
<iidm:voltageLevel id="VLHV2" nominalV="380.0" topologyKind="BUS_BREAKER"> | ||
<iidm:busBreakerTopology> | ||
<iidm:bus id="NHV2"/> | ||
</iidm:busBreakerTopology> | ||
</iidm:voltageLevel> | ||
<iidm:voltageLevel id="VLLOAD" nominalV="150.0" topologyKind="BUS_BREAKER"> | ||
<iidm:busBreakerTopology> | ||
<iidm:bus id="NLOAD"/> | ||
</iidm:busBreakerTopology> | ||
<iidm:load id="LOAD" loadType="UNDEFINED" p0="600.0" q0="200.0" bus="NLOAD" connectableBus="NLOAD"/> | ||
</iidm:voltageLevel> | ||
<iidm:twoWindingsTransformer id="NHV2_NLOAD" r="0.04724999999999999" x="4.049724365620455" g="0.0" b="0.0" ratedU1="400.0" ratedU2="158.0" bus1="NHV2" connectableBus1="NHV2" voltageLevelId1="VLHV2" bus2="NLOAD" connectableBus2="NLOAD" voltageLevelId2="VLLOAD"> | ||
<iidm:ratioTapChanger lowTapPosition="0" tapPosition="1" targetDeadband="0.0" loadTapChangingCapabilities="true" regulating="true" regulationMode="VOLTAGE" regulationValue="158.0"> | ||
<iidm:terminalRef id="NHV2_NLOAD" side="TWO"/> | ||
<iidm:step r="0.0" x="0.0" g="0.0" b="0.0" rho="0.8505666905244191"/> | ||
<iidm:step r="0.0" x="0.0" g="0.0" b="0.0" rho="1.0006666666666666"/> | ||
<iidm:step r="0.0" x="0.0" g="0.0" b="0.0" rho="1.150766642808914"/> | ||
</iidm:ratioTapChanger> | ||
</iidm:twoWindingsTransformer> | ||
</iidm:substation> | ||
<iidm:line id="NHV1_NHV2_1" r="3.0" x="33.0" g1="0.0" b1="1.93E-4" g2="0.0" b2="1.93E-4" bus1="NHV1" connectableBus1="NHV1" voltageLevelId1="VLHV1" bus2="NHV2" connectableBus2="NHV2" voltageLevelId2="VLHV2"/> | ||
<iidm:line id="NHV1_NHV2_2" r="3.0" x="33.0" g1="0.0" b1="1.93E-4" g2="0.0" b2="1.93E-4" bus1="NHV1" connectableBus1="NHV1" voltageLevelId1="VLHV1" bus2="NHV2" connectableBus2="NHV2" voltageLevelId2="VLHV2"/> | ||
<iidm:extension id="P1"> | ||
<sp:substationPosition> | ||
<sp:coordinate longitude="2.0" latitude="48.0"/> | ||
</sp:substationPosition> | ||
</iidm:extension> | ||
<iidm:extension id="P2"> | ||
<sp:substationPosition> | ||
<sp:coordinate longitude="2.1" latitude="48.1"/> | ||
</sp:substationPosition> | ||
</iidm:extension> | ||
|
||
<iidm:extension id="NHV1_NHV2_1"> | ||
<lp:linePosition> | ||
<sp:coordinate longitude="2.0" latitude="48.0"/> | ||
<sp:coordinate longitude="2.1" latitude="48.1"/> | ||
</lp:linePosition> | ||
</iidm:extension> | ||
|
||
<iidm:extension id="NHV1_NHV2_2"> | ||
<lp:linePosition> | ||
<sp:coordinate longitude="2.0" latitude="48.0"/> | ||
<sp:coordinate longitude="2.1" latitude="48.1"/> | ||
</lp:linePosition> | ||
</iidm:extension> | ||
|
||
</iidm:network> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import pypowsybl.network as pn\n", | ||
"import pypowsybl.loadflow as lf\n", | ||
"import ipywidgets as widgets" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from pypowsybl_jupyter import NetworkMapWidget" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Example 1\n", | ||
"# load a CGMES file containing a GL profile (Graphical Layout) and run a LF\n", | ||
"network1 = pn.load('./data/MicroGridTestConfiguration_T4_BE_BB_Complete_v2.zip', {'iidm.import.cgmes.post-processors': 'cgmesGLImport'})\n", | ||
"network_lf_results=lf.run_ac(network1)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"#declare a text place where events data will be displayed\n", | ||
"out_events = widgets.Output()\n", | ||
"def print_infos(data): \n", | ||
" with out_events:\n", | ||
" print(data)\n", | ||
"print_infos('Events log:')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"#create a map widget for the network and activate a callback on the selected VL event\n", | ||
"map_widget1 = NetworkMapWidget(network1)\n", | ||
"map_widget1.on_selectvl(lambda event : print_infos('Selected VL : ' + event.selected_vl))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"#finally, display the widget\n", | ||
"widgets.HBox([map_widget1, out_events])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Example 2\n", | ||
"# load a network that includes geographical data extensions, run a LF and display the network with the NetworkMap widget" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"network2=pn.load('./data/demo_geo1.xml')\n", | ||
"lf_results2=lf.run_ac(network2)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"network_map2=NetworkMapWidget(network2)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"display(network_map2)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# center the map on a specific substation\n", | ||
"network_map2.center_on_substation('P1')" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.12.3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.network-map-viewer-widget { | ||
border: 2px solid lightgrey; | ||
display: inline-block; | ||
} | ||
|
||
.maplibregl-ctrl-bottom-left { | ||
display: none; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The map is empty but centered and zoomed on latitude 0, longitude 0, which is strange. It would be better to have the map unzoomed to see the whole world. Or not to load the map viewer widget, replacing it with a text "No geodata found"? what do you think?