Problem
Habitat eligibility rules (#113 Phase 1) handle edge_type, waterbody_type, gradient, and channel_width predicates. They cannot evaluate mad (mean annual discharge) predicates because the segmented streams table produced by frs_network_segment() (fresh 0.11.0) does not carry a mad_m3s column.
bcfishpass v0.5.0 uses MAD-based habitat classification for many southern BC watershed groups (BULK, LDEN, etc.) — the parameters_habitat_method table sets model = 'mad' for those groups. Per-species MAD thresholds in parameters_habitat_thresholds.csv (e.g. CO spawn_mad_min = 0.164, rear_mad_min = 0.03, rear_mad_max = 40) are required to match those WSGs.
For ADMS the model is cw (channel width) so MAD doesn't apply. Phase 2 unblocks the rest of the province.
Proposed Solution: Phase 2 of #113
1. Enrich segmented streams with mad_m3s
R/frs_network_segment.R already calls frs_col_join to add channel_width from whse_basemapping.fwa_stream_networks_channel_width joined on linear_feature_id. Add a parallel call:
frs_col_join(conn, to,
from = "fwa_stream_networks_discharge",
cols = c("mad_m3s"),
by = "linear_feature_id")
Verify the source table exists in fwapg (whse_basemapping.fwa_stream_networks_discharge or similar).
2. Add mad predicate to the rule evaluator
In R/frs_habitat_classify.R, extend the rule evaluator from #113 to support:
Translates to s.mad_m3s >= 0.164 AND s.mad_m3s <= 9999.
3. Update CSV defaults if needed
The CSV-only species classification path (for species not in the rules file) currently builds spawn_cond/rear_cond from params$ranges$spawn$mad_m3s and similar. fresh 0.11.0 already parses MAD ranges in frs_params() (verified — params$CO$ranges$spawn$mad_m3s is set to c(0.164, 9999)) but frs_habitat_classify() doesn't apply them. Either:
- A: Apply MAD predicates in the CSV-only path too
- B: Require MAD-using species to be in the rules file
Option A is more transparent (CSV row "just works"). Option B is simpler implementation.
Test approach
Use a MAD-model WSG (BULK or LDEN) sub-basin. Run frs_habitat with a rules file that uses MAD predicates for CO/CH/SK/ST. Assert MAD-filtered classification matches expectations.
For ADMS (cw model) this should be a no-op — MAD predicates not used.
Dependencies
Relates to
Problem
Habitat eligibility rules (#113 Phase 1) handle edge_type, waterbody_type, gradient, and channel_width predicates. They cannot evaluate
mad(mean annual discharge) predicates because the segmented streams table produced byfrs_network_segment()(fresh 0.11.0) does not carry amad_m3scolumn.bcfishpass v0.5.0 uses MAD-based habitat classification for many southern BC watershed groups (BULK, LDEN, etc.) — the
parameters_habitat_methodtable setsmodel = 'mad'for those groups. Per-species MAD thresholds inparameters_habitat_thresholds.csv(e.g. COspawn_mad_min = 0.164,rear_mad_min = 0.03,rear_mad_max = 40) are required to match those WSGs.For ADMS the model is
cw(channel width) so MAD doesn't apply. Phase 2 unblocks the rest of the province.Proposed Solution: Phase 2 of #113
1. Enrich segmented streams with mad_m3s
R/frs_network_segment.Ralready callsfrs_col_jointo addchannel_widthfromwhse_basemapping.fwa_stream_networks_channel_widthjoined onlinear_feature_id. Add a parallel call:Verify the source table exists in fwapg (
whse_basemapping.fwa_stream_networks_dischargeor similar).2. Add
madpredicate to the rule evaluatorIn
R/frs_habitat_classify.R, extend the rule evaluator from #113 to support:Translates to
s.mad_m3s >= 0.164 AND s.mad_m3s <= 9999.3. Update CSV defaults if needed
The CSV-only species classification path (for species not in the rules file) currently builds
spawn_cond/rear_condfromparams$ranges$spawn$mad_m3sand similar. fresh 0.11.0 already parses MAD ranges infrs_params()(verified —params$CO$ranges$spawn$mad_m3sis set toc(0.164, 9999)) butfrs_habitat_classify()doesn't apply them. Either:Option A is more transparent (CSV row "just works"). Option B is simpler implementation.
Test approach
Use a MAD-model WSG (BULK or LDEN) sub-basin. Run frs_habitat with a rules file that uses MAD predicates for CO/CH/SK/ST. Assert MAD-filtered classification matches expectations.
For ADMS (cw model) this should be a no-op — MAD predicates not used.
Dependencies
whse_basemapping.fwa_stream_networks_dischargeschema in fwapgRelates to