Skip to content

Commit

Permalink
new function for landscape burn summary
Browse files Browse the repository at this point in the history
  • Loading branch information
ianmseddy committed Jan 10, 2025
1 parent b680604 commit bd6ab89
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Type: Package
Title: Utilities for Working With the 'fireSense' Group of 'SpaDES' Modules
Description: Utilities for working with the 'fireSense' group of 'SpaDES' modules.
Date: 2024-12-20
Version: 0.0.5.9078
Version: 0.0.5.9079
Authors@R: c(
person("Jean", "Marchal", email = "[email protected]",
role = c("aut")),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export(cohortsToFuelClasses)
export(compareMDC)
export(dtReplaceNAwith0)
export(extractSpecial)
export(fuelClassPrep)
export(getFirePoints_NFDB)
export(getFirePoints_NFDB_V2)
export(getFirePolygons)
Expand Down
37 changes: 37 additions & 0 deletions R/fuelClassPrep.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#' Calculate proportional burn of landcover and tree species
#'
#' @template pixelGroupMap
#' @template cohortData
#' @param rstLCC a landcover map
#' @param nonflammableLCC nonflammable landcover in rstLCC
#' @param fires a single sf or SpatVector object of fire polygons containing a YEAR coumn
#' @param yearRange the range of years represented by this landscape
#'
#' @return a data.table with cell, biomass, tree species or lcc for non-forest, and year of fire
#' @export
#'
#' @examples
#' fuelclassPrep(sim$pixelGroupMap2011, sim$cohortData2011, sim$rstLCC2011,
#' nonflammableLCC = P(sim)$nonflammableLCC< yearRange = c(2012, 2020))
fuelClassPrep <- function(pixelGroupMap, cohortData, rstLCC, nonflammableLCC, fires, yearRange) {
# Filter fires by year range
firesSubset <- fires[fires$YEAR >= yearRange[1] & fires$YEAR <= yearRange[2], ] |>
rasterize(pixelGroupMap, field = "YEAR", fun = "min") |>
as.data.frame(cells = TRUE) |> as.data.table()

# Add pixels to cohort data
speciesData <- addPixels2CohortData(cohortData = cohortData, pixelGroupMap)

# Prepare landscape data excluding non-flammable land cover classes
landscapeData <- as.data.table(as.data.frame(rstLCC, cells = TRUE)) |>
setnames(c("cell", "lcc"))
landscapeData <- landscapeData[!lcc %in% nonflammableLCC]

# Merge species data with landscape data
landscapeData <- speciesData[landscapeData, on = c("pixelIndex" = "cell")]

# Merge fires data with landscape data
landscapeData <- firesSubset[landscapeData, on = c("cell" = "pixelIndex")]

return(landscapeData)
}
41 changes: 41 additions & 0 deletions man/fuelClassPrep.Rd

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

0 comments on commit bd6ab89

Please sign in to comment.