[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
fde0cd9aae
commit
3e93c14dd4
@ -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"]
|
||||||
|
@ -3319,10 +3319,11 @@ 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])
|
||||||
|
|
||||||
|
|
||||||
|
@ -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,6 +213,7 @@ 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.
|
||||||
@ -210,28 +225,50 @@ def add_solar_potential_constraints(n, config):
|
|||||||
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 = (
|
||||||
@ -239,22 +276,30 @@ def add_solar_potential_constraints(n, config):
|
|||||||
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]
|
||||||
|
* land_use.squeeze().values
|
||||||
|
)
|
||||||
.groupby(ggrouper)
|
.groupby(ggrouper)
|
||||||
.sum()
|
.sum()
|
||||||
)
|
)
|
||||||
|
|
||||||
print('adding solar rooftop constraints...')
|
print("adding solar rooftop constraints...")
|
||||||
n.model.add_constraints(lhs <= rhs, name="solar_potential")
|
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):
|
||||||
"""
|
"""
|
||||||
Add a global constraint on the amount of Mt CO2 that can be sequestered.
|
Add a global constraint on the amount of Mt CO2 that can be sequestered.
|
||||||
@ -918,8 +963,7 @@ 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)
|
||||||
|
Loading…
Reference in New Issue
Block a user