7878 "UK" : "GB" ,
7979}
8080
81- AC_VIRTUAL_NODES = ["ITCO" , "ITVI" ]
81+ AC_VIRTUAL_NODES_IT = {
82+ "ITCO" : "FR15" ,
83+ "ITVI" : "ITSI" ,
84+ }
8285
8386IBFI_COORD = (63.0 , 25.0 )
8487
@@ -225,6 +228,41 @@ def build_shapes(
225228 return bidding_shapes , country_shapes
226229
227230
231+ def _add_virtual_node (
232+ target_gdf : gpd .GeoDataFrame ,
233+ new_bus : str ,
234+ ref_bus : str ,
235+ source_gdf : gpd .GeoDataFrame | None = None ,
236+ ** overrides ,
237+ ) -> None :
238+ """
239+ Add a virtual node to target Dataframe as a copy of an existing reference bus.
240+
241+ The virtual node inherits every attribute of the reference bus and takes its
242+ own name as ``station_id`` and ``tags``. Any remaining attribute is set
243+ through ``overrides``.
244+
245+ Parameters
246+ ----------
247+ target_gdf : gpd.GeoDataFrame
248+ Bus GeoDataFrame the virtual node is appended to, modified in place.
249+ new_bus : str
250+ Name of the virtual node.
251+ ref_bus : str
252+ Name of the reference bus whose attributes are copied.
253+ source_gdf : gpd.GeoDataFrame, optional
254+ Bus GeoDataFrame holding the reference bus. Defaults to ``target``.
255+ **overrides, optional
256+ Attribute values overriding those inherited from the reference bus.
257+ """
258+ source_gdf = target_gdf if source_gdf is None else source_gdf
259+ target_gdf .loc [new_bus ] = (
260+ source_gdf .loc [[ref_bus ]]
261+ .assign (station_id = new_bus , tags = new_bus , ** overrides )
262+ .loc [ref_bus ]
263+ )
264+
265+
228266def build_buses (
229267 buses_fn : str ,
230268 countries : list [str ],
@@ -283,14 +321,10 @@ def build_buses(
283321
284322 # Manually add Italian virtual nodes # TODO Refine assumptions
285323 if "IT" in countries :
286- buses .loc ["ITCO" ] = (
287- buses .loc [["FR15" ]]
288- .assign (station_id = "ITCO" , country = "IT" , tags = "ITCO" )
289- .loc ["FR15" ]
290- )
291- buses .loc ["ITVI" ] = (
292- buses .loc [["ITSI" ]].assign (station_id = "ITVI" , tags = "ITVI" ).loc ["ITSI" ]
293- )
324+ for node , location in AC_VIRTUAL_NODES_IT .items ():
325+ _add_virtual_node (
326+ target_gdf = buses , new_bus = node , ref_bus = location , country = "IT"
327+ )
294328
295329 buses_h2 = (
296330 country_shapes [["node" , "x" , "y" ]]
@@ -311,23 +345,23 @@ def build_buses(
311345
312346 # Manually add IBIT and IBFI nodes # TODO Refine assumptions
313347 if "IT" in countries :
314- buses_h2 .loc ["IBIT H2" ] = (
315- buses .loc [["ITN1" ]]
316- .assign (station_id = "IBIT H2" , voltage = None , dc = "f" , tags = "IBIT H2" )
317- .loc ["ITN1" ]
348+ _add_virtual_node (
349+ target_gdf = buses_h2 ,
350+ new_bus = "IBIT H2" ,
351+ ref_bus = "ITN1" ,
352+ source_gdf = buses ,
353+ voltage = None ,
354+ dc = "f" ,
318355 )
319356 if "FI" in countries :
320357 ibfi_lat , ibfi_long = IBFI_COORD
321- buses_h2 .loc ["IBFI H2" ] = (
322- buses_h2 .loc [["FI H2" ]]
323- .assign (
324- station_id = "IBFI H2" ,
325- tags = "IBFI H2" ,
326- x = ibfi_long ,
327- y = ibfi_lat ,
328- geometry = Point (ibfi_long , ibfi_lat ),
329- )
330- .loc ["FI H2" ]
358+ _add_virtual_node (
359+ target_gdf = buses_h2 ,
360+ new_bus = "IBFI H2" ,
361+ ref_bus = "FI H2" ,
362+ x = ibfi_long ,
363+ y = ibfi_lat ,
364+ geometry = Point (ibfi_long , ibfi_lat ),
331365 )
332366
333367 return buses , buses_h2
0 commit comments