Skip to main content

pycopdem

Cached Copernicus GLO-30 elevation with on-read terrain derivatives — download once per chunk, never twice. Every elevation pixel this machine ever downloads lands in one sparse, chunk-indexed store on the DEM's native 1-arc-second grid; slope, aspect, flow accumulation, TWI and Heat Load Index are computed on read and never stored. Part of the Borevitz Lab ecosystem.

How it works

{data_root}/copdem_store/
├── index.db      # SQLite ledger: which chunks are populated
└── dem.zarr      # global sparse array; only written 1200×1200-px chunks exist
  • The GLO-30 DEM is served as one COG per 1° × 1° cell on a 1-arc-second EPSG:4326 lattice. The store uses the same lattice globally, chunked at 1200 px (1/3°) — so 3 × 3 chunks nest exactly inside every tile, and fetching a chunk is a single integer-aligned windowed read from one COG. No resampling, ever.
  • Any bbox maps deterministically to a set of chunk ids. Store.get_ds(bbox) diffs them against the ledger and downloads only the missing chunks. Elevation is time-invariant, so there's no time axis and no date bookkeeping.
  • A 1° tile absent from S3 is genuinely all ocean: its chunks are stored as nodata and marked complete.
  • Derivatives are a read-time transform (like everything derived in this ecosystem): request them per call, pay compute not disk.

Usage

The core API is troi-agnostic — just a bbox:

from pycopdem.store import Store

store = Store()
bbox = [148.36265, -33.52606, 148.38265, -33.50606]  # [W, S, E, N]

ds = store.get_ds(bbox)                              # elevation (lat, lon)
ds = store.get_ds(bbox, derivatives=('slope', 'aspect', 'twi', 'hli'))

store.fill(bbox)                                     # → 0: already local

Derivatives: slope and aspect (degrees), accumulation (pysheds fill-pits → fill-depressions → resolve-flats → flowdir → accumulation), twi (ln(accumulation / tan slope)), hli (McCune & Keon 2002). Dependencies resolve automatically — asking for twi computes slope and accumulation internally.

Pipelines that speak the shared troi.troi.Troi use the adapters (dates on the troi are ignored — elevation doesn't change):

ds = store.get_ds_troi(troi, derivatives=('slope',))

download_terrain(troi) remains as a thin wrapper.

Performance

Live measurements against the Copernicus S3 bucket — a ~2 × 2 km AOI (one chunk = 1200 × 1200 px ≈ 37 × 30 km):

Scenario Downloaded Time
Cold fill 1 chunk 10.3 s
Same request again nothing 0.0 s
AOI shifted ~28 km east 1 new chunk 4.2 s
Read cached window (1200²) 0.4 s
Read + all 5 derivatives 3.2 s (pysheds dominates)

Store footprint: ~10 MB for two chunks (~2 200 km² of elevation). Absolute times vary with network; the zero is the point — it's a ledger lookup, no network involved.

Install

pip

pip install git+https://github.com/thestochasticman/pycopdem.git

Dependencies (the troi core included, pulled from GitHub) are declared in pyproject.toml and installed automatically.

From source

git clone https://github.com/thestochasticman/pycopdem.git
cd pycopdem
pip install -e .

Package design (shared across the lab's packages — no inheritance, composition only):

  • Troi (from troi) — identity: what region.
  • CopernicusDEM (pycopdem.copdem) — config: tile source.
  • Paths (pycopdem.paths) — derived locations of the store for a given Config.
  • grid — the fixed 1-arc-second grid and tile/chunk nesting (pure, offline-testable math).
  • derive — the terrain derivatives (pure array math + pysheds).
  • Store (pycopdem.store) — ties them together.

Test

# offline (pure math + synthetic store):
python pycopdem/grid.py     # True
python pycopdem/paths.py    # True
python pycopdem/derive.py   # True
python pycopdem/store.py    # True

# live (small real reads from the Copernicus S3 bucket):
python pycopdem/download_terrain.py  # True

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pycopdem-0.1.0.tar.gz (15.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pycopdem-0.1.0-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file pycopdem-0.1.0.tar.gz.

File metadata

  • Download URL: pycopdem-0.1.0.tar.gz
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.15

File hashes

Hashes for pycopdem-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b850492c5a7666c3eb2a8c46a4a2f0e315c0d8e728b76babee8bcf22d2f1dbe0
MD5 59ab89829d5346f75e0cbed13fe5e3fa
BLAKE2b-256 5ddcc0adb9ccfed343a5e4978afd1f84f458d2e75e51df9e6b1f67de7723002f

See more details on using hashes here.

File details

Details for the file pycopdem-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pycopdem-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.15

File hashes

Hashes for pycopdem-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 be425ae035063506a6b65928ccdda255e6a6784092529748c9dc5c758789d863
MD5 468ea370398107d7fe3ea6aae0f8ff60
BLAKE2b-256 5fbf442dd0282846f2956b5b46327216f99b876ea1c3f5399496a6cb5adb4b30

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page