Skip to content

fix(gee): EE request-size model, bounded retry, explicit scale (DEMO-1 F10a) - #22

Merged
galib9690 merged 2 commits into
mainfrom
fix/ee-coarsen-budget
Nov 12, 2026
Merged

galib9690 merged 2 commits into
mainfrom
fix/ee-coarsen-budget

Conversation

@galib9690

Copy link
Copy Markdown
Member

Problem

DEMO-1 F10a: for basin 01013500, Landsat 8 NDVI (summer 2014), the auto-coarsened "33 m" request was 57.8 MB against EE's 50,331,648-byte limit and failed.

Root cause

  • getDownloadURL exports on EPSG:4326 and converts metres to degrees with 111,319.49 m/deg on both axes: no cos(lat). The old estimate used ground area (lon_km * cos(lat)), under-counting pixels by 1.47x at 47.2 N.
  • It assumed 4 B/band; EE server-side arithmetic is double precision (8 B), up to another 2x.
  • An empirical 2.5 x 1.1 divisor stood in for these. The tiled native-resolution path had the same flaw.
  • Check: the model gives 51.4 MB at 33 m for the Fish River box (0.893 x 0.632 deg), 1 band, 8 B; EE reported 57.8 MB. The model is about 11 % under that one report; this is unexplained, not fitted away. The 1.25 margin covers it and the retry is the backstop.

Changes

  • One size model shared by the single-request and tiled paths: degree-box pixel count, +1 col/row, bytes_per_pixel default 8, safety factor 1.25. Fish River 1 band: 38 m instead of 33 m.
  • Bounded retry (max 3) on EE's size error; every attempt, and the requested/planned/final scale, recorded in FetchResult.upstream["gee_export"], with a note when the scale differs. GEE_REQUEST_TOO_LARGE on exhaustion.
  • Additive scale= on fetch, fetch_batch and the GEE backend (cache key changes only when given; SCALE_INVALID on bad values).
  • Provenance attrs survive the unit-conversion, multiband and SoilGrids paths.

Tests

tests/test_gee_export_size_budget.py: 74 offline tests, 41 fail on 0.2.10. Full offline suite: 989 passed, 56 deselected (live). No live EE or network call was made.

Not verified

The 8 B assumption and the 11 % residual have not been checked against the live service. aihydro-tools does not pass scale yet.

🤖 Generated with Claude Code

mohdgalib and others added 2 commits November 12, 2026 12:35
… explicit scale (F10a)

_coarsen_scale_for_budget counted ground area (cos(lat)) at 4 B/band, but
getDownloadURL exports on a degree grid (no cos term) and server-side
arithmetic is double precision. At 47 N that under-counted bytes ~2.9x, so
the "33 m" Landsat 8 NDVI request for 01013500 was 57.8 MB > 50.3 MB.

- shared size model for the single-request and tiled paths, 1.25 margin
- on EE's size error: coarsen and retry, max 3, every attempt in
  upstream["gee_export"]; GEE_REQUEST_TOO_LARGE on exhaustion
- additive scale= on fetch/fetch_batch and the GEE backend
- 74 offline tests (41 fail on 0.2.10); CHANGELOG Unreleased entry

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…view fixes

- fetch_raster and SoilGrids read bandTypes() for bytes/pixel (index and
  multiband composites keep 8 B); value and source recorded in
  upstream["gee_export"]
- scale= on non-GEE products: ignored with a note, kept out of the cache key
  when no GEE product is in the chain
- tests: provenance through unit conversion, multiband, SoilGrids; cache key
  checked through the real fetch() builder; DEM plans finer than an index

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@galib9690
galib9690 merged commit 5eee0b9 into main Nov 12, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants