Skip to content

Wire frs_order_child as link methodology (default off)#97

Merged
NewGraphEnvironment merged 3 commits intomainfrom
96-frs-order-child-wire
May 1, 2026
Merged

Wire frs_order_child as link methodology (default off)#97
NewGraphEnvironment merged 3 commits intomainfrom
96-frs-order-child-wire

Conversation

@NewGraphEnvironment
Copy link
Copy Markdown
Owner

Summary

Wires fresh::frs_order_child (fresh#158) into link's pipeline as link methodology, not bcfp parity. Captures the biology of small streams plugging directly into large rivers — fish use these reaches for rearing despite low/missing FWA channel-width estimates.

Four new per-species columns in dimensions.csv (both bundles), all opt-in via rear_stream_order_bypass: yes/no:

Column frs_order_child arg Default
rear_stream_order_parent_min parent_order_min 5
rear_stream_order_child_min child_order_min 1
rear_stream_order_child_max child_order_max 1
rear_stream_order_distance_max distance_max empty (no cap)

lnk_rules_build emits the values into a channel_width_min_bypass: block on the rear stream-edge rule. lnk_pipeline_classify reads the block and calls frs_order_child per species post-classification, gated on rear_stream_order_bypass.

Both bundles ship bypass: no for all species. The infrastructure is parametric and tested but disabled by default. Re-enable per species via dimensions.csv once a methodology decision is made (BABL inspection per fresh#158).

Verification

4-WSG regression (HARR / HORS / LFRA / BABL) byte-identical to pre-wire baseline with bypass=off — confirming the wiring is purely additive when disabled. Log: data-raw/logs/20260501_26_regress_4wsg_bypass_off_v2.txt.

Calibration runs with bypass enabled (saved as comparison snapshots in data-raw/maps/):

WSG child range dmax link rearing_stream bcfp ref diff
HORS BT 1..1 300 394 km 396 km −0.5%
HORS BT 1..5 300 404 km 396 km +1.9%
BULK BT 1..5 300 2726 km 2487 km +9.6%

These are exploration data — not the shipped defaults. Methodology decision parked pending wider sample.

Map helper improvements

data-raw/maps/_lnk_map_compare.R updated alongside:

  • Split categorical axis layer into separate link_only / bcfp_only / both toggles (plus spawning_link / spawning_bcfp)
  • Add popups to streams_all underlay (linear_feature_id | blue_line_key | DRM | edge | order | grad | gnis_name)

Test plan

  • devtools::test() — new tests for the rear_stream_order_child_min/max columns pass; pre-existing failures unchanged
  • 4-WSG regression byte-identical to pre-wire baseline (bypass=off)
  • Calibration runs documented above
  • Schema: inst/extdata/configs/dimensions_columns.csv xref updated with all four new columns + corrected rear_stream_order_bypass entry (was stale — said "currently inert")

Bumps fresh dep to >= 0.27.5 for the renamed bypass YAML schema (stream_orderstream_order_min + stream_order_max).

Related: link#23 (CH spawning misread, closed not-a-bug). fresh#158 is the canonical design doc. PWF at planning/active/.

🤖 Generated with Claude Code

NewGraphEnvironment and others added 3 commits May 1, 2026 12:49
Document the wire-up state and design decisions before parking. Anchored
on fresh#158 issue body as canonical design doc — this PWF captures
the implementation summary, HORS calibration, and methodology decision
deferred to next session.

The link wiring code itself stays uncommitted on this branch until
a methodology decision is made (ship default-on after BABL inspection,
or ship infrastructure with bypass=no defaults).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…parking bypass

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds parametric infrastructure for the rearing stream-order bypass —
small streams plugging into large rivers credited as rearing despite
low/missing FWA channel-width estimates. Closes fresh#158 on the
link side.

Four per-species columns in dimensions.csv (both bundles), all opt-in
via rear_stream_order_bypass: yes/no:

  rear_stream_order_parent_min   parent_order_min   (default 5)
  rear_stream_order_child_min    child_order_min    (default 1)
  rear_stream_order_child_max    child_order_max    (default 1)
  rear_stream_order_distance_max distance_max       (default empty)

lnk_rules_build emits the values into a channel_width_min_bypass:
block on the rear stream-edge rule. lnk_pipeline_classify reads the
block and calls fresh::frs_order_child per species post-classification,
gated on rear_stream_order_bypass.

Both bundles ship bypass: no for all species. The infrastructure is
parametric and tested but disabled by default. Re-enable per species
via dimensions.csv. The 4-WSG regression (HARR / HORS / LFRA / BABL)
is byte-identical to the pre-wire baseline with bypass=off,
confirming the wiring is purely additive when disabled.

Updates inst/extdata/configs/dimensions_columns.csv xref doc with all
four new columns and refreshes the rear_stream_order_bypass entry
(was stale — said "currently inert").

Map-helper data-raw/maps/_lnk_map_compare.R updated alongside: split
the categorical axis layer into separate link_only / bcfp_only / both
toggles (plus split spawning_link / spawning_bcfp), and add popups to
the streams_all underlay for segment-level inspection.

Bumps fresh dep to >= 0.27.5 for the renamed bypass YAML schema
(stream_order → stream_order_min + stream_order_max).

Related: link#23 (CH spawning misread, closed not-a-bug). PWF for the
wire-up at planning/active/.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@NewGraphEnvironment NewGraphEnvironment merged commit 73712ce into main May 1, 2026
1 check passed
@NewGraphEnvironment NewGraphEnvironment deleted the 96-frs-order-child-wire branch May 1, 2026 22:22
NewGraphEnvironment added a commit that referenced this pull request May 3, 2026
…le tests (#109)

* Refresh config provenance + regenerate rules.yaml + fix stale tests

Pre-trifecta homework: catch staleness in the config layer before
launching the 3-host distributed run, so we're not chasing ghosts.

Findings (from new `data-raw/audit_configs.R` + lnk_config_verify):

- Both bundles' rules.yaml diverged from `lnk_rules_build()` regen
  (committed via the v0.21-v0.25 PR series; no follow-up regen).
- `provenance:` checksums in both config.yaml were stale for 4 files
  each (rules.yaml + dimensions.csv + parameters_fresh.csv +
  overrides/wsg_species_presence.csv) reflecting the recent edits in
  #94/#96/#97/#103/#106.
- 4 stale tests in test-lnk_rules_build.R asserted on the old
  `stream_order` field name (since renamed to `stream_order_min`/
  `stream_order_max` in fresh#198) and on the bcfishpass-bundle's old
  "every species' rear stream rule has in_waterbody=false" invariant
  (CO + ST flipped to `rear_stream_in_waterbody=yes` in dimensions.csv).

Fixes:

- Regenerate both bundles' rules.yaml (only date-stamp diff vs old —
  byte-identical-after-strip, semantically identical).
- Recompute provenance: checksum + shape_checksum for the 4 drifted
  files in each bundle's config.yaml. Surgical line-replace preserves
  comments + key order.
- Update 3 test assertions: rename `stream_order` -> `stream_order_min`
  + `stream_order_max`; scope the in_waterbody check to spawn rules
  (universal in bcfishpass) instead of all stream-edge rules.
- New `data-raw/audit_configs.R` reports drift across all layers
  (provenance, rules-regen, species axis consistency, undeclared
  override files) — re-runnable before each trifecta or provincial run.
- New `data-raw/regen_provenance.R` runs the surgical fixes.

Verification:

- `lnk_config_verify` reports drifted=0/12 for both bundles.
- ADMS rollup post-regen byte-identical to cached pre-regen baseline
  (data-raw/logs/20260502_09_post_regen_adms.rds vs
  comparison_bcfishpass_ADMS in _targets/).
- `devtools::test()` 668 PASS / 0 FAIL (was 10 FAIL pre-homework).

Out of scope (filed separately or deferred):

- 3 orphan CSVs per bundle in overrides/ (`dfo_known_sockeye_lakes.csv`,
  `wcrp_watersheds.csv`, `user_modelled_crossing_fixes_20240825.csv`)
  not declared in config.yaml and not referenced by any R/test.
- Legacy top-level `parameters_habitat_*` files still consumed by
  `data-raw/run_nge.R`; migrate to per-bundle config first then remove.

Relates to NewGraphEnvironment/sred-2025-2026#24

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* compare_bcfishpass_wsg: NA semantic + species filter (link#108 evidence)

Two related changes for cleaner rollup output when running default-bundle
species (GR / KO / RB) that bcfp doesn't model.

- Reference values fall back to NA (not 0) when bcfp doesn't have a
  `habitat_linear_<sp>` table for the species. Applied to all three
  reference paths: linear km, lake_rearing_ha, wetland_rearing_ha.
  Distinguishes "real measured zero" from "not modelled by bcfp".
  diff_pct then cleanly resolves to NA for these species via the
  existing logic (NA bcfp_value → NA diff_pct).
- New `species` parameter (default NULL) filters the rollup to the
  intersection of the requested set with `lnk_pipeline_species()`.
  Pass `c("BT","CH","CM","CO","PK","SK","ST","WCT")` to drop GR/KO/RB
  entirely from the comparison table.

Verification: PARS default run (data-raw/logs/20260502_10_pars_default_grkorb.rds)
shows GR/KO/RB classified end-to-end:
- KO: spawning 3.83 km, lake_rearing 377 ha (lake-only methodology)
- RB: spawning 1,557 km, rearing 2,462 km, lake 1,839 ha, wetland 7,796 ha
- GR: spawning 984 km, rearing 1,366 km, lake 1,566 ha
All three correctly show bcfishpass_value=NA + diff_pct=NA.

Closes #108

Relates to NewGraphEnvironment/sred-2025-2026#24

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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