Skip to content

Commit

Permalink
issue #884 Update for mask_scl_dilation function (#128)
Browse files Browse the repository at this point in the history
* issue #884 Update for mask_scl_dilation function

* issue #884 Update for mask_scl_dilation function

* issue #884 Update for mask_scl_dilation function

* issue #884 Update for mask_scl_dilation function

* issue #884 Update for mask_scl_dilation function

* issue #884 Update for mask_scl_dilation function

* issue #884 Update for mask_scl_dilation function
  • Loading branch information
ElienVandermaesenVITO authored Jan 15, 2025
1 parent f7ff0e3 commit 8bb8e37
Show file tree
Hide file tree
Showing 25 changed files with 388 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1333,12 +1333,22 @@
"outputs": [],
"source": [
"# download the data if it doesn't exist yet\n",
"\n",
"scl = connection.load_collection('SENTINEL2_L2A_SENTINELHUB',\n",
" spatial_extent=spat_ext,\n",
" temporal_extent=temp_ext,\n",
" bands=[\"SCL\"])\n",
"cloud_mask = scl.process(\n",
" \"to_scl_dilation_mask\",\n",
" data=scl,\n",
" kernel1_size=17, kernel2_size=77,\n",
" mask1_values=[2, 4, 5, 6, 7],\n",
" mask2_values=[3, 8, 9, 10, 11],\n",
" erosion_kernel_size=3)\n",
"s2 = connection.load_collection('SENTINEL2_L2A_SENTINELHUB',\n",
" spatial_extent=spat_ext,\n",
" temporal_extent=temp_ext,\n",
" bands=[\"B04\", \"B08\", \"SCL\"])\n",
"s2 = s2.process(\"mask_scl_dilation\", data=s2, scl_band_name=\"SCL\")\n",
" bands=[\"B04\", \"B08\"])\n",
"s2 = s2.mask(cloud_mask)\n",
"ndvi_cube = s2.ndvi(red=\"B04\", nir=\"B08\", target_band='NDVI')\n",
"\n",
"if not os.path.exists('./s2_meadow.nc'):\n",
Expand Down
17 changes: 14 additions & 3 deletions notebooks/AI4FOOD_Whittaker_OpenEO_NDVI_S2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,22 @@
"metadata": {},
"outputs": [],
"source": [
"scl = connection.load_collection('SENTINEL2_L2A_SENTINELHUB',\n",
" spatial_extent=spat_ext,\n",
" temporal_extent=temp_ext,\n",
" bands=[\"SCL\"])\n",
"cloud_mask = scl.process(\n",
" \"to_scl_dilation_mask\",\n",
" data=scl,\n",
" kernel1_size=17, kernel2_size=77,\n",
" mask1_values=[2, 4, 5, 6, 7],\n",
" mask2_values=[3, 8, 9, 10, 11],\n",
" erosion_kernel_size=3)\n",
"s2 = connection.load_collection('SENTINEL2_L2A_SENTINELHUB',\n",
" spatial_extent=spat_ext,\n",
" temporal_extent=temp_ext,\n",
" bands=[\"B04\",\"B08\",\"SCL\"])\n",
"s2_cloudmasked = s2.process(\"mask_scl_dilation\", data=s2, scl_band_name=\"SCL\")\n",
" bands=[\"B04\",\"B08\"])\n",
"s2_cloudmasked = s2.mask(cloud_mask)\n",
"ndvi_cube = s2.ndvi(red=\"B04\", nir=\"B08\")\n",
"ndvi_cube_cloudmasked = s2_cloudmasked.ndvi(red=\"B04\", nir=\"B08\")"
]
Expand Down Expand Up @@ -332,4 +343,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}
15 changes: 13 additions & 2 deletions notebooks/Local/FuseTS - MOGPR.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,22 @@
"VV = s1_asc.band(\"VV\")\n",
"rvi_asc_cube = (VH + VH) / (VV + VH)\n",
"\n",
"scl = connection.load_collection('SENTINEL2_L2A_SENTINELHUB',\n",
" spatial_extent=spat_ext,\n",
" temporal_extent=temp_ext,\n",
" bands=[\"SCL\"])\n",
"cloud_mask = scl.process(\n",
" \"to_scl_dilation_mask\",\n",
" data=scl,\n",
" kernel1_size=17, kernel2_size=77,\n",
" mask1_values=[2, 4, 5, 6, 7],\n",
" mask2_values=[3, 8, 9, 10, 11],\n",
" erosion_kernel_size=3)\n",
"s2 = connection.load_collection('SENTINEL2_L2A_SENTINELHUB',\n",
" spatial_extent=spat_ext,\n",
" temporal_extent=temp_ext,\n",
" bands=[\"B04\", \"B08\", \"SCL\"])\n",
"s2 = s2.process(\"mask_scl_dilation\", data=s2, scl_band_name=\"SCL\")\n",
" bands=[\"B04\", \"B08\"])\n",
"s2 = s2.mask(cloud_mask=cloud_mask)\n",
"ndvi_cube = s2.ndvi(red=\"B04\", nir=\"B08\")"
]
},
Expand Down
56 changes: 41 additions & 15 deletions notebooks/Local/FuseTS - Peak Valley Detection.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
"More information on the usage of openEO's Python client can be found on [GitHub](https://github.com/Open-EO/openeo-python-client).\n",
"\n",
"The first step is to connect to an openEO compatible backend.\n"
]
],
"id": "ccc826d7e3e794ad"
},
{
"cell_type": "code",
Expand All @@ -74,14 +75,16 @@
],
"source": [
"connection = openeo.connect(\"openeo.vito.be\").authenticate_oidc()"
]
],
"id": "e6ad5560fc9b30dc"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Next we define the area of interest, in this case an extent, for which we would like to fetch time series data.\n"
]
],
"id": "efbacd1f48fedc4a"
},
{
"cell_type": "code",
Expand All @@ -98,14 +101,16 @@
")\n",
"spat_ext = dict(west=minx, east=maxx, north=maxy, south=miny, crs=4326)\n",
"temp_ext = [\"2021-01-01\", \"2021-12-31\"]"
]
],
"id": "10a0472a737b4773"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We will create an openEO process to calculate the NDVI time series for our area of interest. We'll begin by using the SENTINEL2_L2A_SENTINELHUB collection, and apply a cloud masking algorithm to remove any interfering clouds before calculating the NDVI values.\n"
]
],
"id": "df3ee7d1a70f77ee"
},
{
"cell_type": "code",
Expand All @@ -114,22 +119,37 @@
"outputs": [],
"source": [
"# define openEO pipeline\n",
"scl = connection.load_collection(\n",
" \"SENTINEL2_L2A_SENTINELHUB\",\n",
" spatial_extent=spat_ext,\n",
" temporal_extent=temp_ext,\n",
" bands=[\"SCL\"],\n",
")\n",
"cloud_mask = scl.process(\n",
" \"to_scl_dilation_mask\",\n",
" data=scl,\n",
" kernel1_size=17, kernel2_size=77,\n",
" mask1_values=[2, 4, 5, 6, 7],\n",
" mask2_values=[3, 8, 9, 10, 11],\n",
" erosion_kernel_size=3)\n",
"s2 = connection.load_collection(\n",
" \"SENTINEL2_L2A_SENTINELHUB\",\n",
" spatial_extent=spat_ext,\n",
" temporal_extent=temp_ext,\n",
" bands=[\"B04\", \"B08\", \"SCL\"],\n",
" bands=[\"B04\", \"B08\"],\n",
")\n",
"s2 = s2.process(\"mask_scl_dilation\", data=s2, scl_band_name=\"SCL\")\n",
"s2 = s2.mask(cloud_mask)\n",
"ndvi_cube = s2.ndvi(red=\"B04\", nir=\"B08\", target_band=\"NDVI\")"
]
],
"id": "5d862b567ae6f299"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now that we have calculated the NDVI time series for our area of interest, we can request openEO to download the result to our local storage. This will allow us to access the file and use it for further analysis in this notebook. However, if we have already downloaded the file, we can use the existing time series to continue our analysis without the need for a new download.\n"
]
],
"id": "d7c22a63e09838e8"
},
{
"cell_type": "code",
Expand Down Expand Up @@ -174,7 +194,8 @@
"metadata": {},
"source": [
"### Plot Image Chips Across Time\n"
]
],
"id": "63390c062b62fadc"
},
{
"cell_type": "code",
Expand Down Expand Up @@ -209,14 +230,16 @@
" ax.set_title(img.t.dt.date.to_numpy())\n",
"\n",
"plt.tight_layout()"
]
],
"id": "efc69fe5bfb141e5"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Plot Time Series for Specific Polygon Area\n"
]
],
"id": "a7ed4de53954b38f"
},
{
"cell_type": "code",
Expand Down Expand Up @@ -258,7 +281,8 @@
"ax.plot(*np.array(geometry[\"coordinates\"][0]).T, \"C3\", lw=2, ls=\"dashed\")\n",
"ax.set_title(ndvi_filtered.isel(t=7).t.dt.date.to_numpy())\n",
"ax.set_aspect(\"auto\")"
]
],
"id": "b09851b79009b1f3"
},
{
"cell_type": "code",
Expand Down Expand Up @@ -299,7 +323,8 @@
"ax.imshow(ndvi_masked.isel(t=7), extent=[minx, maxx, miny, maxy])\n",
"ax.set_title(ndvi_masked.isel(t=7).t.dt.date.to_numpy())\n",
"ax.set_aspect(\"auto\")"
]
],
"id": "26f11754efa62e6b"
},
{
"cell_type": "code",
Expand Down Expand Up @@ -356,7 +381,8 @@
"ax.plot([], [], \"C0\", label=\"NDVI series of random pixels\")\n",
"ax.axvspan(None, None, color=\"C3\", alpha=0.5, label=\"Detected peak-valley events\")\n",
"ax.legend()"
]
],
"id": "1546c3e816acc487"
}
],
"metadata": {
Expand Down
17 changes: 15 additions & 2 deletions notebooks/Local/FuseTS - Peak Valley Detection_holoviews.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1469,13 +1469,26 @@
"metadata": {},
"outputs": [],
"source": [
"scl = connection.load_collection(\n",
" \"SENTINEL2_L2A_SENTINELHUB\",\n",
" spatial_extent=spat_ext,\n",
" temporal_extent=temp_ext,\n",
" bands=[\"SCL\"],\n",
")\n",
"cloud_mask = scl.process(\n",
" \"to_scl_dilation_mask\",\n",
" data=scl,\n",
" kernel1_size=17, kernel2_size=77,\n",
" mask1_values=[2, 4, 5, 6, 7],\n",
" mask2_values=[3, 8, 9, 10, 11],\n",
" erosion_kernel_size=3)\n",
"s2 = connection.load_collection(\n",
" \"SENTINEL2_L2A_SENTINELHUB\",\n",
" spatial_extent=spat_ext,\n",
" temporal_extent=temp_ext,\n",
" bands=[\"B04\", \"B08\", \"SCL\"],\n",
" bands=[\"B04\", \"B08\"],\n",
")\n",
"s2 = s2.process(\"mask_scl_dilation\", data=s2, scl_band_name=\"SCL\")\n",
"s2 = s2.mask(cloud_mask)\n",
"ndvi_cube = s2.ndvi(red=\"B04\", nir=\"B08\", target_band=\"NDVI\")"
]
},
Expand Down
15 changes: 13 additions & 2 deletions notebooks/Local/FuseTS - Phenology.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,22 @@
},
"outputs": [],
"source": [
"scl = connection.load_collection('SENTINEL2_L2A_SENTINELHUB',\n",
" spatial_extent=spat_ext,\n",
" temporal_extent=temp_ext,\n",
" bands=[\"SCL\"])\n",
"cloud_mask = scl.process(\n",
" \"to_scl_dilation_mask\",\n",
" data=scl,\n",
" kernel1_size=17, kernel2_size=77,\n",
" mask1_values=[2, 4, 5, 6, 7],\n",
" mask2_values=[3, 8, 9, 10, 11],\n",
" erosion_kernel_size=3)\n",
"s2 = connection.load_collection('SENTINEL2_L2A_SENTINELHUB',\n",
" spatial_extent=spat_ext,\n",
" temporal_extent=temp_ext,\n",
" bands=[\"B04\",\"B08\",\"SCL\"])\n",
"s2 = s2.process(\"mask_scl_dilation\", data=s2, scl_band_name=\"SCL\")\n",
" bands=[\"B04\",\"B08\"])\n",
"s2 = s2.mask(cloud_mask)\n",
"s2 = s2.mask_polygon(spat_ext)\n",
"ndvi_cube = s2.ndvi(red=\"B04\", nir=\"B08\", target_band='NDVI')"
]
Expand Down
15 changes: 13 additions & 2 deletions notebooks/Local/FuseTS - Whittaker Smoothing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -857,11 +857,22 @@
},
"outputs": [],
"source": [
"scl = connection.load_collection('SENTINEL2_L2A_SENTINELHUB',\n",
" spatial_extent=spat_ext,\n",
" temporal_extent=temp_ext,\n",
" bands=[\"SCL\"])\n",
"cloud_mask = scl.process(\n",
" \"to_scl_dilation_mask\",\n",
" data=scl,\n",
" kernel1_size=17, kernel2_size=77,\n",
" mask1_values=[2, 4, 5, 6, 7],\n",
" mask2_values=[3, 8, 9, 10, 11],\n",
" erosion_kernel_size=3)\n",
"s2 = connection.load_collection('SENTINEL2_L2A_SENTINELHUB',\n",
" spatial_extent=spat_ext,\n",
" temporal_extent=temp_ext,\n",
" bands=[\"B02\", \"B03\", \"B04\",\"SCL\"])\n",
"s2 = s2.process(\"mask_scl_dilation\", data=s2, scl_band_name=\"SCL\")\n",
" bands=[\"B02\", \"B03\", \"B04\"])\n",
"s2 = s2.mask(cloud_mask)\n",
"\n",
"B02 = s2.band('B02')\n",
"B03 = s2.band('B03')\n",
Expand Down
15 changes: 13 additions & 2 deletions notebooks/MOGPR Process Chain Demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,22 @@
"VV = s1_asc.band(\"VV\")\n",
"rvi_asc_cube = (VH + VH) / (VV + VH)\n",
"\n",
"scl = connection.load_collection('SENTINEL2_L2A_SENTINELHUB',\n",
" spatial_extent=spat_ext,\n",
" temporal_extent=temp_ext,\n",
" bands=[\"SCL\"])\n",
"cloud_mask = scl.process(\n",
" \"to_scl_dilation_mask\",\n",
" data=scl,\n",
" kernel1_size=17, kernel2_size=77,\n",
" mask1_values=[2, 4, 5, 6, 7],\n",
" mask2_values=[3, 8, 9, 10, 11],\n",
" erosion_kernel_size=3)\n",
"s2 = connection.load_collection('SENTINEL2_L2A_SENTINELHUB',\n",
" spatial_extent=spat_ext,\n",
" temporal_extent=temp_ext,\n",
" bands=[\"B04\",\"B08\",\"SCL\"])\n",
"s2 = s2.process(\"mask_scl_dilation\", data=s2, scl_band_name=\"SCL\")\n",
" bands=[\"B04\",\"B08\"])\n",
"s2 = s2.mask(cloud_mask)\n",
"ndvi_cube = s2.ndvi(red=\"B04\", nir=\"B08\")"
]
},
Expand Down
19 changes: 15 additions & 4 deletions notebooks/OpenEO/FuseTS - MOGPR Multi Source Fusion.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
"Requirement already satisfied: packaging>=21.3 in /Users/bramjanssen/projects/vito/FuseTS/venv_clean_v2/lib/python3.8/site-packages (from xarray>=0.12.3->openeo) (23.1)\n",
"Requirement already satisfied: six>=1.5 in /Users/bramjanssen/projects/vito/FuseTS/venv_clean_v2/lib/python3.8/site-packages (from python-dateutil>=2.8.2->pandas>0.20.0->openeo) (1.16.0)\n",
"\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip available: \u001b[0m\u001b[31;49m22.3.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.0\u001b[0m\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n"
"\u001B[1m[\u001B[0m\u001B[34;49mnotice\u001B[0m\u001B[1;39;49m]\u001B[0m\u001B[39;49m A new release of pip available: \u001B[0m\u001B[31;49m22.3.1\u001B[0m\u001B[39;49m -> \u001B[0m\u001B[32;49m24.0\u001B[0m\n",
"\u001B[1m[\u001B[0m\u001B[34;49mnotice\u001B[0m\u001B[1;39;49m]\u001B[0m\u001B[39;49m To update, run: \u001B[0m\u001B[32;49mpip install --upgrade pip\u001B[0m\n"
]
}
],
Expand Down Expand Up @@ -279,11 +279,22 @@
"metadata": {},
"outputs": [],
"source": [
"scl = connection.load_collection('SENTINEL2_L2A',\n",
" spatial_extent=spat_ext,\n",
" temporal_extent=temp_ext,\n",
" bands=[\"SCL\"])\n",
"cloud_mask = scl.process(\n",
" \"to_scl_dilation_mask\",\n",
" data=scl,\n",
" kernel1_size=17, kernel2_size=77,\n",
" mask1_values=[2, 4, 5, 6, 7],\n",
" mask2_values=[3, 8, 9, 10, 11],\n",
" erosion_kernel_size=3)\n",
"base_s2 = connection.load_collection('SENTINEL2_L2A',\n",
" spatial_extent=spat_ext,\n",
" temporal_extent=temp_ext,\n",
" bands=[\"B04\", \"B08\", \"SCL\"])\n",
"base_s2 = base_s2.process(\"mask_scl_dilation\", data=base_s2, scl_band_name=\"SCL\")\n",
" bands=[\"B04\", \"B08\"])\n",
"base_s2 = base_s2.mask(cloud_mask)\n",
"base_s2 = base_s2.ndvi(red=\"B04\", nir=\"B08\", target_band='NDVI')\n",
"base_s2 = base_s2.filter_bands(bands=['NDVI'])\n",
"base_s2 = base_s2.mask_polygon(spat_ext)"
Expand Down
15 changes: 13 additions & 2 deletions notebooks/OpenEO/FuseTS - MOGPR.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,22 @@
"metadata": {},
"outputs": [],
"source": [
"scl = connection.load_collection('SENTINEL2_L2A_SENTINELHUB',\n",
" spatial_extent=spat_ext,\n",
" temporal_extent=temp_ext,\n",
" bands=[\"SCL\"])\n",
"cloud_mask = scl.process(\n",
" \"to_scl_dilation_mask\",\n",
" data=scl,\n",
" kernel1_size=17, kernel2_size=77,\n",
" mask1_values=[2, 4, 5, 6, 7],\n",
" mask2_values=[3, 8, 9, 10, 11],\n",
" erosion_kernel_size=3)\n",
"base = connection.load_collection('SENTINEL2_L2A_SENTINELHUB',\n",
" spatial_extent=spat_ext,\n",
" temporal_extent=temp_ext,\n",
" bands=[\"B04\", \"B08\", \"SCL\"])\n",
"base_cloudmasked = base.process(\"mask_scl_dilation\", data=base, scl_band_name=\"SCL\")\n",
" bands=[\"B04\", \"B08\"])\n",
"base_cloudmasked = base.mask(cloud_mask)\n",
"base_ndvi = base_cloudmasked.ndvi(red=\"B04\", nir=\"B08\")"
]
},
Expand Down
Loading

0 comments on commit 8bb8e37

Please sign in to comment.