[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2024-04-29 11:32:22 +00:00
parent fde0cd9aae
commit 3e93c14dd4
4 changed files with 90 additions and 45 deletions

View File

@ -240,13 +240,13 @@ renewable:
orientation: orientation:
slope: 35. slope: 35.
azimuth: 180. azimuth: 180.
tracking: horizontal tracking: horizontal
capacity_per_sqkm: 4.43 # 15% higher land usage acc. to NREL capacity_per_sqkm: 4.43 # 15% higher land usage acc. to NREL
corine: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 26, 31, 32] corine: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 26, 31, 32]
luisa: false # [1111, 1121, 1122, 1123, 1130, 1210, 1221, 1222, 1230, 1241, 1242, 1310, 1320, 1330, 1410, 1421, 1422, 2110, 2120, 2130, 2210, 2220, 2230, 2310, 2410, 2420, 3210, 3320, 3330] luisa: false # [1111, 1121, 1122, 1123, 1130, 1210, 1221, 1222, 1230, 1241, 1242, 1310, 1320, 1330, 1410, 1421, 1422, 2110, 2120, 2130, 2210, 2220, 2230, 2310, 2410, 2420, 3210, 3320, 3330]
natura: true natura: true
excluder_resolution: 100 excluder_resolution: 100
clip_p_max_pu: 1.e-2 clip_p_max_pu: 1.e-2
hydro: hydro:
cutout: europe-2013-era5 cutout: europe-2013-era5
carriers: [ror, PHS, hydro] carriers: [ror, PHS, hydro]
@ -589,7 +589,7 @@ sector:
biogas_upgrading_cc: false biogas_upgrading_cc: false
conventional_generation: conventional_generation:
OCGT: gas OCGT: gas
solar_utility_singla_axis_tracking : true solar_utility_singla_axis_tracking: true
biomass_to_liquid: false biomass_to_liquid: false
biosng: false biosng: false
limit_max_growth: limit_max_growth:

View File

@ -235,7 +235,7 @@ def load_costs(tech_costs, config, max_hours, Nyears=1.0):
+ (1 - config["rooftop_share"]) * costs.at["solar-utility", "capital_cost"] + (1 - config["rooftop_share"]) * costs.at["solar-utility", "capital_cost"]
) )
costs= costs.rename({'solar-utility single-axis tracking':'solar-hsat'}) costs = costs.rename({"solar-utility single-axis tracking": "solar-hsat"})
def costs_for_storage(store, link1, link2=None, max_hours=1.0): def costs_for_storage(store, link1, link2=None, max_hours=1.0):
capital_cost = link1["capital_cost"] + max_hours * store["capital_cost"] capital_cost = link1["capital_cost"] + max_hours * store["capital_cost"]

View File

@ -3319,13 +3319,14 @@ def remove_h2_network(n):
if "EU H2 Store" in n.stores.index: if "EU H2 Store" in n.stores.index:
n.stores.drop("EU H2 Store", inplace=True) n.stores.drop("EU H2 Store", inplace=True)
def remove_solar_tracking(n): def remove_solar_tracking(n):
for tech in ['solar-hsat']: for tech in ["solar-hsat"]:
print('removing '+tech) print("removing " + tech)
n.mremove("Generator" , n.generators.index[n.generators.carrier==tech]) n.mremove("Generator", n.generators.index[n.generators.carrier == tech])
def limit_individual_line_extension(n, maxext): def limit_individual_line_extension(n, maxext):
logger.info(f"Limiting new HVAC and HVDC extensions to {maxext} MW") logger.info(f"Limiting new HVAC and HVDC extensions to {maxext} MW")
n.lines["s_nom_max"] = n.lines["s_nom"] + maxext n.lines["s_nom_max"] = n.lines["s_nom"] + maxext
@ -3703,7 +3704,7 @@ if __name__ == "__main__":
insert_electricity_distribution_grid(n, costs) insert_electricity_distribution_grid(n, costs)
if not options["solar_utility_singla_axis_tracking"]: if not options["solar_utility_singla_axis_tracking"]:
remove_solar_tracking(n) remove_solar_tracking(n)
maybe_adjust_costs_and_potentials(n, snakemake.params["adjustments"]) maybe_adjust_costs_and_potentials(n, snakemake.params["adjustments"])

View File

@ -31,6 +31,7 @@ import logging
import os import os
import re import re
import sys import sys
from functools import reduce
import numpy as np import numpy as np
import pandas as pd import pandas as pd
@ -43,7 +44,6 @@ from _helpers import (
set_scenario_config, set_scenario_config,
update_config_from_wildcards, update_config_from_wildcards,
) )
from functools import reduce
from pypsa.descriptors import get_activity_mask from pypsa.descriptors import get_activity_mask
from pypsa.descriptors import get_switchable_as_dense as get_as_dense from pypsa.descriptors import get_switchable_as_dense as get_as_dense
@ -124,7 +124,14 @@ def add_land_use_constraint_perfect(n):
def _add_land_use_constraint(n): def _add_land_use_constraint(n):
# warning: this will miss existing offwind which is not classed AC-DC and has carrier 'offwind' # warning: this will miss existing offwind which is not classed AC-DC and has carrier 'offwind'
for carrier in ["solar", "solar rooftop", "solar-hsat", "onwind", "offwind-ac", "offwind-dc"]: for carrier in [
"solar",
"solar rooftop",
"solar-hsat",
"onwind",
"offwind-ac",
"offwind-dc",
]:
extendable_i = (n.generators.carrier == carrier) & n.generators.p_nom_extendable extendable_i = (n.generators.carrier == carrier) & n.generators.p_nom_extendable
n.generators.loc[extendable_i, "p_nom_min"] = 0 n.generators.loc[extendable_i, "p_nom_min"] = 0
@ -159,7 +166,14 @@ def _add_land_use_constraint_m(n, planning_horizons, config):
grouping_years = config["existing_capacities"]["grouping_years_power"] grouping_years = config["existing_capacities"]["grouping_years_power"]
current_horizon = snakemake.wildcards.planning_horizons current_horizon = snakemake.wildcards.planning_horizons
for carrier in ["solar", "solar rooftop", "solar-hsat", "onwind", "offwind-ac", "offwind-dc"]: for carrier in [
"solar",
"solar rooftop",
"solar-hsat",
"onwind",
"offwind-ac",
"offwind-dc",
]:
extendable_i = (n.generators.carrier == carrier) & n.generators.p_nom_extendable extendable_i = (n.generators.carrier == carrier) & n.generators.p_nom_extendable
n.generators.loc[extendable_i, "p_nom_min"] = 0 n.generators.loc[extendable_i, "p_nom_min"] = 0
@ -199,7 +213,8 @@ def _add_land_use_constraint_m(n, planning_horizons, config):
n.generators.p_nom_max.clip(lower=0, inplace=True) n.generators.p_nom_max.clip(lower=0, inplace=True)
def add_solar_potential_constraints(n, config):
def add_solar_potential_constraints(n, config):
""" """
Add constraint to make sure the sum capacity of all solar technologies (fixed, tracking, ets. ) is below the region potential. Add constraint to make sure the sum capacity of all solar technologies (fixed, tracking, ets. ) is below the region potential.
Example: Example:
@ -209,51 +224,81 @@ def add_solar_potential_constraints(n, config):
The constraint ensures that: The constraint ensures that:
solar_p_nom + solar_hsat_p_nom * 1.13 <= 10 GW solar_p_nom + solar_hsat_p_nom * 1.13 <= 10 GW
""" """
land_use_factors= { land_use_factors = {
'solar-hsat' : config['renewable']['solar']['capacity_per_sqkm']/config['renewable']['solar-hsat']['capacity_per_sqkm'] , "solar-hsat": config["renewable"]["solar"]["capacity_per_sqkm"]
} / config["renewable"]["solar-hsat"]["capacity_per_sqkm"],
}
gen_index = n.generators[n.generators.p_nom_extendable].index gen_index = n.generators[n.generators.p_nom_extendable].index
filters = [("solar", True), ("thermal", False), ("rooftop", False)] ## filter all utility solar generation except solar thermal filters = [
solar = reduce(lambda gen_index, f: gen_index[gen_index.str.contains(f[0]) == f[1]], filters, gen_index) ("solar", True),
solar_today = n.generators[(n.generators.carrier=='solar') & (n.generators.p_nom_extendable)].index ("thermal", False),
solar_hsat = n.generators[(n.generators.carrier=='solar-hsat') ].index ("rooftop", False),
land_use = pd.DataFrame(1, index=solar, columns=['land_use_factor']) ] ## filter all utility solar generation except solar thermal
solar = reduce(
lambda gen_index, f: gen_index[gen_index.str.contains(f[0]) == f[1]],
filters,
gen_index,
)
solar_today = n.generators[
(n.generators.carrier == "solar") & (n.generators.p_nom_extendable)
].index
solar_hsat = n.generators[(n.generators.carrier == "solar-hsat")].index
land_use = pd.DataFrame(1, index=solar, columns=["land_use_factor"])
for key in land_use_factors.keys(): for key in land_use_factors.keys():
land_use = land_use.apply(lambda x: (x*land_use_factors[key]) if key in x.name else x, axis=1) land_use = land_use.apply(
lambda x: (x * land_use_factors[key]) if key in x.name else x, axis=1
)
rename = {"Generator-ext": "Generator"} rename = {"Generator-ext": "Generator"}
if "m" in snakemake.wildcards.clusters: if "m" in snakemake.wildcards.clusters:
location = ( location = pd.Series(
pd.Series([' '.join(i.split(' ')[:2]) for i in n.generators.index], index=n.generators.index) [" ".join(i.split(" ")[:2]) for i in n.generators.index],
index=n.generators.index,
) )
ggrouper= pd.Series(n.generators.loc[solar].index.rename('bus').map(location), index=n.generators.loc[solar].index,).to_xarray() ggrouper = pd.Series(
rhs = (n.generators.loc[solar_today,"p_nom_max"] n.generators.loc[solar].index.rename("bus").map(location),
.groupby(n.generators.loc[solar_today].index.rename('bus').map(location)).sum() - index=n.generators.loc[solar].index,
n.generators.loc[solar_hsat,"p_nom_opt"] ).to_xarray()
.groupby(n.generators.loc[solar_hsat].index.rename('bus').map(location)).sum() * land_use_factors['solar-hsat'] ).clip(lower=0) rhs = (
n.generators.loc[solar_today, "p_nom_max"]
.groupby(n.generators.loc[solar_today].index.rename("bus").map(location))
.sum()
- n.generators.loc[solar_hsat, "p_nom_opt"]
.groupby(n.generators.loc[solar_hsat].index.rename("bus").map(location))
.sum()
* land_use_factors["solar-hsat"]
).clip(lower=0)
else : else:
location = ( location = (
n.buses.location n.buses.location
if "location" in n.buses.columns if "location" in n.buses.columns
else pd.Series(n.buses.index, index=n.buses.index) else pd.Series(n.buses.index, index=n.buses.index)
) )
ggrouper= (n.generators.loc[solar].bus) ggrouper = n.generators.loc[solar].bus
rhs = (n.generators.loc[solar_today,"p_nom_max"] rhs = (
.groupby(n.generators.loc[solar_today].bus.map(location)).sum() - n.generators.loc[solar_today, "p_nom_max"]
n.generators.loc[solar_hsat,"p_nom_opt"] .groupby(n.generators.loc[solar_today].bus.map(location))
.groupby(n.generators.loc[solar_hsat].bus.map(location)).sum() * land_use_factors['solar-hsat'] ).clip(lower=0) .sum()
- n.generators.loc[solar_hsat, "p_nom_opt"]
.groupby(n.generators.loc[solar_hsat].bus.map(location))
.sum()
* land_use_factors["solar-hsat"]
).clip(lower=0)
lhs = ( lhs = (
(n.model["Generator-p_nom"].rename(rename).loc[solar] (
*land_use.squeeze().values) n.model["Generator-p_nom"].rename(rename).loc[solar]
.groupby(ggrouper) * land_use.squeeze().values
.sum() )
) .groupby(ggrouper)
.sum()
)
print("adding solar rooftop constraints...")
n.model.add_constraints(lhs <= rhs, name="solar_potential")
print('adding solar rooftop constraints...')
n.model.add_constraints(lhs <= rhs, name="solar_potential")
def add_co2_sequestration_limit(n, limit=200): def add_co2_sequestration_limit(n, limit=200):
""" """
@ -918,9 +963,8 @@ def extra_functionality(n, snapshots):
if EQ_o := constraints["EQ"]: if EQ_o := constraints["EQ"]:
add_EQ_constraints(n, EQ_o.replace("EQ", "")) add_EQ_constraints(n, EQ_o.replace("EQ", ""))
if config["sector"]["solar_utility_singla_axis_tracking"]:
if config["sector"]['solar_utility_singla_axis_tracking']: add_solar_potential_constraints(n, config)
add_solar_potential_constraints(n, config)
add_battery_constraints(n) add_battery_constraints(n)
add_lossy_bidirectional_link_constraints(n) add_lossy_bidirectional_link_constraints(n)