
Build per-segment per-species mapping_code strings (bcfp parity)
Source:R/lnk_pipeline_mapping_code.R
lnk_pipeline_mapping_code.RdMirrors bcfishpass.streams_mapping_code – a per-segment per-species
semicolon-token compound describing the segment's habitat label, the
most-relevant downstream barrier source, and an intermittent flag if
applicable. Pure derivation over the bcfp-shape inputs (no SQL).
Usage
lnk_pipeline_mapping_code(
access,
habitat,
feature_code,
to = NULL,
conn = NULL,
presence = NULL,
species_resident = c("bt", "wct"),
species_anadromous = c("ch", "cm", "co", "pk", "sk", "st"),
species_spawn_only = c("cm", "pk"),
segment_id_col = "id_segment",
intermittent_feature_code = "GA24850150",
resident_species,
anadromous_species,
spawn_only_species
)Arguments
- access
A tibble or data.frame keyed by
segment_id_colwithhas_barriers_<sp>_dnstrboolean per species, plus the bcfp-shape sourceshas_barriers_anthropogenic_dnstr,has_barriers_pscis_dnstr,has_barriers_dams_dnstr, and (optional)has_remediated_dnstr. Typically the output oflnk_pipeline_access()called withbarrier_sourcespopulated.- habitat
A tibble keyed by
segment_id_colwithspawning_<sp>andrearing_<sp>numeric columns per species. Mirrors bcfp'sstreams_habitat_linearshape.- feature_code
Named character or data.frame. Either a named character vector mapping
segment_id->feature_code, or a data.frame withsegment_id_coland"feature_code"columns. Used for theINTERMITTENTflag.- to
Character or
NULL. Optional schema-qualified destination table. When supplied, the result tibble is written viadbWriteTable(overwrite = TRUE)and the tibble is also returned (so callers can chain intolnk_pipeline_persist/build_species_views.R). DefaultNULLreturns-only.- conn
A DBI::DBIConnection. Required only when
tois supplied; ignored otherwise.- species_resident
Character. Species using the resident flavor of
mapping_code_barrier. Defaultc("bt", "wct"). (Renamed fromresident_speciesin v0.40.0; old name accepted with deprecation warning until v0.41.0.)- species_anadromous
Character. Species using the anadromous flavor. Default
c("ch", "cm", "co", "pk", "sk", "st"). (Renamed fromanadromous_speciesin v0.40.0.)- species_spawn_only
Character. Species without rearing semantics (token 1 only emits SPAWN, never REAR). Default
c("cm", "pk"). Mirrors bcfp. (Renamed fromspawn_only_speciesin v0.40.0.)- segment_id_col
Character. Default
"id_segment".- intermittent_feature_code
Character. The
feature_codevalue that flags an intermittent stream. Default"GA24850150"(bcfp).- resident_species
Deprecated alias for
species_resident. Kept for one release (v0.40.0); removal in v0.41.0.- anadromous_species
Deprecated alias for
species_anadromous. Kept for one release (v0.40.0); removal in v0.41.0.- spawn_only_species
Deprecated alias for
species_spawn_only. Kept for one release (v0.40.0); removal in v0.41.0.
Value
A tibble keyed by segment_id_col with one
mapping_code_<sp> character column per species in
union(species_resident, species_anadromous).
Details
Vocabulary (per species):
{ACCESS|SPAWN|REAR|""} ; {NONE|DAM|MODELLED|ASSESSED|REMEDIATED} [;INTERMITTENT]
Token 1 (habitat) per bcfp:
ACCESS: species' barriers all upstream (i.e. accessible to species) AND segment has no spawning AND no rearing eligibility for the speciesSPAWN: spawning eligibility > 0 (always wins over REAR)REAR: rearing eligibility > 0 AND no spawning""(empty): species has at least one downstream barrier blocking it (so habitat label is suppressed – inaccessible).For species without rearing semantics (CM, PK), the rearing conditions drop out – only
ACCESS(no spawn, no barriers) andSPAWN(spawning > 0) emit.
Token 2 (barrier source) only emits when the species' barriers downstream is empty (i.e. accessible). Resident-flavor (BT, WCT) and anadromous-flavor (CH/CM/CO/PK/SK/ST) differ in their CASE order:
Resident: REMEDIATED > DAM > ASSESSED (anthropogenic + pscis + no dam) > MODELLED (anthropogenic + no pscis + no dam) > NONE (no anthropogenic).
Anadromous: REMEDIATED > DAM (any dam) > ASSESSED (any pscis) > MODELLED (any anthropogenic) > NONE.
Token 3 emits INTERMITTENT when the segment's feature_code matches
the bcfp intermittent code (default "GA24850150") AND the species'
barriers downstream is empty.
Empty / NULL tokens are dropped via paste(..., collapse = ";")-style
composition so an inaccessible segment yields "" (empty string) and
an accessible no-habitat-no-intermittent segment yields "ACCESS;NONE".