add more versatile cutout building with weather years

This commit is contained in:
Fabian Neumann 2022-06-15 13:51:08 +02:00
parent 6d260435a6
commit 2b43f43006
2 changed files with 23 additions and 6 deletions

View File

@ -18,7 +18,7 @@ ATLITE_NPROCESSES = config['atlite'].get('nprocesses', 4)
wildcard_constraints: wildcard_constraints:
weather_year="[0-9]*", weather_year="[0-9]{4}|$",
simpl="[a-zA-Z0-9]*|all", simpl="[a-zA-Z0-9]*|all",
clusters="[0-9]+m?|all", clusters="[0-9]+m?|all",
ll="(v|c)([0-9\.]+|opt|all)|all", ll="(v|c)([0-9\.]+|opt|all)|all",
@ -148,6 +148,9 @@ rule build_bus_regions:
script: "scripts/build_bus_regions.py" script: "scripts/build_bus_regions.py"
if config['enable'].get('build_cutout', False): if config['enable'].get('build_cutout', False):
ruleorder: build_cutout_year > build_cutout
rule build_cutout: rule build_cutout:
input: input:
regions_onshore="resources/regions_onshore.geojson", regions_onshore="resources/regions_onshore.geojson",
@ -159,6 +162,14 @@ if config['enable'].get('build_cutout', False):
resources: mem_mb=ATLITE_NPROCESSES * 1000 resources: mem_mb=ATLITE_NPROCESSES * 1000
script: "scripts/build_cutout.py" script: "scripts/build_cutout.py"
rule build_cutout_year:
input: rules.build_cutout.input
output: "cutouts/{cutout}-{weather_year}.nc"
log: "logs/build_cutout/{cutout}-{weather_year}.log"
benchmark: "benchmarks/build_cutout_{cutout}-{weather_year}"
threads: ATLITE_NPROCESSES
resources: mem_mb=ATLITE_NPROCESSES * 1000
script: "scripts/build_cutout.py"
if config['enable'].get('retrieve_cutout', True): if config['enable'].get('retrieve_cutout', True):
rule retrieve_cutout: rule retrieve_cutout:

View File

@ -103,15 +103,21 @@ 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_cutout', cutout='europe-2013-era5') # snakemake = mock_snakemake('build_cutout_year', cutout='europe-era5', weather_year=2011)
snakemake = mock_snakemake('build_cutout', cutout='europe-era5')
configure_logging(snakemake) configure_logging(snakemake)
# TODO make it accept year independent config
cutout_params = snakemake.config['atlite']['cutouts'][snakemake.wildcards.cutout] cutout_params = snakemake.config['atlite']['cutouts'][snakemake.wildcards.cutout]
snapshots = pd.date_range(freq='h', **snakemake.config['snapshots']) if hasattr(snakemake.wildcards, 'weather_year'):
time = [snapshots[0], snapshots[-1]] time = snakemake.wildcards.weather_year
cutout_params['time'] = slice(*cutout_params.get('time', time)) cutout_params["time"] = [time, time]
if "time" not in cutout_params:
snapshots = pd.date_range(freq='h', **snakemake.config['snapshots'])
cutout_params["time"] = [snapshots[0], snapshots[-1]]
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