Repository navigation
fix: GridMET basin-mean on border boxes (NaN retry loop) and missing leap-year 31 Dec - #18
Merged
Merged
Conversation
… years pygridmet treats any NaN as a corrupt download (retries 15x, then "did NOT process your request"); cells outside CONUS are always NaN, so border/coastal boxes such as Fish River could never succeed (~270 requests per failing call). It also never requests 31 Dec of leap years, which the server holds. GridMET is now fetched by a direct NCSS client (sources/_gridmet_ncss.py): no-data cells are counted and disclosed, not retried; basin mean keeps the cell-centre-in-polygon unweighted rule and records it; a non-NetCDF response fails fast (GRIDMET_REQUEST_REJECTED) with a bounded split; retries bounded; all calendar days requested, an absent day is counted and never filled. Cache revision for precipitation/tmax/tmin/pet 2 -> 3. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The NCSS client does not use pygridmet; CI installs without it, so the require_import in the backend failed 20+ tests. Tests now also pass with pygridmet blocked. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…t needs; add probe evidence The NCSS client opened responses with xarray's scipy engine and clipped with rioxarray; neither is installed by the CI extras (nor by the hyriver extra). Now: netCDF4 engine (declared in hyriver and dev), shapely cell-centre mask, structured HYRIVER_NOT_INSTALLED on a missing module, is_available() checks requests/xarray/netCDF4, pygridmet removed from the hyriver extra. Also: default 1 s throttle, stale pygridmet cache comments/log wording, basin-mean note on cells beyond the grid, cache-bump scope in CHANGELOG, and the live-probe artifact under docs/vision-2040/evidence/. Verified in a clean venv with exactly CI's extras (.[dev,viz,gee,opendap,legacy-usgs]). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…allback; keep a raw WY2000 response The mask is shapely.contains_xy (strict interior), not bit-identical to the old GDAL-scanline rio.clip: a centre exactly on the boundary is excluded (about one cell per boundary-aligned edge). A polygon with no cell centre now falls back to the cells it touches (the old code returned an empty grid). Adds the raw Fish River WY2000 NCSS response to the evidence folder so 313/315 re-derives offline. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
galib9690
added a commit
that referenced
this pull request
Nov 10, 2026
… evidence folders (#19) *.nc is gitignored, so the five raw responses cited by the gridmet-ncss-probe-2026-11-10 README were dropped from #18. Add them, and a gitignore negation for docs/vision-2040/evidence/**/*.nc so future evidence is not silently dropped. Co-authored-by: Mohammad Galib <mgalib@purdue.edu> Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Merged
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
Fixes the two GridMET defects from the DEMO-1 rehearsal (finding F1). The root cause differs from the rehearsal's reading.
Root cause
thredds.northwestknowledge.netshow the server returns a valid NetCDF file (HTTP 200, ~4 KB) for the whole 0.893 x 0.632 deg Fish River box. The failure is inpygridmet 0.19.4: it treats any NaN in a downloaded file as a corrupt download, deletes it, re-downloads 15 times, then raises "GridMET did NOT process your request successfully" (that string is pygridmet's, not an NCSS error body). GridMET has no data outside CONUS, so a box that reaches Canada or the sea always holds NaN cells and can never succeed. The rehearsal's 0.15 deg box held no such cell (0 of 20 cells NaN); its 0.18 deg box held one (1 of 30). With ourcall_with_retry+ chunk-retry layers, one failing call cost about 270 requests.dates_tolistdrops 31 Dec of leap years (its docstring is copied from pydaymet, whose calendar has 365 days). GridMET holds the day: 2000-12-31 returned real values (live). Every fetch was one day short per leap year (1460 of 1461 for WY2000-2003).Fix (pygridmet not forked)
aihydro_data/sources/_gridmet_ncss.py: direct THREDDS NCSS client, one request per calendar-year chunk.hyriver.pyuses it through a_gridmet_client()seam; thehyriverextra still installs pygridmet (Daymet path unchanged).FetchResult.upstream["gridmet_ncss"]["basin_mean"](method=cell_centre_in_polygon_unweighted_mean,cells_in_geometry,cells_with_data,cells_without_data,all_touched_fallback), with request URLs and response SHA-256s. A border basin is averaged over its US cells only and says so (Fish River: 313 of 315).GridmetRequestRejected(GRIDMET_REQUEST_REJECTED, anAihydroDataError) at once with the body excerpt; never retried; aborts the whole fetch (no 40 failing yearly calls) so the router can fall through. Before giving up the box is split in two (<= 4 levels, <= 48 requests per call, mosaic checked for gaps) in case a size limit exists. No limit was observed, so this path is exercised against a synthetic server only.skips_leap_dec31is now Daymet-only. A day the server does not return is counted inmissing_ranges/days_missing_internal, flipscoverage_complete, and is never filled._VARIABLE_CACHE_REVISIONprecipitation/tmax/tmin/pet 2 -> 3 (old entries are one day short per leap year and are refetched).Tests
Offline suite (
HOME/AIHYDRO_HOMEin scratch,PYTHONPATH= worktree, imports verified from the worktree):912 passed, 56 deselected.New
tests/test_gridmet_ncss.py(28): synthetic NCSS server returning real NetCDF bytes; error-body-with-HTTP-200 fixture (1 request, with retries on and off); size-limited server (split + mosaic equals whole box); budget and depth bounds; 5xx bounds; partial-NaN re-request; cell-centre masking vs an independent reference; unweighted-not-area-weighted; WY2000 = 366 days, WY2000-2003 = 1461 days; server lacking 31 Dec is counted and not filled; pipelinefetch()surfaces method and upstream.tests/test_gridmet_daily_validation.pymoved to the new seam and leap semantics.Live check (approved host only, throttled 1.5 s, 10 requests of the 50 allowed)
/private/tmp/claude-501/-Users-mgalib-Documents-AI-Hydro/c31e1c57-abc3-4322-9112-432e4aca4c98/scratchpad/gridmet/live/(requests.jsonl,live_result.json).Docs
CHANGELOG (Unreleased), ARCHITECTURE ("GridMET transport"), DECISIONS entry.
Risks / open
MCP/aihydro-dataworking tree untouched (worktree created from its git dir).🤖 Generated with Claude Code