Skip to content

Two bcfishpass-parity fixes: cluster phase-1 + trace_downstream#188

Merged
NewGraphEnvironment merged 1 commit intomainfrom
fix-cluster-trace-bcfp-parity
Apr 30, 2026
Merged

Two bcfishpass-parity fixes: cluster phase-1 + trace_downstream#188
NewGraphEnvironment merged 1 commit intomainfrom
fix-cluster-trace-bcfp-parity

Conversation

@NewGraphEnvironment
Copy link
Copy Markdown
Owner

Summary

Two bcfishpass-parity fixes surfaced during link's WSG-coverage expansion (link's MORR + KISP runs, 2026-04-30).

Fixes #186frs_cluster phase-1 + confluence-boost over-credits clusters

.frs_cluster_both previously excluded on-spawning rearing segments from the clustering CTE. Removing those segments could shift cluster_minimums into the confluence-boost zone (DRM < confluence_m) and validate clusters that bridge_gradient should deny. bcfishpass keeps on-spawning segments in clusters so its cluster_min stays high and the confluence boost doesn't fire.

Phase-1 protection now lives only in the final UPDATE step. Cluster boundaries used for phase-2 / phase-3 testing are unchanged.

Reproduction: link's MORR ST cluster 502 (Nado Creek + tributary 360704379, 12.58% gradient between trib confluence and downstream spawning). bcfp denies the trib; fresh now matches.

Fixes #187.frs_trace_downstream FWA-averaged gradient hides barriers

.frs_trace_downstream previously used whse_basemapping.fwa_downstreamtrace, an iterator returning FWA-original linear_feature_id rows with feature-averaged gradients. Localized barriers on a sub-piece of a long FWA feature (e.g. a 7 m, 84% lake-outlet drop inside an otherwise flat 3 km feature) are invisible to that approach.

Switched to a FWA_Downstream predicate join against the broken streams table arg — same pattern .frs_cluster_both phase-3 already uses. New required columns in origins_sql: wscode_ltree, localcode_ltree (.frs_connected_waterbody is the only caller; updated).

Reproduction: link's KISP SK at Kitwancool Lake (waterbody_key 329229702, 780.6 ha). bcfp's model/02_habitat_linear/sql/load_habitat_linear_sk.sql correctly stops at the lake-outlet drop; fresh now matches.

Test plan

  • devtools::test() — 837 PASS, 1 FAIL pre-existing on test-frs_params.R:92 (unrelated to these changes)
  • Reproduce both bugs on link's compare driver pre-fix (KISP SK +42.3%, MORR ST -5.6%)
  • Reproduce post-fix: KISP SK collapsed to 0.0% exact match, MORR ST -6.1% (correct direction — over-credit removed; remaining gap is a separate under-credit issue)
  • Bump fresh dep in link, rerun full 10-WSG tar_make() for parity rollup

SRED ref

Relates to NewGraphEnvironment/sred-2025-2026#24

🤖 Generated with Claude Code

Fixes #186 — frs_cluster phase-1 + confluence-boost over-credits
clusters

  .frs_cluster_both previously excluded on-spawning rearing segments
  from the clustering CTE. Removing those segments could shift
  cluster_minimums into the confluence-boost zone (DRM less than
  confluence_m) and validate clusters that bridge_gradient should deny.
  bcfishpass keeps on-spawning segments in clusters so its cluster_min
  stays high and the confluence boost does not fire.

  Phase-1 protection now lives only in the final UPDATE: on-spawning
  segments retain label_cluster TRUE regardless of cluster outcome,
  but cluster boundaries used for phase-2 / phase-3 testing are
  unchanged. Reproduction case: link MORR ST cluster 502 (Nado Creek
  + tributary 360704379, 12.58 percent gradient between trib confluence
  and downstream spawning) — bcfp denies the trib; fresh now matches.

Fixes #187 — frs_trace_downstream FWA-averaged gradient hides barriers

  .frs_trace_downstream previously used whse_basemapping.fwa_downstreamtrace
  which iterates FWA-original linear_feature_id rows with feature-averaged
  gradients. Localized barriers on a sub-piece of a long FWA feature
  (e.g. a 7 m, 84 percent lake-outlet drop inside an otherwise flat 3 km
  feature) are invisible to that approach.

  Switched to a FWA_Downstream predicate join against the broken streams
  table arg — same pattern .frs_cluster_both phase-3 already uses.
  Localized gradients produced by frs_network_segment are now visible
  to the trace. New required columns in origins_sql: wscode_ltree,
  localcode_ltree (.frs_connected_waterbody is the only caller; updated).

  Reproduction case: link KISP SK at Kitwancool Lake (waterbody_key
  329229702, area 780.6 ha). bcfp s load_habitat_linear_sk correctly
  stops at the lake-outlet drop; fresh now matches. Verified end-to-end:
  KISP SK spawning rollup pre-fix +42.3 percent, post-fix 0.0 percent
  exact match.

Pre-existing test failure on test-frs_params.R:92 is unrelated to these
changes (was failing on main before this branch).

Version bump 0.24.1 -> 0.25.0.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@NewGraphEnvironment NewGraphEnvironment merged commit ec0c770 into main Apr 30, 2026
1 check passed
@NewGraphEnvironment NewGraphEnvironment deleted the fix-cluster-trace-bcfp-parity branch April 30, 2026 15:21
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.

frs_trace_downstream: FWA-averaged gradient hides localized barriers frs_cluster: phase-1 exclusion + confluence-boost over-credits clusters

1 participant