fix: node distance interpolation for flipped/single reaches - #215
Merged
Conversation
Three node-level interpolation bugs fixed: - Flow-corrected reaches (636) had inverted distances because offset used stale v17b node dist_out without reversing direction - Single-node reaches (25,732) placed node at upstream edge instead of centroid (reach_length / 2) - Node distance columns (hydro_dist_out, hydro_dist_hw, dist_out_dijkstra) missing from export spec and schema migration Also fixes flow_verification.py rebuild_derived_attrs: - Pass flipped_reach_ids to save_to_duckdb for correct node interpolation - Add missing update_node_columns call after save - Update stale docstring to match post-refactor compute order Test fixture cleanup: - Rename is_mainstem_edge -> is_mainstem in test DB - Add topology_suspect/topology_approved to reach_topology fixtures - Match test fixture column order to production schema - Add 5 interpolation regression tests (normal/flipped/single/no-neg) Standalone fix script: scripts/maintenance/fix_node_distances.py
fix_node_distances.py now imports propagate_reach_to_nodes from output.py instead of duplicating the offset/CTE SQL.
Collaborator
Author
Code Review SummaryFindings: 0 P1, 0 P2, 1 P3, 3 P4 P3 — Fixed
P4 — Informational (no action)
Verification
Fix pushed as |
v17c_flow_corrections had 31 missing flipped reach IDs (topology differs from v17b but not logged by section-level flow correction) and 7 false positives (oscillation-reverted reaches still marked as flipped). Synced table to 660 IDs and reran node propagation. Result: 0 monotonicity inversions across 11.1M nodes. Also fixed import path: project root instead of src/ to avoid relative import beyond top-level package error.
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
v17c_flow_correctionstable: add 31 missing flipped IDs, remove 7 oscillation-reverted false positives (636 → 660)hydro_dist_out,hydro_dist_hw,dist_out_dijkstra) to NetCDF export spec and schema migrationflow_verification.py::rebuild_derived_attrsmissingflipped_reach_idsandupdate_node_columnscallis_mainstem_edge, missingtopology_suspectcolumn)Validation
Export file organization
Reorganized
data/exports/into versioned directories with version-tagged filenames:Updated
/preflightskill check #9 (export version tagging) to enforce versioned directory + filename convention.Test plan