From d27e428c96b645dd669c48b215eb2f6ff68f2957 Mon Sep 17 00:00:00 2001 From: Christian Biasuzzi Date: Tue, 3 Sep 2024 16:55:11 +0200 Subject: [PATCH] renames parameters for better clarity; adds the optional use_line_geodata parameter to the explorer Signed-off-by: Christian Biasuzzi --- docs/user_guide/network_explorer.md | 3 ++- docs/user_guide/network_map_widget.md | 6 +++--- src/pypowsybl_jupyter/networkexplorer.py | 6 ++++-- src/pypowsybl_jupyter/networkmapwidget.py | 14 +++++++------- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/docs/user_guide/network_explorer.md b/docs/user_guide/network_explorer.md index 7935105..5d6b2ca 100644 --- a/docs/user_guide/network_explorer.md +++ b/docs/user_guide/network_explorer.md @@ -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() @@ -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. diff --git a/docs/user_guide/network_map_widget.md b/docs/user_guide/network_map_widget.md index 5f0609e..f520d12 100644 --- a/docs/user_guide/network_map_widget.md +++ b/docs/user_guide/network_map_widget.md @@ -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. diff --git a/src/pypowsybl_jupyter/networkexplorer.py b/src/pypowsybl_jupyter/networkexplorer.py index cd4703b..044c881 100644 --- a/src/pypowsybl_jupyter/networkexplorer.py +++ b/src/pypowsybl_jupyter/networkexplorer.py @@ -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. @@ -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: @@ -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: diff --git a/src/pypowsybl_jupyter/networkmapwidget.py b/src/pypowsybl_jupyter/networkmapwidget.py index 3b22f6a..368c1e0 100644 --- a/src/pypowsybl_jupyter/networkmapwidget.py +++ b/src/pypowsybl_jupyter/networkmapwidget.py @@ -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. @@ -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 @@ -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 = [] @@ -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()