1111from typing import Dict , List , MutableMapping , Optional , Tuple , Type
1212
1313import numpy as np
14+ import pandapower as pp
1415import pandas as pd
1516import structlog
17+ from packaging .version import Version
1618from power_grid_model import (
1719 Branch3Side ,
1820 BranchSide ,
3436
3537logger = structlog .get_logger (__file__ )
3638
39+ pp_curr_version = Version (pp .__version__ )
40+ pp_ref_version = Version ("3.1.2" )
41+
3742
3843# pylint: disable=too-many-instance-attributes
3944class PandaPowerConverter (BaseConverter [PandaPowerData ]):
@@ -631,34 +636,53 @@ def _create_pgm_input_sym_loads(self):
631636 data_type = DatasetType .input , component_type = ComponentType .sym_load , shape = 3 * n_loads
632637 )
633638
634- const_i_multiplier = (
635- self ._get_pp_attr ("load" , "const_i_percent" , expected_type = "f8" , default = 0 ) * scaling * (1e-2 * 1e6 )
636- )
637- const_z_multiplier = (
638- self ._get_pp_attr ("load" , "const_z_percent" , expected_type = "f8" , default = 0 ) * scaling * (1e-2 * 1e6 )
639- )
640- const_p_multiplier = (1e6 - const_i_multiplier - const_z_multiplier ) * scaling
639+ if pp_curr_version <= pp_ref_version :
640+ const_i_p_multiplier = (
641+ self ._get_pp_attr ("load" , "const_i_percent" , expected_type = "f8" , default = 0 ) * scaling * (1e-2 * 1e6 )
642+ )
643+ const_z_p_multiplier = (
644+ self ._get_pp_attr ("load" , "const_z_percent" , expected_type = "f8" , default = 0 ) * scaling * (1e-2 * 1e6 )
645+ )
646+ const_p_multiplier = (1e6 - const_i_p_multiplier - const_z_p_multiplier ) * scaling
647+ const_q_multiplier = const_p_multiplier
648+ const_i_p_multiplier = const_i_p_multiplier
649+ const_z_q_multiplier = const_z_p_multiplier
650+ else :
651+ const_i_p_multiplier = (
652+ self ._get_pp_attr ("load" , "const_i_p_percent" , expected_type = "f8" , default = 0 ) * scaling * (1e-2 * 1e6 )
653+ )
654+ const_z_p_multiplier = (
655+ self ._get_pp_attr ("load" , "const_z_p_percent" , expected_type = "f8" , default = 0 ) * scaling * (1e-2 * 1e6 )
656+ )
657+ const_p_multiplier = (1e6 - const_i_p_multiplier - const_z_p_multiplier ) * scaling
658+ const_i_q_multiplier = (
659+ self ._get_pp_attr ("load" , "const_i_q_percent" , expected_type = "f8" , default = 0 ) * scaling * (1e-2 * 1e6 )
660+ )
661+ const_z_q_multiplier = (
662+ self ._get_pp_attr ("load" , "const_z_q_percent" , expected_type = "f8" , default = 0 ) * scaling * (1e-2 * 1e6 )
663+ )
664+ const_q_multiplier = (1e6 - const_i_q_multiplier - const_z_q_multiplier ) * scaling
641665
642666 pgm_sym_loads ["id" ][:n_loads ] = self ._generate_ids ("load" , pp_loads .index , name = "const_power" )
643667 pgm_sym_loads ["node" ][:n_loads ] = self ._get_pgm_ids ("bus" , bus )
644668 pgm_sym_loads ["status" ][:n_loads ] = in_service
645669 pgm_sym_loads ["type" ][:n_loads ] = LoadGenType .const_power
646670 pgm_sym_loads ["p_specified" ][:n_loads ] = const_p_multiplier * p_mw
647- pgm_sym_loads ["q_specified" ][:n_loads ] = const_p_multiplier * q_mvar
671+ pgm_sym_loads ["q_specified" ][:n_loads ] = const_q_multiplier * q_mvar
648672
649673 pgm_sym_loads ["id" ][n_loads : 2 * n_loads ] = self ._generate_ids ("load" , pp_loads .index , name = "const_impedance" )
650674 pgm_sym_loads ["node" ][n_loads : 2 * n_loads ] = self ._get_pgm_ids ("bus" , bus )
651675 pgm_sym_loads ["status" ][n_loads : 2 * n_loads ] = in_service
652676 pgm_sym_loads ["type" ][n_loads : 2 * n_loads ] = LoadGenType .const_impedance
653- pgm_sym_loads ["p_specified" ][n_loads : 2 * n_loads ] = const_z_multiplier * p_mw
654- pgm_sym_loads ["q_specified" ][n_loads : 2 * n_loads ] = const_z_multiplier * q_mvar
677+ pgm_sym_loads ["p_specified" ][n_loads : 2 * n_loads ] = const_z_p_multiplier * p_mw
678+ pgm_sym_loads ["q_specified" ][n_loads : 2 * n_loads ] = const_z_q_multiplier * q_mvar
655679
656680 pgm_sym_loads ["id" ][- n_loads :] = self ._generate_ids ("load" , pp_loads .index , name = "const_current" )
657681 pgm_sym_loads ["node" ][- n_loads :] = self ._get_pgm_ids ("bus" , bus )
658682 pgm_sym_loads ["status" ][- n_loads :] = in_service
659683 pgm_sym_loads ["type" ][- n_loads :] = LoadGenType .const_current
660- pgm_sym_loads ["p_specified" ][- n_loads :] = const_i_multiplier * p_mw
661- pgm_sym_loads ["q_specified" ][- n_loads :] = const_i_multiplier * q_mvar
684+ pgm_sym_loads ["p_specified" ][- n_loads :] = const_i_p_multiplier * p_mw
685+ pgm_sym_loads ["q_specified" ][- n_loads :] = const_i_q_multiplier * q_mvar
662686
663687 assert ComponentType .sym_load not in self .pgm_input_data
664688 self .pgm_input_data [ComponentType .sym_load ] = pgm_sym_loads
@@ -1860,12 +1884,12 @@ def _pp_lines_output_3ph(self):
18601884 "q_b_to_mvar" ,
18611885 "p_c_to_mw" ,
18621886 "q_c_to_mvar" ,
1863- "p_a_l_mw " ,
1864- "q_a_l_mvar " ,
1865- "p_b_l_mw " ,
1866- "q_b_l_mvar " ,
1867- "p_c_l_mw " ,
1868- "q_c_l_mvar " ,
1887+ "pl_a_mw " ,
1888+ "ql_a_mvar " ,
1889+ "pl_b_mw " ,
1890+ "ql_b_mvar " ,
1891+ "pl_c_mw " ,
1892+ "ql_c_mvar " ,
18691893 "i_a_from_ka" ,
18701894 "i_b_from_ka" ,
18711895 "i_c_from_ka" ,
@@ -1898,12 +1922,12 @@ def _pp_lines_output_3ph(self):
18981922 pp_output_lines_3ph ["q_b_to_mvar" ] = pgm_output_lines ["q_to" ][:, 1 ] * 1e-6
18991923 pp_output_lines_3ph ["p_c_to_mw" ] = pgm_output_lines ["p_to" ][:, 2 ] * 1e-6
19001924 pp_output_lines_3ph ["q_c_to_mvar" ] = pgm_output_lines ["q_to" ][:, 2 ] * 1e-6
1901- pp_output_lines_3ph ["p_a_l_mw " ] = (pgm_output_lines ["p_from" ][:, 0 ] + pgm_output_lines ["p_to" ][:, 0 ]) * 1e-6
1902- pp_output_lines_3ph ["q_a_l_mvar " ] = (pgm_output_lines ["q_from" ][:, 0 ] + pgm_output_lines ["q_to" ][:, 0 ]) * 1e-6
1903- pp_output_lines_3ph ["p_b_l_mw " ] = (pgm_output_lines ["p_from" ][:, 1 ] + pgm_output_lines ["p_to" ][:, 1 ]) * 1e-6
1904- pp_output_lines_3ph ["q_b_l_mvar " ] = (pgm_output_lines ["q_from" ][:, 1 ] + pgm_output_lines ["q_to" ][:, 1 ]) * 1e-6
1905- pp_output_lines_3ph ["p_c_l_mw " ] = (pgm_output_lines ["p_from" ][:, 2 ] + pgm_output_lines ["p_to" ][:, 2 ]) * 1e-6
1906- pp_output_lines_3ph ["q_c_l_mvar " ] = (pgm_output_lines ["q_from" ][:, 2 ] + pgm_output_lines ["q_to" ][:, 2 ]) * 1e-6
1925+ pp_output_lines_3ph ["pl_a_mw " ] = (pgm_output_lines ["p_from" ][:, 0 ] + pgm_output_lines ["p_to" ][:, 0 ]) * 1e-6
1926+ pp_output_lines_3ph ["ql_a_mvar " ] = (pgm_output_lines ["q_from" ][:, 0 ] + pgm_output_lines ["q_to" ][:, 0 ]) * 1e-6
1927+ pp_output_lines_3ph ["pl_b_mw " ] = (pgm_output_lines ["p_from" ][:, 1 ] + pgm_output_lines ["p_to" ][:, 1 ]) * 1e-6
1928+ pp_output_lines_3ph ["ql_b_mvar " ] = (pgm_output_lines ["q_from" ][:, 1 ] + pgm_output_lines ["q_to" ][:, 1 ]) * 1e-6
1929+ pp_output_lines_3ph ["pl_c_mw " ] = (pgm_output_lines ["p_from" ][:, 2 ] + pgm_output_lines ["p_to" ][:, 2 ]) * 1e-6
1930+ pp_output_lines_3ph ["ql_c_mvar " ] = (pgm_output_lines ["q_from" ][:, 2 ] + pgm_output_lines ["q_to" ][:, 2 ]) * 1e-6
19071931 pp_output_lines_3ph ["i_a_from_ka" ] = pgm_output_lines ["i_from" ][:, 0 ] * 1e-3
19081932 pp_output_lines_3ph ["i_b_from_ka" ] = pgm_output_lines ["i_from" ][:, 1 ] * 1e-3
19091933 pp_output_lines_3ph ["i_c_from_ka" ] = pgm_output_lines ["i_from" ][:, 2 ] * 1e-3
@@ -2040,12 +2064,12 @@ def _pp_trafos_output_3ph(self): # pylint: disable=too-many-statements
20402064 "q_b_lv_mvar" ,
20412065 "p_c_lv_mw" ,
20422066 "q_c_lv_mvar" ,
2043- "p_a_l_mw " ,
2044- "q_a_l_mvar " ,
2045- "p_b_l_mw " ,
2046- "q_b_l_mvar " ,
2047- "p_c_l_mw " ,
2048- "q_c_l_mvar " ,
2067+ "pl_a_mw " ,
2068+ "ql_a_mvar " ,
2069+ "pl_b_mw " ,
2070+ "ql_b_mvar " ,
2071+ "pl_c_mw " ,
2072+ "ql_c_mvar " ,
20492073 "i_a_hv_ka" ,
20502074 "i_a_lv_ka" ,
20512075 "i_b_hv_ka" ,
@@ -2071,22 +2095,22 @@ def _pp_trafos_output_3ph(self): # pylint: disable=too-many-statements
20712095 pp_output_trafos_3ph ["q_b_lv_mvar" ] = pgm_output_transformers ["q_to" ][:, 1 ] * 1e-6
20722096 pp_output_trafos_3ph ["p_c_lv_mw" ] = pgm_output_transformers ["p_to" ][:, 2 ] * 1e-6
20732097 pp_output_trafos_3ph ["q_c_lv_mvar" ] = pgm_output_transformers ["q_to" ][:, 2 ] * 1e-6
2074- pp_output_trafos_3ph ["p_a_l_mw " ] = (
2098+ pp_output_trafos_3ph ["pl_a_mw " ] = (
20752099 pgm_output_transformers ["p_from" ][:, 0 ] + pgm_output_transformers ["p_to" ][:, 0 ]
20762100 ) * 1e-6
2077- pp_output_trafos_3ph ["q_a_l_mvar " ] = (
2101+ pp_output_trafos_3ph ["ql_a_mvar " ] = (
20782102 pgm_output_transformers ["q_from" ][:, 0 ] + pgm_output_transformers ["q_to" ][:, 0 ]
20792103 ) * 1e-6
2080- pp_output_trafos_3ph ["p_b_l_mw " ] = (
2104+ pp_output_trafos_3ph ["pl_b_mw " ] = (
20812105 pgm_output_transformers ["p_from" ][:, 1 ] + pgm_output_transformers ["p_to" ][:, 1 ]
20822106 ) * 1e-6
2083- pp_output_trafos_3ph ["q_b_l_mvar " ] = (
2107+ pp_output_trafos_3ph ["ql_b_mvar " ] = (
20842108 pgm_output_transformers ["q_from" ][:, 1 ] + pgm_output_transformers ["q_to" ][:, 1 ]
20852109 ) * 1e-6
2086- pp_output_trafos_3ph ["p_c_l_mw " ] = (
2110+ pp_output_trafos_3ph ["pl_c_mw " ] = (
20872111 pgm_output_transformers ["p_from" ][:, 2 ] + pgm_output_transformers ["p_to" ][:, 2 ]
20882112 ) * 1e-6
2089- pp_output_trafos_3ph ["q_c_l_mvar " ] = (
2113+ pp_output_trafos_3ph ["ql_c_mvar " ] = (
20902114 pgm_output_transformers ["q_from" ][:, 2 ] + pgm_output_transformers ["q_to" ][:, 2 ]
20912115 ) * 1e-6
20922116 pp_output_trafos_3ph ["i_a_hv_ka" ] = pgm_output_transformers ["i_from" ][:, 0 ] * 1e-3
0 commit comments