
Build per-segment access codes + downstream-feature arrays
Source:R/lnk_pipeline_access.R
lnk_pipeline_access.RdComposes fresh::frs_network_features() calls across species (and
optionally observations) to produce a streams_access wide table
that mirrors bcfishpass.streams_access's shape — one row per
segment, with per-species barriers_<sp>_dnstr arrays and per-
species integer access_<sp> codes derived via CASE on
(wsg-presence × dnstr-empty × observed-upstream).
Arguments
- conn
A DBI::DBIConnection object pointing at fwapg.
- segments
Character. Schema-qualified segments table.
- aoi
Character. Watershed group code (e.g.
"ADMS"). Filter applied to segments viawatershed_group_code = aoi.- to
Character or
NULL. Optional schema-qualified output table. When supplied, the widestreams_accessshape is written viadbWriteTable(overwrite = TRUE); in either case the tibble is returned invisibly. DefaultNULLreturns-only.- barriers_per_sp
Named list. Each name is a species code (e.g.
"bt"); each value is a schema-qualified barriers table for that species (e.g."working_adms.barriers_bt"). Each barriers table must have a<sp>_idcolumn (e.g.barriers_bt_id) plus the standard(blue_line_key, downstream_route_measure, wscode_ltree, localcode_ltree)keys.- observations
Character or
NULL. Optional schema-qualified observations table with(observation_key, species_code, ...)+ the standard FWA keys. When provided, drives the access code distinction between1(modelled) and2(observed). DefaultNULLcollapses observation-distinguishing logic — every accessible segment getsaccess_<sp> = 1.- wsg_presence
Named logical. One per species (matching
barriers_per_spkeys),TRUEwhen the species is present inaoi. Setsaccess_<sp> = -9for species markedFALSE. Default empty list assumes all species present (no -9 codes emitted).- barrier_sources
Named list. Each name is an arbitrary source tag (e.g.
"anthropogenic","pscis","dams","remediations"); each value is a schema-qualified barriers table for that source. Output gains onehas_barriers_<source>_dnstrboolean column per source. Unlikebarriers_per_sp, sources here don't drive the species access integer code – they're the bcfp-shape dnstr indicators consumed bylnk_pipeline_mapping_code(). Optional; default empty.When both
"anthropogenic"and"dams"are present, the output gains adam_dnstr_indboolean column: TRUE iff the next- downstream anthropogenic barrier is also a dam (sequence-aware, mirrors bcfp'sarray[barriers_anthropogenic_dnstr[1]] && barriers_dams_dnstrSQL). Required for resident-flavormapping_code_bt/mapping_code_wctparity with bcfp.When
"remediations"is present ANDcrossings_tableis set, the output gains aremediated_dnstr_indboolean column.- crossings_table
Character or
NULL. Schema-qualified crossings table withaggregated_crossings_idandpscis_statuscolumns (e.g."bcfishpass.crossings"). Used only to computeremediated_dnstr_ind(TRUE iff the next-downstream remediation is a crossing whosepscis_status IN ('REMEDIATED', 'PASSABLE')).bcfp's own
streams_access.remediated_dnstr_indis currently buggy (see smnorris/bcfishpass#690): the JOIN clausepscis_status = 'REMEDIATED' AND pscis_status = 'PASSABLE'is contradictory and always FALSE – verified against 4.2M rows. link computes the bcfp-intendedINsemantics, so link's mapping_code may emitREMEDIATEDtokens on segments where bcfp's current output emitsDAM/MODELLED/ASSESSED. PR filed against theNewGraphEnvironment/bcfishpassfork; once it lands + propagates upstream the outputs converge. DefaultNULLskips theremediated_dnstr_indcolumn.- segment_id_col
Character. Default
"id_segment".
Details
This phase runs after lnk_pipeline_classify() returns and before
lnk_pipeline_persist() cleanup_working drops the working schema —
it needs the per-species barriers_<sp> tables that prepare/break
built. Output goes to <schema>.streams_access (working schema,
picked up by persist on the next commit).
Access integer codes per species (mirroring bcfp):
-9 = species not present in WSG (per wsg_presence)
0 = barriers downstream (blocked)
1 = no barriers downstream + species not observed upstream
(modelled accessible)
2 = no barriers downstream + species observed upstream