Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# fireSense_dataPrepFit 1.3.0.9011 (development version)

- New parameter `fitFileSuffix` (default `""`), the same in `fireSense_spreadFit`, `fireSense_ignitionFit` and `fireSense_ELFs` (checked with `paramCheckOtherMods()`): with `spreadFitFilename = "latest"`, the SpreadFit ledger is read from the files with that suffix only (`fireSenseUtils::latestSpreadFits(suffix =)`), so a test run never reads the production fits. `""` is unchanged. Needs fireSenseUtils (>= 0.2.3.9104).
- R CMD check of the module's package form has no notes: `NEWS.md` had two "(development version)" headings and none with a version, so it could not be parsed (one heading now, with the version), undefined names are declared (`R/globals.R`), and `methods`, `stats` and `utils` are in `reqdPkgs` for `is()`, `setNames()`, `var()`, `getFromNamespace()` and `modifyList()`. No change to results. One check warning remains: `SpaDES.core::convertToPackage()` writes `import()` for every `reqdPkgs` entry, so the whole-package imports clash ("replacing previous import").

- Fixed: `.inputObjects` (1-2 h of data preparation per ELF) was redone whenever the SpreadFit ledger changed, e.g. when any ELF's fit landed, because `spreadFitPreRun` was declared as an input and `fireSense_ELFs` puts the whole ledger in the simList before `.inputObjects` runs. It is now an output only. `.inputObjects` never reads it; `Init()` always assigns it (this study area's rows from `CacheGeo`, or `NULL`), and `dataPrepBuild`, `prepIgnitionFitData`, `prepEscapeFitData` and `prepSpreadFitData` key on it through `.useCacheArgs`, so a new fit of this study area still re-runs them and a cached event cannot restore an old row. Results are unchanged; the `.inputObjects` key changes once.
Expand Down
6 changes: 4 additions & 2 deletions R/readSpreadFitLedger.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
#' (`prepInputs()` would otherwise find its checksum changed and try to download it).
#'
#' @param spreadFitFilename The module's `spreadFitFilename`: a file in `cloudFolderID`, or `"latest"`.
#' @param fitFileSuffix With `"latest"`, only ledger files with this suffix are read; see
#' `fireSenseUtils::spreadFitFilenameFor()`.
#' @param cloudFolderID The Google Drive folder holding the ledger files.
#' @param domain The study area, an `sf` object.
#' @param destinationPath Where the ledger files are downloaded.
#' @return What `CacheGeo()` returns: the ledger rows within `domain`, or `NULL`.
readSpreadFitLedger <- function(spreadFitFilename, cloudFolderID, domain, destinationPath) {
readSpreadFitLedger <- function(spreadFitFilename, cloudFolderID, domain, destinationPath, fitFileSuffix = "") {
purge <- 7 # download the named file again: it changes on Drive
if (identical(spreadFitFilename, "latest")) {
latest <- fireSenseUtils::latestSpreadFits(cloudFolderID, destinationPath)
latest <- fireSenseUtils::latestSpreadFits(cloudFolderID, destinationPath, suffix = fitFileSuffix)
if (is.null(latest))
return(NULL)
tf <- tempfile(fileext = ".rds")
Expand Down
11 changes: 9 additions & 2 deletions fireSense_dataPrepFit.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ defineModule(sim, list(
reqdPkgs = list("data.table", "fastDummies", "Require",
"PredictiveEcology/reproducible@development (>= 3.2.1.9042)", # CacheGeo re-reads a changed local file
"PredictiveEcology/climateData@development (>= 2.2.3.9006)",
"PredictiveEcology/fireSenseUtils@development (>= 0.2.3.9100)", # dataYearBefore(), dataYearElement(before =); defaultFireYears() from 1986
"PredictiveEcology/fireSenseUtils@development (>= 0.2.3.9104)", # dataYearBefore(), dataYearElement(before =); defaultFireYears() from 1986
"FOR-CAST/fireregimetools@main (>= 0.1.0.9008)",
"ggplot2", "methods", "parallel", "purrr", "raster", "sf", "sp", "stats", "utils",
"PredictiveEcology/LandR@development (>= 1.2.0.9015)",
Expand Down Expand Up @@ -115,6 +115,12 @@ defineModule(sim, list(
"the species, fuel and climate objects itself, as for an unfitted study area.",
"Set it for every fireSense module at once with `.globals = list(heldOutFold = 1L)`;",
"`Init()` stops if `fireSense_spreadFit` has a different value. Any other value is an error.")),
defineParameter("fitFileSuffix", "character", "", NA, NA,
paste("Text put after the model tag in the ledger file names, e.g. `\"_boundfix_rep81\"`, so a test run",
"writes and reads (`\"latest\"`) only its own files, never the production ones. `\"\"` (the",
"default) is the production ledger. The same parameter of `fireSense_spreadFit`, `fireSense_ignitionFit` and `fireSense_ELFs`;",
"set it for all with `.globals = list(fitFileSuffix = ...)`; modules that disagree stop",
"(`SpaDES.core::paramCheckOtherMods()`). Ignored when a file name is given.")),
defineParameter("spreadFitGoogleDriveFolder", "character",
fireSenseUtils::spreadFitLedgerFolder(),
NA, NA, paste("URL of the Google Drive folder holding the ledger of previous SpreadFit results",
Expand Down Expand Up @@ -415,7 +421,8 @@ Init <- function(sim) {
paste(format(heldOutFold), collapse = ", "))
sim$spreadFitPreRun <- if (isTRUE(is.na(heldOutFold))) {
readSpreadFitLedger(Par$spreadFitFilename, Par$spreadFitGoogleDriveFolder,
domain = sa, destinationPath = inputPath(sim))
domain = sa, destinationPath = inputPath(sim),
fitFileSuffix = SpaDES.core::paramCheckOtherMods(sim, "fitFileSuffix"))
}
mod$haveSpreadFit <- is(sim$spreadFitPreRun, "sf") || is(sim$spreadFitPreRun, "data.frame")
if (mod$haveSpreadFit) {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ test_that("parameters are the expected names", {
"forestedLCC", "fuelClassCol", "fuelCovariates", "heldOutFold", "igAggFactor",
"minBufferSize", "minCovariateProp", "nonflammableLCC",
"nonForestCanBeYoungAge", "scanfiVersion", "sppEquivCol", "spreadFitFilename",
"spreadFitGoogleDriveFolder", "spreadIntercept", "targetFuelClasses",
"spreadFitGoogleDriveFolder", "fitFileSuffix", "spreadIntercept", "targetFuelClasses",
"useRasterizedFireForSpread", "whichModulesToPrepare"))
)
})
Expand Down
18 changes: 16 additions & 2 deletions tests/testthat/test-readSpreadFitLedger.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ledger <- function(ids, value) {

test_that("'latest' reads the combined ledger and keeps only this study area's rows", {
d <- withr::local_tempdir()
testthat::local_mocked_bindings(latestSpreadFits = function(cloudFolderID, destinationPath, polygonIDs = NULL)
testthat::local_mocked_bindings(latestSpreadFits = function(cloudFolderID, destinationPath, polygonIDs = NULL, suffix = "")
ledger(c("4.1", "4.3"), c(1, 2)), .package = "fireSenseUtils")
domain <- sf::st_as_sf(square(4e4)) # the second polygon, 4.3
out <- suppressMessages(readSpreadFitLedger("latest", "folder", domain, d))
Expand All @@ -26,7 +26,7 @@ test_that("a changed ledger is read again, not returned from an earlier read", {
d <- withr::local_tempdir()
domain <- sf::st_as_sf(square(4e4))
value <- 2
testthat::local_mocked_bindings(latestSpreadFits = function(cloudFolderID, destinationPath, polygonIDs = NULL)
testthat::local_mocked_bindings(latestSpreadFits = function(cloudFolderID, destinationPath, polygonIDs = NULL, suffix = "")
ledger(c("4.1", "4.3"), c(1, value)), .package = "fireSenseUtils")
first <- suppressMessages(readSpreadFitLedger("latest", "folder", domain, d))
value <- 5 # a newer fit of 4.3 arrives
Expand All @@ -48,3 +48,17 @@ test_that("a named file is read from the Drive folder, as before", {
expect_identical(rec$args$cloudFolderID, "folderURL")
expect_identical(rec$args$action, "nothing")
})

test_that("'latest' reads only the files with this run's fitFileSuffix", {
d <- withr::local_tempdir()
asked <- NULL
testthat::local_mocked_bindings(latestSpreadFits = function(cloudFolderID, destinationPath, polygonIDs = NULL, suffix = "") {
asked <<- suffix
ledger("4.3", 2)
}, .package = "fireSenseUtils")
domain <- sf::st_as_sf(square(2e4 * 1))
suppressMessages(readSpreadFitLedger("latest", "folder", domain, d, fitFileSuffix = "_boundfix_rep81"))
expect_identical(asked, "_boundfix_rep81")
suppressMessages(readSpreadFitLedger("latest", "folder", domain, d))
expect_identical(asked, "")
})
Loading