feat: HarP-derived lake classification corrections (7,425 reaches) - #204
Conversation
Apply lakeflag corrections for 7,425 reaches using HarP v1.1 (Sikder et al. 2024) Intersected SWORD-PLD dataset. HarP identifies reaches geometrically related to PLD lake polygons that SWORD v16/v17 classified as river (lakeflag=0). Correction tiers: - T1 (In-lake): 3,335 reaches inside PLD lake polygons - T2 (Through-lake): 397 reaches where lake runs through entirely - T3 (Inflow/Outflow): 3,693 reaches serving as both inlet and outlet Excluded: type=4 (dam), type=5 (unreliable), type=6 (ghost). Only type=1 (river) and type=3 (lake_on_river) reaches corrected. Pipeline: HarP v16 IDs -> UNC v16-to-v17b translation -> v17c join. 200,201 nodes propagated. Tagged edit_flag='harp_lake'.
The load script was deleting sword_operations before sword_value_snapshots, violating the foreign key constraint and aborting the entire transaction for all remaining tables and regions. Now truncation runs in reverse table-list order (children before parents) while insertion keeps forward order.
PR Review: Harp Lake Corrections & FK Load FixSummaryThe PR introduces a new script for applying lake corrections from the HarP dataset and fixes a foreign key dependency issue in the DuckDB-to-PostgreSQL loader. While the architectural approach is sound and follows established patterns (RTREE index handling, provenance tagging), there is a critical runtime error in the new script and a major resilience issue regarding spatial index restoration. Finding 1: Critical Runtime Error in (P1)In the function, the code attempts to fetch a result from an [�[90m20:43:53�[39m] using file �[32m~/Users/jakegearon/.npm-global/lib/node_modules/update/lib/updatefile.js�[39m Current updaters: �[36minit�[39m no updaters were saved. nodes_updated = conn.execute("""UPDATE nodes ...""").fetchone()[0]Issue: DuckDB's Finding 2: Missing for RTREE Index Restoration (P2)The script correctly identifies and drops RTREE indexes before performing updates to avoid DuckDB segfaults. However, it lacks error handling around the update logic. Finding 3: Inconsistent Reach Type Skip Logic (P3)The Finding 4: FK Delete Ordering in (P3)Observation: The change to reverse the order of truncation/deletion in Finding 5: Potential Duplication (P4)Issue: The RecommendationFix the P1 and P2 issues before merging to avoid database corruption or runtime crashes. The FK ordering fix in |
PR Review: Harp Lake Corrections & FK Load FixSummaryThe PR introduces a new script for applying lake corrections from the HarP dataset and fixes a foreign key dependency issue in the DuckDB-to-PostgreSQL loader. While the architectural approach is sound and follows established patterns (RTREE index handling, provenance tagging), there is a critical runtime error in the new script and a major resilience issue regarding spatial index restoration. Finding 1: Critical Runtime Error in
|
- Wrap UPDATE operations in try/finally to ensure RTREE indexes are always recreated even if an UPDATE fails (P2) - Remove unused imports (json, os, datetime, timezone) - Fix ruff lint: ambiguous variable name, f-strings without placeholders
Review responseGemini review produced 1 P1, 1 P2, 2 P3, 1 P4. Fixed
Dismissed
Quality pipeline
|
Summary
scripts/maintenance/apply_harp_lake_corrections.pyto correct lakeflag using HarP v1.1 (Sikder et al. 2024)edit_flag='harp_lake'load_from_duckdb.py(delete child tables before parents)Data sources
Correction tiers
Exclusions
Validation
lake_sandwichcorrections confirmed by HarP (independent agreement)Flow verification rerun
Ran flow verification on all 6 regions after lakeflag corrections:
1 OC section (section 149: reaches 51180200781, 51180200101) approved and applied:
multi_signal_agreement)f8c9b69f00e9, backup:reach_topology_backup_OC_f8c9b69f00e9Exports synced
Test plan
harp_lake