diff --git a/data-raw/example_context_fwcp_peace.R b/data-raw/example_context_fwcp_peace.R index 965d7e9..1ff00da 100644 --- a/data-raw/example_context_fwcp_peace.R +++ b/data-raw/example_context_fwcp_peace.R @@ -1,6 +1,6 @@ # Fetch spatial context layers for FWCP Peace vignette from fwapg # -# Same recipe as example_context_kotl.R but tuned for the much larger +# Same recipe as example_context_kootenay_lake.R but tuned for the much larger # Peace region: bigger lake threshold, higher minimum stream order to # keep map density reasonable, town list relevant to the Peace. # diff --git a/data-raw/example_context_kotl.R b/data-raw/example_context_kotl.R deleted file mode 100644 index b8801fe..0000000 --- a/data-raw/example_context_kotl.R +++ /dev/null @@ -1,107 +0,0 @@ -# Fetch spatial context layers for KOTL vignette from fwapg docker database -# -# Uses fresh::frs_db_conn() to query the local fwapg/bcfishpass database. -# Run interactively — requires the fresh-db docker container running. -# -# Output: -# inst/extdata/context_kotl.gpkg (multi-layer: towns, lakes, streams, highways) -# -# Prerequisites: -# - docker container fresh-db running (see fresh package) -# - PG_* env vars set (PG_HOST_SHARE, etc.) -# - R packages: fresh, sf, DBI - -library(fresh) -library(sf) - -conn <- frs_db_conn() -aoi <- st_read("inst/extdata/example_aoi_kotl.gpkg", quiet = TRUE) -aoi_3005 <- st_transform(aoi, 3005) -bb <- st_bbox(aoi_3005) -env <- sprintf( - "ST_MakeEnvelope(%s, %s, %s, %s, 3005)", - bb["xmin"], bb["ymin"], bb["xmax"], bb["ymax"] -) -out_path <- "inst/extdata/context_kotl.gpkg" - -# -- Towns (from BC Geographical Names) ---------------------------------------- -towns <- frs_db_query(conn, sprintf(" - SELECT geographical_name AS name, feature_type, geom - FROM whse_basemapping.gns_geographical_names_sp - WHERE feature_type IN ('City', 'Town', 'Village', 'Locality', - 'Community', 'Unincorporated Community') - AND ST_Intersects(geom, %s) - AND geographical_name IN ('Nelson', 'Creston', 'Slocan', 'Castlegar') -", env)) - -# Castlegar/Slocan may be outside KOTL — widen search if needed -if (!("Castlegar" %in% towns$name)) { - extra <- frs_db_query(conn, " - SELECT geographical_name AS name, feature_type, geom - FROM whse_basemapping.gns_geographical_names_sp - WHERE geographical_name IN ('Castlegar', 'Slocan') - AND feature_type IN ('City', 'Town', 'Village', 'Locality', - 'Community', 'Unincorporated Community') - ") - towns <- rbind(towns, extra) -} -towns <- st_transform(towns, 4326) -cat("Towns:", paste(towns$name, collapse = ", "), "\n") - -# -- Lakes (> 100 ha) --------------------------------------------------------- -lakes <- frs_db_query(conn, sprintf(" - SELECT gnis_name_1 AS name, area_ha, geom - FROM whse_basemapping.fwa_lakes_poly - WHERE area_ha > 100 - AND ST_Intersects(geom, %s) -", env)) -lakes <- st_transform(lakes, 4326) -cat("Lakes >100 ha:", nrow(lakes), "\n") - -# -- Rivers (polygon features — major rivers only) ---------------------------- -rivers <- frs_db_query(conn, sprintf(" - SELECT gnis_name_1 AS name, geom - FROM whse_basemapping.fwa_rivers_poly - WHERE ST_Intersects(geom, %s) -", env)) -rivers <- st_zm(rivers, drop = TRUE, what = "ZM") -rivers <- st_transform(rivers, 4326) -cat("River polygons:", nrow(rivers), "\n") - -# -- Streams (order >= 5 for context lines) ----------------------------------- -streams <- frs_db_query(conn, sprintf(" - SELECT gnis_name AS name, stream_order, geom - FROM whse_basemapping.fwa_stream_networks_sp - WHERE stream_order >= 5 - AND ST_Intersects(geom, %s) -", env)) -streams <- st_zm(streams, drop = TRUE, what = "ZM") -streams <- st_collection_extract(st_intersection(streams, aoi_3005), "LINESTRING") -streams <- st_transform(streams, 4326) -cat("Stream segments (order >= 5):", nrow(streams), "\n") - -# -- Highways ------------------------------------------------------------------ -highways <- frs_db_query(conn, sprintf(" - SELECT transport_line_type_code AS road_type, geom - FROM whse_basemapping.transport_line - WHERE transport_line_type_code IN ('RH1', 'RH2') - AND ST_Intersects(geom, %s) -", env)) -highways <- st_zm(highways, drop = TRUE, what = "ZM") -highways <- st_collection_extract(st_intersection(highways, aoi_3005), "LINESTRING") -highways <- st_transform(highways, 4326) -cat("Highway segments:", nrow(highways), "\n") - -DBI::dbDisconnect(conn) - -# -- Write multi-layer gpkg ---------------------------------------------------- -if (file.exists(out_path)) file.remove(out_path) -st_write(towns, out_path, layer = "towns", quiet = TRUE) -st_write(lakes, out_path, layer = "lakes", quiet = TRUE, append = TRUE) -st_write(rivers, out_path, layer = "rivers", quiet = TRUE, append = TRUE) -st_write(streams, out_path, layer = "streams", quiet = TRUE, append = TRUE) -st_write(highways, out_path, layer = "highways", quiet = TRUE, append = TRUE) - -cat("\nWrote:", out_path, "\n") -cat("Layers:", paste(st_layers(out_path)$name, collapse = ", "), "\n") -cat("Size:", round(file.size(out_path) / 1e6, 1), "MB\n") diff --git a/inst/extdata/context_kotl.gpkg b/inst/extdata/context_kotl.gpkg deleted file mode 100644 index dd796b3..0000000 Binary files a/inst/extdata/context_kotl.gpkg and /dev/null differ diff --git a/planning/archive/2026-10-issue-112-context-kotl/README.md b/planning/archive/2026-10-issue-112-context-kotl/README.md new file mode 100644 index 0000000..66fc0e7 --- /dev/null +++ b/planning/archive/2026-10-issue-112-context-kotl/README.md @@ -0,0 +1,14 @@ +## Outcome + +`inst/extdata/context_kotl.gpkg` shipped in every install with no reader. Its only consumer, the KOTL vignette, was removed in #50, and `context_kootenay_lake.gpkg` (#57) holds the same five layer kinds plus wsgs and ecoregions over an area that contains KOTL. The file was deleted. Its producer `data-raw/example_context_kotl.R` was deleted too, rather than marked superseded, so nothing can recreate it; git history keeps the recipe. `example_aoi_kotl.gpkg` and its producer stay because the README quick-start reads them. Three code-check rounds came back Clean: code readers, including an org-wide `gh` code search; the build/publish file set; and the supersession claim and doc truth. One leftover: the two remaining `data-raw/example_context_*` headers now cite each other as "same recipe". Both reviewers who noticed judged it harmless. + +## Measurement + +R 4.5.2. `R CMD build --no-build-vignettes --no-manual` on `git archive` of `048f93a` vs the change, each installed with `R CMD INSTALL -l` into a scratch library: + +- **Tarball:** 7,146,394 → 3,830,880 B (−46%), 101 → 100 files. +- **Installed `cd/`:** 12,776 → 7,948 KB (−38%). + +The issue's "loses 4.9 MB" holds for installed size. The gpkg compresses, so the download shrinks by 3.3 MB. After-tarball `R CMD check --no-manual --ignore-vignettes`: Status OK, 0 NOTEs. `devtools::test()`: PASS 436, FAIL 0. The reproduce commands are in `findings.md`. + +Closed by: commit 1d17163 / PR #115 diff --git a/planning/archive/2026-10-issue-112-context-kotl/findings.md b/planning/archive/2026-10-issue-112-context-kotl/findings.md new file mode 100644 index 0000000..8e741fb --- /dev/null +++ b/planning/archive/2026-10-issue-112-context-kotl/findings.md @@ -0,0 +1,46 @@ +# Findings — inst/extdata/context_kotl.gpkg (4.9 MB) ships but nothing reads it (#112) + +## Issue context + +**If we do it:** the installed package loses 4.9 MB, about 40% of its 12.5 MB installed size. **If we never do:** every install carries a file nothing reads. + +## Problem + +`inst/extdata/context_kotl.gpkg` is 4.9 MB. Nothing in `R/`, `tests/`, `vignettes/` or `README.md` references it. The only mention is its producer, `data-raw/example_context_kotl.R`, plus a comment in `data-raw/example_context_fwcp_peace.R`. It dates from `3ece27c` (2026-04-07, before the Kootenay Lake vignette). The vignette added in #57 uses `context_kootenay_lake.gpkg`, which appears to supersede it. `example_aoi_kotl.gpkg` is still used by the README example, so keep it. + +Found by a code-check reviewer while verifying #100's tarball contents, and confirmed with `git grep -n context_kotl`. + +## Proposed Solution + +- Confirm `context_kootenay_lake.gpkg` supersedes it. Then delete `inst/extdata/context_kotl.gpkg`, and either delete `data-raw/example_context_kotl.R` or mark it superseded. +- Rebuild and compare the tarball size before and after. + +## Supersession (plan-mode exploration, 2026-10-02) + +- `git grep context_kotl` outside `planning/` hit only the producer and one comment in `data-raw/example_context_fwcp_peace.R`. +- The file's consumer, the KOTL vignette, was removed in #50 (NEWS.md, v0.2.x entry). That entry's "KOTL polygon assets stay" refers to `example_aoi_kotl.gpkg`, used at README.md:23 and kept. +- `context_kootenay_lake.gpkg` (#57) layers: lakes, rivers, streams, highways, wsgs, ecoregions, towns over KOTL+LARL+DUNC+SLOC. `context_kotl.gpkg` layers: towns, lakes, rivers, streams, highways over KOTL only. Superset. +- Code-check round 1 widened this: no `list.files()` over `inst/extdata`, no pattern-built filenames, and an org-wide `gh` code search found no other repo reading the file. + +## Measurement + +R 4.5.2, `R CMD build --no-build-vignettes --no-manual` on `git archive` of HEAD (`048f93a`) vs the staged tree (`git write-tree`), then `R CMD INSTALL -l` into a scratch library: + +| | before | after | change | +|---|---|---|---| +| tarball | 7,146,394 B | 3,830,880 B | −3.3 MB (−46%) | +| tarball files | 101 | 100 | only `inst/extdata/context_kotl.gpkg` gone | +| installed `cd/` | 12,776 KB | 7,948 KB | −4.7 MB (−38%) | +| installed `extdata/` | 11,796 KB | 6,968 KB | −4.7 MB | + +The gpkg compresses in the tarball (4.9 MB raw → ~3.3 MB of tarball), so the issue's "loses 4.9 MB" holds for the installed size, not the download. + +After-tarball `_R_CHECK_FORCE_SUGGESTS_=false R CMD check --no-manual --ignore-vignettes`: **Status: OK** (0 NOTEs; #111 had already cleared the last two). `devtools::test()`: FAIL 0 | WARN 6 | SKIP 0 | PASS 436. `system.file("extdata", "example_aoi_kotl.gpkg", package = "cd")` resolves in the installed after-library and reads 1 feature. + +Reproduce (per side; `` is `HEAD` or `$(git write-tree)`): + +```bash +git archive | tar -x -C src && R CMD build --no-build-vignettes --no-manual src +wc -c < cd_0.5.8.tar.gz; tar -tzf cd_0.5.8.tar.gz | wc -l +R CMD INSTALL -l lib cd_0.5.8.tar.gz && du -sk lib/cd lib/cd/extdata +``` diff --git a/planning/archive/2026-10-issue-112-context-kotl/progress.md b/planning/archive/2026-10-issue-112-context-kotl/progress.md new file mode 100644 index 0000000..a25d55e --- /dev/null +++ b/planning/archive/2026-10-issue-112-context-kotl/progress.md @@ -0,0 +1,13 @@ +# Progress — inst/extdata/context_kotl.gpkg (4.9 MB) ships but nothing reads it (#112) + +## Session 2026-10-02 + +- Plan-mode exploration — phases approved by user (delete producer script too, not mark superseded) +- Created branch `112-inst-extdata-context-kotl-gpkg-4-9-mb-shi` off main +- Scaffolded PWF baseline from issue #112 with approved phases +- Next: start Phase 1 +- Phase 1: baseline tarball 7,146,394 B / installed 12,776 KB from `git archive HEAD` +- Phase 2: `git rm` of `inst/extdata/context_kotl.gpkg` + `data-raw/example_context_kotl.R`; repointed `example_context_fwcp_peace.R:3` to `example_context_kootenay_lake.R`; `git grep context_kotl` outside planning/ empty +- Phase 3: after tarball 3,830,880 B / installed 7,948 KB; R CMD check Status OK; `devtools::test()` PASS 436 FAIL 0; README AOI resolves (numbers in findings.md) +- /code-check: 3 rounds (code readers, build/publish file set, supersession + doc truth), all Clean — `review-round{1,2,3}.md` +- Next: /planning-archive, /gh-pr-push diff --git a/planning/archive/2026-10-issue-112-context-kotl/review-round1.md b/planning/archive/2026-10-issue-112-context-kotl/review-round1.md new file mode 100644 index 0000000..8b36c56 --- /dev/null +++ b/planning/archive/2026-10-issue-112-context-kotl/review-round1.md @@ -0,0 +1,14 @@ +# Code-check review round 1 — #112 (staged diff) + +## Clean +No issues found. + +### What was verified +- `git grep -i kotl` outside `planning/archive/`: no reader of `context_kotl` in `R/`, `tests/`, `vignettes/`, `scripts/`, `.github/`, `README.md`, `_pkgdown.yml`, `DESCRIPTION`, `.Rbuildignore`, or other `inst/` files. Remaining `kotl` hits are `example_aoi_kotl.gpkg` (README.md:23, kept), its kept producer `data-raw/example_aoi_kotl.R`, WSG code strings, and NEWS history. +- Indirect readers: every `list.files()` in `R/` and `scripts/` targets cache / grib / cog / monthly dirs, never `inst/extdata`; all `system.file("extdata", ...)` calls use literal names of files that still exist; no `paste0("context_", ...)` style construction anywhere. +- Ecosystem: local grep over `~/Projects/repo` and `gh` code search (`org:NewGraphEnvironment context_kotl`, default branches) find only cd's own producer, the edited comment, and planning/archive + sred evidence dumps (history). No external package reads `system.file(..., "context_kotl.gpkg", package = "cd")`. +- Edited comment (`data-raw/example_context_fwcp_peace.R:3`): `example_context_kootenay_lake.R` exists, uses the same recipe (frs_db_query towns/lakes/rivers/streams/highways/wsgs/ecoregions, same st_write layering), and its thresholds (lakes > 200 ha, stream order >= 5) are lower than Peace's (> 1000 ha, >= 7), so "bigger lake threshold, higher minimum stream order" remains accurate. That file's header reciprocally says "Same recipe as example_context_fwcp_peace.R". +- Deleting the producer removes the only writer of `inst/extdata/context_kotl.gpkg`; nothing left can regenerate the deleted file. + +### Pre-existing, not introduced by this diff (FYI only) +- `data-raw/example_context_fwcp_peace.R:8` lists output layers as "towns, lakes, streams, highways" but the script also writes rivers, wsgs, ecoregions. Untouched line; not a failure. diff --git a/planning/archive/2026-10-issue-112-context-kotl/review-round2.md b/planning/archive/2026-10-issue-112-context-kotl/review-round2.md new file mode 100644 index 0000000..01ce80f --- /dev/null +++ b/planning/archive/2026-10-issue-112-context-kotl/review-round2.md @@ -0,0 +1,15 @@ +# Review round 2 — #112 (build/publish side) + +## Clean +No issues found. + +Checked: +- `.github/workflows/pkgdown.yaml`: no step copies, size-checks, globs or uploads `inst/extdata`. The allowed-pages gate looks at root markdown pages, not extdata. +- `.github/workflows/climate-update.yml`, `update-citation-cff.yaml`: no extdata references. +- Vignettes: `kootenay-lake.Rmd` loads `example_aoi_kootenay_lake.gpkg` and `context_kootenay_lake.gpkg`, and `peace-fwcp.Rmd` loads the fwcp_peace files and the commentary CSV. Both are still present. Neither vignette uses `kotl`. +- `R/cd_stac_catalog.R:37` lists only `\.tif$` in `cog_dir`. The `tests/testthat/test-cd_stac_catalog.R` expectations are `>= 1` row/item checks over `example_climate.tif`, so removing a gpkg cannot change them. +- `list.files` / `dir_ls` across R/, tests/, vignettes/, data-raw/ and scripts/: none of them point at extdata as a directory, apart from the tif-filtered STAC call above. +- No reference to `context_kotl` or `example_context_kotl` is left outside planning/ and .git. README still uses `example_aoi_kotl.gpkg`, which is kept. +- The new referent `data-raw/example_context_kootenay_lake.R` exists and describes the same fwapg recipe. + +Note (not a defect): `example_context_kootenay_lake.R:3` and `example_context_fwcp_peace.R:3` now each say "same recipe as" the other. The pointer is circular but both files exist, so it is harmless. diff --git a/planning/archive/2026-10-issue-112-context-kotl/review-round3.md b/planning/archive/2026-10-issue-112-context-kotl/review-round3.md new file mode 100644 index 0000000..1e24b6c --- /dev/null +++ b/planning/archive/2026-10-issue-112-context-kotl/review-round3.md @@ -0,0 +1,22 @@ +# Review round 3 — #112 supersession claim and documentation truth + +## Clean +No issues found. + +Checked (outside planning/archive/ and docs/): + +- (a) Supersession: `context_kootenay_lake.gpkg` writes towns, lakes, rivers, streams, + highways (the deleted file's five layers) plus wsgs and ecoregions, over an AOI + (KOTL+LARL+DUNC+SLOC) that contains KOTL. Nothing — README, CLAUDE.md, vignettes, + data-raw headers, .github, tests, R/, man/, _pkgdown.yml — promises a KOTL context + layer. No `research/` directory exists. + NEWS.md:169 ("KOTL polygon assets stay in inst/extdata/ because the README quick-start + still uses them") is a v0.1.4 release-history entry; its premise still holds for the + asset the README uses (README.md:23 reads `example_aoi_kotl.gpkg`, which is kept). Not + made false in any way a reader would act on; history is immutable per repo convention. +- (b) No live doc or comment names `context_kotl.gpkg` or `example_context_kotl.R` + (only NEWS.md:149 lists `context_kootenay_lake.gpkg`, which exists). +- (c) `example_context_fwcp_peace.R:3` and `example_context_kootenay_lake.R:3` now cite + each other as "same recipe". Both scripts are self-contained and the comparisons + ("much larger" Peace, ~73,000 vs ~24,200 km^2) are true; the mutual reference conveys + a sibling relationship and would not lead a reader into wrong action. diff --git a/planning/archive/2026-10-issue-112-context-kotl/task_plan.md b/planning/archive/2026-10-issue-112-context-kotl/task_plan.md new file mode 100644 index 0000000..36318af --- /dev/null +++ b/planning/archive/2026-10-issue-112-context-kotl/task_plan.md @@ -0,0 +1,38 @@ +# Task: inst/extdata/context_kotl.gpkg (4.9 MB) ships but nothing reads it (#112) + +`inst/extdata/context_kotl.gpkg` is 4.9 MB. Nothing in `R/`, `tests/`, `vignettes/` or `README.md` references it. The only mention is its producer, `data-raw/example_context_kotl.R`, plus a comment in `data-raw/example_context_fwcp_peace.R`. It dates from `3ece27c` (2026-04-07, before the Kootenay Lake vignette). The vignette added in #57 uses `context_kootenay_lake.gpkg`, which appears to supersede it. `example_aoi_kotl.gpkg` is still used by the README example, so keep it. + +Found by a code-check reviewer while verifying #100's tarball contents, and confirmed with `git grep -n context_kotl`. + +## Context (from plan-mode exploration) + +`inst/extdata/context_kotl.gpkg` ships in every install and nothing reads it. Exploration confirmed the issue's claim and the supersession it asked about: + +- `git grep context_kotl` outside `planning/` hits only its producer `data-raw/example_context_kotl.R` and a "Same recipe as example_context_kotl.R" comment at `data-raw/example_context_fwcp_peace.R:3`. Nothing in `R/`, `tests/`, `vignettes/`, `README.md`. +- Its consumer, the KOTL vignette, was removed in v0.2.x (#50, NEWS.md:169). That NEWS line says the KOTL *polygon* assets stay for the README — that is `example_aoi_kotl.gpkg` (README.md:23), which this work keeps. +- `context_kootenay_lake.gpkg` (2.2 MB, #57) covers the KOTL+LARL+DUNC+SLOC superset with the same layer kinds (towns, lakes, rivers, streams, highways) plus wsgs and ecoregions. Superseded. +- The only test touching `extdata` as a directory (`test-cd_stac_catalog.R`) lists `*.tif` only, so removing a gpkg cannot affect it. + +**Decision taken in this plan (recommended): delete the producer script too**, rather than mark it superseded. A kept script for a deleted output is a trap — running it recreates the 4.9 MB file under `inst/extdata/` — and git history keeps the recipe. `example_aoi_kotl.R` stays (README asset). + +## Phase 1: Baseline measurement +- [x] Build tarball from `git archive HEAD` (`R CMD build --no-build-vignettes --no-manual`), record tarball size and installed `inst/extdata` size — same method as #100's archive README + +## Phase 2: Remove the asset and its producer +- [x] `git rm inst/extdata/context_kotl.gpkg data-raw/example_context_kotl.R` +- [x] `data-raw/example_context_fwcp_peace.R:3`: repoint "Same recipe as example_context_kotl.R" at `example_context_kootenay_lake.R` (the live sibling) +- [x] `git grep -n context_kotl -- ':(exclude)planning'` returns nothing + +## Phase 3: Verify +- [x] Rebuild tarball, compare size before/after; record both in `findings.md` +- [x] `devtools::test()` passes +- [x] `R CMD check --no-manual --ignore-vignettes` on the tarball (`_R_CHECK_FORCE_SUGGESTS_=false`) — no new NOTEs vs v0.5.8 +- [x] README example still resolves `example_aoi_kotl.gpkg` via `system.file()` + +## Validation +- [x] Tests pass +- [x] `/code-check` clean on each commit +- [x] PWF checkboxes match landed work +- [x] `/planning-archive` on completion (README carries the before/after measurement) + +NEWS line and version bump are left to `/gh-pr-merge` (patch release).