Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Oct 9, 2024
1 parent 20768b1 commit 6790fbd
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 53 deletions.
13 changes: 3 additions & 10 deletions Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -765,17 +765,12 @@ rule build_egs_potentials:
+ RDIR
+ "bus_regions/regions_onshore_elec_s{simpl}_{clusters}.geojson",
output:
egs_potentials="resources/"
+ RDIR
+ "egs_potential_s{simpl}_{clusters}.csv",
egs_potentials="resources/" + RDIR + "egs_potential_s{simpl}_{clusters}.csv",
threads: 2
resources:
mem_mb=10000,
benchmark:
(
RDIR
+ "/benchmarks/build_egs_potentials/egs_potential_s{simpl}_{clusters}"
)
(RDIR + "/benchmarks/build_egs_potentials/egs_potential_s{simpl}_{clusters}")
script:
"scripts/build_egs_potentials.py"

Expand All @@ -791,9 +786,7 @@ rule prepare_network:
input:
"networks/" + RDIR + "elec_s{simpl}_{clusters}_ec.nc",
tech_costs=COSTS,
egs_potentials="resources/"
+ RDIR
+ "egs_potential_s{simpl}_{clusters}.csv",
egs_potentials="resources/" + RDIR + "egs_potential_s{simpl}_{clusters}.csv",
threads: 2
output:
"networks/" + RDIR + "elec_s{simpl}_{clusters}_ec_l{ll}_{opts}.nc",
Expand Down
67 changes: 33 additions & 34 deletions scripts/build_egs_potentials.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
# -*- coding: utf-8 -*-
"""Build EGS potentials for different depths and temperatures. Upper limits available
heat content by overlaying subsurface potential with geospatial demand data."""
"""
Build EGS potentials for different depths and temperatures.
Upper limits available heat content by overlaying subsurface potential
with geospatial demand data.
"""


import os

import geopandas as gpd
import numpy as np
import xarray as xr
import pandas as pd
import xarray as xr
from tqdm import tqdm
import geopandas as gpd



def get_demands(df, x, y):
raise NotImplementedError('implement me')
raise NotImplementedError("implement me")


def get_demand_geometries(demand):
raise NotImplementedError('implement me')
raise NotImplementedError("implement me")


if __name__ == "__main__":
Expand All @@ -33,20 +36,21 @@ def get_demand_geometries(demand):
)

regions = gpd.read_file(snakemake.input.regions_onshore).set_index("name")
egs_potentials = pd.read_csv(snakemake.input["egs_potential"], index_col=[0,1,2])
egs_potentials = pd.read_csv(snakemake.input["egs_potential"], index_col=[0, 1, 2])

gdf = gpd.GeoDataFrame(
egs_potentials,
geometry=gpd.points_from_xy(
egs_potentials.index.get_level_values('lon'),
egs_potentials.index.get_level_values('lat')
)).set_crs(epsg=4326)
egs_potentials.index.get_level_values("lon"),
egs_potentials.index.get_level_values("lat"),
),
).set_crs(epsg=4326)

nodal_egs_potentials = pd.DataFrame(
np.nan,
index=regions.index,
columns=['capex[$/kW]', 'opex[$/kWh]', 'p_nom_max[MW]']
)
columns=["capex[$/kW]", "opex[$/kWh]", "p_nom_max[MW]"],
)

config = snakemake.params["enhanced_geothermal"]

Expand All @@ -59,38 +63,33 @@ def get_demand_geometries(demand):
continue

ss = (
ss[['capex[$/kW]', 'opex[$/kWh]', 'available_capacity[MW]']]
ss[["capex[$/kW]", "opex[$/kWh]", "available_capacity[MW]"]]
.reset_index(drop=True)
.sort_values(by='capex[$/kW]')
.sort_values(by="capex[$/kW]")
)

ss['agg_available_capacity[MW]'] = ss['available_capacity[MW]'].cumsum()
ss["agg_available_capacity[MW]"] = ss["available_capacity[MW]"].cumsum()

bins = pd.Series(
np.linspace(
ss['capex[$/kW]'].min(),
ss['capex[$/kW]'].max(),
config['max_levels']+1
)
)
np.linspace(
ss["capex[$/kW]"].min(),
ss["capex[$/kW]"].max(),
config["max_levels"] + 1,
)
)

labels = bins.rolling(2).mean().dropna().tolist()

ss['level'] = pd.cut(ss['capex[$/kW]'], bins=bins, labels=labels)
ss["level"] = pd.cut(ss["capex[$/kW]"], bins=bins, labels=labels)
ss = ss.dropna()

ss = (
ss
.groupby('level')[['available_capacity[MW]', 'opex[$/kWh]']]
.agg({'available_capacity[MW]': 'sum', 'opex[$/kWh]': 'mean'})
ss = ss.groupby("level")[["available_capacity[MW]", "opex[$/kWh]"]].agg(
{"available_capacity[MW]": "sum", "opex[$/kWh]": "mean"}
)
ss.index = pd.MultiIndex.from_product(
[[name], ss.index], names=["network_region", "capex[$/kW]"]
)
ss.index = (
pd.MultiIndex.from_product(
[[name], ss.index],
names=['network_region', 'capex[$/kW]']
)
)

regional_potentials.append(ss)
regional_potentials.append(ss)

pd.concat(regional_potentials).dropna().to_csv(snakemake.output.egs_potentials)
14 changes: 5 additions & 9 deletions scripts/prepare_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,9 @@ def set_line_nom_max(n, s_nom_max_set=np.inf, p_nom_max_set=np.inf):
n.links.p_nom_max = n.links.p_nom_max.clip(upper=p_nom_max_set)



def add_enhanced_geothermal(n):

egs_potential = pd.read_csv(
snakemake.input["egs_potentials"],
index_col=[0,1]
)
egs_potential = pd.read_csv(snakemake.input["egs_potentials"], index_col=[0, 1])

idx = pd.IndexSlice

Expand All @@ -346,11 +342,11 @@ def add_enhanced_geothermal(n):
p_nom_extendable=True,
)

eta = 0.15 # preliminary
eta = 0.15 # preliminary

for bus in egs_potential.index.get_level_values(0).unique():

ss = egs_potential.loc[idx[bus,:]]
ss = egs_potential.loc[idx[bus, :]]

nodes = f"{bus} " + pd.Index(range(len(ss)), dtype=str)

Expand Down Expand Up @@ -382,7 +378,7 @@ def add_enhanced_geothermal(n):
nodes,
suffix=" EGS reservoir",
bus=nodes + " EGS surface",
max_hours=100, # should be agreed on, constraint to be implemented
max_hours=100, # should be agreed on, constraint to be implemented
)

n.madd(
Expand Down Expand Up @@ -423,7 +419,7 @@ def add_enhanced_geothermal(n):

set_line_s_max_pu(n, s_max_pu)

if snakemake.params.renewable['enhanced_geothermal']['enable']:
if snakemake.params.renewable["enhanced_geothermal"]["enable"]:
add_enhanced_geothermal(n)

for o in opts:
Expand Down

0 comments on commit 6790fbd

Please sign in to comment.