|
1 | 1 | """Rules to used to download automatic resource files.""" |
2 | 2 |
|
| 3 | +if config["tiny_files"]: |
3 | 4 |
|
4 | | -rule download_cutout_slope: |
5 | | - message: |
6 | | - "Download slope data covering the bounds of the input shapefile." |
7 | | - params: |
8 | | - cog_url=internal["resources"]["automatic"]["slope"], |
9 | | - input: |
10 | | - vector="resources/user/shapes/{shape}.parquet", |
11 | | - output: |
12 | | - path="resources/automatic/cutout/{shape}/slope.tif", |
13 | | - log: |
14 | | - "logs/{shape}/download_cutout_slope.log", |
15 | | - wrapper: |
16 | | - "v7.2.0/geo/rasterio/clip-geotiff" |
| 5 | + ## |
| 6 | + # Directly download clipped slope and bathymetry data |
| 7 | + ## |
17 | 8 |
|
| 9 | + rule clip_slope: |
| 10 | + message: |
| 11 | + "Download slope data covering the bounds of the input shapefile." |
| 12 | + params: |
| 13 | + cog_url=internal["resources"]["automatic"]["slope"], |
| 14 | + input: |
| 15 | + vector="resources/user/shapes/{shape}.parquet", |
| 16 | + output: |
| 17 | + path="resources/automatic/cutout/{shape}/slope.tif", |
| 18 | + log: |
| 19 | + "logs/{shape}/clip_slope.log", |
| 20 | + wrapper: |
| 21 | + "v7.2.0/geo/rasterio/clip-geotiff" |
18 | 22 |
|
19 | | -rule download_cutout_bathymetry: |
20 | | - message: |
21 | | - "Download bathymetry data covering the bounds of the input shapefile." |
22 | | - params: |
23 | | - cog_url=internal["resources"]["automatic"]["bathymetry"], |
24 | | - input: |
25 | | - vector="resources/user/shapes/{shape}.parquet", |
26 | | - output: |
27 | | - path="resources/automatic/cutout/{shape}/bathymetry.tif", |
28 | | - log: |
29 | | - "logs/{shape}/download_cutout_bathymetry.log", |
30 | | - wrapper: |
31 | | - "v7.2.0/geo/rasterio/clip-geotiff" |
| 23 | + rule clip_bathymetry: |
| 24 | + message: |
| 25 | + "Download bathymetry data covering the bounds of the input shapefile." |
| 26 | + params: |
| 27 | + cog_url=internal["resources"]["automatic"]["bathymetry"], |
| 28 | + input: |
| 29 | + vector="resources/user/shapes/{shape}.parquet", |
| 30 | + output: |
| 31 | + path="resources/automatic/cutout/{shape}/bathymetry.tif", |
| 32 | + log: |
| 33 | + "logs/{shape}/clip_bathymetry.log", |
| 34 | + wrapper: |
| 35 | + "v7.2.0/geo/rasterio/clip-geotiff" |
| 36 | + |
| 37 | +else: |
| 38 | + |
| 39 | + ## |
| 40 | + # Download global slope and bathymetry data, then clip the files locally |
| 41 | + ## |
| 42 | + |
| 43 | + rule download_slope: |
| 44 | + message: |
| 45 | + "Download global slope data." |
| 46 | + params: |
| 47 | + url=internal["resources"]["automatic"]["slope"], |
| 48 | + output: |
| 49 | + path="resources/automatic/global/slope.tif", |
| 50 | + log: |
| 51 | + "logs/download_slope.log", |
| 52 | + conda: |
| 53 | + "../envs/shell.yaml" |
| 54 | + shell: |
| 55 | + """ |
| 56 | + curl -sSLo "{output}" "{params.url}" |
| 57 | + """ |
| 58 | + |
| 59 | + rule download_bathymetry: |
| 60 | + message: |
| 61 | + "Download global bathymetry data." |
| 62 | + params: |
| 63 | + url=internal["resources"]["automatic"]["bathymetry"], |
| 64 | + output: |
| 65 | + path="resources/automatic/global/bathymetry.tif", |
| 66 | + log: |
| 67 | + "logs/download_bathymetry.log", |
| 68 | + conda: |
| 69 | + "../envs/shell.yaml" |
| 70 | + shell: |
| 71 | + """ |
| 72 | + curl -sSLo "{output}" "{params.url}" |
| 73 | + """ |
| 74 | + |
| 75 | + rule clip_slope: |
| 76 | + message: |
| 77 | + "Cut slope data to the bounds of the input shapefile." |
| 78 | + input: |
| 79 | + script=workflow.source_path("../scripts/clip_raster.py"), |
| 80 | + shapes="resources/user/shapes/{shape}.parquet", |
| 81 | + slope=rules.download_slope.output, |
| 82 | + output: |
| 83 | + "resources/automatic/cutout/{shape}/slope.tif", |
| 84 | + log: |
| 85 | + "logs/{shape}/clip_slope.log", |
| 86 | + conda: |
| 87 | + "../envs/default.yaml" |
| 88 | + shell: |
| 89 | + """ |
| 90 | + python "{input.script}" "{input.slope}" "{input.shapes}" "{output}" 2> "{log}" |
| 91 | + """ |
| 92 | + |
| 93 | + rule clip_bathymetry: |
| 94 | + message: |
| 95 | + "Cut bathymetry data to the bounds of the input shapefile." |
| 96 | + input: |
| 97 | + script=workflow.source_path("../scripts/clip_raster.py"), |
| 98 | + shapes="resources/user/shapes/{shape}.parquet", |
| 99 | + bathymetry=rules.download_bathymetry.output, |
| 100 | + output: |
| 101 | + "resources/automatic/cutout/{shape}/bathymetry.tif", |
| 102 | + log: |
| 103 | + "logs/{shape}/clip_bathymetry.log", |
| 104 | + conda: |
| 105 | + "../envs/default.yaml" |
| 106 | + shell: |
| 107 | + """ |
| 108 | + python "{input.script}" "{input.bathymetry}" "{input.shapes}" "{output}" 2> "{log}" |
| 109 | + """ |
| 110 | + |
| 111 | + |
| 112 | +## |
| 113 | +# Globcover |
| 114 | +## |
32 | 115 |
|
33 | 116 |
|
34 | 117 | rule download_globcover: |
@@ -68,6 +151,30 @@ rule unzip_globcover: |
68 | 151 | """ |
69 | 152 |
|
70 | 153 |
|
| 154 | +rule clip_landcover: |
| 155 | + message: |
| 156 | + "Cut land cover data to the bounds of the input shapefile." |
| 157 | + input: |
| 158 | + script=workflow.source_path("../scripts/clip_raster.py"), |
| 159 | + shapes="resources/user/shapes/{shape}.parquet", |
| 160 | + landcover=rules.unzip_globcover.output, |
| 161 | + output: |
| 162 | + "resources/automatic/cutout/{shape}/landcover.tif", |
| 163 | + log: |
| 164 | + "logs/{shape}/clip_landcover.log", |
| 165 | + conda: |
| 166 | + "../envs/default.yaml" |
| 167 | + shell: |
| 168 | + """ |
| 169 | + python "{input.script}" "{input.landcover}" "{input.shapes}" "{output}" 2> "{log}" |
| 170 | + """ |
| 171 | + |
| 172 | + |
| 173 | +## |
| 174 | +# Global Human Settlement Layer (GHSL) |
| 175 | +## |
| 176 | + |
| 177 | + |
71 | 178 | rule download_ghsl: |
72 | 179 | message: |
73 | 180 | "Download the GHSL (Global Human Settlement Layer) built-up surface data." |
@@ -103,3 +210,47 @@ rule unzip_ghsl: |
103 | 210 | """ |
104 | 211 | python "{input.script}" "{input.zipfile}" -f "{params.target_file}" -o "{output}" 2> "{log}" |
105 | 212 | """ |
| 213 | + |
| 214 | + |
| 215 | +rule clip_settlement: |
| 216 | + message: |
| 217 | + "Cut settlement data to the bounds of the input shapefile." |
| 218 | + input: |
| 219 | + script=workflow.source_path("../scripts/clip_raster.py"), |
| 220 | + shapes="resources/user/shapes/{shape}.parquet", |
| 221 | + settlement=rules.unzip_ghsl.output, |
| 222 | + output: |
| 223 | + "resources/automatic/cutout/{shape}/settlement.tif", |
| 224 | + log: |
| 225 | + "logs/{shape}/clip_settlement.log", |
| 226 | + conda: |
| 227 | + "../envs/default.yaml" |
| 228 | + shell: |
| 229 | + """ |
| 230 | + python "{input.script}" "{input.settlement}" "{input.shapes}" "{output}" 2> "{log}" |
| 231 | + """ |
| 232 | + |
| 233 | + |
| 234 | +## |
| 235 | +# Protected Areas (WDPA) |
| 236 | +## |
| 237 | + |
| 238 | + |
| 239 | +rule rasterise_clip_wdpa: |
| 240 | + message: |
| 241 | + "Rasterise and cut WDPA data to the bounds of the input shapefile, using the landcover raster as reference for the rasterisation." |
| 242 | + input: |
| 243 | + script=workflow.source_path("../scripts/clip_and_rasterise_polys.py"), |
| 244 | + shapes="resources/user/shapes/{shape}.parquet", |
| 245 | + reference_raster=rules.clip_landcover.output, |
| 246 | + protected_areas="resources/user/wdpa.gdb", |
| 247 | + output: |
| 248 | + "resources/automatic/cutout/{shape}/wdpa.tif", |
| 249 | + log: |
| 250 | + "logs/{shape}/clip_wdpa.log", |
| 251 | + conda: |
| 252 | + "../envs/default.yaml" |
| 253 | + shell: |
| 254 | + """ |
| 255 | + python "{input.script}" "{input.shapes}" "{input.reference_raster}" "{input.protected_areas}" "{output}" 2> "{log}" |
| 256 | + """ |
0 commit comments