diff --git a/Snakefile b/Snakefile index e2c1a881..0ca4e7c8 100644 --- a/Snakefile +++ b/Snakefile @@ -12,7 +12,7 @@ configfile: "config.yaml" wildcard_constraints: - weather_year="[0-9]*", + weather_year="[0-9]{4}|", lv="[a-z0-9\.]+", simpl="[a-zA-Z0-9]*", clusters="[0-9]+m?", @@ -68,6 +68,7 @@ if config.get('retrieve_sector_databundle', True): rule build_population_layouts: input: + cutout=pypsaeur("cutouts/" + snakemake.config['atlite']['cutout'] + ".nc"), nuts3_shapes=pypsaeur('resources/nuts3_shapes.geojson'), urban_percent="data/urban_percent.csv" output: @@ -82,6 +83,7 @@ rule build_population_layouts: rule build_clustered_population_layouts: input: + cutout=pypsaeur("cutouts/" + snakemake.config['atlite']['cutout'] + ".nc"), pop_layout_total="resources/pop_layout_total{weather_year}.nc", pop_layout_urban="resources/pop_layout_urban{weather_year}.nc", pop_layout_rural="resources/pop_layout_rural{weather_year}.nc", @@ -163,6 +165,7 @@ else: rule build_heat_demands: input: + cutout=pypsaeur("cutouts/" + snakemake.config['atlite']['cutout'] + ".nc"), pop_layout_total="resources/pop_layout_total{weather_year}.nc", pop_layout_urban="resources/pop_layout_urban{weather_year}.nc", pop_layout_rural="resources/pop_layout_rural{weather_year}.nc", @@ -178,6 +181,7 @@ rule build_heat_demands: rule build_temperature_profiles: input: + cutout=pypsaeur("cutouts/" + snakemake.config['atlite']['cutout'] + ".nc"), pop_layout_total="resources/pop_layout_total{weather_year}.nc", pop_layout_urban="resources/pop_layout_urban{weather_year}.nc", pop_layout_rural="resources/pop_layout_rural{weather_year}.nc", @@ -216,6 +220,7 @@ rule build_cop_profiles: rule build_solar_thermal_profiles: input: + cutout=pypsaeur("cutouts/" + snakemake.config['atlite']['cutout'] + ".nc"), pop_layout_total="resources/pop_layout_total{weather_year}.nc", pop_layout_urban="resources/pop_layout_urban{weather_year}.nc", pop_layout_rural="resources/pop_layout_rural{weather_year}.nc", diff --git a/config.default.yaml b/config.default.yaml index 3ed14371..7f137515 100644 --- a/config.default.yaml +++ b/config.default.yaml @@ -66,7 +66,8 @@ snapshots: closed: left # end is not inclusive atlite: - cutout: ../pypsa-eur/cutouts/europe-2013-era5.nc + cutout: europe-era5-{weather_year} + drop_leap_day: false # this information is NOT used but needed as an argument for # pypsa-eur/scripts/add_electricity.py/load_costs in make_summary.py diff --git a/scripts/build_clustered_population_layouts.py b/scripts/build_clustered_population_layouts.py index 7a8de88b..ca50db51 100644 --- a/scripts/build_clustered_population_layouts.py +++ b/scripts/build_clustered_population_layouts.py @@ -15,10 +15,10 @@ if __name__ == '__main__': clusters=48, ) + cutout_name = snakemake.input.cutout year = snakemake.wildcards.weather_year - cutout_config = snakemake.config['atlite']['cutout'] - if year: cutout_name = cutout_config.format(weather_year=year) - cutout = atlite.Cutout(cutout_config) + if year: cutout_name = cutout_name.format(weather_year=year) + cutout = atlite.Cutout(cutout_name) clustered_regions = gpd.read_file( snakemake.input.regions_onshore).set_index('name').buffer(0).squeeze() diff --git a/scripts/build_heat_demand.py b/scripts/build_heat_demand.py index 1640379c..23eeae27 100644 --- a/scripts/build_heat_demand.py +++ b/scripts/build_heat_demand.py @@ -16,22 +16,21 @@ if __name__ == '__main__': clusters=48, ) - if 'snakemake' not in globals(): - from vresutils import Dict - import yaml - snakemake = Dict() - with open('config.yaml') as f: - snakemake.config = yaml.safe_load(f) - snakemake.input = Dict() - snakemake.output = Dict() - + cutout_name = snakemake.input.cutout year = snakemake.wildcards.weather_year - snapshots = dict(start=year, end=str(int(year)+1), closed="left") if year else snakemake.config['snapshots'] - time = pd.date_range(freq='m', **snapshots) + drop_leap_day = snakemake.config["atlite"].get("drop_leap_day", False) - cutout_config = snakemake.config['atlite']['cutout'] - if year: cutout_name = cutout_config.format(weather_year=year) - cutout = atlite.Cutout(cutout_config).sel(time=time) + if year: + snapshots = dict(start=year, end=str(int(year)+1), closed="left") + cutout_name = cutout_name.format(weather_year=year) + else: + snapshots = snakemake.config['snapshots'] + + time = pd.date_range(freq='m', **snapshots) + if drop_leap_day: + time = time[~((time.month == 2) & (time.day == 29))] + + cutout = atlite.Cutout(cutout_name).sel(time=time) clustered_regions = gpd.read_file( snakemake.input.regions_onshore).set_index('name').buffer(0).squeeze() diff --git a/scripts/build_population_layouts.py b/scripts/build_population_layouts.py index e6dc767d..01727777 100644 --- a/scripts/build_population_layouts.py +++ b/scripts/build_population_layouts.py @@ -17,10 +17,10 @@ if __name__ == '__main__': weather_year='', ) + cutout_name = snakemake.input.cutout year = snakemake.wildcards.weather_year - cutout_config = snakemake.config['atlite']['cutout'] - if year: cutout_name = cutout_config.format(weather_year=year) - cutout = atlite.Cutout(cutout_config) + if year: cutout_name = cutout_name.format(weather_year=year) + cutout = atlite.Cutout(cutout_name) grid_cells = cutout.grid_cells() diff --git a/scripts/build_solar_thermal_profiles.py b/scripts/build_solar_thermal_profiles.py index 6ae522eb..e87c9a1e 100644 --- a/scripts/build_solar_thermal_profiles.py +++ b/scripts/build_solar_thermal_profiles.py @@ -16,24 +16,23 @@ if __name__ == '__main__': clusters=48, ) - if 'snakemake' not in globals(): - from vresutils import Dict - import yaml - snakemake = Dict() - with open('config.yaml') as f: - snakemake.config = yaml.safe_load(f) - snakemake.input = Dict() - snakemake.output = Dict() - config = snakemake.config['solar_thermal'] + cutout_name = snakemake.input.cutout year = snakemake.wildcards.weather_year - snapshots = dict(start=year, end=str(int(year)+1), closed="left") if year else snakemake.config['snapshots'] - time = pd.date_range(freq='m', **snapshots) + drop_leap_day = snakemake.config["atlite"].get("drop_leap_day", False) - cutout_config = snakemake.config['atlite']['cutout'] - if year: cutout_name = cutout_config.format(weather_year=year) - cutout = atlite.Cutout(cutout_config).sel(time=time) + if year: + snapshots = dict(start=year, end=str(int(year)+1), closed="left") + cutout_name = cutout_name.format(weather_year=year) + else: + snapshots = snakemake.config['snapshots'] + + time = pd.date_range(freq='m', **snapshots) + if drop_leap_day: + time = time[~((time.month == 2) & (time.day == 29))] + + cutout = atlite.Cutout(cutout_name).sel(time=time) clustered_regions = gpd.read_file( snakemake.input.regions_onshore).set_index('name').buffer(0).squeeze() diff --git a/scripts/build_temperature_profiles.py b/scripts/build_temperature_profiles.py index 75fc9ca1..02cae24c 100644 --- a/scripts/build_temperature_profiles.py +++ b/scripts/build_temperature_profiles.py @@ -16,13 +16,21 @@ if __name__ == '__main__': clusters=48, ) + cutout_name = snakemake.input.cutout year = snakemake.wildcards.weather_year - snapshots = dict(start=year, end=str(int(year)+1), closed="left") if year else snakemake.config['snapshots'] - time = pd.date_range(freq='m', **snapshots) + drop_leap_day = snakemake.config["atlite"].get("drop_leap_day", False) - cutout_config = snakemake.config['atlite']['cutout'] - if year: cutout_name = cutout_config.format(weather_year=year) - cutout = atlite.Cutout(cutout_config).sel(time=time) + if year: + snapshots = dict(start=year, end=str(int(year)+1), closed="left") + cutout_name = cutout_name.format(weather_year=year) + else: + snapshots = snakemake.config['snapshots'] + + time = pd.date_range(freq='m', **snapshots) + if drop_leap_day: + time = time[~((time.month == 2) & (time.day == 29))] + + cutout = atlite.Cutout(cutout_name).sel(time=time) clustered_regions = gpd.read_file( snakemake.input.regions_onshore).set_index('name').buffer(0).squeeze()