Skip to content

Commit

Permalink
💥 Change vector segmentation mask tutorial to Northern Kelantan
Browse files Browse the repository at this point in the history
The link to the 20191215 Johor flood water shapefile is no longer available, so switching to 20170104 flood shapefile over the Narathiwat Province in Thailand and Northern Kelantan State in Malaysia. Using an internet archive link this time instead of the UNOSAT link, not only to future-proof against future link rot, but also because the server hosting https://unosat.org/static/unosat_filesystem/2460/FL20170106THA_SHP.zip does not support range requests. Increased chip size from 128x128 to 512x512 to reduce number of batches.
  • Loading branch information
weiji14 committed Apr 11, 2024
1 parent 17713c8 commit 558190d
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions docs/vector-segmentation-masks.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,32 @@ import zen3geo

## 0️⃣ Find cloud-hosted raster and vector data ⛳

In this case study, we'll look at the flood water extent over Johor,
Malaysia 🇲🇾 on 15 Dec 2019 that were digitized by 🇺🇳 UNITAR-UNOSAT's rapid
mapping service over Synthetic Aperture Radar (SAR) 🛰️ images. Specifically,
we'll be using the 🇪🇺 Sentinel-1 Ground Range Detected (GRD) product's VV
polarization channel.
In this case study, we'll look at the flood water extent over the Narathiwat Province
in Thailand 🇹🇭 and the Northern Kelantan State in Malaysia 🇲🇾 on 04 Jan 2017 that were
digitized by 🇺🇳 UNITAR-UNOSAT's rapid mapping service over Synthetic Aperture Radar
(SAR) 🛰️ images. Specifically, we'll be using the 🇪🇺 Sentinel-1 Ground Range Detected
(GRD) product's VV polarization channel.

🔗 Links:
- https://www.unitar.org/maps/unosat-rapid-mapping-service
- https://unitar.org/maps/countries
- [Microsoft Planetary Computer STAC Explorer](https://planetarycomputer.microsoft.com/explore?c=103.6637%2C2.1494&z=8.49&v=2&d=sentinel-1-grd&s=false%3A%3A100%3A%3Atrue&ae=0&m=cql%3Afc3d85b6ab43d3e8ebe168da0206f2cf&r=VV%2C+VH+False-color+composite)
- https://www.unitar.org/maps
- https://unitar.org/maps/all-maps
- [Microsoft Planetary Computer STAC Explorer](https://planetarycomputer.microsoft.com/explore?c=102.7555%2C5.7222&z=7.92&v=2&d=sentinel-1-grd&m=cql%3Afdba821238c1a390e7c75d7ced805b2e&r=VV%2C+VH+False-color+composite&s=false%3A%3A100%3A%3Atrue&sr=desc&ae=0)

To start, let's get the 🛰️ satellite scene we'll be using for this tutorial.

```{code-cell}
item_url = "https://planetarycomputer.microsoft.com/api/stac/v1/collections/sentinel-1-grd/items/S1A_IW_GRDH_1SDV_20191215T224757_20191215T224822_030365_037955"
item_url = "https://planetarycomputer.microsoft.com/api/stac/v1/collections/sentinel-1-grd/items/S1A_IW_GRDH_1SDV_20170104T225443_20170104T225512_014688_017E5D"
# Load the individual item metadata and sign the assets
item = pystac.Item.from_file(item_url)
signed_item = planetary_computer.sign(item)
signed_item
```

This is how the Sentinel-1 🩻 image looks like over Johor in Peninsular
Malaysia on 15 Dec 2019.
This is how the Sentinel-1 🩻 image looks like over Southern Thailand / Northern
Peninsular Malaysia on 04 Jan 2017.

![Sentinel-1 GRD image over Johor, Malaysia on 20191215](https://planetarycomputer.microsoft.com/api/data/v1/item/preview.png?collection=sentinel-1-grd&item=S1A_IW_GRDH_1SDV_20191215T224757_20191215T224822_030365_037955&assets=vv&assets=vh&expression=vv%3Bvh%3Bvv%2Fvh&rescale=0%2C600&rescale=0%2C270&rescale=0%2C9&asset_as_band=True&tile_format=png&format=png)
![Sentinel-1 GRD image over Southern Thailand and Northern Peninsular Malaysia on 20170104](https://planetarycomputer.microsoft.com/api/data/v1/item/preview.png?collection=sentinel-1-grd&item=S1A_IW_GRDH_1SDV_20170104T225443_20170104T225512_014688_017E5D&assets=vv&assets=vh&expression=vv%3Bvh%3Bvv%2Fvh&rescale=0%2C600&rescale=0%2C270&rescale=0%2C9&asset_as_band=True&tile_format=png&format=png)

### Load and reproject image data 🔄

Expand Down Expand Up @@ -164,7 +164,7 @@ of the analysis extent areas we'll be working on later.
it = iter(dp_decibel_image)
dataarray = next(it)
da_clip = dataarray.rio.clip_box(minx=371483, miny=190459, maxx=409684, maxy=229474)
da_clip = dataarray.rio.clip_box(minx=125718, miny=523574, maxx=326665, maxy=722189)
da_clip.isel(band=0).plot.imshow(figsize=(11.5, 9), cmap="Blues_r", vmin=18, vmax=26)
```

Expand All @@ -182,12 +182,12 @@ We'll be converting these vector polygons to 🌈 raster masks later.

🔗 Links:
- https://github.com/UNITAR-UNOSAT/UNOSAT-AI-Based-Rapid-Mapping-Service
- [Humanitarian Data Exchange link to polygon dataset](https://data.humdata.org/dataset/waters-extents-as-of-15-december-2019-over-kota-tinggi-and-mersing-district-johor-state-of)
- [UNOSAT link to polygon dataset](https://unosat.org/products/2460)
- [Disaster Risk Monitoring Using Satellite Imagery online course](https://courses.nvidia.com/courses/course-v1:DLI+S-ES-01+V1)

```{code-cell}
# https://gdal.org/user/virtual_file_systems.html#vsizip-zip-archives
shape_url = "/vsizip/vsicurl/https://unosat-maps.web.cern.ch/MY/FL20191217MYS/FL20191217MYS_SHP.zip/ST1_20191215_WaterExtent_Johor_AOI2.shp"
shape_url = "/vsizip/vsicurl/https://web.archive.org/web/20240411214446/https://unosat.org/static/unosat_filesystem/2460/FL20170106THA_SHP.zip/ST20170104_SatelliteDetectedWaterAndSaturatedSoil.shp"
```

This is a shapefile containing 🔷 polygons of the mapped water extent. Let's
Expand Down Expand Up @@ -419,16 +419,16 @@ plt.show()

### Slice into chips and turn into tensors 🗡️

To cut 🔪 the {py:class}`xarray.Dataset` into 128x128 sized chips, we'll use
To cut 🔪 the {py:class}`xarray.Dataset` into 512x512 sized chips, we'll use
{py:class}`zen3geo.datapipes.XbatcherSlicer` (functional name:
`slice_with_xbatcher`). Refer to {doc}`./chipping` if you need a 🧑‍🎓 refresher.

```{code-cell}
dp_xbatcher = dp_dataset.slice_with_xbatcher(input_dims={"y": 128, "x": 128})
dp_xbatcher = dp_dataset.slice_with_xbatcher(input_dims={"y": 512, "x": 512})
dp_xbatcher
```

Next step is to convert the 128x128 chips into a {py:class}`torch.Tensor` via
Next step is to convert the 512x512 chips into a {py:class}`torch.Tensor` via
{py:class}`torchdata.datapipes.iter.Mapper` (functional name: `map`). The 🛰️
Sentinel-1 image and 💧 water mask will be split out at this point too.

Expand Down

0 comments on commit 558190d

Please sign in to comment.