Skip to content

Use AOI bounds for FCF clip_box (fix WindowError on some non-CONUS AOIs)#84

Closed
ZachHoppinen wants to merge 1 commit into
mainfrom
fix-fcf-clipbox-bounds
Closed

Use AOI bounds for FCF clip_box (fix WindowError on some non-CONUS AOIs)#84
ZachHoppinen wants to merge 1 commit into
mainfrom
fix-fcf-clipbox-bounds

Conversation

@ZachHoppinen

Copy link
Copy Markdown
Contributor

Summary

  • Some non-CONUS AOIs (e.g. white_mtns 2024_2025) fail at `generate_forest_fraction_dataarray` with `rasterio.errors.WindowError: Bounds and transform are inconsistent` when `fcf.rio.clip_box(...)` is called with bounds derived from `ref.rio.bounds()`.
  • Investigation: `generate_reference_grid` already reprojects `ref` to EPSG:4326 (line 130) and clips it to `aoi.bounds` (line 137). So `ref.rio.bounds()` ≈ `aoi.bounds` — the "tighter crop" benefit from Fix OOM when downloading Proba-V forest cover for non-CONUS AOIs #80 was illusory.
  • Pixel-edge snapping in `pad_box` and projection round-tripping in `reproject` can produce subtly degenerate bounds that break `rasterio.windows.from_bounds`. Bypass the issue by using `aoi.bounds` directly.
  • Also removes the now-unused `transform_bounds` import.

Test plan

  • `pytest tests/` — 73/73 pass.
  • Re-run white_mtns 2024_2025 and confirm FCF clip succeeds.
  • Confirm CONUS AOIs still work (NLCD path is untouched).

🤖 Generated with Claude Code

The ref-based clip_box bounds in generate_forest_fraction_dataarray
were failing on some non-CONUS AOIs (white_mtns 2024_2025) with:

    rasterio.errors.WindowError: Bounds and transform are inconsistent

Investigation: generate_reference_grid already reprojects ref to
EPSG:4326 and clips to aoi.bounds, so ref.rio.bounds() was effectively
the same as aoi.bounds anyway. The "tighter crop" optimization gave
zero practical benefit but introduced a bug surface where pixel-edge
snapping or projection round-trip quirks could produce a degenerate
window on the FCF raster.

Drop the if-ref branch, always use aoi.bounds + 0.05 deg halo.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

1 participant