Dedup NWIS site time-series features by location - #115
Merged
Conversation
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>
|
Your pull request is automatically being deployed to Dagster Cloud.
|
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.
Problem
nm_waterlevels_timeserieshad exact-duplicate observations. WellUSGS-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-metadataendpoint 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 samemonitoring_location_idand identical geometry/metadata.NWISSiteSource.get_recordsreturned all 5 → 5SiteRecords with the same id →read_timeseriesiterated 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_idinNWISSiteSource.get_records, keeping the first. Readings come only from thefield-measurementscollection 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