|
14 | 14 | "source": [
|
15 | 15 | "This notebook contains information about accessing the data for LC-CMS use case.\n",
|
16 | 16 | "\n",
|
17 |
| - "The tutorial focusses on the accessing and visualizing the prediction results derived from the LC-CMS use case.\n", |
| 17 | + "The tutorial focuses on the accessing and visualizing the prediction results derived from the LC-CMS use case.\n", |
18 | 18 | "The results are also available on the Map Viewer which can be accessed using this **[link](https://www.globalearthmonitor.eu/sites/default/files/LC_CMS/index.html)**.\n",
|
19 | 19 | "\n",
|
20 | 20 | "The predictions are stored in _[BYOC SentinelHub layers](https://docs.sentinel-hub.com/api/latest/data/byoc/)_. \n",
|
|
58 | 58 | "cell_type": "markdown",
|
59 | 59 | "metadata": {},
|
60 | 60 | "source": [
|
61 |
| - "# Predicitons over pilot Africa AOI\n", |
| 61 | + "# Predictions over pilot Africa AOI\n", |
62 | 62 | "Following code snippets show how to access and visualize the predictions generated using LC-CMS pipeline. </br>\n",
|
63 | 63 | "</br>\n",
|
64 | 64 | "The predictions were generated using following input data and modelling technique : </br>\n",
|
65 | 65 | "\n",
|
66 | 66 | "**Input Data**\n",
|
67 | 67 | "- Sentinel-2 L2A : Bands B1 to B12\n",
|
68 |
| - "- 120m with bilinear resampling\n", |
| 68 | + "- 120m with bi-linear resampling\n", |
69 | 69 | "- Sub-regions (AOIs) with different biomes and geographies \n",
|
70 | 70 | "- Yearly data aggregated every two months\n",
|
71 | 71 | "- Predictions generated yearly\n",
|
|
74 | 74 | "- Pixel Based Classification using Random Forest Classifier\n",
|
75 | 75 | "- 9 Classes\n",
|
76 | 76 | "\n",
|
77 |
| - "Additionaly, LC-Classes are represented by following values in the prediction array: \n", |
| 77 | + "Additionally, LC-Classes are represented by following values in the prediction array: \n", |
78 | 78 | "\n",
|
79 | 79 | "| **Land Cover Class** | **Value** |\n",
|
80 | 80 | "| -------------------- | --------- |\n",
|
|
138 | 138 | ],
|
139 | 139 | "source": [
|
140 | 140 | "nigeria_bbox = BBox((643000.0, 1105000.0, 715000.0, 1175000.0), CRS.UTM_31N)\n",
|
141 |
| - "eopatch = predictions_download_task.execute(bbox=nigeria_bbox) #, time_interval=[\"2019-01-01\", \"2023-01-01\"]" |
| 141 | + "eopatch = predictions_download_task.execute(bbox=nigeria_bbox) # , time_interval=[\"2019-01-01\", \"2023-01-01\"]" |
142 | 142 | ]
|
143 | 143 | },
|
144 | 144 | {
|
|
162 | 162 | " \"\"\"\n",
|
163 | 163 | " Function to transform the predictions to RGB for visualization\n",
|
164 | 164 | " \"\"\"\n",
|
165 |
| - " ids_to_rgb = {0: [0, 0, 0], 1: [23, 91, 55], 3: [178, 223, 186], 4: [72, 234, 37], 6: [243, 245, 234], 7: [254, 247, 180], 8: [245, 42, 5], 9: [50, 74, 221], 10: [140, 203, 255], 11: [111, 124, 128]}\n", |
166 |
| - " resulr_arr = np.zeros((preds.shape[0], preds.shape[1], 3), dtype=np.uint8)\n", |
167 |
| - " for id, mapping in ids_to_rgb.items():\n", |
168 |
| - " resulr_arr[np.where(preds == id)] = np.array(mapping)\n", |
169 |
| - " return resulr_arr" |
| 165 | + " ids_to_rgb = {\n", |
| 166 | + " 0: [0, 0, 0],\n", |
| 167 | + " 1: [23, 91, 55],\n", |
| 168 | + " 3: [178, 223, 186],\n", |
| 169 | + " 4: [72, 234, 37],\n", |
| 170 | + " 6: [243, 245, 234],\n", |
| 171 | + " 7: [254, 247, 180],\n", |
| 172 | + " 8: [245, 42, 5],\n", |
| 173 | + " 9: [50, 74, 221],\n", |
| 174 | + " 10: [140, 203, 255],\n", |
| 175 | + " 11: [111, 124, 128],\n", |
| 176 | + " }\n", |
| 177 | + " result_arr = np.zeros((preds.shape[0], preds.shape[1], 3), dtype=np.uint8)\n", |
| 178 | + " for idx, mapping in ids_to_rgb.items():\n", |
| 179 | + " result_arr[np.where(preds == idx)] = np.array(mapping)\n", |
| 180 | + " return result_arr" |
170 | 181 | ]
|
171 | 182 | },
|
172 | 183 | {
|
|
196 | 207 | }
|
197 | 208 | ],
|
198 | 209 | "source": [
|
199 |
| - "# Generate a plot for each year \n", |
| 210 | + "# Generate a plot for each year\n", |
200 | 211 | "# we visualize the predictions using transform_to_rgb function\n",
|
201 | 212 | "preds_data = eopatch.data[\"lcms_pred\"].astype(int).squeeze(axis=0)\n",
|
202 | 213 | "y2019_preds = preds_data[:, :, 0]\n",
|
|
206 | 217 | "fig, axes = plt.subplots(1, 3, figsize=(30, 10))\n",
|
207 | 218 | "ax1, ax2, ax3 = axes\n",
|
208 | 219 | "ax1.set_title(\"For year 2019\", fontweight=\"bold\")\n",
|
209 |
| - "ax1.imshow(transform_to_rgb(y2019_preds),interpolation=\"nearest\")\n", |
| 220 | + "ax1.imshow(transform_to_rgb(y2019_preds), interpolation=\"nearest\")\n", |
210 | 221 | "ax2.set_title(\"For year 2020\", fontweight=\"bold\")\n",
|
211 |
| - "ax2.imshow(transform_to_rgb(y2020_preds),interpolation=\"nearest\")\n", |
| 222 | + "ax2.imshow(transform_to_rgb(y2020_preds), interpolation=\"nearest\")\n", |
212 | 223 | "ax3.set_title(\"For year 2021\", fontweight=\"bold\")\n",
|
213 |
| - "ax3.imshow(transform_to_rgb(y2021_preds),interpolation=\"nearest\")\n", |
| 224 | + "ax3.imshow(transform_to_rgb(y2021_preds), interpolation=\"nearest\")\n", |
214 | 225 | "plt.suptitle(\"LCMS Predictions for Kainji Lake, Nigeria in the pilot AOI Africa\", y=0.9, fontweight=\"bold\", fontsize=15)"
|
215 | 226 | ]
|
216 | 227 | },
|
|
232 | 243 | "# Similarly, we can visualize the data mask\n",
|
233 | 244 | "def get_pred_diff(preds_from, preds_to):\n",
|
234 | 245 | " \"\"\"\n",
|
235 |
| - " This function generates the diff between the the LC-CMS predictions taken over two different time periods.\n", |
| 246 | + " This function generates the diff between the LC-CMS predictions taken over two different time periods.\n", |
236 | 247 | " \"\"\"\n",
|
237 | 248 | " return np.where(preds_from != preds_to, preds_to, 0)"
|
238 | 249 | ]
|
|
277 | 288 | "fig, axes = plt.subplots(1, 3, figsize=(30, 10))\n",
|
278 | 289 | "ax1, ax2, ax3 = axes\n",
|
279 | 290 | "ax1.set_title(\"Between 2019 to 2020\", fontweight=\"bold\")\n",
|
280 |
| - "ax1.imshow(transform_to_rgb(diff_2019_2020),interpolation=\"nearest\")\n", |
| 291 | + "ax1.imshow(transform_to_rgb(diff_2019_2020), interpolation=\"nearest\")\n", |
281 | 292 | "ax2.set_title(\"Between 2020 to 2021\", fontweight=\"bold\")\n",
|
282 |
| - "ax2.imshow(transform_to_rgb(diff_2020_2021),interpolation=\"nearest\")\n", |
| 293 | + "ax2.imshow(transform_to_rgb(diff_2020_2021), interpolation=\"nearest\")\n", |
283 | 294 | "ax3.set_title(\"Between 2019 to 2021\", fontweight=\"bold\")\n",
|
284 |
| - "ax3.imshow(transform_to_rgb(diff_2019_2021),interpolation=\"nearest\")\n", |
285 |
| - "# plt.suptitle('LC-CMS Predictions for Nigeration in the pilot AOI Africa for years 2019, 2020, 2021')\n", |
286 |
| - "plt.suptitle(\"LCMS Predictions Delta (1 and 2-year change) for the Kainji Lake, Nigeria from 2019 to 2021 with various combinations\", y=0.9, fontweight=\"bold\", fontsize=15)" |
| 295 | + "ax3.imshow(transform_to_rgb(diff_2019_2021), interpolation=\"nearest\")\n", |
| 296 | + "\n", |
| 297 | + "plt.suptitle(\n", |
| 298 | + " (\n", |
| 299 | + " \"LCMS Predictions Delta (1 and 2-year change) for the Kainji Lake, Nigeria from 2019 to 2021 with various\"\n", |
| 300 | + " \" combinations\"\n", |
| 301 | + " ),\n", |
| 302 | + " y=0.9,\n", |
| 303 | + " fontweight=\"bold\",\n", |
| 304 | + " fontsize=15,\n", |
| 305 | + ")" |
287 | 306 | ]
|
288 | 307 | },
|
289 | 308 | {
|
|
302 | 321 | "source": [
|
303 | 322 | "# Predictions over experiment AOI of France\n",
|
304 | 323 | "In the following code snippets, we will see how we can access the data for the France AOI. </br>\n",
|
305 |
| - "France AOI was primariliy used for experimentation and model tuning. </br>\n", |
| 324 | + "France AOI was primarily used for experimentation and model tuning. </br>\n", |
306 | 325 | "\n",
|
307 | 326 | "The final predictions that we will see were generated using following input data and modelling technique : </br>\n",
|
308 | 327 | "**Input Data**\n",
|
309 | 328 | "- Sentinel-2 L2A : Bands B1 to B12\n",
|
310 |
| - "- 120m with bilinear resampling\n", |
| 329 | + "- 120m with bi-linear resampling\n", |
311 | 330 | "- Sub-regions (AOIs) with different biomes and geographies \n",
|
312 | 331 | "- Yearly data aggregated every two months\n",
|
313 | 332 | "- Predictions generated yearly\n",
|
|
365 | 384 | " max_threads=3,\n",
|
366 | 385 | ")\n",
|
367 | 386 | "\n",
|
368 |
| - "eopatch_paris = predictions_download_task.execute(bbox=paris_bbox) #, time_interval=[\"2019-01-01\", \"2023-01-01\"]\n", |
| 387 | + "eopatch_paris = predictions_download_task.execute(bbox=paris_bbox) # , time_interval=[\"2019-01-01\", \"2023-01-01\"]\n", |
369 | 388 | "paris_120m = eopatch_paris.data[\"lcms_pred\"].astype(int).squeeze(axis=0)"
|
370 | 389 | ]
|
371 | 390 | },
|
|
404 | 423 | " max_threads=3,\n",
|
405 | 424 | ")\n",
|
406 | 425 | "\n",
|
407 |
| - "eopatch_paris = predictions_download_task.execute(bbox=paris_bbox) #, time_interval=[\"2019-01-01\", \"2023-01-01\"]\n", |
| 426 | + "eopatch_paris = predictions_download_task.execute(bbox=paris_bbox) # , time_interval=[\"2019-01-01\", \"2023-01-01\"]\n", |
408 | 427 | "paris_60m = eopatch_paris.data[\"lcms_pred\"].astype(int).squeeze(axis=0)"
|
409 | 428 | ]
|
410 | 429 | },
|
|
443 | 462 | " max_threads=3,\n",
|
444 | 463 | ")\n",
|
445 | 464 | "\n",
|
446 |
| - "eopatch_paris = predictions_download_task.execute(bbox=paris_bbox) #, time_interval=[\"2019-01-01\", \"2023-01-01\"]\n", |
| 465 | + "eopatch_paris = predictions_download_task.execute(bbox=paris_bbox) # , time_interval=[\"2019-01-01\", \"2023-01-01\"]\n", |
447 | 466 | "paris_20m = eopatch_paris.data[\"lcms_pred\"].astype(int).squeeze(axis=0)"
|
448 | 467 | ]
|
449 | 468 | },
|
|
486 | 505 | "fig, axes = plt.subplots(1, 3, figsize=(30, 10))\n",
|
487 | 506 | "ax1, ax2, ax3 = axes\n",
|
488 | 507 | "ax1.set_title(\"120m resolution\", fontweight=\"bold\")\n",
|
489 |
| - "ax1.imshow(transform_to_rgb(paris_120m.squeeze(-1)),interpolation=\"nearest\")\n", |
| 508 | + "ax1.imshow(transform_to_rgb(paris_120m.squeeze(-1)), interpolation=\"nearest\")\n", |
490 | 509 | "ax2.set_title(\"60m resolution\", fontweight=\"bold\")\n",
|
491 |
| - "ax2.imshow(transform_to_rgb(paris_60m.squeeze(-1)),interpolation=\"nearest\")\n", |
| 510 | + "ax2.imshow(transform_to_rgb(paris_60m.squeeze(-1)), interpolation=\"nearest\")\n", |
492 | 511 | "ax3.set_title(\"20m resolution\", fontweight=\"bold\")\n",
|
493 |
| - "ax3.imshow(transform_to_rgb(paris_20m.squeeze(-1)),interpolation=\"nearest\")\n", |
494 |
| - "plt.suptitle(\"LCMS Predictions for Paris region in France AOI for different resolutions\", y=0.8, fontweight=\"bold\", fontsize=15)" |
| 512 | + "ax3.imshow(transform_to_rgb(paris_20m.squeeze(-1)), interpolation=\"nearest\")\n", |
| 513 | + "plt.suptitle(\n", |
| 514 | + " \"LCMS Predictions for Paris region in France AOI for different resolutions\", y=0.8, fontweight=\"bold\", fontsize=15\n", |
| 515 | + ")" |
495 | 516 | ]
|
496 | 517 | }
|
497 | 518 | ],
|
|
0 commit comments