Skip to content

Dedup NWIS site time-series features by location - #115

Merged
jirhiker merged 1 commit into
mainfrom
fix-nwis-duplicate-timeseries
Jul 9, 2026
Merged

Dedup NWIS site time-series features by location#115
jirhiker merged 1 commit into
mainfrom
fix-nwis-duplicate-timeseries

Conversation

@jirhiker

@jirhiker jirhiker commented Jul 9, 2026

Copy link
Copy Markdown
Member

Problem

nm_waterlevels_timeseries had exact-duplicate observations. Well USGS-344431106393403 (06N.03E.18.442B TOME SITE): 166 real quarterly readings, but ~840 rows returned (~5×, same datetime + value + everything).

Root cause

Source is NWIS. The combined-metadata endpoint returns one feature per time series, not per well. TOME has 5 series for parameter 72019 (Field measurements, Continuous, Daily Mean/Max/Min) → 5 identical site features with the same monitoring_location_id and identical geometry/metadata.

NWISSiteSource.get_records returned all 5 → 5 SiteRecords with the same id → read_timeseries iterated each and re-emitted that well's field-measurement readings once per series → 5×169 ≈ 840 dup rows downstream.

Verified live against the USGS API: 448 NM groundwater locations are duplicated this way (some up to 6×). Confirmed NWIS field-measurements (169 distinct, no dup), NMBGMR, and WQP fetches are all clean — the duplication is purely the site list.

Fix

Dedup site features by monitoring_location_id in NWISSiteSource.get_records, keeping the first. Readings come only from the field-measurements collection regardless of which series listed the well, so dropping the extra metadata rows is safe. Warns with the drop count.

Fixes every affected NM well, not just TOME.

Test

Added test_nwis_site_source_dedups_duplicate_timeseries_features (mocks the requester, no live API) — passes.

🤖 Generated with Claude Code

NWIS combined-metadata returns one feature per time series, so a well
with multiple series (field measurements + daily mean/max/min) appears
several times with the same monitoring_location_id and identical site
metadata. read_timeseries then iterates each duplicate site and re-emits
that well's field-measurement readings once per series, producing
exact-duplicate observations downstream (e.g. USGS-344431106393403
returned ~840 rows for 166 real readings). 448 NM locations were affected.

Dedup site features by monitoring_location_id in NWISSiteSource.get_records,
keeping the first. Readings come only from the field-measurements
collection regardless of series, so dropping the extra metadata rows is
safe.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@jirhiker
jirhiker merged commit 44ce3c8 into main Jul 9, 2026
2 checks passed
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown

Your pull request is automatically being deployed to Dagster Cloud.

Location Status Link Updated
die-orchestration View in Cloud Jul 09, 2026 at 04:48 AM (UTC)

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