Skip to content

Commit

Permalink
renames parameters for better clarity; adds the optional use_line_geo…
Browse files Browse the repository at this point in the history
…data parameter to the explorer

Signed-off-by: Christian Biasuzzi <christian.biasuzzi@soft.it>
  • Loading branch information
CBiasuzzi committed Sep 3, 2024
1 parent 7851615 commit d27e428
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
3 changes: 2 additions & 1 deletion docs/user_guide/network_explorer.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ A further click on an entry in the list will navigate the explorer to the corres
Other than the target network, the Network explorer can be customized using additional parameters:

```python
network_explorer(network: Network, vl_id : str = None, use_name:bool = True, depth: int = 0, high_nominal_voltage_bound: float = -1, low_nominal_voltage_bound: float = -1, nad_parameters: NadParameters = None, sld_parameters: SldParameters = None):
network_explorer(network: Network, vl_id : str = None, use_name:bool = True, depth: int = 0, high_nominal_voltage_bound: float = -1, low_nominal_voltage_bound: float = -1, nad_parameters: NadParameters = None, sld_parameters: SldParameters = None, use_line_geodata:bool = False):
```

- vl_id: the starting VL to display. If None, display the first VL from network.get_voltage_levels()
Expand All @@ -59,3 +59,4 @@ network_explorer(network: Network, vl_id : str = None, use_name:bool = True, de
- nominal_voltages_top_tiers_filter: number of nominal voltages to select in the Network map's nominal voltages filter, starting from the highest. -1 means all the nominal voltages.
- nad_parameters: layout properties to adjust the svg rendering for the NAD
- sld_parameters: layout properties to adjust the svg rendering for the SLD
- use_line_geodata: When False (default) the network map tab does not use the network's line geodata extensions; Each line is drawn as a straight line connecting two substations.
6 changes: 3 additions & 3 deletions docs/user_guide/network_map_widget.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ A click on a substation pops up a list of its VL.

## Widget API
```python
NetworkMapWidget(network:Network, subId:str = None, use_name:bool = True, display_lines:bool = True, use_line_extensions = False, nominal_voltages_top_tiers_filter = -1) -> NetworkMapWidget
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.
- subId: if not None, centers the network on the substation with the given substation id. Default is None.
- 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_extensions: When False (default) the widget does not use the network's line extensions; Each line is drawn as a straight line connecting two 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.


Expand Down
6 changes: 4 additions & 2 deletions src/pypowsybl_jupyter/networkexplorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
def network_explorer(network: Network, vl_id : str = None, use_name:bool = True, depth: int = 0,
high_nominal_voltage_bound: float = -1, low_nominal_voltage_bound: float = -1,
nominal_voltages_top_tiers_filter:int = -1,
nad_parameters: NadParameters = None, sld_parameters: SldParameters = None):
nad_parameters: NadParameters = None, sld_parameters: SldParameters = None,
use_line_geodata:bool = False):
"""
Creates a combined NAD and SLD explorer widget for the network. Diagrams are displayed on two different tabs.
A third tab, 'Network map' displays the network's substations and lines on a map.
Expand All @@ -31,6 +32,7 @@ def network_explorer(network: Network, vl_id : str = None, use_name:bool = True,
nominal_voltages_top_tiers_filter: number of nominal voltages to select in the nominal voltages filter, starting from the highest. -1 means all the nominal voltages (map viewer tab)
nad_parameters: layout properties to adjust the svg rendering for the NAD
sld_parameters: layout properties to adjust the svg rendering for the SLD
use_line_geodata: When False (default) the network map tab does not use the network's line geodata extensions; Each line is drawn as a straight line connecting two substations.
Examples:
Expand Down Expand Up @@ -110,7 +112,7 @@ def update_map():
nonlocal map_widget
if sel_ctx.get_selected() is not None:
if map_widget==None:
map_widget=NetworkMapWidget(network, use_name=use_name, nominal_voltages_top_tiers_filter = nominal_voltages_top_tiers_filter)
map_widget=NetworkMapWidget(network, use_name=use_name, nominal_voltages_top_tiers_filter = nominal_voltages_top_tiers_filter, use_line_geodata = use_line_geodata)
map_widget.on_selectvl(lambda event : go_to_vl_from_map(event))

else:
Expand Down
14 changes: 7 additions & 7 deletions src/pypowsybl_jupyter/networkmapwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class NetworkMapWidget(anywidget.AnyWidget):
Args:
network: the input network.
subId: if not None, centers the network on the substation with the given substation id. Default is None.
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_extensions: When False (default) the widget does not use the network's line extensions; Each line is drawn as a straight line connecting two 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.
Expand Down Expand Up @@ -58,16 +58,16 @@ class NetworkMapWidget(anywidget.AnyWidget):
selected_vl = traitlets.Unicode().tag(sync=True)


def __init__(self, network:Network, subId:str = None, use_name:bool = True, display_lines:bool = True, use_line_extensions = False, nominal_voltages_top_tiers_filter = -1, **kwargs):
def __init__(self, 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, **kwargs):
super().__init__(**kwargs)

(lmap, lpos, smap, spos, vl_subs, sub_vls, subs_ids) = self.extract_map_data(network, display_lines, use_line_extensions)
(lmap, lpos, smap, spos, vl_subs, sub_vls, subs_ids) = self.extract_map_data(network, display_lines, use_line_geodata)
self.lmap=json.dumps(lmap)
self.lpos=json.dumps(lpos)
self.smap=json.dumps(smap)
self.spos=json.dumps(spos)
self.use_name=use_name
self.params={"subId": subId}
self.params={"subId": sub_id}
self.vl_subs=vl_subs
self.sub_vls=sub_vls
self.subs_ids=subs_ids
Expand Down Expand Up @@ -101,7 +101,7 @@ def center_on_voltage_level(self, vl_id):
if sub_id is not None:
self.params = {"subId": sub_id}

def extract_map_data(self, network, display_lines, use_line_extensions):
def extract_map_data(self, network, display_lines, use_line_geodata):
lmap = []
lpos = []
smap = []
Expand Down Expand Up @@ -141,7 +141,7 @@ def extract_map_data(self, network, display_lines, use_line_extensions):
'connected2': 'terminal2Connected'
}).to_dict(orient='records')

if use_line_extensions:
if use_line_geodata:
lines_positions_from_extensions_df=network.get_extensions('linePosition').reset_index()
lines_positions_from_extensions_sorted_df = lines_positions_from_extensions_df.sort_values(by=['id', 'num'])
lines_positions_from_extensions_grouped_df = lines_positions_from_extensions_sorted_df.groupby('id').apply(lambda x: x[['latitude', 'longitude']].to_dict('records'), include_groups=False).to_dict()
Expand Down

0 comments on commit d27e428

Please sign in to comment.