-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds a function parameter to the explorer, to filter the voltage leve…
…ls list using some custom logic Signed-off-by: Christian Biasuzzi <christian.biasuzzi@soft.it>
- Loading branch information
Showing
3 changed files
with
144 additions
and
6 deletions.
There are no files selected for viewing
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,117 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "f42abf42-4718-4f92-a542-68ae289906a6", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import pypowsybl.network as pn\n", | ||
"from pypowsybl_jupyter import network_explorer" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "ece1d9b1-31b4-4b43-8e2c-42773d7ffbeb", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"#Define a ComponentType enum for a Network, and a filter function that returns the set of the network VL's ids, \n", | ||
"#for all the VLs that include a component of type c_type" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "20558132-2382-49e9-ac8e-c5b7afd0d139", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from enum import Enum\n", | ||
"\n", | ||
"class ComponentType(Enum):\n", | ||
" LINE = 'LINE'\n", | ||
" TWT = 'TWT'\n", | ||
" SVC = 'SVC' \n", | ||
" GENERATOR = 'GENERATOR'\n", | ||
" BATTERY = 'BATTERY'\n", | ||
"\n", | ||
"def filter_vls_by_included_component_type(network: pn.Network, c_type:ComponentType):\n", | ||
" if c_type == ComponentType.LINE:\n", | ||
" df = network.get_lines()[['voltage_level1_id', 'voltage_level2_id']]\n", | ||
" vls = set(df['voltage_level1_id']).union(set(df['voltage_level2_id']))\n", | ||
" elif c_type == ComponentType.TWT:\n", | ||
" df = network.get_2_windings_transformers()[['voltage_level1_id', 'voltage_level2_id']]\n", | ||
" vls = set(df['voltage_level1_id']).union(set(df['voltage_level2_id']))\n", | ||
" elif c_type == ComponentType.GENERATOR:\n", | ||
" df = network.get_generators()[['voltage_level_id']]\n", | ||
" vls = set(df['voltage_level_id']) \n", | ||
" elif c_type == ComponentType.SVC:\n", | ||
" df = network.get_static_var_compensators()[['voltage_level_id']]\n", | ||
" vls = set(df['voltage_level_id']) \n", | ||
" elif c_type == ComponentType.BATTERY:\n", | ||
" df = network.get_batteries()[['voltage_level_id']]\n", | ||
" vls = set(df['voltage_level_id']) \n", | ||
" \n", | ||
" if len(vls) == 0: \n", | ||
" raise ValueError(f'the network does not contain any voltage level that includse a {c_type.name}')\n", | ||
"\n", | ||
" return vls" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "5ca2e7af-7d2a-4169-b71d-57cf3f8980a4", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Creates a network, then opens an explorer filtering the VL by component type" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "ce646543-5d2d-4933-8106-dfb7a281124e", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"four_substations_network = pn.create_four_substations_node_breaker_network()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "6bb2f0a1-97e4-4cf5-975b-7e1651c830bb", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"network_explorer(four_substations_network,\n", | ||
" filter_vls_function = lambda network: filter_vls_by_included_component_type(network, ComponentType.SVC))" | ||
] | ||
} | ||
], | ||
"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": 5 | ||
} |
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