Add coho habitat pipeline with DB-side classification#56
Merged
NewGraphEnvironment merged 11 commits intomainfrom Mar 19, 2026
Merged
Add coho habitat pipeline with DB-side classification#56NewGraphEnvironment merged 11 commits intomainfrom
NewGraphEnvironment merged 11 commits intomainfrom
Conversation
Bundled CSV from GeoBC Freshwater Atlas User Guide (2009) Table 2 — 41 edge type codes with descriptions and category groupings. Exported helper frs_edge_types(category = "lake") for filtering. Categories: stream, lake, wetland, river, construction, connector, subsurface, canal, island, coastline, boundary, unknown. Also adds feature_codes.csv from Table 3 (feature code attributes). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Scopes which rows get classified via SQL predicate. Works with ranges, breaks, and overrides modes. Enables lake-specific rearing classification via waterbody_key filtering and edge_type-aware habitat modelling. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Joins columns from any lookup table onto a working table via SQL UPDATE FROM. Detects source column types from information_schema (handles search_path for unqualified table names). Supports direct keys, composite keys, named key mapping, and subqueries. Used for channel_width, MAD, upstream_area, MAP — any FWA lookup or custom model output. Fixes #51 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…1410) edge_type 1410 (network connector) is real wetland connectivity (204K segments in wetlands). Only 1425 (subsurface flow, 343 segments) should be excluded from snap candidates by default. Adds exclude_edge_types param to frs_point_snap() — default 1425, NULL to snap to everything. Fixes #52 Relates to NewGraphEnvironment/bcfishpass#8 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When to is provided, writes results to working table(s) via CREATE TABLE AS instead of returning sf. Multi-table uses prefix + suffix naming. Returns conn invisibly for pipe chaining. Keeps data on PostgreSQL — no R memory bottleneck at scale. Relates to #53 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
where filters rows from points_table (e.g. barrier_ind = TRUE). append = TRUE inserts into existing breaks table instead of creating — enables combining gradient barriers + falls in one breaks table. Adds points_where param to frs_break() convenience wrapper. Relates to #38 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
parameters_habitat_thresholds.csv — bcfishpass defaults from smnorris/bcfishpass/parameters/example_newgraph (11 species). parameters_habitat_method.csv — MAD vs channel_width control per watershed group (187 WSGs). parameters_fresh.csv — fresh-specific: access gradient thresholds (from bcfishpass model_access_*.sql) and spawn/rear gradient mins. data-raw/bcfishpass_params.R fetches upstream defaults from GitHub. Fixes #54 Relates to #55 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
data-raw/example_byman_ailport.R uses frs_network(to=) + frs_col_join() pipeline. byman_ailport.rds now includes channel_width and channel_width_source on streams. byman_ailport_habitat.rds caches the full habitat pipeline results for the vignette. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Full pipeline on Byman-Ailport subbasin: extract → col_join → col_generate → break (access gradient + barrier falls) → classify (accessible, spawning, rearing, lake rearing) → aggregate at crossings. Scenario comparison at 0%, 0.5%, 1.0% minimum spawn gradient. Lake rearing gap vs bcfishpass. All computation on PostgreSQL. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
dev/rag_build.R builds local ragnar DuckDB store from FWA User Guide PDF (171 chunks, gitignored at data/rag/). Planning files updated to reflect habitat pipeline progress. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…gnore - Qualify read.csv as utils::read.csv in frs_edge_types() - Document points_where param in frs_break() roxygen - Add data/rag and figure to .Rbuildignore R CMD check: 0 errors, 0 warnings, 1 note (.lintr hidden file) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This was referenced Apr 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Habitat model pipeline — extract, enrich, break, classify, aggregate — all on PostgreSQL. Proves the workflow on the Byman-Ailport subbasin before scaling to full Neexdzii study area.
New functions
frs_edge_types()— FWA edge type lookup from bundled CSV (41 codes from GeoBC User Guide)frs_col_join()— generic lookup table enrichment (channel_width, MAD, upstream_area, any key)Enhanced functions
frs_classify(where=)— scope classification by SQL predicate (edge_type, waterbody_key, accessible)frs_network(to=)— write results to DB working tables instead of pulling to R memoryfrs_break_find(where=, append=)— filter points_table rows, combine multiple break sourcesfrs_point_snap(exclude_edge_types=)— configurable snap guard (only exclude subsurface 1425, not wetland connectors 1410)Bundled data
parameters_habitat_thresholds.csv— bcfishpass defaults (11 species)parameters_habitat_method.csv— MAD vs channel_width per watershed groupparameters_fresh.csv— access gradients + spawn gradient minsedge_types.csv+feature_codes.csv— FWA reference tablesVignette: Classifying Coho Habitat on the Byman-Ailport Subbasin
Issues
Test plan
devtools::test())devtools::check()— 0 errors, 0 warningsRelates to NewGraphEnvironment/sred-2025-2026#16