Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
da7469e
Format test-consolidateClimateTypes.R with air
achubaty Nov 4, 2026
74d42e2
Use S archives for seasonal-only requests; extend history to 2025
achubaty Nov 4, 2026
ac25f19
Add batch specs and ClimateNA folder and argument names
achubaty Nov 4, 2026
c70e2ae
Add period stamps and the rule for skipping finished periods
achubaty Nov 4, 2026
80598e0
Add the ClimateNA release compatibility verdict
achubaty Nov 4, 2026
eeee678
Add the docker arguments for a ClimateNA run
achubaty Nov 4, 2026
34d841f
Format test-climateMosaicsParallel.R with air
achubaty Nov 4, 2026
8172459
Read future normals, using ClimateNA's folder names
achubaty Nov 4, 2026
e3a4e4a
Add climateDataRelease() to identify the data behind the index
achubaty Nov 4, 2026
139583c
Add a vignette on fetching climate data for a study area
achubaty Nov 4, 2026
35d6f06
Add a pkgdown site built by the org workflow
achubaty Nov 4, 2026
64a10ff
Add the ClimateNA pipeline skeleton and release config
achubaty Nov 4, 2026
3c2c665
Run ClimateNA batches in Docker and cut subset zips
achubaty Nov 4, 2026
2511582
Upload release zips as new Drive files and build the index
achubaty Nov 4, 2026
94251e5
Re-check batch outputs on every pipeline run
achubaty Nov 4, 2026
ac1da95
Cut no zips for a failed batch
achubaty Nov 4, 2026
7001c71
Stop the pipeline on a failed compatibility check
achubaty Nov 4, 2026
5d455ee
Record the pipeline prototype checks
achubaty Nov 4, 2026
fd8821b
Reuse an earlier release's Drive file for an identical zip
achubaty Nov 4, 2026
5e1b1dd
Add a maintainer vignette on running the ClimateNA pipeline
achubaty Nov 4, 2026
9642d7e
Rebuild zips byte-identically and upload them in parallel
achubaty Nov 4, 2026
5ad3839
Run ClimateNA into a node-local directory, then copy to out_root
achubaty Nov 4, 2026
442afdf
Keep upload branches independent of release-wide targets
achubaty Nov 4, 2026
2b630aa
Store each ClimateNA output as one zip in the raw tree
achubaty Nov 4, 2026
fe46f73
Let the archive audit check a pipeline release
achubaty Nov 4, 2026
c889982
Ship the cna-v7.70-3arcmin tile index
achubaty Nov 5, 2026
6fd797b
Merge development into feat/climatena-docker
achubaty Nov 5, 2026
4de7f98
Keep each data release's downloads apart; seasonal from MSY
achubaty Nov 6, 2026
d31f1f7
Test future normals through a real download
achubaty Nov 6, 2026
4a66e00
Stop the pre-pipeline scripts before they overwrite the index
achubaty Nov 6, 2026
9346809
Keep pipeline reruns cheap and self-healing
achubaty Nov 6, 2026
4cf4950
Bump version to 2.2.3.9011
achubaty Nov 6, 2026
8bafc09
List rmarkdown as a vignette builder
achubaty Nov 6, 2026
a8da670
Merge branch 'development' into feat/climatena-docker
achubaty Nov 9, 2026
afc84a8
Read the data release from the shipped index in place
achubaty Nov 9, 2026
092a554
Bump version to 2.2.3.9012
achubaty Nov 9, 2026
d9bb0b7
Describe the read-only index connections in CLAUDE.md
achubaty Nov 9, 2026
4e86528
Note in NEWS that read-only lookups now work from any library
achubaty Nov 9, 2026
5c29fed
Format test-sqliteConcurrency.R with Air
achubaty Nov 9, 2026
498a5d9
Close the connection when a ClimateNA_sql() lookup fails
achubaty Nov 9, 2026
3cf7dbc
Compute each tile's no-DEM cells outside Canada
achubaty Nov 10, 2026
845ae1b
Blank masked cells in ClimateNA .asc files in place
achubaty Nov 10, 2026
880a136
Update a changed zip's Drive file in place
achubaty Nov 10, 2026
f372539
Blank no-DEM cells outside Canada when cutting zips
achubaty Nov 10, 2026
1fb1986
Drop maskInvalidPPT(); read seasonal-only from S archives
achubaty Nov 10, 2026
d5521a6
Cap pipeline workers at half of each node's cores
achubaty Nov 10, 2026
2187197
Keep a masked file's modification time
achubaty Nov 11, 2026
24ca2e9
Load the package in upload workers
achubaty Nov 11, 2026
274bcf0
Replace changed Drive files only when asked
achubaty Nov 11, 2026
d205773
Update the maintainer vignette for the mask and new settings
achubaty Nov 11, 2026
0d178eb
Ship the release index rebuilt after the #40 mask
achubaty Nov 12, 2026
a6aeac7
Write given values into NODATA cells of a ClimateNA grid
achubaty Nov 12, 2026
bebce64
Make tile masks depend on the DEM files' contents
achubaty Nov 12, 2026
cdf1203
Choose the nearest checked source for each empty land cell
achubaty Nov 12, 2026
36bc534
Run ClimateNA point mode in the image and read its values
achubaty Nov 12, 2026
11a464b
Run ClimateNA point mode for empty land cells
achubaty Nov 12, 2026
dc4ad2f
Fill empty land cells when cutting zips; warn on any left
achubaty Nov 12, 2026
0615ed5
Record filled cells in the release index
achubaty Nov 12, 2026
181be6d
Add filledCells() to find cells filled from a nearby point
achubaty Nov 12, 2026
46c271c
Name DEM files by tile from their file names
achubaty Nov 12, 2026
8c69a7b
List the DEM tiles on every run; stop on release-wide failures
achubaty Nov 13, 2026
83d69db
Ship the release index with filled cells
achubaty Nov 13, 2026
1e21833
Give the filled-cell figures of the shipped release
achubaty Nov 14, 2026
0687f55
Check the point-mode script under either shell quoting
achubaty Nov 14, 2026
60bfc83
Merge development (#43) into feat/climatena-docker
achubaty Dec 4, 2026
1e8c385
Order the read-only lookup test by id
achubaty Dec 4, 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
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@
^\.claude$
^_tmp$
^docker$
^_pkgdown\.yml$
^docs$
^pkgdown$
20 changes: 20 additions & 0 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## Thin caller -- the pkgdown build and the gh-pages deploy live in PredictiveEcology/actions.

name: pkgdown

on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
release:
types: [published]
workflow_dispatch:

permissions:
contents: write

jobs:
pkgdown:
uses: PredictiveEcology/actions/.github/workflows/pkgdown.yaml@main
## No `secrets:` block: the shared workflow uses only the automatic GITHUB_TOKEN.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,9 @@ tmp/

## scratch: drafts, plans, handoffs
_tmp/

## pkgdown site (built by GitHub Actions)
docs/

## per-machine pipeline settings
data-raw/pipeline/_local.R
7 changes: 5 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,11 @@ serialization cheap. `stopForInvalidBackend()` centralizes the error path.

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`. The connection opens in
WAL mode with a 60s busy timeout to allow concurrent writers from the `data-raw/` scripts.
file ID; archives are grouped by decade, so many rows share a `gid`. `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
Expand Down
9 changes: 6 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: climateData
Title: Utilities For Working With North American Climate Data
Version: 2.2.3.9011
Version: 2.2.3.9012
Date: 2026-04-15
Authors@R: c(
person("Alex M", "Chubaty", email = "achubaty@for-cast.ca",
Expand All @@ -13,7 +13,8 @@ Authors@R: c(
Description: Utilities for working with North American climate data from
'ClimateNA' <https://climatena.ca/>.
License: GPL-3
URL: https://github.com/PredictiveEcology/climateData
URL: https://predictiveecology.github.io/climateData/,
https://github.com/PredictiveEcology/climateData
BugReports: https://github.com/PredictiveEcology/climateData/issues
Depends:
R (>= 4.4)
Expand Down Expand Up @@ -50,10 +51,12 @@ Suggests:
rprojroot,
SpaDES.tools (>= 2.0.4),
sys,
targets,
testthat (>= 3.0.0),
withr
VignetteBuilder:
knitr
knitr,
rmarkdown
Remotes:
PredictiveEcology/reproducible@development,
PredictiveEcology/SpaDES.tools@development
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ export(calcMDC)
export(calcStackLayersType)
export(checkCalcStackLayers)
export(checksums_sql)
export(climateDataRelease)
export(climateLayers)
export(climateStacksByPeriod)
export(climateStacksByYear)
export(extractTimes)
export(filledCells)
export(getClimateTable)
export(getClimateTiles)
export(getClimateURLs)
Expand Down
48 changes: 36 additions & 12 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# climateData (development version)

- 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.
every land cell of tile 63, on Baffin Island's east coast), and a few cells had no values at all.
Of 608 such cells, 48 have no covered land cell within 50 km and stay empty. New `filledCells()`
lists these cells, with where ClimateNA was run for each.
- The 3 arcmin release no longer has a tile 53: at 3 arcmin it has no land cell, and its archives
had been built from the 1 arcmin DEM tile.

- New `climateDataRelease()` identifies the climate data release behind the installed package
(e.g. `"cna-v7.70-3arcmin"`). Code that caches `prepClimateLayers()` results can add it to the
cache key, so a new data release isn't served from an old cache.
- Historical data now run to 2025 (ClimateNA v7.70).
- Future climate normals (2011-2040, 2041-2070, 2071-2100) can be requested, e.g. `future_MAT_normal`
with `future_period`. `prepClimateLayers()` used to stop with "future normals not yet implemented".
- `prepClimateLayers()` downloads and extracts archives to a subfolder of `srcdir` named for the
data release (e.g. `<srcdir>/cna-v7.70-3arcmin/historical/39/`). A new release's archives keep
the earlier file names: in a `srcdir` that already held them, the download was skipped and the
old data were used. Folders from earlier releases are not read and can be deleted.
- Reading the bundled tile index (`latestHistoricalYear()`, the tile lookup in `ClimateNA_useTiles()`) no longer
writes `-wal`/`-shm` files into the installed package folder. Read-only `ClimateNA_sql()` connections open the
file with SQLite's `immutable=1`, and the bundled index is shipped in rollback-journal mode instead of WAL.
Expand All @@ -8,22 +27,27 @@
and set the SQLite busy timeout before any other statement. Before, many processes opening it together
(e.g. parallel hindcast jobs parsing fireSense modules on NFS) could fail with "database is locked".
`ClimateNA_sql()` gets a `readonly` argument; writing connections set WAL only when they create the file.

The bundled index is no longer in WAL mode, so these lookups also work from a library folder the user
cannot write to, and leave no `-wal`/`-shm` files in it.
- Solar radiation variables now use the ClimateNA v7.60+ names: `rsds` (annual; was `MAR`), `rsds_wt`,
`rsds_sp`, `rsds_sm`, `rsds_at` (seasonal; were `Rad_*`) and `rsds01`-`rsds12` (monthly; were `Rad01`-`Rad12`).
ClimateNA v7.60 (April 2025) replaced its RAD variables with rsds, based on CHELSA. Only the historical
2023 and 2024 data were made with v7.60, so radiation can't be requested for other years or for future
scenarios until those archives are regenerated. The old radiation layers held values only for 1948-2010.

ClimateNA v7.60 (April 2025) replaced its RAD variables with rsds, based on CHELSA. All archives were
rebuilt with ClimateNA v7.70 (data release `cna-v7.70-3arcmin`), so radiation now has values for every
historical year and future scenario. The old radiation layers held values only for 1948-2010.
- The `prepClimateLayers()` cache key now includes the bodies of the functions that build the layers
(`maskInvalidPPT()`, `climateMosaicsParallel()`, the `calc*()` functions ...). Before, layers cached
before the PPT guard or before the `reproducible` 3.2.1.9060 `postProcessTo()` smoothing fix kept
coming back from the cache. Every existing entry is rebuilt once. Mosaics themselves were always rebuilt
(`climateMosaicsParallel()`, the `calc*()` functions ...). Before, layers cached before a change to
them, or before the `reproducible` 3.2.1.9060 `postProcessTo()` smoothing fix, kept coming back from
the cache. Every existing entry is rebuilt once. Mosaics themselves were always rebuilt
(`overwrite = TRUE`); only the final cached `postProcessTo()` step was stale.

- `climateMosaicsParallel()` sets every variable to NA, for that year, in cells where all 12 monthly `PPT` values are
exactly 0. ClimateNA tiles 6 and 7 have such cells south of the Canada/US border (45.8-49 N), where the DEM is
not valid and temperatures are nonsense (Tmax up to 42.7 C); they gave absurd `cumMDC` and `CMD`.
- Cells outside Canada that have no DEM elevation are NA (#40). The DEM tiles cover Canada and a 3 arcmin
margin, but ClimateNA still wrote values beyond it, computed at the wrong elevation: next to the border,
US cells were a median 4.5 C warmer than the Canadian cells beside them (tile 6, 1991-2020 normals), and
tiles 6 and 7 had cells with no precipitation at all and Tmax up to 42.7 C, which gave absurd `cumMDC`
and `CMD`. In data release `cna-v7.70-3arcmin` these cells are NA in every archive, normals included.
Canadian coast and lakeshore cells with no DEM value keep their values. This replaces a check on reading
(cells whose 12 monthly `PPT` were all 0), which found only the zero-precipitation cells, and only when
the monthly files were downloaded. Seasonal variables requested alone now come from the smaller S
archives.

- When a seasonal variable is needed, monthly and yearly variables now come from the same MSY ("all")
archive, which contains all their files. Before, they were also downloaded from their own M and Y archives
Expand Down
103 changes: 99 additions & 4 deletions R/ClimateNA_createTiles.R
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ sqlite_connect_db <- function(dbfile, readonly = FALSE) {
## dbplyr is an Import: without it every tile lookup fails, as R CMD check without Suggests showed.
ClimateNA_sql <- function(dbfile, type, readonly = FALSE) {
db <- sqlite_connect_db(dbfile, readonly = readonly)
## the caller owns the connection once it is returned; close it if anything below fails
## (e.g. a read-only lookup of a table the file lacks)
returned <- FALSE
on.exit(if (!returned) DBI::dbDisconnect(db), add = TRUE)

df_template <- switch(
type,
Expand All @@ -172,7 +176,8 @@ ClimateNA_sql <- function(dbfile, type, readonly = FALSE) {
zipfile = "CHARACTER", ## relative file path
archived = "DATETIME", ## timestamp of when tile set archive was created (zipped)
gid = "CHARACTER", ## google drive file id; archives built by decade, so there will be dupe gids
uploaded = "DATETIME" ## timestamp of when archive uploaded to google drive
uploaded = "DATETIME", ## timestamp of when archive uploaded to google drive
climatena_version = "CHARACTER" ## ClimateNA version that produced this year/period
),
future_normals = c(
id = "INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE",
Expand All @@ -185,7 +190,8 @@ ClimateNA_sql <- function(dbfile, type, readonly = FALSE) {
zipfile = "CHARACTER", ## relative file path
archived = "DATETIME", ## timestamp of when tile set archive was created (zipped)
gid = "CHARACTER", ## google drive file id; archives built by decade, so there will be dupe gids
uploaded = "DATETIME" ## timestamp of when archive uploaded to google drive
uploaded = "DATETIME", ## timestamp of when archive uploaded to google drive
climatena_version = "CHARACTER" ## ClimateNA version that produced this year/period
),
historical = c(
id = "INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE",
Expand All @@ -196,7 +202,8 @@ ClimateNA_sql <- function(dbfile, type, readonly = FALSE) {
zipfile = "CHARACTER", ## relative file path
archived = "DATETIME", ## timestamp of when tile set archive was created (zipped)
gid = "CHARACTER", ## google drive file id; archives built by decade, so there will be dupe gids
uploaded = "DATETIME" ## timestamp of when archive uploaded to google drive
uploaded = "DATETIME", ## timestamp of when archive uploaded to google drive
climatena_version = "CHARACTER" ## ClimateNA version that produced this year/period
),
future = c(
id = "INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE",
Expand All @@ -209,7 +216,8 @@ ClimateNA_sql <- function(dbfile, type, readonly = FALSE) {
zipfile = "CHARACTER", ## relative file path
archived = "DATETIME", ## timestamp of when tile set archive was created (zipped)
gid = "CHARACTER", ## google drive file id; archives built by decade, so there will be dupe gids
uploaded = "DATETIME" ## timestamp of when archive uploaded to google drive
uploaded = "DATETIME", ## timestamp of when archive uploaded to google drive
climatena_version = "CHARACTER" ## ClimateNA version that produced this year/period
)
)

Expand All @@ -221,6 +229,7 @@ ClimateNA_sql <- function(dbfile, type, readonly = FALSE) {

df <- dplyr::tbl(db, tbl)

returned <- TRUE
return(list(db = db, df = df))
}

Expand Down Expand Up @@ -280,6 +289,92 @@ checksums_sql <- function(dbfile, type) {
return(list(db = db, df = df))
}

## The data release behind an index: one row, written by the pipeline (data-raw/pipeline/) and
## read by climateDataRelease(). Written with explicit SQL types.
.releaseCreate <- function(db) {
DBI::dbExecute(
db,
"CREATE TABLE IF NOT EXISTS release (
release_id TEXT NOT NULL, -- e.g. cna-v7.70-3arcmin
climatena_version TEXT NOT NULL, -- ClimateNA release that produced the data
dem_resolution TEXT NOT NULL, -- e.g. 3arcmin, 1arcmin
created REAL NOT NULL -- epoch seconds
)"
)
invisible(db)
}

.releaseWrite <- function(db, df) {
DBI::dbExecute(db, "DELETE FROM release")
DBI::dbExecute(
db,
"INSERT INTO release (release_id, climatena_version, dem_resolution, created) VALUES (?, ?, ?, ?)",
params = unname(as.list(df[
1,
c("release_id", "climatena_version", "dem_resolution", "created")
]))
)
invisible(db)
}

## Land cells ClimateNA left empty, filled from its point-mode output at the nearest land cell it
## covers (data-raw/pipeline/R/fill.R): one row per cell and class (historical: historical years
## and normals; future: future years and normals). A cell left empty (no source within reach)
## has NULL src_lon, src_lat and km. Written by the pipeline, read by filledCells().
.filledCellsColumns <- c(
"class",
"tileid",
"cell",
"lon",
"lat",
"elev",
"src_lon",
"src_lat",
"km"
)

.filledCellsCreate <- function(db) {
DBI::dbExecute(
db,
"CREATE TABLE IF NOT EXISTS filled_cells (
class TEXT NOT NULL, -- historical | future
tileid INTEGER NOT NULL,
cell INTEGER NOT NULL, -- cell in the tile's DEM grid, row by row from the top left
lon REAL NOT NULL, -- cell centre
lat REAL NOT NULL,
elev REAL NOT NULL, -- the cell's DEM elevation (m), which ClimateNA was run with
src_lon REAL, -- where ClimateNA was run; NULL if the cell is left empty
src_lat REAL,
km REAL, -- distance from the cell's centre to the source
PRIMARY KEY (class, tileid, cell)
)"
)
invisible(db)
}

## Replace the table's rows with `df` (as pipeline_fill_points() gives it: `tile` for tileid, and
## the elevation as text).
.filledCellsWrite <- function(db, df) {
if (!"tileid" %in% names(df)) {
df$tileid <- df$tile
}
df$tileid <- as.integer(df$tileid)
df$cell <- as.integer(df$cell)
df$elev <- as.numeric(df$elev)
DBI::dbExecute(db, "DELETE FROM filled_cells")
if (nrow(df) > 0) {
sql <- paste0(
"INSERT INTO filled_cells (",
paste(.filledCellsColumns, collapse = ", "),
") VALUES (",
paste(rep("?", length(.filledCellsColumns)), collapse = ", "),
")"
)
DBI::dbExecute(db, sql, params = unname(as.list(df[.filledCellsColumns])))
}
invisible(db)
}

## One fingerprint per published zip (see data-raw/06-archive_fingerprints.R).
## Written with explicit SQL types: dplyr::rows_*() would remap them.
.archivesColumns <- c("gid", "type", "zipfile", "md5", "n_files", "size", "verified")
Expand Down
Loading
Loading