Skip to content

Commit

Permalink
automated non-forest covers, fix doc
Browse files Browse the repository at this point in the history
  • Loading branch information
ianmseddy committed Jan 23, 2025
1 parent 0427543 commit d692c28
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 21 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ Imports:
Suggests:
cowplot,
dplyr,
ggplot2,
knitr,
lintr,
PtProcess,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ importFrom(stats,dbinom)
importFrom(stats,dnorm)
importFrom(stats,glm)
importFrom(stats,is.empty.model)
importFrom(stats,kmeans)
importFrom(stats,lm)
importFrom(stats,median)
importFrom(stats,model.matrix)
Expand Down
22 changes: 10 additions & 12 deletions R/fuelClassPrep.R
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
utils::globalVariables(c(
"burned", "burnprob", "cell", "lcc", "pixelIndex", "speciesCode", "YEAR", "yearRange",
"absCoef", "possGroups", "propB", "pvalue", "sig", "sim", "species", "above10PctRelB",
"assignedFuelClass", "B_MgHa", "coef"
"above10PctRelB", "absCoef", "assignedFuelClass", "B_MgHa", "burned", "burnprob",
"cell", "coef", "lcc", "pixelIndex", "newName", "possGroups", "propB",
"pvalue", "sig", "sim", "species","speciesCode", "YEAR", "yearRange"
))

#' Calculate proportional burn of landcover and tree species
#'
#' @template pixelGroupMap
#'
#' @template cohortData
#'
#' @param rstLCC a landcover map
#'
#' @param nonflammableLCC nonflammable landcover in `rstLCC`
#'
#' @param nonforestLCC vector or list of vectors of flammable nonforest LCC
#' @param fires a single `sf` or `SpatVector` object of fire polygons containing a `YEAR` column
#'
#' @param yearRange the range of years represented by this landscape
#'
#' @return `data.table` with cell, biomass, tree species or lcc for non-forest, and year of fire
#'
#' @examples
#' # fuelClassPrep(
#' # sim$pixelGroupMap2011, sim$cohortData2011, sim$rstLCC2011,
#' # rstLCC = sim$rstLCC2011, nonForestLCC = sim$nonForestLCCGroups,
#' # nonflammableLCC = P(sim)$nonflammableLCC,
#' # fires = TODO,
#' # fires = do.call(rbind, sim$spreadFirePolys),
#' # yearRange = c(2012, 2020)
#' # )
#'
Expand Down Expand Up @@ -65,6 +62,7 @@ fuelClassPrep <- function(pixelGroupMap, cohortData, rstLCC,
#'
#' @param fuel vector of tree species or lcc in landscape by which to subset
#' @param landscape created by `fuelClassPrep`
#' @param form the formula to use - as a character
#' @importFrom stats glm binomial
makeGLM <- function(fuel, landscape, form) {

Expand All @@ -76,12 +74,12 @@ makeGLM <- function(fuel, landscape, form) {
#'
#' @param landscape data.table created by `prepFuelClasses`
#' @param fuelCol the column in `sppEquiv` with default fuel classes
#' @param rstLCC a landcover map
#' @template sppEquiv
#' @template sppEquivCol
#' @param targetNonForestClasses the number of non-forest fuel classes to generate
#' @param targetFuelClasses target number of fuel classes to generate
#' @param yearRange the range of years represented by this landscape
#' @param targetFuelClasses target number of treed fuel classes to generate
#' @param nonforestLCC vector or list of vectors of non-forest fuel classes
#' @param pValue for glm coef significance when deciding to merge fuel classes
#' @importFrom data.table melt
#' @importFrom stats coefficients binomial glm kmeans
#' @export
Expand Down
26 changes: 22 additions & 4 deletions man/assessFuelClasses.Rd

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

6 changes: 5 additions & 1 deletion man/fuelClassPrep.Rd

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

2 changes: 2 additions & 0 deletions man/makeGLM.Rd

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

6 changes: 3 additions & 3 deletions tests/testthat/test-fuelClasses.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test_that("combine_fuel_classes behaves reasonably", {

#birch and aspen will be combined, fir will not be combined with Picea
out <- combine_fuel_classes(tempDF)
expect_true("PopBrch" %in% out$assignedFuelClass)
expect_true("Bt_p.Pp_t" %in% out$assignedFuelClass)
expect_true("Abie_las" %in% out$assignedFuelClass)

#with birch positive instead of negative
Expand Down Expand Up @@ -41,7 +41,7 @@ test_that("combine_fuel_classes behaves reasonably", {
#Abie_las should NOT be combined
out <- combine_fuel_classes(tempDF3)
expect_true("Abie_las" %in% out$assignedFuelClass)
expect_true("LdJkPine" %in% out$assignedFuelClass)
expect_true("PopBrch" %in% out$assignedFuelClass)
expect_true("Pn_b.Pn_c" %in% out$assignedFuelClass)
expect_true("Bt_p.Pp_t" %in% out$assignedFuelClass)

})

0 comments on commit d692c28

Please sign in to comment.