changed overlap indexing, general cleanup

This commit is contained in:
LukasFrankenQ 2023-09-26 00:06:44 +01:00
parent 4734618bff
commit 9a5c010c25
2 changed files with 21 additions and 12 deletions

View File

@ -67,7 +67,12 @@ def prepare_egs_data(egs_file):
for col in df.columns: for col in df.columns:
country_df[col] = country_data[0][years.index(year)][col] country_df[col] = country_data[0][years.index(year)][col]
df = pd.concat((df, country_df.dropna()), axis=0, ignore_index=True) if country_df.dropna().empty:
continue
elif df.empty:
df = country_df.dropna()
else:
df = pd.concat((df, country_df.dropna()), ignore_index=True)
gdf = gpd.GeoDataFrame( gdf = gpd.GeoDataFrame(
df.drop(columns=["Lon", "Lat"]), geometry=gpd.points_from_xy(df.Lon, df.Lat) df.drop(columns=["Lon", "Lat"]), geometry=gpd.points_from_xy(df.Lon, df.Lat)
@ -89,7 +94,12 @@ if __name__ == "__main__":
clusters=37, clusters=37,
) )
sustainability_factor = 0.0025 # factor sustainable p_nom vs p_nom sustainability_factor = 0.0025
# the share of heat that is replenished from the earth's core.
# we are not constraining ourselves to the sustainable share, but
# inversely apply it to our underlying data, which refers to the
# sustainable heat.
config = snakemake.config config = snakemake.config
egs_data = prepare_egs_data(snakemake.input.egs_cost) egs_data = prepare_egs_data(snakemake.input.egs_cost)
@ -97,7 +107,7 @@ if __name__ == "__main__":
if config["sector"]["enhanced_geothermal_optimism"]: if config["sector"]["enhanced_geothermal_optimism"]:
egs_data = egs_data[(year := config["costs"]["year"])] egs_data = egs_data[(year := config["costs"]["year"])]
logger.info( logger.info(
f"EGS optimism! Builing EGS potentials with costs estimated for {year}." f"EGS optimism! Building EGS potentials with costs estimated for {year}."
) )
else: else:
@ -106,7 +116,7 @@ if __name__ == "__main__":
f"No EGS optimism! Building EGS potentials with {default_year} costs." f"No EGS optimism! Building EGS potentials with {default_year} costs."
) )
egs_data.index = egs_data.geometry.astype(str) egs_data = egs_data.loc[egs_data["PowerSust"] > 0].reset_index(drop=True)
egs_shapes = egs_data.geometry egs_shapes = egs_data.geometry
network_shapes = ( network_shapes = (
@ -117,7 +127,7 @@ if __name__ == "__main__":
overlap_matrix = pd.DataFrame( overlap_matrix = pd.DataFrame(
index=network_shapes.index, index=network_shapes.index,
columns=(egs_shapes := egs_data.geometry).astype(str).values, columns=egs_data.index,
) )
for name, polygon in network_shapes.geometry.items(): for name, polygon in network_shapes.geometry.items():
@ -127,5 +137,7 @@ if __name__ == "__main__":
overlap_matrix.to_csv(snakemake.output["egs_overlap"]) overlap_matrix.to_csv(snakemake.output["egs_overlap"])
# consider not only replenished heat
egs_data["p_nom_max"] = egs_data["PowerSust"] / sustainability_factor egs_data["p_nom_max"] = egs_data["PowerSust"] / sustainability_factor
egs_data[["p_nom_max", "CAPEX"]].to_csv(snakemake.output["egs_potentials"]) egs_data[["p_nom_max", "CAPEX"]].to_csv(snakemake.output["egs_potentials"])

View File

@ -3303,6 +3303,7 @@ def add_enhanced_geothermal(
config = snakemake.config config = snakemake.config
overlap = pd.read_csv(egs_overlap, index_col=0) overlap = pd.read_csv(egs_overlap, index_col=0)
overlap.columns = overlap.columns.astype(int)
egs_potentials = pd.read_csv(egs_potentials, index_col=0) egs_potentials = pd.read_csv(egs_potentials, index_col=0)
Nyears = n.snapshot_weightings.generators.sum() / 8760 Nyears = n.snapshot_weightings.generators.sum() / 8760
@ -3343,20 +3344,16 @@ def add_enhanced_geothermal(
"EU geothermal heat", "EU geothermal heat",
bus="EU geothermal heat", bus="EU geothermal heat",
carrier="geothermal heat", carrier="geothermal heat",
p_nom_max=np.inf, p_nom_max=egs_potentials["p_nom_max"].sum() / efficiency,
p_nom_extendable=True, p_nom_extendable=True,
) )
egs_potentials.index = np.arange(len(egs_potentials)).astype(str)
overlap.columns = egs_potentials.index
for bus, bus_overlap in overlap.iterrows(): for bus, bus_overlap in overlap.iterrows():
if not bus_overlap.sum(): if not bus_overlap.sum():
continue continue
overlap = bus_overlap.loc[bus_overlap > 0.0] overlap = bus_overlap.loc[bus_overlap > 0.0]
bus_egs = egs_potentials.loc[overlap.index]
bus_egs = egs_potentials.loc[bus_overlap.loc[bus_overlap > 0.0].index]
if not len(bus_egs): if not len(bus_egs):
continue continue
@ -3567,7 +3564,7 @@ if __name__ == "__main__":
if options.get("cluster_heat_buses", False) and not first_year_myopic: if options.get("cluster_heat_buses", False) and not first_year_myopic:
cluster_heat_buses(n) cluster_heat_buses(n)
if options.get("enhanced_geothermal"): if options.get("enhanced_geothermal", False):
logger.info("Adding Enhanced Geothermal Potential.") logger.info("Adding Enhanced Geothermal Potential.")
add_enhanced_geothermal( add_enhanced_geothermal(
n, snakemake.input["egs_potentials"], snakemake.input["egs_overlap"], costs n, snakemake.input["egs_potentials"], snakemake.input["egs_overlap"], costs