99import pandapower .plotting as plt
1010
1111DIGITS = 5
12+ miles_to_km = 1.60934
13+ baseMVA = 100.
1214
1315
1416def _read_csv (table ):
@@ -135,7 +137,7 @@ def create_gens():
135137
136138def create_ppc ():
137139 ppc = dict ()
138- ppc ["baseMVA" ] = 100.
140+ ppc ["baseMVA" ] = baseMVA
139141 # ppc["areas"] =
140142 ppc ["bus" ] = create_buses ()
141143 ppc ["branch" ] = create_branches ()
@@ -144,15 +146,68 @@ def create_ppc():
144146 return ppc
145147
146148
149+ def _update_line_data (net , branch_data , element = "line" ):
150+ b = net ["bus" ].loc [:, "id" ].values .astype (int )
151+ from_var = "from_bus"
152+ to_var = "to_bus"
153+
154+ for i in branch_data .index :
155+ a = branch_data .loc [i , ["From Bus" , "To Bus" ]].values .astype (int )
156+ bus_ind = np .where (np .in1d (b , a ))[0 ]
157+ element_rows = (net [element ].loc [:, [from_var , to_var ]] == bus_ind ).values
158+ element_index = element_rows [:, 0 ] & element_rows [:, 1 ]
159+ net [element ].loc [element_index , "name" ] = branch_data .at [i , "UID" ]
160+ net [element ].loc [element_index , "length_km" ] = branch_data .at [i , "Length" ] * miles_to_km
161+
162+
163+ def create_trafo_c35 (net , branch_data ):
164+ rk = branch_data .loc [119 , 'R' ]
165+ xk = branch_data .loc [119 , 'X' ]
166+ zk = (rk ** 2 + xk ** 2 ) ** 0.5
167+ sn = branch_data .loc [119 , 'Cont Rating' ]
168+ i0_percent = - branch_data .loc [119 , 'B' ] * 100 * baseMVA / sn
169+
170+ pp .create_transformer_from_parameters (net , hv_bus = 70 , lv_bus = 72 , sn_mva = sn ,
171+ vn_hv_kv = net .bus .loc [70 , "vn_kv" ], vn_lv_kv = net .bus .loc [72 , "vn_kv" ],
172+ vk_percent = np .sign (xk ) * zk * sn * 100 / baseMVA ,
173+ vkr_percent = rk * sn * 100 / baseMVA , max_loading_percent = 100 ,
174+ i0_percent = i0_percent , pfe_kw = 0. ,
175+ tap_side = "lv" , tap_neutral = 0 , name = branch_data .loc [119 , "UID" ],
176+ shift_degree = 0. , tap_step_percent = 1.5 , tap_pos = 0 , tap_phase_shifter = False )
177+
178+
147179def add_additional_information (net ):
148180 bus_data = _read_csv ("bus" )
149- bus_index = net ["bus" ].loc [:, "name" ].values == bus_data ["Bus ID" ]
181+ # store bus id
182+ net ["bus" ].loc [:, "id" ] = net ["bus" ].loc [:, "name" ].values
183+ # check if indices are identical
184+ assert np .allclose (bus_data ["Bus ID" ].values .astype (int ), net ["bus" ].loc [:, "id" ].values .astype (int ))
150185 # bus names
151- net ["bus" ].loc [:, "name" ] = bus_data .loc [bus_index , "Bus Name" ]
186+ net ["bus" ].loc [:, "name" ] = bus_data .loc [: , "Bus Name" ]
152187
153188 # bus geodata
154189 net ["bus_geodata" ] = pd .DataFrame (index = np .arange (len (bus_data )), columns = ["x" , "y" , "coords" ])
155- net ["bus_geodata" ].loc [:, ["x" , "y" ]] = bus_data .loc [bus_index , ["lat" , "lng" ]].values
190+ net ["bus_geodata" ].loc [:, ["x" , "y" ]] = bus_data .loc [:, ["lat" , "lng" ]].values
191+
192+ # correct line names and lengths
193+ branch_data = _read_csv ("branch" )
194+ _update_line_data (net , branch_data , element = "line" )
195+
196+ # 104 is a transformer, not a line
197+ net ["line" ].drop (104 , inplace = True )
198+ create_trafo_c35 (net , branch_data )
199+ # set trafo names
200+ net .trafo .loc [:, "name" ] = branch_data .loc [branch_data .loc [:, "Length" ] == 0.0 , "UID" ]
201+
202+ # manual corrections
203+ net ["line" ].loc [102 :103 , "name" ] = branch_data .loc [117 :118 , "UID" ].values
204+ net ["line" ].loc [102 :103 , "length_km" ] = branch_data .loc [117 :118 , "Length" ].values * miles_to_km
205+
206+ # correct R, X, and C (since they are in per_km)
207+ net ["line" ].loc [:, "r_ohm_per_km" ] /= net ["line" ].loc [:, "length_km" ].values
208+ net ["line" ].loc [:, "x_ohm_per_km" ] /= net ["line" ].loc [:, "length_km" ].values
209+ net ["line" ].loc [:, "c_nf_per_km" ] /= net ["line" ].loc [:, "length_km" ].values
210+ net ["line" ].loc [:, "g_us_per_km" ] /= net ["line" ].loc [:, "length_km" ].values
156211
157212 return net
158213
@@ -162,9 +217,16 @@ def create_pp_from_ppc():
162217 ppc = create_ppc ()
163218 # convert it to a pandapower net
164219 net = cv .from_ppc (ppc , validate_conversion = False )
220+ # run a power flow
221+ pp .runpp (net )
222+ vm_pu_before = net .res_bus .vm_pu .values
223+ # manual corrections and additional information such as line length in km and names
165224 net = add_additional_information (net )
166- # run power flow
225+ # run power flow again and validate results
167226 pp .runpp (net )
227+ vm_pu_after = net .res_bus .vm_pu .values
228+ # power flow results should not change
229+ assert np .allclose (vm_pu_after , vm_pu_before )
168230 # save it
169231 pp .to_json (net , "pandapower_net.json" )
170232 # plot it :)
0 commit comments