merge master

This commit is contained in:
Fabian Neumann 2023-04-29 12:41:37 +02:00
parent 30beee0959
commit e16fa286ec
10 changed files with 58 additions and 42 deletions

View File

@ -22,20 +22,25 @@ rule all:
rule cluster_networks: rule cluster_networks:
input: input:
expand(RESOURCES + "networks/elec{weather_year}_s{simpl}_{clusters}.nc", **config["scenario"]), expand(
RESOURCES + "networks/elec{weather_year}_s{simpl}_{clusters}.nc",
**config["scenario"]
),
rule extra_components_networks: rule extra_components_networks:
input: input:
expand( expand(
RESOURCES + "networks/elec{weather_year}_s{simpl}_{clusters}_ec.nc", **config["scenario"] RESOURCES + "networks/elec{weather_year}_s{simpl}_{clusters}_ec.nc",
**config["scenario"]
), ),
rule prepare_elec_networks: rule prepare_elec_networks:
input: input:
expand( expand(
RESOURCES + "networks/elec{weather_year}_s{simpl}_{clusters}_ec_l{ll}_{opts}.nc", RESOURCES
+ "networks/elec{weather_year}_s{simpl}_{clusters}_ec_l{ll}_{opts}.nc",
**config["scenario"] **config["scenario"]
), ),
@ -52,7 +57,8 @@ rule prepare_sector_networks:
rule solve_elec_networks: rule solve_elec_networks:
input: input:
expand( expand(
RESULTS + "networks/elec{weather_year}_s{simpl}_{clusters}_ec_l{ll}_{opts}.nc", RESULTS
+ "networks/elec{weather_year}_s{simpl}_{clusters}_ec_l{ll}_{opts}.nc",
**config["scenario"] **config["scenario"]
), ),

View File

@ -701,19 +701,20 @@ def add_nice_carrier_names(n, config):
n.carriers["color"] = colors n.carriers["color"] = colors
def drop_leap_day(n): def drop_leap_day(n):
if not n.snapshots.is_leap_year.any(): return if not n.snapshots.is_leap_year.any():
return
leap_days = (n.snapshots.day == 29) & (n.snapshots.month == 2) leap_days = (n.snapshots.day == 29) & (n.snapshots.month == 2)
n.set_snapshots(n.snapshots[~leap_days]) n.set_snapshots(n.snapshots[~leap_days])
n.snapshot_weightings[:] = 8760/len(n.snapshots) n.snapshot_weightings[:] = 8760 / len(n.snapshots)
logger.info("Dropped February 29 from leap year.") logger.info("Dropped February 29 from leap year.")
if __name__ == "__main__": if __name__ == "__main__":
if "snakemake" not in globals(): if "snakemake" not in globals():
from _helpers import mock_snakemake from _helpers import mock_snakemake
snakemake = mock_snakemake('add_electricity', weather_year='')
snakemake = mock_snakemake("add_electricity", weather_year="")
configure_logging(snakemake) configure_logging(snakemake)
n = pypsa.Network(snakemake.input.base_network) n = pypsa.Network(snakemake.input.base_network)
@ -721,15 +722,13 @@ if __name__ == "__main__":
weather_year = snakemake.wildcards.weather_year weather_year = snakemake.wildcards.weather_year
if weather_year: if weather_year:
snapshots = dict( snapshots = dict(
start=weather_year, start=weather_year, end=str(int(weather_year) + 1), closed="left"
end=str(int(weather_year)+1),
closed="left"
) )
else: else:
snapshots = snakemake.config['snapshots'] snapshots = snakemake.config["snapshots"]
n.set_snapshots(pd.date_range(freq='h', **snapshots)) n.set_snapshots(pd.date_range(freq="h", **snapshots))
Nyears = n.snapshot_weightings.objective.sum() / 8760. Nyears = n.snapshot_weightings.objective.sum() / 8760.0
costs = load_costs( costs = load_costs(
snakemake.input.tech_costs, snakemake.input.tech_costs,
@ -855,7 +854,7 @@ if __name__ == "__main__":
add_nice_carrier_names(n, snakemake.config) add_nice_carrier_names(n, snakemake.config)
if snakemake.config['enable'].get('drop_leap_days', True): if snakemake.config["enable"].get("drop_leap_days", True):
drop_leap_day(n) drop_leap_day(n)
n.meta = snakemake.config n.meta = snakemake.config

View File

@ -230,8 +230,10 @@ def attach_hydrogen_pipelines(n, costs, elec_opts):
if __name__ == "__main__": if __name__ == "__main__":
if "snakemake" not in globals(): if "snakemake" not in globals():
from _helpers import mock_snakemake from _helpers import mock_snakemake
snakemake = mock_snakemake('add_extra_components', weather_year='',
simpl='', clusters=5) snakemake = mock_snakemake(
"add_extra_components", weather_year="", simpl="", clusters=5
)
configure_logging(snakemake) configure_logging(snakemake)
n = pypsa.Network(snakemake.input.network) n = pypsa.Network(snakemake.input.network)

View File

@ -108,15 +108,15 @@ if __name__ == "__main__":
cutout_params = snakemake.config["atlite"]["cutouts"][snakemake.wildcards.cutout] cutout_params = snakemake.config["atlite"]["cutouts"][snakemake.wildcards.cutout]
if hasattr(snakemake.wildcards, 'weather_year'): if hasattr(snakemake.wildcards, "weather_year"):
time = snakemake.wildcards.weather_year time = snakemake.wildcards.weather_year
cutout_params["time"] = [time, time] cutout_params["time"] = [time, time]
if "time" not in cutout_params: if "time" not in cutout_params:
snapshots = pd.date_range(freq='h', **snakemake.config['snapshots']) snapshots = pd.date_range(freq="h", **snakemake.config["snapshots"])
cutout_params["time"] = [snapshots[0], snapshots[-1]] cutout_params["time"] = [snapshots[0], snapshots[-1]]
cutout_params['time'] = slice(*cutout_params['time']) cutout_params["time"] = slice(*cutout_params["time"])
if {"x", "y", "bounds"}.isdisjoint(cutout_params): if {"x", "y", "bounds"}.isdisjoint(cutout_params):
# Determine the bounds from bus regions with a buffer of two grid cells # Determine the bounds from bus regions with a buffer of two grid cells

View File

@ -275,23 +275,25 @@ if __name__ == "__main__":
if "snakemake" not in globals(): if "snakemake" not in globals():
from _helpers import mock_snakemake from _helpers import mock_snakemake
snakemake = mock_snakemake("build_electricity_demand", weather_year='') snakemake = mock_snakemake("build_electricity_demand", weather_year="")
configure_logging(snakemake) configure_logging(snakemake)
weather_year = snakemake.wildcards.weather_year weather_year = snakemake.wildcards.weather_year
if weather_year: if weather_year:
snapshots = dict( snapshots = dict(
start=weather_year, start=weather_year, end=str(int(weather_year) + 1), closed="left"
end=str(int(weather_year)+1),
closed="left"
) )
else: else:
snapshots = snakemake.config['snapshots'] snapshots = snakemake.config["snapshots"]
snapshots = pd.date_range(freq='h', **snapshots) snapshots = pd.date_range(freq="h", **snapshots)
fixed_year = snakemake.config["load"].get("fixed_year", False) fixed_year = snakemake.config["load"].get("fixed_year", False)
years = slice(str(fixed_year), str(fixed_year)) if fixed_year else slice(snapshots[0], snapshots[-1]) years = (
slice(str(fixed_year), str(fixed_year))
if fixed_year
else slice(snapshots[0], snapshots[-1])
)
powerstatistics = snakemake.config["load"]["power_statistics"] powerstatistics = snakemake.config["load"]["power_statistics"]
interpolate_limit = snakemake.config["load"]["interpolate_limit"] interpolate_limit = snakemake.config["load"]["interpolate_limit"]

View File

@ -65,9 +65,8 @@ import atlite
import country_converter as coco import country_converter as coco
import geopandas as gpd import geopandas as gpd
import pandas as pd import pandas as pd
from numpy.polynomial import Polynomial
from _helpers import configure_logging from _helpers import configure_logging
from numpy.polynomial import Polynomial
cc = coco.CountryConverter() cc = coco.CountryConverter()
@ -132,11 +131,10 @@ def correct_eia_stats_by_capacity(eia_stats, fn, countries, baseyear=2019):
eia_stats_corrected = eia_stats / ratio eia_stats_corrected = eia_stats / ratio
to_keep = ["AL", "AT", "CH", "DE", "GB", "NL", "RS", "RO", "SK"] to_keep = ["AL", "AT", "CH", "DE", "GB", "NL", "RS", "RO", "SK"]
to_correct = eia_stats_corrected.columns.difference(to_keep) to_correct = eia_stats_corrected.columns.difference(to_keep)
eia_stats.loc[:,to_correct] = eia_stats_corrected.loc[:,to_correct] eia_stats.loc[:, to_correct] = eia_stats_corrected.loc[:, to_correct]
def approximate_missing_eia_stats(eia_stats, runoff_fn, countries): def approximate_missing_eia_stats(eia_stats, runoff_fn, countries):
runoff = pd.read_csv(runoff_fn, index_col=0).T[countries] runoff = pd.read_csv(runoff_fn, index_col=0).T[countries]
# fix ES, PT data points # fix ES, PT data points
@ -147,7 +145,6 @@ def approximate_missing_eia_stats(eia_stats, runoff_fn, countries):
eia_stats_approximated = {} eia_stats_approximated = {}
for c in countries: for c in countries:
X = runoff_eia[c] X = runoff_eia[c]
Y = eia_stats[c] Y = eia_stats[c]
@ -168,7 +165,8 @@ logger = logging.getLogger(__name__)
if __name__ == "__main__": if __name__ == "__main__":
if "snakemake" not in globals(): if "snakemake" not in globals():
from _helpers import mock_snakemake from _helpers import mock_snakemake
snakemake = mock_snakemake('build_hydro_profile', weather_year='')
snakemake = mock_snakemake("build_hydro_profile", weather_year="")
configure_logging(snakemake) configure_logging(snakemake)
config_hydro = snakemake.config["renewable"]["hydro"] config_hydro = snakemake.config["renewable"]["hydro"]
@ -185,18 +183,18 @@ if __name__ == "__main__":
fn = snakemake.input.eia_hydro_generation fn = snakemake.input.eia_hydro_generation
eia_stats = get_eia_annual_hydro_generation(fn, countries) eia_stats = get_eia_annual_hydro_generation(fn, countries)
if config_hydro.get('eia_correct_by_capacity'): if config_hydro.get("eia_correct_by_capacity"):
fn = snakemake.input.eia_hydro_capacity fn = snakemake.input.eia_hydro_capacity
correct_eia_stats_by_capacity(eia_stats, fn, countries) correct_eia_stats_by_capacity(eia_stats, fn, countries)
if config_hydro.get('eia_approximate_missing'): if config_hydro.get("eia_approximate_missing"):
fn = snakemake.input.era5_runoff fn = snakemake.input.era5_runoff
eia_stats = approximate_missing_eia_stats(eia_stats, fn, countries) eia_stats = approximate_missing_eia_stats(eia_stats, fn, countries)
eia_stats.to_csv(snakemake.output.eia_hydro) eia_stats.to_csv(snakemake.output.eia_hydro)
weather_year = snakemake.wildcards.weather_year weather_year = snakemake.wildcards.weather_year
norm_year = config_hydro.get('eia_norm_year') norm_year = config_hydro.get("eia_norm_year")
if norm_year: if norm_year:
eia_stats.loc[weather_year] = eia_stats.loc[norm_year] eia_stats.loc[weather_year] = eia_stats.loc[norm_year]
elif weather_year and weather_year not in eia_stats.index: elif weather_year and weather_year not in eia_stats.index:

View File

@ -199,7 +199,9 @@ if __name__ == "__main__":
if "snakemake" not in globals(): if "snakemake" not in globals():
from _helpers import mock_snakemake from _helpers import mock_snakemake
snakemake = mock_snakemake("build_renewable_profiles", technology="solar", weather_year="") snakemake = mock_snakemake(
"build_renewable_profiles", technology="solar", weather_year=""
)
configure_logging(snakemake) configure_logging(snakemake)
nprocesses = int(snakemake.threads) nprocesses = int(snakemake.threads)

View File

@ -457,7 +457,9 @@ if __name__ == "__main__":
if "snakemake" not in globals(): if "snakemake" not in globals():
from _helpers import mock_snakemake from _helpers import mock_snakemake
snakemake = mock_snakemake("cluster_network", simpl="", clusters="5", weather_year="") snakemake = mock_snakemake(
"cluster_network", simpl="", clusters="5", weather_year=""
)
configure_logging(snakemake) configure_logging(snakemake)
n = pypsa.Network(snakemake.input.network) n = pypsa.Network(snakemake.input.network)

View File

@ -243,7 +243,12 @@ if __name__ == "__main__":
from _helpers import mock_snakemake from _helpers import mock_snakemake
snakemake = mock_snakemake( snakemake = mock_snakemake(
"prepare_network", weather_year="", simpl="", clusters="40", ll="v0.3", opts="Co2L-24H" "prepare_network",
weather_year="",
simpl="",
clusters="40",
ll="v0.3",
opts="Co2L-24H",
) )
configure_logging(snakemake) configure_logging(snakemake)