Refactor frs_habitat: unified pipeline + performance fixes#94
Merged
NewGraphEnvironment merged 5 commits intomainfrom Apr 7, 2026
Merged
Refactor frs_habitat: unified pipeline + performance fixes#94NewGraphEnvironment merged 5 commits intomainfrom
NewGraphEnvironment merged 5 commits intomainfrom
Conversation
Rewrites frs_habitat as a thin orchestrator that per WSG: 1. Generates gradient access barriers at species thresholds 2. Segments network via frs_network_segment (one table, shared geometry) 3. Classifies habitat via frs_habitat_classify (long format, per species) 4. Persists to to_streams + to_habitat tables Replaces to_prefix with to_streams + to_habitat params. Species-specific accessibility: CO/CH/SK at 15%, BT/RB at 25%. mirai parallel: each WSG is one task. Tested: ADMS sequential — 16,606 segments, 5 species, 183s. BT/RB: 6,338 accessible. CO/CH/SK: 3,719 accessible. Relates to #83 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Bottleneck is frs_habitat_classify — NOT EXISTS per species without threshold recycling. ADMS 781s, BULK 2,090s. Fix in #89. Relates to NewGraphEnvironment/sred-2025-2026#16 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Pre-compute accessibility ONCE per unique access threshold into temp tables, then JOIN when classifying each species. 5 species with 2 thresholds = 2 queries instead of 5. ADMS: 183s → 54s. Per-species classify: ~40s → 0.1s. Composite index on (label, blue_line_key) for breaks table. Fixes #89 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add .frs_index_working on breaks table after enrichment. Cross-BLK accessibility query drops from 17s to 1.1s with ltree GIST indexes. ADMS total: 54s → 39s. Province estimate: ~2.7 hours sequential. Relates to #89 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add watershed_group_code to habitat table. DELETE uses column filter instead of id_segment IN (subquery) — constant time regardless of table size. Benchmark: 6 WSGs (1.3M habitat rows), timing stays flat. Per-species: 0.1-1.2s at 1.3M rows (was 30-58s in province run). Province estimate: ~4 hours (was 8+). Fixes #91 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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
frs_habitat()to wrapfrs_network_segment()+frs_habitat_classify()to_streams+to_habitatparams for persistent output tablesPerformance
Province run completed: 229 WSGs, 5.98M segments, 9.1 hours (before #91 fix).
With #91 fix, 6 WSG benchmark shows flat timing at 1.3M rows — estimate ~4 hours.
Test plan
devtools::test()— 528 passFixes #89, #91
Relates to #83
Relates to NewGraphEnvironment/sred-2025-2026#16
🤖 Generated with Claude Code