Skip to content

Add waterlevel-trends data product (one feature per well)#84

Merged
jirhiker merged 3 commits into
mainfrom
feature/waterlevel-trends-product
Jun 26, 2026
Merged

Add waterlevel-trends data product (one feature per well)#84
jirhiker merged 3 commits into
mainfrom
feature/waterlevel-trends-product

Conversation

@jirhiker

Copy link
Copy Markdown
Member

What

New ogc_waterlevel_trend product — nm_waterlevel_trends. One GeoJSON feature per well carrying a depth-to-water trend computed from that well's water-level timeseries, across all NM sources. The collection includes a trend_method description of how the trend was calculated.

Algorithm (ported from Ocotillo)

Replicates the Ocotillo API ogc_depth_to_water_trend_wells materialized view (OcotilloAPI alembic migration):

  • least-squares slope (PostgreSQL REGR_SLOPE equivalent) of depth-to-water (ft) vs observation time, scaled to ft/year (×31,557,600 s/yr, a 365.25-day year);
  • classify only when a well has ≥10 measurements, or ≥4 measurements spanning ≥2 years; then slope > 0.25 ft/yrincreasing (water level deeper / declining table), < -0.25decreasing, else stable; otherwise not enough data.

DIE water-level values are already depth-to-water below ground surface (feet), so no measuring-point adjustment is applied (Ocotillo subtracts measuring_point_height from its raw values).

Per-feature properties

record_count, first_observation_datetime, last_observation_datetime, span_years, slope_ft_per_year, trend_category, well_depth(+units), geometry. Collection-level trend_method documents the method.

Changes

  • backend/persisters/ogc_features.py: dump_waterlevel_trend_collection + _regr_slope / _classify_trend / _parse_epoch_seconds and the ported thresholds + TREND_METHOD_DESCRIPTION.
  • orchestration/assets/products.py: combine asset dumps the trend collection for ogc_waterlevel_trend (per-well timeseries, index-aligned with sites).
  • orchestration/definitions.py: register the output type (auto-gets a job + schedule).
  • orchestration/config/products.yaml: nm_waterlevel_trends (all NM sources, daily 12:00).
  • tests/test_persisters/test_ogc_features.py: trend classification (increasing / stable / decreasing / not-enough-data) + required-field coverage.

Verification

  • Defs load; product expands to 9 water-level source assets → combine → geoserver, plus nm_waterlevel_trends_job.
  • 13 persister tests pass (4 new trend cases).

🤖 Generated with Claude Code

New ogc_waterlevel_trend product: nm_waterlevel_trends. One GeoJSON
feature per well with a depth-to-water trend computed from the well's
water-level timeseries, across all NM sources.

Algorithm ported from the Ocotillo API ogc_depth_to_water_trend_wells
materialized view:
- least-squares slope (REGR_SLOPE) of depth-to-water (ft) vs observation
  time, scaled to ft/year (365.25-day year);
- classify only with >=10 records, or >=4 records spanning >=2 years;
  slope > 0.25 ft/yr "increasing" (deeper/declining), < -0.25
  "decreasing", else "stable"; otherwise "not enough data".

The product includes a trend_method description of how the trend was
calculated (TREND_METHOD_DESCRIPTION).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown

Your pull request is automatically being deployed to Dagster Cloud.

Location Status Link Updated
die-orchestration View in Cloud Jun 26, 2026 at 05:36 PM (UTC)

jirhiker and others added 2 commits June 26, 2026 11:31
Replace the OLS slope/threshold classification with the non-parametric
Mann-Kendall trend test (pymannkendall.original_test, alpha=0.05) for
direction/significance, and the Theil-Sen slope (scipy, time-aware) for
the ft/year rate. More robust to outliers and irregular sampling than
ordinary least squares.

- trend_category: significant increasing/decreasing, else 'stable';
  'not enough data' below the record/span gate (unchanged gate).
- new per-feature mk_p_value and mk_tau properties.
- add pymannkendall dependency (pulls scipy); serverless gets it via the
  root pyproject backend deps.
- updated TREND_METHOD_DESCRIPTION.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The four dump_* functions each repeated the FeatureCollection envelope +
file write, the coords/geometry build, the feature-id rule, and ISO-UTC
formatting. Extract:

- _dump_collection(path, id, features, meta, extra) — envelope + write,
  with extra for collection-level keys (trend_method).
- _point_geometry(lat, lon, elev) — Point geometry.
- _feature_id(source, rid) — "source:id" rule.
- _iso_utc(epoch) — shared ISO-8601 UTC formatting.

Behavior-identical (-58 lines); all 13 persister tests pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@jirhiker jirhiker merged commit 6eba025 into main Jun 26, 2026
3 checks passed
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