Skip to content

frs_wsg_drainage: FWA WSG drainage-closure primitive #211

@NewGraphEnvironment

Description

@NewGraphEnvironment

Problem

link currently computes WSG drainage closure (every WSG a focal set drains through, downstream-first) inline in data-raw/study_area_wsgs.R — see NewGraphEnvironment/link@v0.40.5. The query reads public.wsg_outlet, joins focal → closure via f.outlet <@ w.outlet, sorts by nlevel(outlet) ASC.

This is FWA-topology — it belongs in fresh, not link. No bundle/species/overrides knowledge involved; pure network shape.

Proposed

frs_wsg_drainage(conn, wsgs)
  • wsgs: character vector of WSG codes (the focal set)
  • Returns: character vector covering the drainage closure (focal + every WSG they flow through), ordered downstream-first (nlevel(outlet) ASC)
  • Pure FWA topology — no bundle / species / overrides logic

Where it lives

R/frs_wsg_drainage.R. Sits alongside frs_wsg_species() as part of a frs_wsg_* family — the WSG-topology surface of fresh.

Why fresh, not link

wsg_outlet is FWA infrastructure. Drainage closure is a network-shape question with no link/bundle knowledge. Other fresh consumers (vignettes, ad-hoc analyses, future provincial drivers in other packages) want this without going through link.

Acceptance

  • frs_wsg_drainage(conn, c("PARS","BULK")) returns the 15-WSG Skeena+Peace closure: KISP, KLUM, LKEL, LSKE, MSKE, USKE, BULK, FINA, LBTN, LPCE, MORR, PARA, PCEA, UPCE, PARS — matches NewGraphEnvironment/link@v0.40.5 study_area_wsgs.R output
  • DS-first ordering preserved
  • Closure invariant to focal ordering
  • Runnable @example
  • Test against a small live focal set

Replaces

Inline closure query in NewGraphEnvironment/link@v0.40.5 data-raw/study_area_wsgs.R (lines computing wsg_outlet-based closure).

Composes with

link::lnk_wsg_resolve (NewGraphEnvironment/link#207) — the link wrapper adds the bundle's species-presence filter.

Naming considered

frs_wsg_drainage (chosen) is frs_wsg_*-family consistent. wsg is FWA-specific terminology — honest to fresh's current FWA-only scope. If fresh ever grows a second network (NHD/HUC), a network = "fwa" param can be introduced then (YAGNI today).

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