From 9da5e23f37f74925d664ef1cd1b90a69063e32bb Mon Sep 17 00:00:00 2001 From: Eliot McIntire Date: Fri, 4 Dec 2026 17:06:20 -0700 Subject: [PATCH 1/2] Add scoreELFs: score only the named ELFs; bump version to 0.0.0.9032 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Lx3DXhXsFis2pbqBTh2PPh --- NEWS.md | 2 ++ fireSimulator_validation.R | 13 ++++++++++--- tests/testthat/test-module.R | 13 +++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index a688e63..069d6ac 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # fireSimulator_validation (development version) +* New parameter `scoreELFs`: the ELFs of `hindcastPath` to read and score (less `skipELFs`). The default, empty, reads every finished ELF as before. A named ELF that has not finished stops the job and is named in the message. In a campaign whose jobs each score one ELF, the jobs no longer all read every ELF (they waited on each other's cache locks). + * Fix: S9 placed every fire's circle with the wrong grid. `readHindcastLocation()` stored the ignition maps' grid (960 m in the fireSense hindcasts) as `burn$grid`, but the burn cells are numbered on the burn maps' 240 m grid (`core`), so `gridXY()` put the cells and starts in the wrong places. `burn$grid` is now `gridOf(core)`. On ELF 14.3 (lp05 in-sample, 141 fires) the median AUC goes from 0.94 to 0.72, AUC minus the distance-only baseline from +0.28 to -0.08, and the share of a fire inside its circle from 0.42 to 0.93. Every S9 value scored before this fix is wrong. `writeSeededFires()` failed on the same grid ("no valid cells"). The cached ELF reads are rebuilt once. * S8 and S9 per parameter set, and the seeded fires as maps. `scoreBySet()` now also scores S8 (size given escape) and S9 (shape given escape) of each set of an in-sample ELF: columns `S8_rho`, `S8_log2ratio`, `S9_aucDiff`, `S9_auc`, `S9_aucDist`, `S9_shareInside`, `S8_nFires`, `S9_nFires`, with `_runLo`/`_runHi` (the ELF rows of `escapeResultRows()`). `elfOfSet()` now keeps only the set's runs in `location$seeded$sizes` and `location$burn` too; before, it subset only `simYears` and `simSizes`. To split the burns by set, `readHindcastLocation()` records the run of each burn map (`burn$runIds`, from `hindcast_reps.csv`, new `burnRunIds()`) and keeps each burned cell's fire (`fire`, its burn ID), and `readHindcastSeeded()` keeps `fire` in `sizes`; the grid also carries its `crs`. New `writeSeededFires()`: `writeOutputs` writes, for each in-sample ELF, `/seededFires//_/observed.tif` and `predicted.tif` (one layer per run, `set_rep`), holding exactly the cells S8 and S9 score (1 burned, 0 burnable and not burned, NA not scored, so lakes are NA), with `fires.csv`; a predicted layer holds only the fire grown from that start. `bySet` defaults to `NA`: score by set when some ELF's runs are of more than one set. The cached ELF reads are rebuilt once. diff --git a/fireSimulator_validation.R b/fireSimulator_validation.R index 7b52fb3..73c8650 100644 --- a/fireSimulator_validation.R +++ b/fireSimulator_validation.R @@ -8,7 +8,7 @@ defineModule(sim, list( keywords = c("fire", "validation", "hindcast", "CRPS"), authors = c(person("Eliot", "McIntire", email = "eliot.mcintire@nrcan-rncan.gc.ca", role = c("aut", "cre"))), childModules = character(0), - version = list(fireSimulator_validation = "0.0.0.9031"), + version = list(fireSimulator_validation = "0.0.0.9032"), timeframe = as.POSIXlt(c(NA, NA)), timeunit = "year", citation = list(), @@ -86,6 +86,9 @@ defineModule(sim, list( "Mode 'weights': bySet scores of other years to select on (to tune and report on the same ELFs). NA: `weightsBySet`.", cacheKey = FALSE), # only .inputObjects (never cached) reads the files; what it read is in init's key defineParameter("skipELFs", "character", character(0), NA, NA, "ELFs of hindcastPath left out."), + defineParameter("scoreELFs", "character", character(0), NA, NA, + "ELFs of hindcastPath to read and score, less skipELFs; each must have finished all hindcastYears. Empty: every finished ELF. One per job lets the jobs of a campaign run without reading each other's ELFs.", + cacheKey = FALSE), # only .inputObjects (never cached) reads it; the ELFs it gives are in init's key defineParameter("inputsPath", "character", NA_character_, NA, NA, "Folder of the ELF input folders: // has rtml_.tif, the spread-fit ledger fireSenseParams_*.rds and the NFDB_point_*.shp and NBAC_merged_*.shp observations (the latest of each).", cacheKey = FALSE), # as hindcastPath @@ -125,8 +128,12 @@ scoredMinHa <- function(p) if (is.na(p$minHa)) p$escapeSizeHa else p$minHa hc <- P(sim)$hindcastPath; yrs <- P(sim)$hindcastYears; sets <- P(sim)$hindcastSets; inp <- P(sim)$inputsPath obsDir <- file.path(outputPath(sim), "obs"); dir.create(obsDir, recursive = TRUE, showWarnings = FALSE) elfDir <- file.path(outputPath(sim), "elfs"); dir.create(elfDir, recursive = TRUE, showWarnings = FALSE) - done <- Filter(function(e) length(hindcastFinishedYears(hc, e, yrs, sets)) == length(yrs), - setdiff(list.files(hc), P(sim)$skipELFs)) + isDone <- function(e) length(hindcastFinishedYears(hc, e, yrs, sets)) == length(yrs) + wanted <- setdiff(if (length(P(sim)$scoreELFs)) P(sim)$scoreELFs else list.files(hc), P(sim)$skipELFs) + done <- Filter(isDone, wanted) + if (length(P(sim)$scoreELFs) && length(unfinished <- setdiff(wanted, done))) + stop("scoreELFs not finished in ", hc, " (no hindcast of every one of hindcastYears ", min(yrs), "-", max(yrs), " in hindcastSets ", paste(sets, collapse = ", "), "): ", + paste(unfinished, collapse = ", ")) sim$validationELFs <- readHindcastELFs(done, hc, years = yrs, sets = sets, inputsDir = inp, ledgerSuffix = P(sim)$ledgerSuffix, covariateDir = if (is.na(P(sim)$covariatePath)) hc else P(sim)$covariatePath, obsCacheDir = obsDir, elfCacheDir = elfDir, fireCauses = P(sim)$fireCauses, diff --git a/tests/testthat/test-module.R b/tests/testthat/test-module.R index 5c41e89..fda90ea 100644 --- a/tests/testthat/test-module.R +++ b/tests/testthat/test-module.R @@ -274,3 +274,16 @@ test_that("readHindcastELFs: the same hindcast under another root is a cache hit do.call(readHindcastELFs, elfReadArgs(root, "1.1", dtReader)) expect_equal(length(readLines(counter)), 1L) }) + +test_that("scoreELFs reads and scores only the named ELFs; a named ELF that has not finished stops the job naming it", { + skip_if_not_installed("SpaDES.core") + root <- withr::local_tempdir() + a <- toyElf(seed = 3, name = "9.9"); b <- toyElf(seed = 4, name = "7.7") + hc <- toyHindcastFiles(a, root); toyHindcastFiles(b, root) + dir.create(file.path(hc, "8.8")) # an ELF with no finished year + elfsOf <- function(sim) vapply(sim$validationELFs, `[[`, "", "elf") + expect_setequal(elfsOf(runToyModule(root, a, hc)), c("9.9", "7.7")) # default: every finished ELF + expect_equal(elfsOf(runToyModule(root, a, hc, scoreELFs = "7.7")), "7.7") + expect_equal(elfsOf(runToyModule(root, a, hc, scoreELFs = c("7.7", "9.9"), skipELFs = "9.9")), "7.7") + expect_error(runToyModule(root, a, hc, scoreELFs = c("7.7", "8.8")), "8.8") +}) From 3bf1269eb6872e493353021063ebc16bebde320d Mon Sep 17 00:00:00 2001 From: Eliot McIntire Date: Fri, 4 Dec 2026 17:14:24 -0700 Subject: [PATCH 2/2] scoreELFs: say when a named ELF has no folder, or all are skipped Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Lx3DXhXsFis2pbqBTh2PPh --- fireSimulator_validation.R | 4 ++++ tests/testthat/test-module.R | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/fireSimulator_validation.R b/fireSimulator_validation.R index 73c8650..54778b0 100644 --- a/fireSimulator_validation.R +++ b/fireSimulator_validation.R @@ -130,6 +130,10 @@ scoredMinHa <- function(p) if (is.na(p$minHa)) p$escapeSizeHa else p$minHa elfDir <- file.path(outputPath(sim), "elfs"); dir.create(elfDir, recursive = TRUE, showWarnings = FALSE) isDone <- function(e) length(hindcastFinishedYears(hc, e, yrs, sets)) == length(yrs) wanted <- setdiff(if (length(P(sim)$scoreELFs)) P(sim)$scoreELFs else list.files(hc), P(sim)$skipELFs) + if (length(P(sim)$scoreELFs)) { + if (!length(wanted)) stop("every ELF of scoreELFs is also in skipELFs: ", paste(P(sim)$scoreELFs, collapse = ", ")) + if (length(missing <- setdiff(wanted, list.files(hc)))) stop("scoreELFs not in hindcastPath ", hc, ": ", paste(missing, collapse = ", ")) + } done <- Filter(isDone, wanted) if (length(P(sim)$scoreELFs) && length(unfinished <- setdiff(wanted, done))) stop("scoreELFs not finished in ", hc, " (no hindcast of every one of hindcastYears ", min(yrs), "-", max(yrs), " in hindcastSets ", paste(sets, collapse = ", "), "): ", diff --git a/tests/testthat/test-module.R b/tests/testthat/test-module.R index fda90ea..bd2ea32 100644 --- a/tests/testthat/test-module.R +++ b/tests/testthat/test-module.R @@ -285,5 +285,7 @@ test_that("scoreELFs reads and scores only the named ELFs; a named ELF that has expect_setequal(elfsOf(runToyModule(root, a, hc)), c("9.9", "7.7")) # default: every finished ELF expect_equal(elfsOf(runToyModule(root, a, hc, scoreELFs = "7.7")), "7.7") expect_equal(elfsOf(runToyModule(root, a, hc, scoreELFs = c("7.7", "9.9"), skipELFs = "9.9")), "7.7") - expect_error(runToyModule(root, a, hc, scoreELFs = c("7.7", "8.8")), "8.8") + expect_error(runToyModule(root, a, hc, scoreELFs = c("7.7", "8.8")), "not finished.*8.8") + expect_error(runToyModule(root, a, hc, scoreELFs = c("7.7", "6.6")), "not in hindcastPath.*6.6") # no folder: a typo + expect_error(runToyModule(root, a, hc, scoreELFs = "7.7", skipELFs = "7.7"), "also in skipELFs") })