Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
ed84a60
Declare object keys and the bucket's base URL in the tile index
achubaty Dec 3, 2026
4901c07
Upload release zips to the Arbutus bucket, batch by batch
achubaty Dec 3, 2026
027bb69
Build the release index from bucket uploads
achubaty Dec 3, 2026
73697e4
Refresh the bucket catalogue after uploads
achubaty Dec 3, 2026
11b58a5
Record the bucket devtest
achubaty Dec 3, 2026
3936e23
Turn the bucket catalogue refresh off for now
achubaty Dec 3, 2026
1c662bf
Leave wbi/ out of the bucket catalogue, as its live pages do
achubaty Dec 3, 2026
f2bb930
Download archives from the Arbutus bucket
achubaty Dec 3, 2026
1d73310
Document downloads from Arbutus
achubaty Dec 3, 2026
a3a7a05
Fetch makeClimateDEM()'s GTOPO30 DEM from the bucket
achubaty Dec 4, 2026
c0094a2
Remove the Drive archive audit and its helpers
achubaty Dec 4, 2026
a121712
Retry network failures in bucket downloads and HEAD checks
achubaty Dec 4, 2026
4526f8c
Remove the Windows-era archive build scripts
achubaty Dec 4, 2026
d0e803f
Merge feat/climatena-docker (development with #43) into feat/arbutus-…
achubaty Dec 4, 2026
5ec1e7e
Check DEM tiles for CRLF, cell size and lon/lat; CRLF on every platform
achubaty Dec 4, 2026
14d8f7c
Encode the tile grid rule that made tiles.gpkg
achubaty Dec 4, 2026
2688a72
Build DEM tiles from the GTOPO30 mosaic, as data-raw/02 did
achubaty Dec 4, 2026
aee92f9
Build a new release's DEM tiles in the pipeline
achubaty Dec 4, 2026
d945e1a
Report settings that differ from available() and small or extra zip f…
achubaty Dec 4, 2026
73f032e
Remove data-raw/01 and 02 and their unused exports; document DEM tiles
achubaty Dec 4, 2026
71b8b35
Start DEM tile rows with a space, as the releases' tiles do
achubaty Dec 4, 2026
ab52a51
Stop the run when the GTOPO30 download fails
achubaty Dec 4, 2026
5575ee4
Say which catalogue pages the refresh rewrites
achubaty Dec 4, 2026
f394c46
Declare yaml for the report test
achubaty Dec 4, 2026
4360197
Ship the 3 arcmin index with bucket keys
achubaty Dec 4, 2026
351d842
Record the DEM devtest
achubaty Dec 4, 2026
dcfa841
Report only unexpected files in zips, not small ones
achubaty Dec 4, 2026
5cc09dd
Drop the removed ClimateNA_path from the pkgdown index
achubaty Dec 4, 2026
c05211b
Check that each built DEM tile lies in its tile's polygon
achubaty Dec 4, 2026
b9c24d4
Upload a found object again when it isn't public
achubaty Dec 4, 2026
757e85e
Create the download folder before fetching an archive
achubaty Dec 4, 2026
c5ee3dc
Load the package in pipeline_zip_notes() on its worker
achubaty Dec 4, 2026
7c6e6fc
Harden downloads: failed renames, stale partials, missing MD5s
achubaty Dec 5, 2026
b25986e
Name a missing header line in a DEM tile
achubaty Dec 5, 2026
cb69904
Pipeline: check paths, fetch GTOPO30 from the release's bucket
achubaty Dec 5, 2026
f5fb700
Label indexes from before 2.3.0 as pre-2.3.0
achubaty Dec 5, 2026
d0a3fe2
Fix stale docs; guard the shipped-index test against NAs
achubaty Dec 5, 2026
5e7409c
Normalize the tile index: rows refer to archives by id
achubaty Dec 5, 2026
310f6cf
Ship the 3 arcmin index in the normalized schema
achubaty Dec 5, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 36 additions & 27 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
`climateData` is an R package that wraps access to [ClimateNA](https://climatena.ca/) outputs for
North America. The package itself does not bundle raster data; instead, `inst/extdata/` contains
a SQLite lookup database and a GeoPackage of tile polygons, and raw raster archives are pulled on
demand from Google Drive. The `data-raw/` scripts (run by the maintainer on a Windows box with the
ClimateNA executable) regenerate those archives and the SQLite index; they are excluded from the
built package via `.Rbuildignore` and should not be treated as user-facing code.
demand over HTTPS from a public bucket on Arbutus (S3-compatible object storage). The
`data-raw/pipeline/` targets pipeline (run by the maintainer on Linux compute nodes, ClimateNA in
Docker) regenerates those archives and the SQLite index, and builds a new release's DEM tiles
(`R/pipelineDem.R`, `data-raw/pipeline/R/dem.R`; the tile polygons in `tiles.gpkg` never change).
`data-raw/` is excluded from the built package via `.Rbuildignore` and should not be treated as
user-facing code.

## Common commands

Expand All @@ -34,9 +37,9 @@ testthat::test_file("tests/testthat/test-prepClimateLayers.R")
devtools::load_all()
```

Most tests `skip_on_ci()` and `skip_on_cran()` because they require interactive `googledrive`
auth and multi-GB downloads from Google Drive. Expect the CI test run to be effectively empty;
real validation requires running `devtools::test()` locally with credentials in `.secrets/`.
Most tests `skip_on_ci()` and `skip_on_cran()` because they need multi-GB downloads from the
bucket. Expect the CI test run to be effectively empty; real validation requires running
`devtools::test()` locally.

`makeClimateDEM` tests are Windows-only (ClimateNA rejects DEMs written on non-Windows platforms
due to line-ending differences — see `rewrite_asc()`).
Expand All @@ -55,8 +58,9 @@ climate variables, it:
(seasonal), two trailing digits → M (monthly), otherwise Y (yearly).
2. Consolidates M/S/Y requests into the combined `MSY` archive when all three are needed for the
same type (avoids downloading three overlapping zips).
3. Calls `getClimateURLs()` → `getClimateTiles()` to pull archives from Google Drive via
`reproducible::preProcess()`. URLs are looked up in the bundled SQLite
3. Calls `getClimateURLs()` → `getClimateTiles()` to download archives from the bucket with
httr2 (`.fetchArchive()` in `R/download.R`), each checked against its MD5 in the index's
`archives` table. URLs (`release.base_url` + `key`) are looked up in the bundled SQLite
(`ClimateNA_tiles_sqlite()`); the schema differs per `type` and is defined in `ClimateNA_sql()`.
4. Calls `buildClimateMosaics()` / `buildClimateMosaicsNormals()` to build GDAL VRTs per tile and
warp them to per-year/period GeoTIFFs — this is the CPU-heavy step and runs in parallel (see
Expand Down Expand Up @@ -89,26 +93,31 @@ serialization cheap. `stopForInvalidBackend()` centralizes the error path.

### SQLite schema

The index at `inst/extdata/ClimateNA_tiles.sqlite` holds four main tables —
`historical`, `historical_normals`, `future`, `future_normals`. `gid` is the Google Drive
file ID; archives are grouped by decade, so many rows share a `gid`. `sqlite_connect_db()`
The index at `inst/extdata/ClimateNA_tiles.sqlite` holds four tile tables,
`tiles_historical`, `tiles_historical_normals`, `tiles_future`, `tiles_future_normals`: one row
per tile, subset and year or period, referring to its zip in the `archives` table by id
(`archive`). Archives are grouped by decade, so many rows share one. A view named for each type
(`historical`, ...) joins them back into the columns readers use (`zipfile`, `archived`, `key`,
`uploaded`); `ClimateNA_sql()` reads the view, and writers append to `tiles_<type>`. `key` is the
archive's object key in the bucket (its URL is `release.base_url` + `/` + `key`). Storing the
paths once per archive, not once per row, keeps the index at 20 MB, from 52 MB.
`sqlite_connect_db()`
sets a 60s busy timeout before anything else; lookups (`readonly = TRUE`) open the file
read-only, and writing connections switch a file to WAL only when they create it. The shipped
index is left in rollback-journal mode (`build_index()` in `data-raw/pipeline/R/index.R`), so
read-only lookups work from a library folder the user cannot write to.

Optional `checksums_<type>` tables are created by `checksums_sql()` when a maintainer runs the
`data-raw/` checksum loops; they may or may not be present in a given copy of the bundled
database. Don't assume they exist when querying.
Indexes from before climateData 2.3.0 may hold `checksums_<type>` tables, written by the
Windows-era build scripts (removed in 2.3.0); the pipeline's index has none. Don't assume they
exist when querying.

**The declared schemas in `ClimateNA_sql()` / `checksums_sql()` are not authoritative for
what's actually stored.** `dbCreateTable()` emits e.g. `year CHARACTER` / `created DATETIME`,
but the `data-raw/` scripts populate rows via `dplyr::rows_append(copy = TRUE, in_place = TRUE)`
which can map R column types to its own SQLite types (e.g. R `integer` → `INTEGER`, R `POSIXct`
→ `TIMESTAMP`, R `character` → `TEXT`) — so the PRAGMA-reported column types in the shipped
file can diverge from the R schema strings. When changing a schema, inspect the bundled file
with `PRAGMA table_info(<tbl>)` before writing migration code; it may already be in the
target state.
**The declared schemas in `ClimateNA_sql()` are not authoritative for older indexes.** The pipeline creates each tile table with `ClimateNA_sql()` (`dbCreateTable()`
emits e.g. `year CHARACTER` / `created DATETIME`) and fills it with `DBI::dbAppendTable()`, so
its declared types are the templates'. Indexes from before 2.3.0 were filled with
`dplyr::rows_append(copy = TRUE, in_place = TRUE)`, which maps R column types to its own SQLite
types (e.g. R `integer` → `INTEGER`, R `POSIXct` → `TIMESTAMP`). When changing a schema, inspect
the bundled file with `PRAGMA table_info(<tbl>)` before writing migration code; it may already be
in the target state.

### Allowed variables

Expand All @@ -119,10 +128,10 @@ discovery. `available()` exposes the allowed years, periods, GCMs, and SSPs.

## Dependencies worth knowing

- `reproducible` (≥ 2.0.8) — `preProcess()`, `prepInputs()`, `postProcessTo()`, `Cache()`.
Many of the long-running behaviors (downloads, reprojection, masking) are delegated here.
- `reproducible` (≥ 2.0.8) — `postProcessTo()`, `Cache()`, `checkPath()`. Reprojection,
masking and caching are delegated here; the archive downloads are not.
- `SpaDES.tools` comes from the `development` branch (see `Remotes:` in DESCRIPTION); the
r-universe build picks this up automatically, but plain `install.packages()` will not.
- `googledrive` and `httr2` are Imports because `getClimateTiles()` and `makeClimateDEM()` need
them to download, and reproducible has both only in Suggests. httr2 is never called directly;
`R/imports.R` imports `httr2::request` so that R CMD check accepts it in Imports.
- `httr2` downloads the archives and `makeClimateDEM()`'s GTOPO30 DEM
(`climateData/dem/gtopo30Canada.zip` in the bucket) through `.downloadArchive()`. Nothing in
the package uses Google Drive.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ Imports:
fs,
future.apply,
glue,
googledrive,
hms,
httr2,
httr2 (>= 1.0.4),
methods,
parallel,
parallelly,
Expand All @@ -53,7 +52,8 @@ Suggests:
sys,
targets,
testthat (>= 3.0.0),
withr
withr,
yaml
VignetteBuilder:
knitr,
rmarkdown
Expand Down
8 changes: 1 addition & 7 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Generated by roxygen2: do not edit by hand

export(ClimateNA_path)
export(ClimateNA_sql)
export(ClimateNA_tiles_gpkg)
export(ClimateNA_tiles_sqlite)
Expand All @@ -12,7 +11,6 @@ export(calcCumMDC)
export(calcMDC)
export(calcStackLayersType)
export(checkCalcStackLayers)
export(checksums_sql)
export(climateDataRelease)
export(climateLayers)
export(climateStacksByPeriod)
Expand Down Expand Up @@ -58,7 +56,6 @@ importFrom(dplyr,
)
importFrom(fs,dir_ls)
importFrom(future.apply,future_lapply)
importFrom(httr2,request)
importFrom(parallel,
parLapply,
stopCluster
Expand All @@ -69,9 +66,7 @@ importFrom(reproducible,
.robustDigest,
Cache,
checkPath,
postProcessTo,
preProcess,
prepInputs
postProcessTo
)
importFrom(sf,
gdal_utils,
Expand Down Expand Up @@ -103,6 +98,5 @@ importFrom(terra,
importFrom(tools,file_path_sans_ext)
importFrom(utils,
getFromNamespace,
packageVersion,
write.table
)
23 changes: 23 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
# climateData (development version)

- The climate archives now download over HTTPS from a public bucket on Arbutus, the Digital
Research Alliance of Canada's object storage. No Google account or `googledrive::drive_auth()`
is needed, so downloads no longer fail on Google logins or service accounts (#13). Each
download is checked against the MD5 in the tile index, and downloaded once more if it doesn't
match. A partial download left by an interrupted session is removed by a later one (after a
day). climateData 2.2.3 and earlier download from Google Drive, which will stop serving the
archives.
- `makeClimateDEM()` downloads its GTOPO30 elevation data from the same bucket, checked against
its MD5. climateData no longer depends on googledrive.
- `getClimateURLs()` returns, for each tile, a data frame of archive URLs and MD5s instead of
Google Drive IDs.
- The tile index stores each archive's object key and path once, in its `archives` table, rather
than in every row: it is 20 MB instead of 52 MB. `historical`, `future` and the normals tables
are now views with the same columns, read as before through `ClimateNA_sql()`.
- The tile index names each archive by its object key in the bucket (`key`, replacing `gid`); the
bucket's URL is in the `release` table (`base_url`) and each archive's MD5 in `archives`.
- `rewrite_asc()` writes Windows (CRLF) line endings on every platform. On Linux and macOS it
wrote LF, which ClimateNA rejects.
- `ClimateNA_path()` and `checksums_sql()` are removed: only the old Windows build scripts used
them. Those scripts (`data-raw/01` to `06`) are replaced by the data pipeline
(`data-raw/pipeline/`), which now also builds a new release's DEM tiles and reports settings
that differ from `available()`.

- Land cells where ClimateNA writes no values now hold ClimateNA's own values for the nearest land
cell it covers within 50 km, computed at the empty cell's elevation (in the 3 arcmin release, a
median of 3.5 km away; 90% within 10 km). ClimateNA's future data miss some coastal cells (e.g.
Expand Down
Loading