Generate cutouts on-demand

This commit is contained in:
Jonas Hörsch 2018-08-03 11:54:28 +02:00
parent 6866ce6b06
commit c6a4de7469
6 changed files with 51 additions and 7 deletions

View File

@ -77,8 +77,16 @@ rule build_bus_regions:
resources: mem_mb=1000
script: "scripts/build_bus_regions.py"
rule build_cutout:
output: "cutouts/{cutout}"
resources: mem_mb=5000
threads: config['atlite'].get('nprocesses', 4)
benchmark: "benchmarks/build_cutout_{cutout}"
script: "scripts/build_cutout.py"
rule build_renewable_potentials:
input:
cutout=lambda wildcards: "cutouts/" + config["renewable"][wildcards.technology]['cutout'],
corine="data/bundle/corine/g250_clc06_V18_5.tif",
natura="data/bundle/natura/Natura2000_end2015.shp"
output: "resources/potentials_{technology}.nc"
@ -92,7 +100,8 @@ rule build_renewable_profiles:
potentials="resources/potentials_{technology}.nc",
regions=lambda wildcards: ("resources/regions_onshore.geojson"
if wildcards.technology in ('onwind', 'solar')
else "resources/regions_offshore.geojson")
else "resources/regions_offshore.geojson"),
cutout=lambda wildcards: "cutouts/" + config["renewable"][wildcards.technology]['cutout'],
output:
profile="resources/profile_{technology}.nc",
resources: mem_mb=5000

View File

@ -30,9 +30,25 @@ electricity:
conventional_carriers: [nuclear, oil, OCGT, CCGT, coal, lignite, geothermal, biomass]
atlite:
cutout_directory: 'cutouts'
nprocesses: 1
cutouts:
europe-2013-era5:
module: era5
xs: [-12., 35.]
ys: [72., 33.]
years: [2013, 2013]
europe-2013-sarah:
module: sarah
resolution: 0.2
xs: [-12., 42.]
ys: [65., 33.]
years: [2013, 2013]
renewable:
onwind:
cutout: europe-2012-2016-era5
cutout: europe-2013-era5
resource:
method: wind
turbine: Vestas_V112_3MW
@ -51,7 +67,7 @@ renewable:
distance_grid_codes: [1, 2, 3, 4, 5, 6]
natura: true
offwind:
cutout: europe-2012-2016-era5
cutout: europe-2013-era5
resource:
method: wind
turbine: NREL_ReferenceTurbine_5MW_offshore
@ -63,7 +79,7 @@ renewable:
grid_codes: [44, 255]
natura: true
solar:
cutout: europe-2013-2015-sarah
cutout: europe-2013-sarah
resource:
method: pv
panel: CSi

12
scripts/build_cutout.py Normal file
View File

@ -0,0 +1,12 @@
import os
import atlite
import logging
logger = logging.getLogger(__name__)
logging.basicConfig(level=snakemake.config['logging_level'])
cutout = atlite.Cutout(snakemake.wildcards.cutout,
cutout_dir=os.path.dirname(snakemake.output.cutout),
**snakemake.config['atlite']['cutouts'][snakemake.wildcards.cutout])
cutout.prepare(nprocesses=snakemake.config['atlite'].get('nprocesses', 4))

View File

@ -1,5 +1,6 @@
#!/usr/bin/env python
import os
import atlite
import pandas as pd
import geopandas as gpd
@ -8,7 +9,8 @@ import logging
logger = logging.getLogger(__name__)
logger.setLevel(level=snakemake.config['logging_level'])
cutout = atlite.Cutout(snakemake.config['renewable']['hydro']['cutout'])
cutout = atlite.Cutout(snakemake.config['renewable']['hydro']['cutout'],
cutout_dir=os.path.dirname(snakemake.input.cutout))
countries = snakemake.config['countries']
country_shapes = gpd.read_file(snakemake.input.country_shapes).set_index('id')['geometry'].reindex(countries)

View File

@ -1,3 +1,4 @@
import os
import atlite
import xarray as xr
import pandas as pd
@ -6,7 +7,8 @@ from vresutils import landuse as vlanduse
config = snakemake.config['renewable'][snakemake.wildcards.technology]
cutout = atlite.Cutout(config['cutout'])
cutout = atlite.Cutout(config['cutout'],
cutout_dir=os.path.dirname(snakemake.input.cutout))
total_capacity = config['capacity_per_sqm'] * vlanduse._cutout_cell_areas(cutout)
potentials = xr.DataArray(total_capacity *

View File

@ -1,5 +1,6 @@
#!/usr/bin/env python
import os
import atlite
import numpy as np
import xarray as xr
@ -18,7 +19,9 @@ params = dict(years=slice(*time.year[[0, -1]]), months=slice(*time.month[[0, -1]
regions = gpd.read_file(snakemake.input.regions).set_index('name')
regions.index.name = 'bus'
cutout = atlite.Cutout(config['cutout'], **params)
cutout = atlite.Cutout(config['cutout'],
cutout_dir=os.path.dirname(snakemake.input.cutout),
**params)
# Potentials
potentials = xr.open_dataarray(snakemake.input.potentials)