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(fromtroi) — identity: what region.CopernicusDEM(pycopdem.copdem) — config: tile source.Paths(pycopdem.paths) — derived locations of the store for a givenConfig.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
Metadata
Release files for pycopdem 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pycopdem-0.1.0.tar.gz | 15.2 kB | Without provenance | Details for pycopdem-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pycopdem-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for pycopdem-0.1.0-py3-none-any.whl |
Total release size: 31.2 kB
Release files / pycopdem-0.1.0.tar.gz
| Download URL | pycopdem-0.1.0.tar.gz |
|---|---|
| Size | 15.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b850492c5a7666c3eb2a8c46a4a2f0e315c0d8e728b76babee8bcf22d2f1dbe0
|
|
BLAKE2b-256 checksum How to use checksums |
5ddcc0adb9ccfed343a5e4978afd1f84f458d2e75e51df9e6b1f67de7723002f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.15
|
Release files / pycopdem-0.1.0-py3-none-any.whl
| Download URL | pycopdem-0.1.0-py3-none-any.whl |
|---|---|
| Size | 16.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
be425ae035063506a6b65928ccdda255e6a6784092529748c9dc5c758789d863
|
|
BLAKE2b-256 checksum How to use checksums |
5fbf442dd0282846f2956b5b46327216f99b876ea1c3f5399496a6cb5adb4b30
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.15
|
Security for pycopdem 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.