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
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Description: Builds landscape inputs for Canadian forest models from national
disturbances.
URL: https://github.com/PredictiveEcology/forestInputs
BugReports: https://github.com/PredictiveEcology/forestInputs/issues
Version: 0.0.1.9001
Version: 0.0.1.9002
Authors@R: c(
person("Eliot J B", "McIntire", email = "eliot.mcintire@nrcan-rncan.gc.ca",
role = c("aut", "cre"), comment = c(ORCID = "0000-0002-6914-8316")),
Expand All @@ -34,7 +34,8 @@ Imports:
utils
Suggests:
curl,
httr2,
googledrive,
raster,
testthat (>= 3.0.0),
withr
Remotes:
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# forestInputs (development version)

* `prepInputsFireYear()` reads a fire year stored as text as the year. It gave factor codes 1, 2, ...,
so the map was entirely `NA` (#4).
* `prepInputsDisturbanceYear(polygon = )` no longer partially matches `polygonAgreement`, because
`polygonsBefore` shares the prefix; give the full name.
* Cached calls of `prepInputsFireYear()`, including the one inside `prepInputsStandAgeMap()`, run again
once after upgrading from LandR, because `Cache()` keys include the function's code.
* `inputsTable()`: the SCANFI stand age rows have `access = restricted` (their `url` is a shared Google
Drive folder); the public copies are in `mirror`.
* `prepInputsDisturbanceYear()` takes regional settings, each defaulting to the current rule, so results do not
change unless they are set (from Julie Turner's test in the southern interior BC mountains):
`polygonsBefore` (before it an NFDB polygon counts without Pre-CanLaD; `1950` counts Pre-CanLaD alone),
Expand Down
5 changes: 4 additions & 1 deletion R/inputs.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
#' functions here read by default, with where each comes from. The columns follow the inputs
#' table of hsaCEtool (`name`, `title`, `theme`, `url`, `path`, `target_file`, `archive`,
#' `access`, `provider`, `terms`, `notes`), plus `year` (the year or years a row covers) and
#' `mirror` (a public copy of `url`, used when `url` cannot be reached). A `%d` in `url` and
#' `mirror` (a public copy of `url`; the SCANFI readers use it through [scanfiUrlRemap()]). A `%d` in `url` and
#' `target_file` stands for the year, for inputs with one file per year.
#'
#' `access` is `public` when anyone can download `url`, and `restricted` when `url` needs
#' permission (e.g., a shared Google Drive folder).
#'
#' The function defaults read their URLs from this table, so a moved file is fixed here once.
#' The table is `system.file("extdata", "inputs.csv", package = "forestInputs")`.
#'
Expand Down
14 changes: 0 additions & 14 deletions R/scanfi-access.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,3 @@
call. = FALSE)
})
}

## ---------------------------------------------------------------------------
## Messaging for SCANFI v3 access failures
##
## V3 is served directly by NRCan (no Google Drive layer), so a failure here is
## usually a network hiccup or an outage, not a permissions problem, and the
## guidance differs from .withSCANFIAccess() above.
## ---------------------------------------------------------------------------

## Where else to get v3 if the https server is unreachable.
.scanfiV3FTPURL <- "ftp://ftp.maps.canada.ca/pub/nrcan_rncan/Forests_Foret/SCANFI/v3/"

## Does this error look like the v3 https server refusing or dropping us? A bare status
## code is enough here because this is only ever applied to a known SCANFI v3 fetch.
18 changes: 10 additions & 8 deletions R/standAge.R
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ prepInputsStandAgeMap <- function(
#'
#' @export
#'
#' @examplesIf !isTRUE(as.logical(Sys.getenv("CI")))
#' @examplesIf !isTRUE(as.logical(Sys.getenv("CI"))) && requireNamespace("withr", quietly = TRUE)
#' ## NOTE: runs locally, skipped on CI -- downloads NFDB_poly.zip from
#' ## cwfis.cfs.nrcan.gc.ca (same predicate as testthat::skip_on_ci())
#' withr::local_options(list(
Expand Down Expand Up @@ -378,12 +378,6 @@ prepInputsFireYear <- function(..., rasterToMatch, fireField = "YEAR", earliestY
if (!terra::same.crs(allFires, rasterToMatch)) {
allFires <- terra::project(allFires, rasterToMatch)
}
yr <- as.data.frame(allFires)[[fireField]]
if (!is.numeric(yr)) {
warning("Chosen fireField will be coerced to numeric")
allFires[[fireField]] <- as.numeric(as.factor(yr))
}

## fun = max to take the most recent fire year
fireRas <- terra::rasterize(allFires, rasterToMatch, field = fireField, fun = max)
v <- terra::values(fireRas, mat = FALSE)
Expand Down Expand Up @@ -480,6 +474,13 @@ prepInputsFireYear <- function(..., rasterToMatch, fireField = "YEAR", earliestY
## the reason this isn't combined into one function is due to geometry issues in NFDB
allFires <- allFires[terra::is.valid(allFires), ] ## drop invalid geometries

## a year stored as text ("1995") is read as the year; as.factor() gave factor codes 1..k
yr <- as.data.frame(allFires)[[fireField]]
if (!is.numeric(yr)) {
warning("Chosen fireField will be coerced to numeric")
allFires[[fireField]] <- suppressWarnings(as.numeric(as.character(yr)))
}

## rasterize(fun = max) keeps only the latest fire per pixel, which would hide an earlier fire
## from a caller whose data year is before it: drop the later fires first.
if (is.finite(latestYear)) {
Expand All @@ -504,7 +505,8 @@ prepInputsFireYear <- function(..., rasterToMatch, fireField = "YEAR", earliestY
#' Replace stand age with time since last fire
#'
#' @param standAgeMap a raster layer stand age map
#' @param firePerimeters the earliest fire date to allow
#' @param firePerimeters a `SpatRaster` of fire years on the grid of `standAgeMap`,
#' e.g., from [prepInputsFireYear()]
#' @template startTime
#'
#' @return a raster layer stand age map corrected for fires, with an attribute vector of pixel IDs
Expand Down
20 changes: 10 additions & 10 deletions inst/extdata/inputs.csv
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ ntems_fire,NTEMS forest fire year 1985-2022,fire,1985-2022,https://opendata.nfis
ntems_harvest,NTEMS forest harvest year 1985-2022,harvest,1985-2022,https://opendata.nfis.org/downloads/forest_change/CA_Forest_Harvest_1985-2022.zip,,CA_Forest_Harvest_1985-2022.tif,CA_Forest_Harvest_1985-2022.zip,,public,"Canadian Forest Service, NTEMS (NFIS)",,"0 none, else the year"
ntems_fire_2020,NTEMS forest fire year 1985-2020,fire,1985-2020,https://opendata.nfis.org/downloads/forest_change/CA_Forest_Fire_1985-2020.zip,,,CA_Forest_Fire_1985-2020.zip,,public,"Canadian Forest Service, NTEMS (NFIS)",,used to move SCANFI v1 ages from 2020
ntems_harvest_2020,NTEMS forest harvest year 1985-2020,harvest,1985-2020,https://opendata.nfis.org/downloads/forest_change/CA_Forest_Harvest_1985-2020.zip,,,CA_Forest_Harvest_1985-2020.zip,,public,"Canadian Forest Service, NTEMS (NFIS)",,used to move SCANFI v1 ages from 2020
scanfi_age_v1,SCANFI v1 stand age 2020,forest_age,2020,https://drive.google.com/file/d/1OdZ7Tznk53KceEyt9dFOBOkxDHEX5X0U,,,,,public,"Natural Resources Canada, Canadian Forest Service (SCANFI)",,Google Drive folder shared with collaborators
scanfi_age_v2,SCANFI v2 stand age 1985,forest_age,1985,https://drive.google.com/file/d/1KoGbzQZB-wR8LkngAKTZGShDR0ILBK5r,,SCANFI_age_median_1985_v2_20260119.tif,,https://object-arbutus.alliancecan.ca/529feda02d404836b0e91b1d360b4df0:predictiveecology/SCANFI_v2/1985/SCANFI_age_median_1985_v2_20260119.tif,public,"Natural Resources Canada, Canadian Forest Service (SCANFI)",,Google Drive folder shared with collaborators; public copy at mirror
scanfi_age_v2,SCANFI v2 stand age 1990,forest_age,1990,https://drive.google.com/file/d/1083izY1R-uBRdnnJL6KTYTPg3RFKCU6V,,SCANFI_age_median_1990_v2_20260119.tif,,https://object-arbutus.alliancecan.ca/529feda02d404836b0e91b1d360b4df0:predictiveecology/SCANFI_v2/1990/SCANFI_age_median_1990_v2_20260119.tif,public,"Natural Resources Canada, Canadian Forest Service (SCANFI)",,Google Drive folder shared with collaborators; public copy at mirror
scanfi_age_v2,SCANFI v2 stand age 1995,forest_age,1995,https://drive.google.com/file/d/12aqGD4YQKrZXUrzSPIOz2DcVY00mQZAT,,SCANFI_age_median_1995_v2_20260119.tif,,https://object-arbutus.alliancecan.ca/529feda02d404836b0e91b1d360b4df0:predictiveecology/SCANFI_v2/1995/SCANFI_age_median_1995_v2_20260119.tif,public,"Natural Resources Canada, Canadian Forest Service (SCANFI)",,Google Drive folder shared with collaborators; public copy at mirror
scanfi_age_v2,SCANFI v2 stand age 2000,forest_age,2000,https://drive.google.com/file/d/1v-9sx1a_-WqKfuULT80QZ1b0CAI8lLGV,,SCANFI_age_median_2000_v2_20260119.tif,,https://object-arbutus.alliancecan.ca/529feda02d404836b0e91b1d360b4df0:predictiveecology/SCANFI_v2/2000/SCANFI_age_median_2000_v2_20260119.tif,public,"Natural Resources Canada, Canadian Forest Service (SCANFI)",,Google Drive folder shared with collaborators; public copy at mirror
scanfi_age_v2,SCANFI v2 stand age 2005,forest_age,2005,https://drive.google.com/file/d/1HSWZ7aHW9GxfYTI3aAZRz5i2rD9-pymq,,SCANFI_age_median_2005_v2_20260119.tif,,https://object-arbutus.alliancecan.ca/529feda02d404836b0e91b1d360b4df0:predictiveecology/SCANFI_v2/2005/SCANFI_age_median_2005_v2_20260119.tif,public,"Natural Resources Canada, Canadian Forest Service (SCANFI)",,Google Drive folder shared with collaborators; public copy at mirror
scanfi_age_v2,SCANFI v2 stand age 2010,forest_age,2010,https://drive.google.com/file/d/1PIC0pvDUZFx7DfauJvB2WsJjgBgkCaXb,,SCANFI_age_median_2010_v2_20260119.tif,,https://object-arbutus.alliancecan.ca/529feda02d404836b0e91b1d360b4df0:predictiveecology/SCANFI_v2/2010/SCANFI_age_median_2010_v2_20260119.tif,public,"Natural Resources Canada, Canadian Forest Service (SCANFI)",,Google Drive folder shared with collaborators; public copy at mirror
scanfi_age_v2,SCANFI v2 stand age 2015,forest_age,2015,https://drive.google.com/file/d/1_ZGdjepqS3tGHKykAG5SCecic4Qn-Nx-,,SCANFI_age_median_2015_v2_20260119.tif,,https://object-arbutus.alliancecan.ca/529feda02d404836b0e91b1d360b4df0:predictiveecology/SCANFI_v2/2015/SCANFI_age_median_2015_v2_20260119.tif,public,"Natural Resources Canada, Canadian Forest Service (SCANFI)",,Google Drive folder shared with collaborators; public copy at mirror
scanfi_age_v2,SCANFI v2 stand age 2020,forest_age,2020,https://drive.google.com/file/d/1nXPS3bpFUESYieNfXO25OKlZJEgqtRnD,,SCANFI_age_median_2020_v2_20260119.tif,,https://object-arbutus.alliancecan.ca/529feda02d404836b0e91b1d360b4df0:predictiveecology/SCANFI_v2/2020/SCANFI_age_median_2020_v2_20260119.tif,public,"Natural Resources Canada, Canadian Forest Service (SCANFI)",,Google Drive folder shared with collaborators; public copy at mirror
scanfi_age_v2,SCANFI v2 stand age 2025,forest_age,2025,https://drive.google.com/file/d/1mM2z-_sjt9HGv1JQIt2VZkhW_HrldhgT,,SCANFI_age_median_2025_v2_20260119.tif,,https://object-arbutus.alliancecan.ca/529feda02d404836b0e91b1d360b4df0:predictiveecology/SCANFI_v2/2025/SCANFI_age_median_2025_v2_20260119.tif,public,"Natural Resources Canada, Canadian Forest Service (SCANFI)",,Google Drive folder shared with collaborators; public copy at mirror
scanfi_age_v1,SCANFI v1 stand age 2020,forest_age,2020,https://drive.google.com/file/d/1OdZ7Tznk53KceEyt9dFOBOkxDHEX5X0U,,,,,restricted,"Natural Resources Canada, Canadian Forest Service (SCANFI)",,Google Drive folder shared with collaborators
scanfi_age_v2,SCANFI v2 stand age 1985,forest_age,1985,https://drive.google.com/file/d/1KoGbzQZB-wR8LkngAKTZGShDR0ILBK5r,,SCANFI_age_median_1985_v2_20260119.tif,,https://object-arbutus.alliancecan.ca/529feda02d404836b0e91b1d360b4df0:predictiveecology/SCANFI_v2/1985/SCANFI_age_median_1985_v2_20260119.tif,restricted,"Natural Resources Canada, Canadian Forest Service (SCANFI)",,Google Drive folder shared with collaborators; public copy at mirror
scanfi_age_v2,SCANFI v2 stand age 1990,forest_age,1990,https://drive.google.com/file/d/1083izY1R-uBRdnnJL6KTYTPg3RFKCU6V,,SCANFI_age_median_1990_v2_20260119.tif,,https://object-arbutus.alliancecan.ca/529feda02d404836b0e91b1d360b4df0:predictiveecology/SCANFI_v2/1990/SCANFI_age_median_1990_v2_20260119.tif,restricted,"Natural Resources Canada, Canadian Forest Service (SCANFI)",,Google Drive folder shared with collaborators; public copy at mirror
scanfi_age_v2,SCANFI v2 stand age 1995,forest_age,1995,https://drive.google.com/file/d/12aqGD4YQKrZXUrzSPIOz2DcVY00mQZAT,,SCANFI_age_median_1995_v2_20260119.tif,,https://object-arbutus.alliancecan.ca/529feda02d404836b0e91b1d360b4df0:predictiveecology/SCANFI_v2/1995/SCANFI_age_median_1995_v2_20260119.tif,restricted,"Natural Resources Canada, Canadian Forest Service (SCANFI)",,Google Drive folder shared with collaborators; public copy at mirror
scanfi_age_v2,SCANFI v2 stand age 2000,forest_age,2000,https://drive.google.com/file/d/1v-9sx1a_-WqKfuULT80QZ1b0CAI8lLGV,,SCANFI_age_median_2000_v2_20260119.tif,,https://object-arbutus.alliancecan.ca/529feda02d404836b0e91b1d360b4df0:predictiveecology/SCANFI_v2/2000/SCANFI_age_median_2000_v2_20260119.tif,restricted,"Natural Resources Canada, Canadian Forest Service (SCANFI)",,Google Drive folder shared with collaborators; public copy at mirror
scanfi_age_v2,SCANFI v2 stand age 2005,forest_age,2005,https://drive.google.com/file/d/1HSWZ7aHW9GxfYTI3aAZRz5i2rD9-pymq,,SCANFI_age_median_2005_v2_20260119.tif,,https://object-arbutus.alliancecan.ca/529feda02d404836b0e91b1d360b4df0:predictiveecology/SCANFI_v2/2005/SCANFI_age_median_2005_v2_20260119.tif,restricted,"Natural Resources Canada, Canadian Forest Service (SCANFI)",,Google Drive folder shared with collaborators; public copy at mirror
scanfi_age_v2,SCANFI v2 stand age 2010,forest_age,2010,https://drive.google.com/file/d/1PIC0pvDUZFx7DfauJvB2WsJjgBgkCaXb,,SCANFI_age_median_2010_v2_20260119.tif,,https://object-arbutus.alliancecan.ca/529feda02d404836b0e91b1d360b4df0:predictiveecology/SCANFI_v2/2010/SCANFI_age_median_2010_v2_20260119.tif,restricted,"Natural Resources Canada, Canadian Forest Service (SCANFI)",,Google Drive folder shared with collaborators; public copy at mirror
scanfi_age_v2,SCANFI v2 stand age 2015,forest_age,2015,https://drive.google.com/file/d/1_ZGdjepqS3tGHKykAG5SCecic4Qn-Nx-,,SCANFI_age_median_2015_v2_20260119.tif,,https://object-arbutus.alliancecan.ca/529feda02d404836b0e91b1d360b4df0:predictiveecology/SCANFI_v2/2015/SCANFI_age_median_2015_v2_20260119.tif,restricted,"Natural Resources Canada, Canadian Forest Service (SCANFI)",,Google Drive folder shared with collaborators; public copy at mirror
scanfi_age_v2,SCANFI v2 stand age 2020,forest_age,2020,https://drive.google.com/file/d/1nXPS3bpFUESYieNfXO25OKlZJEgqtRnD,,SCANFI_age_median_2020_v2_20260119.tif,,https://object-arbutus.alliancecan.ca/529feda02d404836b0e91b1d360b4df0:predictiveecology/SCANFI_v2/2020/SCANFI_age_median_2020_v2_20260119.tif,restricted,"Natural Resources Canada, Canadian Forest Service (SCANFI)",,Google Drive folder shared with collaborators; public copy at mirror
scanfi_age_v2,SCANFI v2 stand age 2025,forest_age,2025,https://drive.google.com/file/d/1mM2z-_sjt9HGv1JQIt2VZkhW_HrldhgT,,SCANFI_age_median_2025_v2_20260119.tif,,https://object-arbutus.alliancecan.ca/529feda02d404836b0e91b1d360b4df0:predictiveecology/SCANFI_v2/2025/SCANFI_age_median_2025_v2_20260119.tif,restricted,"Natural Resources Canada, Canadian Forest Service (SCANFI)",,Google Drive folder shared with collaborators; public copy at mirror
knn_age,kNN stand age 2001,forest_age,2001,https://ftp.maps.canada.ca/pub/nrcan_rncan/Forests_Foret/canada-forests-attributes_attributs-forests-canada/2001-attributes_attributs-2001/NFI_MODIS250m_2001_kNN_Structure_Stand_Age_v1.tif,,NFI_MODIS250m_2001_kNN_Structure_Stand_Age_v1.tif,,,public,"Natural Resources Canada, Canadian Forest Service (NFI kNN)",,250 m
knn_age,kNN stand age 2011,forest_age,2011,https://ftp.maps.canada.ca/pub/nrcan_rncan/Forests_Foret/canada-forests-attributes_attributs-forests-canada/2011-attributes_attributs-2011/NFI_MODIS250m_2011_kNN_Structure_Stand_Age_v1.tif,,NFI_MODIS250m_2011_kNN_Structure_Stand_Age_v1.tif,,,public,"Natural Resources Canada, Canadian Forest Service (NFI kNN)",,250 m
5 changes: 4 additions & 1 deletion man/inputsTable.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/prepInputsFireYear.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/replaceAgeInFires.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading