Skip to content

Phase 2: enrich streams with mad_m3s and add mad predicate to rule evaluator #114

@NewGraphEnvironment

Description

@NewGraphEnvironment

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:

- mad: [0.164, 9999]

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions