Skip to content

Commit 98f0a4e

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent c7a7038 commit 98f0a4e

9 files changed

+92
-87
lines changed

Snakefile

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,7 @@ rule prepare_district_heating_subnodes:
358358
baseyear=config_provider("scenario", "planning_horizons", 0),
359359
input:
360360
heating_technologies_nuts3=resources("heating_technologies_nuts3.geojson"),
361-
regions_onshore=resources(
362-
"regions_onshore_base_s_{clusters}.geojson"
363-
),
361+
regions_onshore=resources("regions_onshore_base_s_{clusters}.geojson"),
364362
fernwaermeatlas="data/fernwaermeatlas/fernwaermeatlas.xlsx",
365363
cities="data/fernwaermeatlas/cities_geolocations.geojson",
366364
lau_regions="data/lau_regions.zip",
@@ -375,8 +373,8 @@ rule prepare_district_heating_subnodes:
375373
natura=ancient("data/bundle/natura/natura.tiff"),
376374
groundwater_depth=storage(
377375
"http://thredds-gfnl.usc.es/thredds/fileServer/GLOBALWTDFTP/annualmeans/EURASIA_WTD_annualmean.nc",
378-
keep_local=True
379-
),
376+
keep_local=True,
377+
),
380378
output:
381379
district_heating_subnodes=resources(
382380
"district_heating_subnodes_base_s_{clusters}.geojson"
@@ -387,52 +385,51 @@ rule prepare_district_heating_subnodes:
387385
regions_onshore_restricted=resources(
388386
"regions_onshore_base-restricted_s_{clusters}.geojson"
389387
),
390-
391388
resources:
392389
mem_mb=20000,
393390
script:
394391
"scripts/pypsa-de/prepare_district_heating_subnodes.py"
395392

393+
396394
baseyear_value = config["scenario"]["planning_horizons"][0]
397395

396+
398397
rule add_district_heating_subnodes:
399398
params:
400399
district_heating=config_provider("sector", "district_heating"),
401400
baseyear=config_provider("scenario", "planning_horizons", 0),
402401
sector=config_provider("sector"),
403-
heat_pump_sources=config_provider("sector", "heat_pump_sources", "urban central"),
402+
heat_pump_sources=config_provider(
403+
"sector", "heat_pump_sources", "urban central"
404+
),
404405
heat_utilisation_potentials=config_provider(
405-
"sector", "district_heating", "heat_utilisation_potentials"
406+
"sector", "district_heating", "heat_utilisation_potentials"
406407
),
407408
direct_utilisation_heat_sources=config_provider(
408409
"sector", "district_heating", "direct_utilisation_heat_sources"
409410
),
410-
adjustments=config_provider( "adjustments", "sector"),
411+
adjustments=config_provider("adjustments", "sector"),
411412
input:
412413
unpack(input_heat_source_power),
413414
network=resources(
414-
"networks/base_s_{clusters}_{opts}_{sector_opts}_{planning_horizons}.nc"
415-
),
416-
subnodes=resources(
417-
"district_heating_subnodes_base_s_{clusters}.geojson"
415+
"networks/base_s_{clusters}_{opts}_{sector_opts}_{planning_horizons}.nc"
418416
),
417+
subnodes=resources("district_heating_subnodes_base_s_{clusters}.geojson"),
419418
nuts3=resources("nuts3_shapes.geojson"),
420-
regions_onshore=resources(
421-
"regions_onshore_base_s_{clusters}.geojson"
422-
),
419+
regions_onshore=resources("regions_onshore_base_s_{clusters}.geojson"),
423420
fernwaermeatlas="data/fernwaermeatlas/fernwaermeatlas.xlsx",
424421
cities="data/fernwaermeatlas/cities_geolocations.geojson",
425422
cop_profiles=resources("cop_profiles_base_s_{clusters}_{planning_horizons}.nc"),
426423
direct_heat_source_utilisation_profiles=resources(
427-
"direct_heat_source_utilisation_profiles_base_s_{clusters}_{planning_horizons}.nc"
424+
"direct_heat_source_utilisation_profiles_base_s_{clusters}_{planning_horizons}.nc"
428425
),
429426
existing_heating_distribution=resources(
430427
f"existing_heating_distribution_base_s_{{clusters}}_{baseyear_value}.csv"
431428
),
432429
lau_regions="data/lau_regions.zip",
433430
output:
434431
network=resources(
435-
"networks/base-extended_s_{clusters}_{opts}_{sector_opts}_{planning_horizons}.nc"
432+
"networks/base-extended_s_{clusters}_{opts}_{sector_opts}_{planning_horizons}.nc"
436433
),
437434
district_heating_subnodes=resources(
438435
"district_heating_subnodes_base_s_{clusters}_{opts}_{sector_opts}_{planning_horizons}.geojson"
@@ -600,16 +597,12 @@ rule build_existing_chp_de:
600597
),
601598
regions=resources("regions_onshore_base_s_{clusters}.geojson"),
602599
district_heating_subnodes=(
603-
resources(
604-
"district_heating_subnodes_base_s_{clusters}.geojson"
605-
)
600+
resources("district_heating_subnodes_base_s_{clusters}.geojson")
606601
if config["sector"]["district_heating"].get("add_subnodes", True)
607602
else []
608603
),
609604
output:
610-
german_chp=resources(
611-
"german_chp_base_s_{clusters}.csv"
612-
),
605+
german_chp=resources("german_chp_base_s_{clusters}.csv"),
613606
log:
614607
logs("build_existing_chp_de_{clusters}.log"),
615608
script:

rules/build_sector.smk

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,11 @@ rule build_temperature_profiles:
199199
drop_leap_day=config_provider("enable", "drop_leap_day"),
200200
input:
201201
pop_layout=resources("pop_layout_total.nc"),
202-
regions_onshore=resources("regions_onshore_base-extended_s_{clusters}.geojson") if config["sector"][
203-
"district_heating"
204-
].get("add_subnodes", True) else resources("regions_onshore_base_s_{clusters}.geojson"),
202+
regions_onshore=(
203+
resources("regions_onshore_base-extended_s_{clusters}.geojson")
204+
if config["sector"]["district_heating"].get("add_subnodes", True)
205+
else resources("regions_onshore_base_s_{clusters}.geojson")
206+
),
205207
cutout=lambda w: input_cutout(
206208
w, config_provider("sector", "heat_demand_cutout")(w)
207209
),
@@ -270,9 +272,11 @@ rule build_central_heating_temperature_profiles:
270272
energy_totals_year=config_provider("energy", "energy_totals_year"),
271273
input:
272274
temp_air_total=resources("temp_air_total_base_s_{clusters}.nc"),
273-
regions_onshore=resources("regions_onshore_base-extended_s_{clusters}.geojson") if config["sector"][
274-
"district_heating"
275-
].get("add_subnodes", True) else resources("regions_onshore_base_s_{clusters}.geojson"),
275+
regions_onshore=(
276+
resources("regions_onshore_base-extended_s_{clusters}.geojson")
277+
if config["sector"]["district_heating"].get("add_subnodes", True)
278+
else resources("regions_onshore_base_s_{clusters}.geojson")
279+
),
276280
output:
277281
central_heating_forward_temperature_profiles=resources(
278282
"central_heating_forward_temperature_profiles_base_s_{clusters}_{planning_horizons}.nc"
@@ -316,9 +320,11 @@ rule build_geothermal_heat_potential:
316320
),
317321
input:
318322
isi_heat_potentials="data/isi_heat_utilisation_potentials.xlsx",
319-
regions_onshore=resources("regions_onshore_base-restricted_s_{clusters}.geojson")
320-
if config["sector"]["district_heating"].get("add_subnodes", True)
321-
else resources("regions_onshore_base_s_{clusters}.geojson"),
323+
regions_onshore=(
324+
resources("regions_onshore_base-restricted_s_{clusters}.geojson")
325+
if config["sector"]["district_heating"].get("add_subnodes", True)
326+
else resources("regions_onshore_base_s_{clusters}.geojson")
327+
),
322328
lau_regions="data/lau_regions.zip",
323329
output:
324330
heat_source_power=resources(
@@ -361,9 +367,11 @@ rule build_cop_profiles:
361367
),
362368
temp_soil_total=resources("temp_soil_total_base_s_{clusters}.nc"),
363369
temp_air_total=resources("temp_air_total_base_s_{clusters}.nc"),
364-
regions_onshore=resources("regions_onshore_base-extended_s_{clusters}.geojson") if config["sector"][
365-
"district_heating"
366-
].get("add_subnodes", True) else resources("regions_onshore_base_s_{clusters}.geojson"),
370+
regions_onshore=(
371+
resources("regions_onshore_base-extended_s_{clusters}.geojson")
372+
if config["sector"]["district_heating"].get("add_subnodes", True)
373+
else resources("regions_onshore_base_s_{clusters}.geojson")
374+
),
367375
output:
368376
cop_profiles=resources("cop_profiles_base_s_{clusters}_{planning_horizons}.nc"),
369377
resources:

rules/solve_myopic.smk

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ rule add_existing_baseyear:
1515
"sector", "district_heating", "add_subnodes"
1616
),
1717
input:
18-
network=resources(
19-
"networks/base-extended_s_{clusters}_{opts}_{sector_opts}_{planning_horizons}.nc"
20-
) if config["sector"]["district_heating"].get("add_subnodes", True)
18+
network=(
19+
resources(
20+
"networks/base-extended_s_{clusters}_{opts}_{sector_opts}_{planning_horizons}.nc"
21+
)
22+
if config["sector"]["district_heating"].get("add_subnodes", True)
2123
else resources(
22-
"networks/base_s_{clusters}_{opts}_{sector_opts}_{planning_horizons}.nc"
24+
"networks/base_s_{clusters}_{opts}_{sector_opts}_{planning_horizons}.nc"
25+
)
2326
),
2427
powerplants=resources("powerplants_s_{clusters}.csv"),
2528
busmap_s=resources("busmap_base_s.csv"),
@@ -41,9 +44,7 @@ rule add_existing_baseyear:
4144
)
4245
),
4346
heating_efficiencies=resources("heating_efficiencies.csv"),
44-
custom_powerplants=resources(
45-
"german_chp_base_s_{clusters}.csv"
46-
),
47+
custom_powerplants=resources("german_chp_base_s_{clusters}.csv"),
4748
output:
4849
resources(
4950
"networks/base_s_{clusters}_{opts}_{sector_opts}_{planning_horizons}_brownfield.nc"
@@ -97,12 +98,15 @@ rule add_brownfield:
9798
unpack(input_profile_tech_brownfield),
9899
simplify_busmap=resources("busmap_base_s.csv"),
99100
cluster_busmap=resources("busmap_base_s_{clusters}.csv"),
100-
network=resources(
101-
"networks/base-extended_s_{clusters}_{opts}_{sector_opts}_{planning_horizons}.nc"
102-
) if config["sector"]["district_heating"].get("add_subnodes", True)
101+
network=(
102+
resources(
103+
"networks/base-extended_s_{clusters}_{opts}_{sector_opts}_{planning_horizons}.nc"
104+
)
105+
if config["sector"]["district_heating"].get("add_subnodes", True)
103106
else resources(
104107
"networks/base_s_{clusters}_{opts}_{sector_opts}_{planning_horizons}.nc"
105-
),
108+
)
109+
),
106110
network_p=solved_previous_horizon, #solved network at previous time step
107111
costs=resources("costs_{planning_horizons}.csv"),
108112
cop_profiles=resources("cop_profiles_base_s_{clusters}_{planning_horizons}.nc"),

scripts/build_existing_heating_distribution.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ def build_existing_heating():
145145
)
146146
nodal_heat_name_tech[(f"{sector} urban decentral", "ground heat pump")] = 0.0
147147

148-
nodal_heat_name_tech[
149-
(f"{sector} urban decentral", "air heat pump")
150-
] += nodal_heat_name_tech[(f"{sector} rural", "air heat pump")]
148+
nodal_heat_name_tech[(f"{sector} urban decentral", "air heat pump")] += (
149+
nodal_heat_name_tech[(f"{sector} rural", "air heat pump")]
150+
)
151151
nodal_heat_name_tech[(f"{sector} rural", "air heat pump")] = 0.0
152152

153153
# add large-scale heat pump sources as columns for district heating with 0 capacity

scripts/prepare_sector_network.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3031,9 +3031,7 @@ def add_heat(
30313031
# 1e3 converts from W/m^2 to MW/(1000m^2) = kW/m^2
30323032
solar_thermal = options["solar_cf_correction"] * solar_thermal / 1e3
30333033

3034-
for (
3035-
heat_system
3036-
) in (
3034+
for heat_system in (
30373035
HeatSystem
30383036
): # this loops through all heat systems defined in _entities.HeatSystem
30393037
overdim_factor = options["overdimension_heat_generators"][
@@ -6013,9 +6011,9 @@ def add_enhanced_geothermal(
60136011
* Nyears
60146012
)
60156013

6016-
assert (
6017-
egs_potentials["capital_cost"] > 0
6018-
).all(), "Error in EGS cost, negative values found."
6014+
assert (egs_potentials["capital_cost"] > 0).all(), (
6015+
"Error in EGS cost, negative values found."
6016+
)
60196017

60206018
orc_annuity = calculate_annuity(costs.at["organic rankine cycle", "lifetime"], dr)
60216019
orc_capital_cost = (orc_annuity + FOM / (1 + FOM)) * orc_capex * Nyears

scripts/pypsa-de/add_district_heating_subnodes.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
1-
# -*- coding: utf-8 -*-
21
import logging
32

43
logger = logging.getLogger(__name__)
54

5+
import os
6+
import sys
7+
from typing import Union
8+
69
import geopandas as gpd
710
import pandas as pd
811
import pypsa
912
import xarray as xr
10-
from typing import Union
11-
12-
import os
13-
import sys
1413

1514
sys.path.append(os.path.join(os.path.dirname(__file__), "..", ".."))
1615

17-
from scripts.prepare_network import maybe_adjust_costs_and_potentials
1816
from scripts._helpers import (
1917
configure_logging,
2018
set_scenario_config,
2119
update_config_from_wildcards,
2220
)
21+
from scripts.prepare_network import maybe_adjust_costs_and_potentials
2322

2423

2524
def add_subnodes(
@@ -36,6 +35,7 @@ def add_subnodes(
3635
- the heat demand profiles taken from the mother node,
3736
- the district heating investment options (stores, storage units, links, generators) from the mother node,
3837
The district heating loads in the mother nodes are reduced accordingly.
38+
3939
Parameters
4040
----------
4141
n : pypsa.Network
@@ -46,6 +46,7 @@ def add_subnodes(
4646
COPs for heat pumps.
4747
direct_heat_source_utilisation_profile : xr.DataArray
4848
Direct heat source utilisation profiles.
49+
4950
Returns
5051
-------
5152
None
@@ -67,7 +68,7 @@ def add_subnodes(
6768

6869
# Add subnodes to network
6970
for _, subnode in subnodes_head.iterrows():
70-
name = f'{subnode["cluster"]} {subnode["Stadt"]} urban central'
71+
name = f"{subnode['cluster']} {subnode['Stadt']} urban central"
7172
location = f"{subnode['cluster']} {subnode['Stadt']}"
7273

7374
# Add buses
@@ -160,10 +161,10 @@ def add_subnodes(
160161
)
161162

162163
# Adjust loads of cluster buses
163-
n.loads_t.p_set.loc[:, f'{subnode["cluster"]} urban central heat'] -= uch_load
164+
n.loads_t.p_set.loc[:, f"{subnode['cluster']} urban central heat"] -= uch_load
164165

165166
n.loads.loc[
166-
f'{subnode["cluster"]} low-temperature heat for industry', "p_set"
167+
f"{subnode['cluster']} low-temperature heat for industry", "p_set"
167168
] -= lti_load
168169

169170
if lost_load > 0:
@@ -211,7 +212,7 @@ def add_subnodes(
211212
if storage_units.carrier.str.contains("pits$").any():
212213
storage_units.loc[
213214
storage_units.carrier.str.contains("pits$"), "p_nom_max"
214-
] = (subnode["ptes_pot_mwh"] / storage_units["max_hours"])
215+
] = subnode["ptes_pot_mwh"] / storage_units["max_hours"]
215216
n.add("StorageUnit", storage_units.index, **storage_units)
216217

217218
# restrict PTES capacity in mother nodes
@@ -365,6 +366,7 @@ def extend_heating_distribution(
365366
DataFrame containing the existing heating distribution.
366367
subnodes : gpd.GeoDataFrame
367368
GeoDataFrame containing information about district heating subnodes.
369+
368370
Returns
369371
-------
370372
pd.DataFrame
@@ -409,7 +411,6 @@ def extend_heating_distribution(
409411

410412
if __name__ == "__main__":
411413
if "snakemake" not in globals():
412-
413414
from scripts._helpers import mock_snakemake
414415

415416
# Change directory to this script directory

scripts/pypsa-de/build_existing_chp_de.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ def assign_subnode(
212212
) -> pd.DataFrame:
213213
"""
214214
Assign subnodes to the CHP plants based on their location.
215+
215216
Parameters
216217
----------
217218
CHP_de : pd.DataFrame
@@ -220,6 +221,7 @@ def assign_subnode(
220221
GeoDataFrame containing subnode data with geometries.
221222
head : Union[bool, int]
222223
If int, select the largest N subnodes. If True, use all subnodes.
224+
223225
Returns
224226
-------
225227
pd.DataFrame

0 commit comments

Comments
 (0)