Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

A geocloud tour — buckets, COG windows and a validated COG

Open In Colab

You list and download objects from a public bucket, read windows of a Sentinel-2 COG without downloading it, and write an NDVI result as a validated COG. Every call shares one obstore client per bucket. The last section replays the workflow against an in-memory bucket, the way the tests run offline.

What you’ll learn:

  1. Register anonymous access per bucket with geocloud.credentials.set_credentials.

  2. List, inspect and download objects with geocloud.files (ls, info, download).

  3. Read COG windows with geocloud.cog.CogSource, fetching each tile once.

  4. Write a COG with geocloud.cog.write_cog and check it with rasterio through credentials.gdal_access.

  5. Mirror files into a mounted MemoryStore with geocloud.files.sync and geocloud.store.mount.

The package overview and the extras table are on the geotoolz-cloud page.

Setup

On Colab the next cell installs geotoolz-cloud[cog]; locally, use the workspace environment (make install).

Python implementation: CPython
Python version       : 3.13.16
IPython version      : 9.13.0

numpy        : 2.4.5
matplotlib   : 3.10.9
obstore      : 0.9.5
async_geotiff: 0.5.1
rasterio     : 1.5.0
georeader    : unknown
geocloud     : 0.3.0

Compiler    : GCC 13.3.0
OS          : Linux
Release     : 6.18.44-fc-v80
Machine     : x86_64
Processor   : x86_64
CPU cores   : 4
Architecture: 64bit

1. Register the buckets

set_credentials registers options once per bucket; every later call under that root picks them up. Both buckets here are public, so anonymous=True sends unsigned requests. Each gets its own region. Nothing is written to os.environ.

['s3://noaa-goes19', 's3://sentinel-cogs']

2. List, inspect and download

files.ls lists a prefix. With recursive=False it lists one level, with sub-directories as is_dir entries. NOAA’s GOES bucket is keyed by product, year, day of year and hour.

104 products, e.g. ['ABI-Flood-Day-Shapefiles', 'ABI-Flood-Day-TIF', 'ABI-Flood-Day', 'ABI-Flood-Hourly-Shapefiles', 'ABI-Flood-Hourly-TIF']
120 mesoscale clear sky masks in that hour; first three:
     364 kB  18:00:53  OR_ABI-L2-ACMM1-M6_G19_s20262811800286_e20262811800344_c20262811800455.nc
     364 kB  18:01:46  OR_ABI-L2-ACMM1-M6_G19_s20262811801258_e20262811801315_c20262811801410.nc
     364 kB  18:02:45  OR_ABI-L2-ACMM1-M6_G19_s20262811802258_e20262811802316_c20262811802408.nc

files.info reads one object’s size, time and entity tag without fetching it. files.download streams it into a .part file and renames it when complete, so a failed transfer never leaves a truncated file. Downloads go to a temporary directory.

ObjectInfo(uri='s3://noaa-goes19/ABI-L2-ACMM/2026/281/18/OR_ABI-L2-ACMM1-M6_G19_s20262811800286_e20262811800344_c20262811800455.nc', size=363520, last_modified=datetime.datetime(2026, 10, 8, 18, 0, 53, tzinfo=datetime.timezone.utc), e_tag='"01f7ad6e5c4f0fa02422c2107b21b2e5"', is_dir=False)
/tmp/geocloud-zm7b01a2/goes/OR_ABI-L2-ACMM1-M6_G19_s20262811800286_e20262811800344_c20262811800455.nc 364 kB

3. Read COG windows

CogSource.open fetches the header of a remote COG once. read_windows then fetches every tile the windows touch exactly once, concurrently, and returns one geoarray.GeoArray per window. The scene is a nearly cloud-free Sentinel-2 L2A granule over Lake Tahoe, 19 September 2026.

['AOT.tif', 'B01.tif', 'B02.tif', 'B03.tif', 'B04.tif', 'B05.tif', 'B06.tif', 'B07.tif', 'B08.tif', 'B09.tif', 'B11.tif', 'B12.tif', 'B8A.tif', 'L2A_PVI.tif', 'S2A_10SGJ_20260919_0_L2A.json', 'SCL.tif', 'TCI.tif', 'WVP.tif', 'granule_metadata.xml', 'preview.jpg', 'tileinfo_metadata.json']
(1, 10980, 10980) EPSG:32610 (10.0, 10.0)

Turn a lon/lat box around the lake into a pixel window of the 10 m grid, and read it from both bands. A window is a geoarray.PixelWindow or, as here, a rasterio.windows.Window. A second B04 window overlaps the first; the tiles they share are fetched once.

Window(col_off=3772, row_off=4755, width=3144, height=4546)
(1, 4546, 3144) (1, 4546, 3144) uint16 EPSG:32610 0

4. Compute NDVI and write a COG

NDVI is a float computation on the two windows. Sentinel-2 marks no data with 0, so those pixels become NaN.

<Figure size 1200x500 with 3 Axes>

write_cog builds the COG in a temporary directory, checks it, then renames it into place. The defaults follow the dtype: a floating-point predictor, average overviews and a NaN nodata for this float32 NDVI.

/tmp/geocloud-zm7b01a2/ndvi_tahoe.tif 44.09 MB

5. Check it with rasterio

credentials.gdal_access gives GDAL the same credentials the pool uses: a /vsis3/ path and config options. Pass the options to rasterio.Env. A local path comes back unchanged with no options.

LAYOUT: COG
blocks: [(512, 512)] overviews: [2, 4, 8, 16]
dtype: ('float32',) nodata: nan description: ('ndvi',)
/vsis3/sentinel-cogs/sentinel-s2-l2a-cogs/10/S/GJ/2026/9/S2A_10SGJ_20260919_0_L2A/TCI.tif {'AWS_NO_SIGN_REQUEST': 'YES', 'AWS_REGION': 'us-west-2'}
(3, 686, 686) uint8
<Figure size 500x500 with 1 Axes>

6. Test offline with a mounted MemoryStore

store.mount serves a bucket root from any obstore store you build. Every geocloud.files and geocloud.cog call under that root then uses it, so code written against s3:// runs in memory. Here files.sync mirrors the downloads into a fake bucket, and write_cog uploads straight into it.

synced 2 objects
second sync copies 0: same sizes are skipped
     44361 kB  s3://my-results/products/ndvi.tif
       364 kB  s3://my-results/run-001/goes/OR_ABI-L2-ACMM1-M6_G19_s20262811800286_e20262811800344_c20262811800455.nc
     44086 kB  s3://my-results/run-001/ndvi_tahoe.tif

The COG reader works against the mount too: open the uploaded NDVI and read one window back.

(1, 256, 256) float32 matches the written NDVI: True

Summary

  • credentials.set_credentials registers access once per bucket; gdal_access hands the same access to GDAL.

  • files.ls, info, download and sync move objects between buckets and local paths on one client pool.

  • CogSource.read_windows reads COG windows remotely, fetching each tile once.

  • write_cog writes a checked COG locally or to any bucket, and store.mount makes all of it testable offline.

Next: geotoolz-cloud for the package overview and the API reference.