From bd026b27497e0660a6623aecf804f25c93d19145 Mon Sep 17 00:00:00 2001 From: camillegiuliano Date: Wed, 27 Aug 2025 09:02:11 -0700 Subject: [PATCH 1/7] add param descriptions to cumPoolsCreate --- R/Boudewyn_cumPoolsCreate.R | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/R/Boudewyn_cumPoolsCreate.R b/R/Boudewyn_cumPoolsCreate.R index d0101f9..5206151 100644 --- a/R/Boudewyn_cumPoolsCreate.R +++ b/R/Boudewyn_cumPoolsCreate.R @@ -1,14 +1,14 @@ #' Create `cumPools` data.table #' -#' @param fullSpecies DESCRIPTION NEEDED -#' @param gcMeta DESCRIPTION NEEDED -#' @param userGcM3 DESCRIPTION NEEDED -#' @param stable3 DESCRIPTION NEEDED -#' @param stable4 DESCRIPTION NEEDED -#' @param stable5 DESCRIPTION NEEDED -#' @param stable6 DESCRIPTION NEEDED -#' @param stable7 DESCRIPTION NEEDED -#' @param thisAdmin DESCRIPTION NEEDED +#' @param fullSpecies Species names found in study area. +#' @param gcMeta Growth curve metadata table that links species with additional attributes. +#' @param userGcM3 Growth curve metadata table that links species with additional attributes. +#' @param stable3 Boudewyn table 3 subset to study area attributes. +#' @param stable4 Boudewyn table 3 subset to study area attributes. +#' @param stable5 Boudewyn table 3 subset to study area attributes. +#' @param stable6 Boudewyn table 3 subset to study area attributes. +#' @param stable7 Boudewyn table 3 subset to study area attributes. +#' @param thisAdmin Study area metadata #' #' @return `cumPools` data.table #' From ca0d03ddce0f1dfbbe08410e98254a5084c2e6d6 Mon Sep 17 00:00:00 2001 From: camillegiuliano Date: Wed, 27 Aug 2025 09:35:22 -0700 Subject: [PATCH 2/7] new function: gcLocatorCreate --- R/CBM-tools_gcLocatorCreate.R | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 R/CBM-tools_gcLocatorCreate.R diff --git a/R/CBM-tools_gcLocatorCreate.R b/R/CBM-tools_gcLocatorCreate.R new file mode 100644 index 0000000..7ef5df9 --- /dev/null +++ b/R/CBM-tools_gcLocatorCreate.R @@ -0,0 +1,34 @@ +#' Create gcLocator raster layer +#' +#' @param siteProductivity Productivity class raster layer +#' @param spuRaster spatial unit ID raster layer +#' @param leadSpecies leading species raster layer +#' @param gcidLookup Table with metadata for each gcid +#' +#' +#' @return `gcLocator` SpatRaster +#' +#' @export +#' @importFrom data.table data.table +gcLocatorCreate <- function(siteProductivity, spuRaster, leadSpecies, gcidLookup) { + + #build gcTable from the raster layers + combine <- c(leadSpecies, spuRaster, siteProductivity) + gcTable <- as.data.table(combine, na.rm = FALSE) + setnames(gcTable, c("speciesID", "spatialunit", "prodclass")) + gcTable[, cell := 1:.N] + + #merge gcTable with gcidLookup to get growth curve information for each pixel + gcTable <- merge(gcTable, gcidLookup, by = c("speciesId", "spatialunit", "prodclass"), all.x = TRUE) + colstokeep <- c("cell", "growthcurveid") + gcTable <- gcTable[, ..colstokeep] + setnames(gcTable, c("cell", "growthcurveid")) + + #build the gcLocator raster layer + gcLocator <- rast(leadSP_resampled) + values(gcLocator) <- NA + values(gcLocator)[gcTable$cell] <- gcTable$growthcurveid + + return(gcLocator) + +} From 2c590a0bb8d5431bf8a0a2985d7460521ace7390 Mon Sep 17 00:00:00 2001 From: camillegiuliano Date: Wed, 27 Aug 2025 09:38:56 -0700 Subject: [PATCH 3/7] gcLocatorCreate: added description --- R/CBM-tools_gcLocatorCreate.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/R/CBM-tools_gcLocatorCreate.R b/R/CBM-tools_gcLocatorCreate.R index 7ef5df9..1defff2 100644 --- a/R/CBM-tools_gcLocatorCreate.R +++ b/R/CBM-tools_gcLocatorCreate.R @@ -1,5 +1,8 @@ #' Create gcLocator raster layer #' +#' Builds the gcLocator raster from site productivity, spatial unit, and leading species matched to +#' a growth curve lookup table +#' #' @param siteProductivity Productivity class raster layer #' @param spuRaster spatial unit ID raster layer #' @param leadSpecies leading species raster layer From 80a43c7477340400347af14cf92e851dca29bd95 Mon Sep 17 00:00:00 2001 From: camillegiuliano Date: Wed, 27 Aug 2025 09:40:39 -0700 Subject: [PATCH 4/7] doc update --- NAMESPACE | 1 + man/cumPoolsCreate.Rd | 18 +++++++++--------- man/gcLocatorCreate.Rd | 24 ++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 man/gcLocatorCreate.Rd diff --git a/NAMESPACE b/NAMESPACE index 59bd8ca..6f9e87d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -19,6 +19,7 @@ export(cumPoolsCreateAGB) export(cumPoolsSmooth) export(distMatch) export(extractToRast) +export(gcLocatorCreate) export(gcidsCreate) export(m3ToBiomPlots) export(nmfac) diff --git a/man/cumPoolsCreate.Rd b/man/cumPoolsCreate.Rd index c9d969a..d7c0b70 100644 --- a/man/cumPoolsCreate.Rd +++ b/man/cumPoolsCreate.Rd @@ -17,23 +17,23 @@ cumPoolsCreate( ) } \arguments{ -\item{fullSpecies}{DESCRIPTION NEEDED} +\item{fullSpecies}{Species names found in study area.} -\item{gcMeta}{DESCRIPTION NEEDED} +\item{gcMeta}{Growth curve metadata table that links species with additional attributes.} -\item{userGcM3}{DESCRIPTION NEEDED} +\item{userGcM3}{Growth curve metadata table that links species with additional attributes.} -\item{stable3}{DESCRIPTION NEEDED} +\item{stable3}{Boudewyn table 3 subset to study area attributes.} -\item{stable4}{DESCRIPTION NEEDED} +\item{stable4}{Boudewyn table 3 subset to study area attributes.} -\item{stable5}{DESCRIPTION NEEDED} +\item{stable5}{Boudewyn table 3 subset to study area attributes.} -\item{stable6}{DESCRIPTION NEEDED} +\item{stable6}{Boudewyn table 3 subset to study area attributes.} -\item{stable7}{DESCRIPTION NEEDED} +\item{stable7}{Boudewyn table 3 subset to study area attributes.} -\item{thisAdmin}{DESCRIPTION NEEDED} +\item{thisAdmin}{Study area metadata} } \value{ \code{cumPools} data.table diff --git a/man/gcLocatorCreate.Rd b/man/gcLocatorCreate.Rd new file mode 100644 index 0000000..0803379 --- /dev/null +++ b/man/gcLocatorCreate.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/CBM-tools_gcLocatorCreate.R +\name{gcLocatorCreate} +\alias{gcLocatorCreate} +\title{Create gcLocator raster layer} +\usage{ +gcLocatorCreate(siteProductivity, spuRaster, leadSpecies, gcidLookup) +} +\arguments{ +\item{siteProductivity}{Productivity class raster layer} + +\item{spuRaster}{spatial unit ID raster layer} + +\item{leadSpecies}{leading species raster layer} + +\item{gcidLookup}{Table with metadata for each gcid} +} +\value{ +\code{gcLocator} SpatRaster +} +\description{ +Builds the gcLocator raster from site productivity, spatial unit, and leading species matched to +a growth curve lookup table +} From f412e1a8afa1d00decb2f721b3f43f457100684b Mon Sep 17 00:00:00 2001 From: camillegiuliano Date: Wed, 27 Aug 2025 10:02:31 -0700 Subject: [PATCH 5/7] gcLocatorCreate fix --- R/CBM-tools_gcLocatorCreate.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/CBM-tools_gcLocatorCreate.R b/R/CBM-tools_gcLocatorCreate.R index 1defff2..5d3defd 100644 --- a/R/CBM-tools_gcLocatorCreate.R +++ b/R/CBM-tools_gcLocatorCreate.R @@ -28,7 +28,7 @@ gcLocatorCreate <- function(siteProductivity, spuRaster, leadSpecies, gcidLookup setnames(gcTable, c("cell", "growthcurveid")) #build the gcLocator raster layer - gcLocator <- rast(leadSP_resampled) + gcLocator <- rast(leadSpecies) values(gcLocator) <- NA values(gcLocator)[gcTable$cell] <- gcTable$growthcurveid From a99936a5ad2b80e854d2bc661414dba5c49ab78c Mon Sep 17 00:00:00 2001 From: camillegiuliano Date: Wed, 27 Aug 2025 15:15:26 -0700 Subject: [PATCH 6/7] gcLocatorCreate: adds a check if rasters share the same CRS --- R/CBM-tools_gcLocatorCreate.R | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/R/CBM-tools_gcLocatorCreate.R b/R/CBM-tools_gcLocatorCreate.R index 5d3defd..e2b4a7a 100644 --- a/R/CBM-tools_gcLocatorCreate.R +++ b/R/CBM-tools_gcLocatorCreate.R @@ -15,6 +15,11 @@ #' @importFrom data.table data.table gcLocatorCreate <- function(siteProductivity, spuRaster, leadSpecies, gcidLookup) { + #check if all rasters share the same CRS + if (!length(unique(lapply(list(siteProductivity, spuRaster, leadSpecies), crs))) == 1){ + stop("Rasters do not all share the same CRS.") + } + #build gcTable from the raster layers combine <- c(leadSpecies, spuRaster, siteProductivity) gcTable <- as.data.table(combine, na.rm = FALSE) From 17d86ef8a7f4484da79c70c1fd964012186e82c3 Mon Sep 17 00:00:00 2001 From: camillegiuliano Date: Thu, 28 Aug 2025 08:55:27 -0700 Subject: [PATCH 7/7] gcLocatorCreate: doc update --- R/CBM-tools_gcLocatorCreate.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/CBM-tools_gcLocatorCreate.R b/R/CBM-tools_gcLocatorCreate.R index e2b4a7a..0307d8a 100644 --- a/R/CBM-tools_gcLocatorCreate.R +++ b/R/CBM-tools_gcLocatorCreate.R @@ -12,7 +12,8 @@ #' @return `gcLocator` SpatRaster #' #' @export -#' @importFrom data.table data.table +#' @importFrom data.table data.table as.data.table +#' @importFrom terra rast gcLocatorCreate <- function(siteProductivity, spuRaster, leadSpecies, gcidLookup) { #check if all rasters share the same CRS