44
55import os
66import sys
7+ from typing import Dict , List
78
89import geopandas as gpd
910import pandas as pd
1011import pypsa
1112import xarray as xr
12- from typing import Dict , List
13-
14- import os
15- import sys
1613
1714sys .path .append (os .path .join (os .path .dirname (__file__ ), ".." , ".." ))
1815
@@ -59,10 +56,12 @@ def add_buses(n: pypsa.Network, subnode: pd.Series, name: str) -> None:
5956def get_district_heating_loads (n : pypsa .Network ):
6057 """
6158 Get the district heating loads from the network.
59+
6260 Parameters
6361 ----------
6462 n : pypsa.Network
6563 The PyPSA network object from which to extract district heating loads.
64+
6665 Returns
6766 -------
6867 float
@@ -71,9 +70,9 @@ def get_district_heating_loads(n: pypsa.Network):
7170 return (
7271 n .snapshot_weightings .generators
7372 @ n .loads_t .p_set .filter (
74- like = f "urban central heat" ,
73+ like = "urban central heat" ,
7574 )
76- ).sum () + n .loads .filter (like = f "low-temperature heat for industry" , axis = 0 )[
75+ ).sum () + n .loads .filter (like = "low-temperature heat for industry" , axis = 0 )[
7776 "p_set"
7877 ].sum () * 8760
7978
@@ -178,13 +177,13 @@ def add_loads(
178177 )
179178
180179 # Adjust loads of cluster buses
181- n .loads_t .p_set .loc [
182- :, f' { subnode [ "cluster" ] } urban central heat'
183- ] -= urban_central_heat_load
180+ n .loads_t .p_set .loc [:, f" { subnode [ 'cluster' ] } urban central heat" ] -= (
181+ urban_central_heat_load
182+ )
184183
185- n .loads .loc [
186- f' { subnode [ "cluster" ] } low-temperature heat for industry' , "p_set"
187- ] -= low_temperature_heat_for_industry_load
184+ n .loads .loc [f" { subnode [ 'cluster' ] } low-temperature heat for industry" , "p_set" ] -= (
185+ low_temperature_heat_for_industry_load
186+ )
188187
189188 if lost_load > 0 :
190189 lost_load_subnode = subnode ["yearly_heat_demand_MWh" ] - (
@@ -528,6 +527,7 @@ def add_subnodes(
528527 Dictionary mapping heat sources to paths with potential data.
529528 output_path : str
530529 Path to save the subnodes_head GeoDataFrame.
530+
531531 Returns
532532 -------
533533 None
@@ -548,7 +548,7 @@ def add_subnodes(
548548 dh_loads_before = get_district_heating_loads (n )
549549 # Add subnodes to network
550550 for _ , subnode in subnodes_head .iterrows ():
551- name = f' { subnode [" cluster" ]} { subnode [" Stadt" ]} urban central'
551+ name = f" { subnode [' cluster' ]} { subnode [' Stadt' ]} urban central"
552552
553553 # Add different component types
554554 add_buses (n , subnode , name )
@@ -577,9 +577,9 @@ def add_subnodes(
577577 )
578578 dh_loads_after = get_district_heating_loads (n )
579579 # Check if the total district heating load is preserved
580- assert (
581- dh_loads_before == dh_loads_after
582- ), "Total district heating load is not preserved after adding subnodes."
580+ assert dh_loads_before == dh_loads_after , (
581+ "Total district heating load is not preserved after adding subnodes."
582+ )
583583
584584
585585def extend_heating_distribution (
0 commit comments