Skip to content

Commit a260f8f

Browse files
authored
✏️ Edit URLs to shapefiles from UNOSAT (#138)
* ✏️ Edit URL to Mount Talakmau landslide shapefile Old CERN link seems to be unavailable. New link from https://unosat.org/products/3064 points to https://unosat.org/static/unosat_filesystem/3064/LS20220308IDN_SHP.zip instead. * 💥 Change vector segmentation mask tutorial to Northern Kelantan 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. * ✅ Update bbox coords in test_pystac_client_item_search Minor changes to the bounding box coordinates of the returned STAC item. * 🚨 Bump GitHub Actions workflows to fix deprecations Updated actions/checkout and actions/setup-python to silence deprecated warning on Node.js 16 (see https://github.blog/changelog/2023-09-22-github-actions-transitioning-from-node-16-to-node-20/). * 📌 Pin to Python 3.11.8 to avoid dask.dataframe TypeError Xref dask/dask#11038 * 🐛 Replace UNOSAT link with Wayback Machine permalink The UNOSAT link doesn't support range requests, resulting in a `DataSourceError: Range downloading not supported by this server!` error. Using the Internet Archive's permalink instead. * 📌 Temporarily pin dask to <2024.3.0 on readthedocs build The latest dask=2024.4.1 version installed via readthedocs has a bug with `import datashader` raising `ModuleNotFoundError: No module named 'dask_expr'`. Xref holoviz/datashader#1319 * 📌 Pin to dask=2024.2.1 The less than sign at c24338a didn't work on the readthedocs build.
1 parent d9f4774 commit a260f8f

6 files changed

+35
-31
lines changed

.github/workflows/ci-tests.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
strategy:
2121
fail-fast: false
2222
matrix:
23-
python-version: ["3.8", "3.10", "3.11"]
23+
python-version: ["3.8", "3.10", "3.11.8"]
2424
os: [ubuntu-22.04]
2525
# Is it a draft Pull Request (true or false)?
2626
isDraft:
@@ -29,25 +29,25 @@ jobs:
2929
exclude:
3030
- python-version: '3.8'
3131
isDraft: true
32-
- python-version: '3.11'
32+
- python-version: '3.11.8'
3333
isDraft: true
3434
# Only install optional packages on Ubuntu-22.04/Python 3.10 and 3.11
3535
include:
3636
- os: 'ubuntu-22.04'
3737
python-version: '3.10'
3838
extra-packages: '--extras "raster spatial stac vector"'
3939
- os: 'ubuntu-22.04'
40-
python-version: '3.11'
40+
python-version: '3.11.8'
4141
extra-packages: '--extras "raster spatial stac vector"'
4242

4343
steps:
4444
# Checkout current git repository
4545
- name: Checkout
46-
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
46+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
4747

4848
# Install Python
4949
- name: Set up Python ${{ matrix.python-version }}
50-
uses: actions/setup-python@bd6b4b6205c4dbad673328db7b31b7fab9e241c0 # v4.6.1
50+
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
5151
with:
5252
python-version: ${{ matrix.python-version }}
5353

.github/workflows/publish-to-pypi.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ jobs:
3030

3131
steps:
3232
- name: Checkout
33-
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
33+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
3434
with:
3535
# fetch all history so that poetry-dynamic-versioning works
3636
fetch-depth: 0
3737

3838
- name: Set up Python 3.11
39-
uses: actions/setup-python@bd6b4b6205c4dbad673328db7b31b7fab9e241c0 # v4.6.1
39+
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
4040
with:
41-
python-version: '3.11'
41+
python-version: '3.11.8'
4242

4343
- name: Install Poetry and dynamic-versioning plugin
4444
run: |

docs/.readthedocs.yaml

+5-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ build:
2323
# see https://github.com/gjoseph92/stackstac/pull/208
2424
# Need to wait for rasterio/GDAL to support float16
2525
# see https://gdal.org/api/raster_c_api.html#_CPPv412GDALDataType
26-
- "pip install stackstac==0.4.4"
26+
# Install dask<2024.3.0 to prevent
27+
# ModuleNotFoundError: No module named 'dask_expr'
28+
# ImportError: Dask dataframe requirements are not installed
29+
# https://github.com/holoviz/datashader/issues/1319
30+
- "pip install stackstac==0.4.4 dask==2024.2.1"
2731

2832
# Optional but recommended, declare the Python requirements required
2933
# to build your documentation

docs/stacking.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ we'll first load the digitized landslide polygons from a vector file 📁 using
197197

198198
```{code-cell}
199199
# https://gdal.org/user/virtual_file_systems.html#vsizip-zip-archives
200-
shape_url = "/vsizip/vsicurl/https://unosat-maps.web.cern.ch/ID/LS20220308IDN/LS20220308IDN_SHP.zip/LS20220308IDN_SHP/S2_20220304_LandslideExtent_MountTalakmau.shp"
200+
shape_url = "/vsizip/vsicurl/https://web.archive.org/web/20240202034335/https://unosat.org/static/unosat_filesystem/3064/LS20220308IDN_SHP.zip/LS20220308IDN_SHP/S2_20220304_LandslideExtent_MountTalakmau.shp"
201201
202202
dp_shapes = torchdata.datapipes.iter.IterableWrapper(iterable=[shape_url])
203203
dp_pyogrio = dp_shapes.read_from_pyogrio()

docs/vector-segmentation-masks.md

+18-18
Original file line numberDiff line numberDiff line change
@@ -43,32 +43,32 @@ import zen3geo
4343

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

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

5252
🔗 Links:
53-
- https://www.unitar.org/maps/unosat-rapid-mapping-service
54-
- https://unitar.org/maps/countries
55-
- [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)
53+
- https://www.unitar.org/maps
54+
- https://unitar.org/maps/all-maps
55+
- [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)
5656

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

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

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

71-
![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)
71+
![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)
7272

7373
### Load and reproject image data 🔄
7474

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

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

183183
🔗 Links:
184184
- https://github.com/UNITAR-UNOSAT/UNOSAT-AI-Based-Rapid-Mapping-Service
185-
- [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)
185+
- [UNOSAT link to polygon dataset](https://unosat.org/products/2460)
186186
- [Disaster Risk Monitoring Using Satellite Imagery online course](https://courses.nvidia.com/courses/course-v1:DLI+S-ES-01+V1)
187187

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

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

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

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

426426
```{code-cell}
427-
dp_xbatcher = dp_dataset.slice_with_xbatcher(input_dims={"y": 128, "x": 128})
427+
dp_xbatcher = dp_dataset.slice_with_xbatcher(input_dims={"y": 512, "x": 512})
428428
dp_xbatcher
429429
```
430430

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

zen3geo/tests/test_datapipes_pystac_client.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ def test_pystac_client_item_search():
4242

4343
assert stac_item.bbox == [
4444
149.965907628116,
45-
-35.199398016548095,
46-
152.10531016837078,
47-
-32.972806586656844,
45+
-35.199398016548116,
46+
152.1053101683708,
47+
-32.97280658665687,
4848
]
4949
assert stac_item.datetime.isoformat() == "2001-07-02T00:00:00+00:00"
5050
assert stac_item.geometry["type"] == "Polygon"

0 commit comments

Comments
 (0)