Skip to content

Commit

Permalink
Update MS stac.load sample notebook
Browse files Browse the repository at this point in the history
* Get rid of `cfg`, instead `dtype=` and `nodata=` can be used at
  call site.
* Fix dask warning
  • Loading branch information
Kirill888 committed Dec 19, 2023
1 parent 3fe4ef3 commit 0ac758e
Showing 1 changed file with 10 additions and 27 deletions.
37 changes: 10 additions & 27 deletions notebooks/stac-load-S2-ms.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
# name: python3
# ---

# %% [markdown] tags=[]
# %% [markdown]
# # Access Sentinel 2 Data on Planetary Computer
#
# [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/opendatacube/odc-stac/develop?labpath=notebooks%2Fstac-load-S2-ms.ipynb)

# %% [markdown] tags=[]
# %% [markdown]
# ## Setup Instructions
#
# This notebook is meant to run on Planetary Computer lab hub.
Expand All @@ -34,24 +34,6 @@

from odc.stac import configure_rio, stac_load

# %% [markdown]
# ## Configuration
#
# For now we need to manually supply band `dtype` and `nodata` information for
# each band in the collection. Use band named `*` as a wildcard.

# %%
cfg = {
"sentinel-2-l2a": {
"assets": {
"*": {"data_type": "uint16", "nodata": 0},
"SCL": {"data_type": "uint8", "nodata": 0},
"visual": {"data_type": "uint8", "nodata": 0},
},
},
"*": {"warnings": "ignore"},
}

# %% [markdown]
# ## Start Dask Client
#
Expand Down Expand Up @@ -89,15 +71,12 @@
# won't be loaded. We are "loading" data with Dask, which means that at this
# point no reads will be happening just yet.
#
# If you were to skip `warnings: ignore` in the configuration, you'll see a
# warning about `rededge` common name being used on several bands. Basically we
# can only work with common names that uniquely identify some band. In this
# case EO extension defines common name `rededge` for bands 5, 6 and 7.
# We have to supply `dtype=` and `nodata=` because items in this collection are missing [raster extension](https://github.com/stac-extensions/raster) metadata.

# %%
resolution = 10
SHRINK = 4
if client.cluster.workers[0].memory_limit < dask.utils.parse_bytes("4G"):
if client.cluster.workers[0].memory_manager.memory_limit < dask.utils.parse_bytes("4G"):
SHRINK = 8 # running on Binder with 2Gb RAM

if SHRINK > 1:
Expand All @@ -106,9 +85,11 @@
xx = stac_load(
items,
chunks={"x": 2048, "y": 2048},
stac_cfg=cfg,
patch_url=pc.sign,
resolution=resolution,
# force dtype and nodata
dtype="uint16",
nodata=0,
)

print(f"Bands: {','.join(list(xx.data_vars))}")
Expand All @@ -128,8 +109,10 @@
bands=["red", "green", "blue", "nir", "SCL"],
resolution=resolution,
chunks={"x": 2048, "y": 2048},
stac_cfg=cfg,
patch_url=pc.sign,
# force dtype and nodata
dtype="uint16",
nodata=0,
)

print(f"Bands: {','.join(list(xx.data_vars))}")
Expand Down

0 comments on commit 0ac758e

Please sign in to comment.