-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathautomatic.smk
More file actions
256 lines (226 loc) · 7.24 KB
/
automatic.smk
File metadata and controls
256 lines (226 loc) · 7.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
"""Rules to used to download automatic resource files."""
if config.get("tiny_files", False):
##
# Directly download clipped slope and bathymetry data
##
rule clip_slope:
input:
vector="resources/user/shapes/{shape}.parquet",
output:
path="resources/automatic/cutout/{shape}/slope.tif",
log:
"logs/{shape}/clip_slope.log",
params:
cog_url=internal["resources"]["automatic"]["slope"],
message:
"Download slope data covering the bounds of the input shapefile."
wrapper:
"v7.2.0/geo/rasterio/clip-geotiff"
rule clip_bathymetry:
input:
vector="resources/user/shapes/{shape}.parquet",
output:
path="resources/automatic/cutout/{shape}/bathymetry.tif",
log:
"logs/{shape}/clip_bathymetry.log",
params:
cog_url=internal["resources"]["automatic"]["bathymetry"],
message:
"Download bathymetry data covering the bounds of the input shapefile."
wrapper:
"v7.2.0/geo/rasterio/clip-geotiff"
else:
##
# Download global slope and bathymetry data, then clip the files locally
##
rule download_slope:
output:
path="resources/automatic/global/slope.tif",
log:
"logs/download_slope.log",
conda:
"../envs/shell.yaml"
params:
url=internal["resources"]["automatic"]["slope"],
message:
"Download global slope data."
shell:
"""
curl -sSLo {output:q} {params.url:q}
"""
rule download_bathymetry:
output:
path="resources/automatic/global/bathymetry.tif",
log:
"logs/download_bathymetry.log",
conda:
"../envs/shell.yaml"
params:
url=internal["resources"]["automatic"]["bathymetry"],
message:
"Download global bathymetry data."
shell:
"""
curl -sSLo {output:q} {params.url:q}
"""
rule clip_slope:
input:
script=workflow.source_path("../scripts/clip_raster.py"),
shapes="resources/user/shapes/{shape}.parquet",
slope=rules.download_slope.output,
output:
"resources/automatic/cutout/{shape}/slope.tif",
log:
"logs/{shape}/clip_slope.log",
conda:
"../envs/default.yaml"
message:
"Cut slope data to the bounds of the input shapefile."
shell:
"""
python {input.script:q} {input.slope:q} {input.shapes:q} {output:q} 2> {log:q}
"""
rule clip_bathymetry:
input:
script=workflow.source_path("../scripts/clip_raster.py"),
shapes="resources/user/shapes/{shape}.parquet",
bathymetry=rules.download_bathymetry.output,
output:
"resources/automatic/cutout/{shape}/bathymetry.tif",
log:
"logs/{shape}/clip_bathymetry.log",
conda:
"../envs/default.yaml"
message:
"Cut bathymetry data to the bounds of the input shapefile."
shell:
"""
python {input.script:q} {input.bathymetry:q} {input.shapes:q} {output:q} 2> {log:q}
"""
##
# Globcover
##
rule download_globcover:
output:
"resources/automatic/global/globcover.zip",
log:
"logs/download_globcover.log",
conda:
"../envs/shell.yaml"
params:
url=internal["resources"]["automatic"]["globcover"],
message:
"Download the GlobCover land cover data (~380 MB)."
shell:
"""
curl -sSLo {output:q} {params.url:q}
"""
rule unzip_globcover:
input:
script=workflow.source_path("../scripts/unzip_like.py"),
zipfile=rules.download_globcover.output,
output:
"resources/automatic/global/globcover-landcover.tif",
log:
"logs/unzip_globcover.log",
conda:
"../envs/shell.yaml"
params:
target_file=internal["resources"]["automatic"]["globcover_landcover_tif"],
message:
"Unzip the relevant TIF files from the GlobCover zip file."
shell:
"""
python {input.script:q} {input.zipfile:q} -f {params.target_file:q} -o {output:q} 2> {log:q}
"""
rule clip_landcover:
input:
script=workflow.source_path("../scripts/clip_raster.py"),
shapes="resources/user/shapes/{shape}.parquet",
landcover=rules.unzip_globcover.output,
output:
"resources/automatic/cutout/{shape}/landcover.tif",
log:
"logs/{shape}/clip_landcover.log",
conda:
"../envs/default.yaml"
message:
"Cut land cover data to the bounds of the input shapefile."
shell:
"""
python {input.script:q} {input.landcover:q} {input.shapes:q} {output:q} 2> {log:q}
"""
##
# Global Human Settlement Layer (GHSL)
##
rule download_ghsl:
output:
"resources/automatic/global/ghsl_built_s.zip",
log:
"logs/download_ghsl.log",
conda:
"../envs/shell.yaml"
params:
url=internal["resources"]["automatic"]["ghsl"],
message:
"Download the GHSL (Global Human Settlement Layer) built-up surface data."
shell:
"""
curl -sSLo {output:q} {params.url:q}
"""
rule unzip_ghsl:
input:
script=workflow.source_path("../scripts/unzip_like.py"),
zipfile=rules.download_ghsl.output,
output:
"resources/automatic/global/ghsl_built_s.tif",
log:
"logs/unzip_ghsl.log",
conda:
"../envs/shell.yaml"
params:
target_file=internal["resources"]["automatic"]["ghsl_tif"],
message:
"Unzip the relevant TIF file from the GHSL data."
shell:
"""
python {input.script:q} {input.zipfile:q} -f {params.target_file:q} -o {output:q} 2> {log:q}
"""
rule clip_settlement:
input:
script=workflow.source_path("../scripts/clip_raster.py"),
shapes="resources/user/shapes/{shape}.parquet",
settlement=rules.unzip_ghsl.output,
output:
"resources/automatic/cutout/{shape}/settlement.tif",
log:
"logs/{shape}/clip_settlement.log",
conda:
"../envs/default.yaml"
message:
"Cut settlement data to the bounds of the input shapefile."
shell:
"""
python {input.script:q} {input.settlement:q} {input.shapes:q} {output:q} 2> {log:q}
"""
##
# Protected Areas (WDPA)
##
rule rasterise_clip_wdpa:
input:
script=workflow.source_path("../scripts/clip_and_rasterise_polys.py"),
shapes="resources/user/shapes/{shape}.parquet",
reference_raster=rules.clip_landcover.output,
protected_areas="resources/user/wdpa.gdb",
output:
"resources/automatic/cutout/{shape}/wdpa.tif",
log:
"logs/{shape}/clip_wdpa.log",
conda:
"../envs/default.yaml"
message:
"Rasterise and cut WDPA data to the bounds of the input shapefile, using the landcover raster as reference for the rasterisation."
shell:
"""
python {input.script:q} {input.shapes:q} {input.reference_raster:q} {input.protected_areas:q} {output:q} 2> {log:q}
"""