Skip to content

Commit

Permalink
Remove and fix hydro in add_electricity
Browse files Browse the repository at this point in the history
  • Loading branch information
davide-f committed Aug 12, 2023
1 parent 8526aad commit 3daf756
Showing 1 changed file with 29 additions and 16 deletions.
45 changes: 29 additions & 16 deletions scripts/add_electricity.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,19 +331,25 @@ def attach_wind_and_solar(
if suptech == "offwind":
underwater_fraction = ds["underwater_fraction"].to_pandas()
connection_cost = (
snakemake.config["lines"]["length_factor"] *
ds["average_distance"].to_pandas() *
(underwater_fraction *
costs.at[tech + "-connection-submarine", "capital_cost"] +
(1.0 - underwater_fraction) *
costs.at[tech + "-connection-underground", "capital_cost"]
))
capital_cost = (costs.at["offwind", "capital_cost"] +
costs.at[tech + "-station", "capital_cost"] +
connection_cost)
snakemake.config["lines"]["length_factor"]
* ds["average_distance"].to_pandas()
* (
underwater_fraction
* costs.at[tech + "-connection-submarine", "capital_cost"]
+ (1.0 - underwater_fraction)
* costs.at[tech + "-connection-underground", "capital_cost"]
)
)
capital_cost = (
costs.at["offwind", "capital_cost"]
+ costs.at[tech + "-station", "capital_cost"]
+ connection_cost
)
logger.info(
"Added connection cost of {:0.0f}-{:0.0f} Eur/MW/a to {}".
format(connection_cost.min(), connection_cost.max(), tech))
"Added connection cost of {:0.0f}-{:0.0f} Eur/MW/a to {}".format(
connection_cost.min(), connection_cost.max(), tech
)
)
else:
capital_cost = costs.at[tech, "capital_cost"]

Expand Down Expand Up @@ -455,9 +461,14 @@ def attach_hydro(n, costs, ppl):
.rename(index=lambda s: str(s) + " hydro")
)

# TODO: remove this line to address nan when powerplantmatching is stable
# Current fix, NaN technologies set to ROR
ppl.loc[ppl.technology.isna(), "technology"] = "Run-Of-River"
if ppl.technology.isna().any():
n_nans = ppl.technology.isna().sum()
logger.warning(
f"Identified {n_nans} hydro powerplants with unknown technology.\n"
"Initialized to 'Run-Of-River'"
)
ppl.loc[ppl.technology.isna(), "technology"] = "Run-Of-River"

ror = ppl.query('technology == "Run-Of-River"')
phs = ppl.query('technology == "Pumped Storage"')
Expand Down Expand Up @@ -550,11 +561,11 @@ def attach_hydro(n, costs, ppl):
hydro_max_hours = c.get("hydro_max_hours")
hydro_stats = pd.read_csv(
snakemake.input.hydro_capacities, comment="#", na_values=["-"], index_col=0
)
).set_index("Country")
e_target = hydro_stats["E_store[TWh]"].clip(lower=0.2) * 1e6
e_installed = hydro.eval("p_nom * max_hours").groupby(hydro.country).sum()
e_missing = e_target - e_installed
missing_mh_i = hydro.query("max_hours == 0").index
missing_mh_i = hydro.query("max_hours.isnull()").index

if hydro_max_hours == "energy_capacity_totals_by_country":
max_hours_country = (
Expand All @@ -566,6 +577,8 @@ def attach_hydro(n, costs, ppl):
hydro_stats["E_store[TWh]"] * 1e3 / hydro_stats["p_nom_discharge[GW]"]
)

max_hours_country.clip(0, inplace=True)

missing_countries = pd.Index(hydro["country"].unique()).difference(
max_hours_country.dropna().index
)
Expand Down

0 comments on commit 3daf756

Please sign in to comment.