Restore dft_stac_cube() AOI-polygon clip via terra::mask (#32)#37
Merged
NewGraphEnvironment merged 6 commits intoJul 9, 2026
Merged
Conversation
Restore dft_stac_cube() AOI-polygon clip via client-side terra::mask (clip = TRUE default), replacing the removed gdalcubes::filter_geom. Phases + Plan-agent-reviewed findings scaffolded. Relates to NewGraphEnvironment/sred#16 Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01DKqnW6Fni3tc44Lo5D5fJz
Failing-first contract for the clip = TRUE restoration: - cube_key() helper threads `clip`; cube_key(clip = FALSE) != base (guards the silent wrong-extent cache-hit if clip is not in the key) - offline stac_cube_clip() masking test (synthetic raster + half-covering polygon): out-of-polygon cells -> NA on every layer, nlyr preserved (network-free) - opt-in network e2e asserts most bbox cells are fully NA under default clip (example AOI area/bbox ~= 0.105) Confirmed red against current code: FAIL 6 | SKIP 2 | PASS 1. Relates to NewGraphEnvironment/sred#16 Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01DKqnW6Fni3tc44Lo5D5fJz
Add `clip = TRUE`: mask the assembled index stack to the AOI polygon with terra::mask() (mirrors dft_stac_fetch(), never gdalcubes::filter_geom which segfaults on the pinned build). Out-of-polygon cells become NA on every layer, so dft_rast_break()/dft_rast_trend() skip them via their rowSums(!is.na) gate, and the reduced raster is polygon-tight with no caller-side mask. - new @nord helper stac_cube_clip(stk, aoi) = terra::mask(stk, terra::vect(aoi)) - `clip` threaded into stac_cube_cache_key() (hashed) AND the call site, so clip=TRUE/FALSE key distinctly (no wrong-extent cache hit) - normalize `clip <- isTRUE(as.logical(clip))` once so the mask gate and the key can't disagree for truthy-but-non-TRUE inputs (/code-check finding) - roxygen @param clip + @return rewrite; drop the stale filter_geom comments Full suite 319 pass, lint clean. clip is default TRUE (restores intended behavior); clip = FALSE keeps the full bbox. Relates to NewGraphEnvironment/sred#16 Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01DKqnW6Fni3tc44Lo5D5fJz
- gdalcubes-pc-gotchas.md: filter_geom bullet now notes the #32 resolution (clip restored via cube-level terra::mask in dft_stac_cube(clip=TRUE)) and the residual (fetch-time COG streaming stays bbox-bound) - NEWS.md 0.5.0: dft_stac_cube() clip default, output/behavior change, cache rebuild, Closes #32 Relates to NewGraphEnvironment/sred#16 Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01DKqnW6Fni3tc44Lo5D5fJz
dft_stac_cube() AOI-polygon clip restored (#32). devtools::check() clean (0 errors / 0 warnings / 0 notes); full suite 319 pass. Relates to NewGraphEnvironment/sred#16 Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01DKqnW6Fni3tc44Lo5D5fJz
dft_stac_cube AOI-polygon clip restored via terra::mask (clip = TRUE), released v0.5.0. Fresh planning/active/ retained. Relates to NewGraphEnvironment/sred#16 Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01DKqnW6Fni3tc44Lo5D5fJz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
dft_stac_cube()gainsclip(defaultTRUE), restoring AOI-polygon-tight output removed in Continuous index-trajectory change detection (Sentinel-2 + BFAST) for floodplain reaches #30. The assembled index stack is masked to the AOI polygon withterra::mask()client-side (helperstac_cube_clip(), mirroringdft_stac_fetch()) — nevergdalcubes::filter_geom(), which segfaults / returns an all-NA cube on the pinned build. Out-of-polygon cells becomeNAon every layer, sodft_rast_break()/dft_rast_trend()skip them via theirrowSums(!is.na) >= min_obsgate and the reduced raster is polygon-tight with no caller-side mask.clip = FALSEkeeps the full bbox.clipis threaded into both the mask step and the cube cache key, and normalized once (clip <- isTRUE(as.logical(clip))) so a truthy-but-non-TRUEinput can't skip the mask yet key asTRUE(which would let a laterclip = TRUEread an unclipped cube).Scope / honest framing
Clips the output only —
cube_view(extent = bbox)still streams the full bbox of COGs (the AOI can't be pushed into the read on the pinned gdalcubes build), so fetch time is unchanged. Genuine wins: polygon-tight output by default + a modest reducer speedup (out-of-AOI pixels skipped). This residual is recorded ininst/notes/gdalcubes-pc-gotchas.md.Behavior change
Direct cube users now get
NAoutside the AOI by default; the clip is folded into the cube cache key, so existing cached cubes rebuild once. Released as v0.5.0.Test plan
stac_cube_clip()masking test (synthetic raster + polygon) +cube_key(clip = FALSE) != base— network-free contractNAunder default clip (example AOI area/bbox ≈ 0.105)devtools::check()clean (0 errors / 0 warnings / 0 notes); full suite 319 pass; lint cleanRelated Issues
🤖 Generated with Claude Code
https://claude.ai/code/session_01DKqnW6Fni3tc44Lo5D5fJz