
Run the link pipeline end-to-end for one watershed group
Source:R/lnk_pipeline_run.R
lnk_pipeline_run.RdModelling-only umbrella: chains the lnk_pipeline_* phases and the
persist write-out into a single call. Produces per-WSG segment data
in the persistent province-wide tables (<persist_schema>.streams,
streams_habitat_<sp> per species, barriers).
Arguments
- conn
DBI connection to the local pipeline database (typically localhost fwapg).
- aoi
Watershed group code (e.g.
"ADMS"). Validated against^[A-Z]{3,5}$.- cfg
An
lnk_configobject (fromlnk_config()).- loaded
Named list from
lnk_load_overrides().- schema
Working schema name. Default
paste0("working_", tolower(aoi)). Per-WSG staging tables live here; dropped on exit whencleanup_working = TRUE.- dams
Logical. When
TRUE(default), passconnasconn_tunneltolnk_pipeline_prepare()so the CABD dams step runs from localcabd.dams. PassFALSEto skip dams entirely.- cleanup_working
Logical. When
TRUE(default), drop the<schema>working schema at the end. PassFALSEfor interactive debug / manual inspection.- mapping_code
Logical. When
TRUE, additionally runs the tunnel-free mapping_code build phase (10b above) — produces<persist_schema>.streams_accessand<persist_schema>.streams_mapping_codefor the WSG, consumed downstream bydata-raw/build_species_views.R --bcfp(QGIS bcfp- shape symbology). DefaultFALSE. Methodology shift from pre-#187 compare_wsg: access uses link's own per-species barriers (viablocks_speciespredicate on<schema>.barriers), not bcfp's tunnel-staged tables.
Value
conn, invisibly. Side effects are the writes into
<persist_schema>.streams, streams_habitat_<sp>, and barriers.
Details
This is the modelling boundary — the link package's deliverable.
Comparison against bcfishpass (or any future reference) lives in
lnk_compare_rollup(), which reads the persisted state. The split
lets re-running the pipeline and re-running the comparison happen
independently; an orchestrator loop's resume check can probe PG
state via link:::.lnk_wsg_persisted() rather than the comparison
RDS artifact.
Phase order
lnk_pipeline_setup()— create per-WSG working schema.lnk_pipeline_load()— crossings + modelled fixes + PSCIS status.lnk_pipeline_prepare()— falls, definite + control, habitat confirms, gradient barriers, natural barriers, barrier overrides, per-model minimal reduction, base segments. Passesconnasconn_tunnelwhendams = TRUEso CABD dams flow through.lnk_pipeline_crossings()— match PSCIS to modelled crossings.lnk_pipeline_break()— observations, gradient minimal, definite, habitat endpoints, crossings — in config-defined order.lnk_pipeline_classify()— assemblestreams_breaksand runfrs_habitat_classify().lnk_pipeline_connect()— per-species cluster + connected_waterbody.lnk_pipeline_species()— resolve the active species set for this AOI (cfg$species ∩ wsg_species_presence). Empty set is an error.lnk_persist_init()— create persistent target tables if absent.lnk_barriers_unify()— unify per-source barriers into a single working-schema table (always; promotes the mapping_code-only flag inlnk_compare_wsg()to canonical PG state). 10b. Optional mapping_code phase — gated bymapping_code = TRUE. Runs between barriers_unify and persist:lnk_barriers_views()over working<schema>.barriers(tunnel- free, link-canonical per-species views),lnk_pipeline_access()(writes workingstreams_access),lnk_mapping_code()(writes workingstreams_mapping_code). Persist phase copies both to<persist_schema>. See link#187.lnk_pipeline_persist()— copy per-WSG streams + per-species habitat + barriers (+ optional streams_access + streams_mapping_code) into<persist_schema>(idempotent DELETE-WHERE-WSG + INSERT).
See also
lnk_compare_rollup(), lnk_compare_wsg(),
lnk_pipeline_setup(), lnk_pipeline_persist()
Other pipeline:
lnk_pipeline_access(),
lnk_pipeline_break(),
lnk_pipeline_classify(),
lnk_pipeline_connect(),
lnk_pipeline_crossings(),
lnk_pipeline_load(),
lnk_pipeline_mapping_code(),
lnk_pipeline_prepare(),
lnk_pipeline_setup(),
lnk_pipeline_species(),
lnk_presence()
Examples
if (FALSE) { # \dontrun{
conn <- lnk_db_conn()
cfg <- lnk_config("bcfishpass")
loaded <- lnk_load_overrides(cfg)
# Model one WSG end-to-end (~70s)
lnk_pipeline_run(conn = conn, aoi = "ADMS",
cfg = cfg, loaded = loaded)
# Verify PG state
DBI::dbGetQuery(conn,
"SELECT count(*) FROM fresh.streams WHERE watershed_group_code = 'ADMS'")
} # }