
Prepare the Network and Barrier Inputs for a Pipeline Run
Source:R/lnk_pipeline_prepare.R
lnk_pipeline_prepare.RdThird phase of the habitat classification pipeline. Loads the
evidence and network data that downstream phases (break,
classify, connect) consume:
Usage
lnk_pipeline_prepare(
conn,
aoi,
cfg,
loaded,
schema,
observations = "bcfishobs.observations",
conn_tunnel = NULL,
classes = NULL
)Arguments
- conn
A DBI::DBIConnection object.
- aoi
Character. Watershed group code today; extends to ltree filters / sf polygons later (same AOI abstraction fresh uses).
- cfg
An
lnk_configobject fromlnk_config().- loaded
Named list of tibbles from
lnk_load_overrides(). Carriesuser_barriers_definite,user_barriers_definite_control,user_habitat_classification, andparameters_fresh.- schema
Character. Working schema name (must already exist — call
lnk_pipeline_setup()first).- observations
Character. Schema-qualified observations table used for building barrier overrides. Default
"bcfishobs.observations"— matches bcfishpass's reference data on both M4 and M1 fwapg instances (seertj/docs/distributed-fwapg.md).- conn_tunnel
A DBI::DBIConnection object pointed at
db_newgraph(the tunnel-DB carrying bcfp's pre-built tables). Optional. When supplied,<schema>.damsis populated frombcfishpass.damsfiltered to the AOI — parallel reporting layer for downstream consumers, NOT consumed by habitat classification. WhenNULL, any existing<schema>.damsis dropped and the dams step is a no-op.- classes
Optional named numeric vector of gradient class thresholds passed to
fresh::frs_break_find(). Names are the integer-encoded class labels (gradient × 10000, zero-padded to width 4 — e.g."1500"for 0.15); values are the gradient fractions. WhenNULL, falls back tocfg$pipeline$gradient_classesif set in the config bundle, otherwise to the bcfishpass defaultc("1500" = 0.15, "2000" = 0.20, "2500" = 0.25, "3000" = 0.30). Per-species access barrier filters inprep_minimalare derived fromloaded$parameters_fresh$access_gradient_max: a class is a barrier for speciesswhen its value is ≥s$access_gradient_max.
Details
Falls (from the
freshpackage), user-identified definite barriers, user barriers-definite control table, and expert habitat confirmation CSVs from the config bundleGradient barriers detected on the raw FWA network via
fresh::frs_break_find(), pruned against the control table, enriched withwscode_ltreeandlocalcode_ltreeforfwa_upstream()joinsA natural-barriers table (gradient + falls) used by
lnk_barrier_overrides()to compute the per-species skip list. User-definite barriers are intentionally excluded here and consumed by later phases directly — bcfishpass parity.Per-model barrier tables reduced to the minimal downstream-most set via
fresh::frs_barriers_minimal(), then unioned intogradient_barriers_minimalfor segmentationBase stream segments (
fresh.streams) loaded from FWA with channel width, stream order parent, GENERATED gradient / measures / length columns, and a uniqueid_segment
Writes to (under the caller's working schema unless noted):
<schema>.falls,<schema>.barriers_definite,<schema>.barriers_definite_control,<schema>.user_habitat_classification<schema>.gradient_barriers_raw(with ltree)<schema>.natural_barriers(gradient + falls + opt-in subsurfaceflow)<schema>.barriers_subsurfaceflow(only when subsurfaceflow opted in viacfg$pipeline$break_order)<schema>.barrier_overrides<schema>.barriers_<model>+<schema>.barriers_<model>_minper-model pre/post minimal reduction<schema>.gradient_barriers_minimal(union of minimal positions)fresh.streams(base segments — not namespaced by AOI; fresh owns its output schema)<schema>.dams(only whenconn_tunnelis supplied) — pulled frombcfishpass.damsfiltered to AOI. Parallel reporting layer; NOT consumed by habitat classification.
Examples
if (FALSE) { # \dontrun{
conn <- lnk_db_conn()
cfg <- lnk_config("bcfishpass")
loaded <- lnk_load_overrides(cfg)
schema <- "working_bulk"
lnk_pipeline_setup(conn, schema)
lnk_pipeline_load(conn, "BULK", cfg, loaded, schema)
lnk_pipeline_prepare(conn, "BULK", cfg, loaded, schema)
# Override break vector for an experimental scenario:
lnk_pipeline_prepare(conn, "BULK", cfg, loaded, schema,
classes = c("0500" = 0.05, "1000" = 0.10, "1500" = 0.15))
DBI::dbGetQuery(conn, sprintf(
"SELECT count(*) FROM %s.gradient_barriers_minimal", schema))
DBI::dbDisconnect(conn)
} # }