Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update WDPA processing #12

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ parameters:
max-building-share: 0.01 # Above, a pixel cannot be used for energy farms. Equals roughly 900m2
max-urban-green-share: 0.01 # Above, a pixel cannot be used for energy farms. Equals roughly 900m2. Removes e.g. Berlin's Tempelhofer Feld.
nuts-year: 2010 # Choice of NUTS data to use from [2006, 2010, 2013, 2016, 2021]
wdpa-date: Mar2021 # Pointer to latest WDPA data.
scenarios:
technical-potential:
use-protected-areas: True
Expand Down
6 changes: 5 additions & 1 deletion config/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ properties:
type: number
enum: [2006, 2010, 2013, 2016, 2021]
default: 2016
description: Indicates the reference NUTS year
description: Indicates the reference NUTS year
wdpa-date:
type: string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could check for the form MMMYYYY, but maybe that's just too restrictive.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, who knows how they'll choose to do versioning in future...

enum: [Mar2021, Apr2021]
brynpickering marked this conversation as resolved.
Show resolved Hide resolved
descriptions: Indicates the latest Protected Planet WDPA year. Only the two latest datasets are available for download at any given time.
33 changes: 27 additions & 6 deletions rules/data-preprocessing.smk
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ URL_NUTS = "https://ec.europa.eu/eurostat/cache/GISCO/distribution/v2/nuts/shp/N
URL_LAU = "http://ec.europa.eu/eurostat/cache/GISCO/geodatafiles/COMM-01M-2013-SH.zip"
URL_DEGURBA = "http://ec.europa.eu/eurostat/cache/GISCO/geodatafiles/DGURBA_2014_SH.zip"
URL_LAND_COVER = "http://due.esrin.esa.int/files/Globcover2009_V2.3_Global_.zip"
URL_PROTECTED_AREAS = "https://www.protectedplanet.net/downloads/WDPA_Feb2019?type=shapefile"
URL_PROTECTED_AREAS = "http://d1gam3xoknrgr2.cloudfront.net/current/WDPA_{}_Public_shp.zip"
URL_CGIAR_TILE = "http://srtm.csi.cgiar.org/wp-content/uploads/files/srtm_5x5/TIFF/"
URL_GMTED_TILE = "https://edcintl.cr.usgs.gov/downloads/sciweb1/shared/topo/downloads/GMTED/Global_tiles_GMTED/075darcsec/mea/"
URL_GADM = "https://biogeo.ucdavis.edu/data/gadm3.6/gpkg/"
Expand Down Expand Up @@ -135,17 +135,38 @@ rule raw_land_cover:
rule raw_protected_areas_zipped:
message: "Download protected areas data as zip."
output: protected("data/automatic/raw-wdpa.zip")
shell: "curl -sLo {output} -H 'Referer: {URL_PROTECTED_AREAS}' {URL_PROTECTED_AREAS}"
params:
url = URL_PROTECTED_AREAS.format(config["parameters"]["wdpa-date"])
shell: "curl -sLo {output} -H 'Referer: {params.url}' {params.url}"
brynpickering marked this conversation as resolved.
Show resolved Hide resolved


rule raw_protected_areas:
message: "Extract protected areas data as zip."
input: rules.raw_protected_areas_zipped.output
params:
year = config["parameters"]["wdpa-date"]
brynpickering marked this conversation as resolved.
Show resolved Hide resolved
output:
polygons = "build/raw-wdpa-feb2019/WDPA_Feb2019-shapefile-polygons.shp",
polygon_data = "build/raw-wdpa-feb2019/WDPA_Feb2019-shapefile-polygons.dbf",
points = "build/raw-wdpa-feb2019/WDPA_Feb2019-shapefile-points.shp"
shell: "unzip -o {input} -d build/raw-wdpa-feb2019"
polygons = "build/raw-wdpa/wdpa-shapes.shp",
polygon_data = "build/raw-wdpa/wdpa-shapes.dbf",
brynpickering marked this conversation as resolved.
Show resolved Hide resolved
points = "build/raw-wdpa/wdpa-points.shp"
conda: "../envs/default.yaml"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This conda env is useless here.

shell:
"""
set +e
unzip -o {input} -d build/raw-wdpa
brynpickering marked this conversation as resolved.
Show resolved Hide resolved
unzip -o build/raw-wdpa/WDPA_{params.year}-shapefile0.zip -d build/raw-wdpa/WDPA_to_merge_0
brynpickering marked this conversation as resolved.
Show resolved Hide resolved
unzip -o build/raw-wdpa/WDPA_{params.year}-shapefile1.zip -d build/raw-wdpa/WDPA_to_merge_0
unzip -o build/raw-wdpa/WDPA_{params.year}-shapefile2.zip -d build/raw-wdpa/WDPA_to_merge_0
ogrmerge.py -single -o {output.polygons} build/raw-wdpa/WDPA_to_merge_**/*-polygons.shp
brynpickering marked this conversation as resolved.
Show resolved Hide resolved
ogrmerge.py -single -o {output.polygons} build/raw-wdpa/WDPA_to_merge_**/*-points.shp
brynpickering marked this conversation as resolved.
Show resolved Hide resolved
exitcode=$?
brynpickering marked this conversation as resolved.
Show resolved Hide resolved
if [ $exitcode -eq 1 ]
then
exit 1
else
exit 0
fi
"""


rule raw_srtm_elevation_tile_zipped:
Expand Down