remove remaining {weather_year} wildcard usages

This commit is contained in:
Fabian Neumann 2024-03-04 18:24:01 +01:00
parent 1f7d4da3e6
commit 249cfab429
14 changed files with 27 additions and 101 deletions

View File

@ -805,14 +805,7 @@ if __name__ == "__main__":
n = pypsa.Network(snakemake.input.base_network)
weather_year = snakemake.wildcards.weather_year
if weather_year:
snapshots = dict(
start=weather_year, end=str(int(weather_year) + 1), inclusive="left"
)
else:
snapshots = snakemake.config["snapshots"]
n.set_snapshots(pd.date_range(freq="h", **snapshots))
n.set_snapshots(pd.date_range(freq="h", **snakemake.params.snapshots))
Nyears = n.snapshot_weightings.objective.sum() / 8760.0

View File

@ -20,14 +20,7 @@ if __name__ == "__main__":
configure_logging(snakemake)
weather_year = snakemake.wildcards.weather_year
if weather_year:
snapshots = dict(
start=weather_year, end=str(int(weather_year) + 1), inclusive="left"
)
else:
snapshots = snakemake.config["snapshots"]
snapshots = pd.date_range(freq="h", **snapshots)
snapshots = pd.date_range(freq="h", **snakemake.params.snapshots)
fixed_year = snakemake.config["load"].get("fixed_year", False)
years = (

View File

@ -25,11 +25,7 @@ if __name__ == "__main__":
set_scenario_config(snakemake)
cutout_name = snakemake.input.cutout
year = snakemake.wildcards.weather_year
if year:
cutout_name = cutout_name.format(weather_year=year)
cutout = atlite.Cutout(cutout_name)
cutout = atlite.Cutout(snakemake.input.cutout)
clustered_regions = (
gpd.read_file(snakemake.input.regions_onshore).set_index("name").buffer(0)

View File

@ -109,10 +109,6 @@ if __name__ == "__main__":
cutout_params = snakemake.params.cutouts[snakemake.wildcards.cutout]
if hasattr(snakemake.wildcards, "weather_year"):
time = snakemake.wildcards.weather_year
cutout_params["time"] = [time, time]
if "time" not in cutout_params:
snapshots = pd.date_range(freq="h", **snakemake.params.snapshots)
cutout_params["time"] = [snapshots[0], snapshots[-1]]

View File

@ -31,16 +31,9 @@ if __name__ == "__main__":
client = Client(cluster, asynchronous=True)
cutout_name = snakemake.input.cutout
year = snakemake.wildcards.weather_year
if year:
snapshots = dict(start=year, end=str(int(year) + 1), inclusive="left")
cutout_name = cutout_name.format(weather_year=year)
else:
snapshots = snakemake.params.snapshots
time = pd.date_range(freq="h", **snapshots)
daily = pd.date_range(freq="D", **snapshots)
time = pd.date_range(freq="h", **snakemake.params.snapshots)
daily = pd.date_range(freq="D", **snakemake.params.snapshots)
if snakemake.params.drop_leap_day:
time = time[~((time.month == 2) & (time.day == 29))]
daily = daily[~((daily.month == 2) & (daily.day == 29))]

View File

@ -263,14 +263,7 @@ if __name__ == "__main__":
configure_logging(snakemake)
set_scenario_config(snakemake)
weather_year = snakemake.wildcards.weather_year
if weather_year:
snapshots = dict(
start=weather_year, end=str(int(weather_year) + 1), inclusive="left"
)
else:
snapshots = snakemake.params.snapshots
snapshots = pd.date_range(freq="h", **snapshots)
snapshots = pd.date_range(freq="h", **snakemake.params.snapshots)
fixed_year = snakemake.config["load"].get("fixed_year", False)
years = (

View File

@ -24,14 +24,7 @@ if __name__ == "__main__":
)
set_scenario_config(snakemake)
year = snakemake.wildcards.weather_year
if year:
snapshots = dict(start=year, end=str(int(year) + 1), inclusive="left")
else:
snapshots = snakemake.params.snapshots
snapshots = pd.date_range(freq="h", **snapshots)
snapshots = pd.date_range(freq="h", **snakemake.params.snapshots)
if snakemake.params.drop_leap_day:
snapshots = snapshots[~((snapshots.month == 2) & (snapshots.day == 29))]

View File

@ -65,8 +65,8 @@ import atlite
import country_converter as coco
import geopandas as gpd
import pandas as pd
from _helpers import configure_logging, set_scenario_config
from numpy.polynomial import Polynomial
from _helpers import configure_logging, set_scenario_config
cc = coco.CountryConverter()
@ -167,7 +167,7 @@ if __name__ == "__main__":
if "snakemake" not in globals():
from _helpers import mock_snakemake
snakemake = mock_snakemake("build_hydro_profile", weather_year="")
snakemake = mock_snakemake("build_hydro_profile")
configure_logging(snakemake)
set_scenario_config(snakemake)
@ -197,12 +197,12 @@ if __name__ == "__main__":
eia_stats.to_csv(snakemake.output.eia_hydro)
weather_year = snakemake.wildcards.weather_year
contained_years = pd.date_range(freq="YE", **snakemake.params.snapshots).year
norm_year = config_hydro.get("eia_norm_year")
if norm_year:
eia_stats.loc[weather_year] = eia_stats.loc[norm_year]
elif weather_year and weather_year not in eia_stats.index:
eia_stats.loc[weather_year] = eia_stats.median()
eia_stats.loc[contained_years] = eia_stats.loc[norm_year]
elif missing_years := eia_stats.index.difference(contained_years):
eia_stats.loc[missing_years] = eia_stats.median()
inflow = cutout.runoff(
shapes=country_shapes,

View File

@ -28,11 +28,7 @@ if __name__ == "__main__":
configure_logging(snakemake)
set_scenario_config(snakemake)
cutout_name = snakemake.input.cutout
year = snakemake.wildcards.weather_year
if year:
cutout_name = cutout_name.format(weather_year=year)
cutout = atlite.Cutout(cutout_name)
cutout = atlite.Cutout(snakemake.input.cutout)
grid_cells = cutout.grid.geometry

View File

@ -21,9 +21,13 @@ if __name__ == "__main__":
set_scenario_config(snakemake)
config = snakemake.config["energy"]
if snakemake.wildcards.kind == "heat":
years = pd.date_range(freq="YE", **snakemake.config["snapshots"]).year
assert len(years) == 1, "Currently only works for single year."
data_year = years[0]
else:
data_year = int(config["energy_totals_year"])
if snakemake.wildcards.weather_year and snakemake.wildcards.kind == "heat":
data_year = int(snakemake.wildcards.weather_year)
pop_layout = pd.read_csv(snakemake.input.clustered_pop_layout, index_col=0)

View File

@ -229,14 +229,7 @@ if __name__ == "__main__":
else:
client = None
weather_year = snakemake.wildcards.weather_year
if weather_year:
snapshots = dict(
start=weather_year, end=str(int(weather_year) + 1), inclusive="left"
)
else:
snapshots = snakemake.params.snapshots
sns = pd.date_range(freq="h", **snapshots)
sns = pd.date_range(freq="h", **snakemake.params.snapshots)
cutout = atlite.Cutout(snakemake.input.cutout).sel(time=sns)
regions = gpd.read_file(snakemake.input.regions)

View File

@ -32,20 +32,11 @@ if __name__ == "__main__":
config = snakemake.params.solar_thermal
config.pop("cutout", None)
cutout_name = snakemake.input.cutout
year = snakemake.wildcards.weather_year
if year:
snapshots = dict(start=year, end=str(int(year) + 1), inclusive="left")
cutout_name = cutout_name.format(weather_year=year)
else:
snapshots = snakemake.params.snapshots
time = pd.date_range(freq="h", **snapshots)
time = pd.date_range(freq="h", **snakemake.params.snapshots)
if snakemake.params.drop_leap_day:
time = time[~((time.month == 2) & (time.day == 29))]
cutout = atlite.Cutout(cutout_name).sel(time=time)
cutout = atlite.Cutout(snakemake.input.cutout).sel(time=time)
clustered_regions = (
gpd.read_file(snakemake.input.regions_onshore).set_index("name").buffer(0)

View File

@ -20,7 +20,6 @@ if __name__ == "__main__":
snakemake = mock_snakemake(
"build_temperature_profiles",
weather_year="",
simpl="",
clusters=48,
)
@ -29,20 +28,12 @@ if __name__ == "__main__":
nprocesses = int(snakemake.threads)
cluster = LocalCluster(n_workers=nprocesses, threads_per_worker=1)
client = Client(cluster, asynchronous=True)
cutout_name = snakemake.input.cutout
year = snakemake.wildcards.weather_year
if year:
snapshots = dict(start=year, end=str(int(year) + 1), inclusive="left")
cutout_name = cutout_name.format(weather_year=year)
else:
snapshots = snakemake.params.snapshots
time = pd.date_range(freq="h", **snapshots)
time = pd.date_range(freq="h", **snakemake.params.snapshots)
if snakemake.params.drop_leap_day:
time = time[~((time.month == 2) & (time.day == 29))]
cutout = atlite.Cutout(cutout_name).sel(time=time)
cutout = atlite.Cutout(snakemake.input.cutout).sel(time=time)
clustered_regions = (
gpd.read_file(snakemake.input.regions_onshore).set_index("name").buffer(0)

View File

@ -183,13 +183,7 @@ if __name__ == "__main__":
options = snakemake.params.sector
year = snakemake.wildcards.weather_year
snapshots = (
dict(start=year, end=str(int(year) + 1), inclusive="left")
if year
else snakemake.params.snapshots
)
snapshots = pd.date_range(freq="h", **snapshots, tz="UTC")
snapshots = pd.date_range(freq="h", **snakemake.params.snapshots, tz="UTC")
if snakemake.params.drop_leap_day:
leap_day = (snapshots.month == 2) & (snapshots.day == 29)
snapshots = snapshots[~leap_day]