From e7d6c11caf921d269a4772df4d1528fa35fe4534 Mon Sep 17 00:00:00 2001 From: Shashank Singh Date: Fri, 15 Sep 2023 10:35:06 +0000 Subject: [PATCH 01/17] fix warnings/notes in data.land --- modules/data.land/R/IC_BADM_Utilities.R | 28 +++---- modules/data.land/R/InventoryGrowthFusion.R | 14 ++-- .../R/InventoryGrowthFusionDiagnostics.R | 76 +++++++++---------- modules/data.land/R/extract_FIA.R | 6 +- modules/data.land/R/extract_soil_nc.R | 20 ++--- modules/data.land/R/fia2ED.R | 16 ++-- modules/data.land/R/get_veg_module.R | 2 +- modules/data.land/R/ic_process.R | 2 +- modules/data.land/R/matchInventoryRings.R | 2 +- modules/data.land/R/match_species_id.R | 2 +- modules/data.land/R/plot2AGB.R | 44 +++++------ modules/data.land/R/read.plot.R | 2 +- modules/data.land/R/read.velmex.R | 2 +- modules/data.land/R/soil_process.R | 2 +- modules/data.land/R/soil_utils.R | 70 +++++++++++------ 15 files changed, 155 insertions(+), 133 deletions(-) diff --git a/modules/data.land/R/IC_BADM_Utilities.R b/modules/data.land/R/IC_BADM_Utilities.R index 5e0c0687d29..18c62ef277e 100644 --- a/modules/data.land/R/IC_BADM_Utilities.R +++ b/modules/data.land/R/IC_BADM_Utilities.R @@ -21,7 +21,7 @@ Read.IC.info.BADM <-function(lat, long){ #Reading in the DB # U.S.SB <- - read.csv(system.file("data","BADM.csv", package = "PEcAn.data.land")) + utils::read.csv(system.file("data","BADM.csv", package = "PEcAn.data.land")) Regions <- EPA_ecoregion_finder(lat, long) @@ -31,8 +31,8 @@ Read.IC.info.BADM <-function(lat, long){ #L2 biomass.df <- U.S.SB %>% dplyr::filter( - NA_L2CODE == Code_Level, - VARIABLE %>% grepl("ROOT_|AG_BIOMASS|SOIL_STOCK|SOIL_CHEM", .) + .data$NA_L2CODE == Code_Level, + .data$VARIABLE %>% grepl("ROOT_|AG_BIOMASS|SOIL_STOCK|SOIL_CHEM", .) ) %>% dplyr::select("SITE_ID", "GROUP_ID", "VARIABLE_GROUP", "VARIABLE", "DATAVALUE") @@ -43,8 +43,8 @@ Read.IC.info.BADM <-function(lat, long){ biomass.df <- U.S.SB %>% dplyr::filter( - NA_L1CODE == Code_Level, - VARIABLE %>% grepl("ROOT_|AG_BIOMASS|SOIL_STOCK|SOIL_CHEM", .) + .data$NA_L1CODE == Code_Level, + .data$VARIABLE %>% grepl("ROOT_|AG_BIOMASS|SOIL_STOCK|SOIL_CHEM", .) ) %>% dplyr::select("SITE_ID", "GROUP_ID", "VARIABLE_GROUP", "VARIABLE", "DATAVALUE") } @@ -54,7 +54,7 @@ Read.IC.info.BADM <-function(lat, long){ if (nrow(biomass.df) < 3) { Code_Level <- "ALL" biomass.df <- U.S.SB %>% - dplyr::filter(VARIABLE %>% grepl("ROOT_|AG_BIOMASS|SOIL_STOCK|SOIL_CHEM", .)) %>% + dplyr::filter(.data$VARIABLE %>% grepl("ROOT_|AG_BIOMASS|SOIL_STOCK|SOIL_CHEM", .)) %>% dplyr::select("SITE_ID", "GROUP_ID", "VARIABLE_GROUP", "VARIABLE", "DATAVALUE") } @@ -94,8 +94,8 @@ Read.IC.info.BADM <-function(lat, long){ type <- type[-which(type == "*_BIOMASS")] #----------------- Unit conversion unit.in <- Gdf %>% - dplyr::filter(VARIABLE %>% grepl("UNIT", .)) %>% - dplyr::pull(DATAVALUE) %>% + dplyr::filter(.data$VARIABLE %>% grepl("UNIT", .)) %>% + dplyr::pull(.data$DATAVALUE) %>% as.character() @@ -113,8 +113,8 @@ Read.IC.info.BADM <-function(lat, long){ unit.ready <- "kg/m^2" Date.in <- Gdf %>% - dplyr::filter(VARIABLE %>% grepl("DATE", .)) %>% - dplyr::pull(DATAVALUE) %>% + dplyr::filter(.data$VARIABLE %>% grepl("DATE", .)) %>% + dplyr::pull(.data$DATAVALUE) %>% as.Date() if (length(Date.in) == 0) @@ -124,8 +124,8 @@ Read.IC.info.BADM <-function(lat, long){ # if it's biomass if (type == "*_BIOMASS") { Oregan.in <- Gdf %>% - dplyr::filter(VARIABLE %>% grepl("ORGAN", .)) %>% - dplyr::pull(DATAVALUE) + dplyr::filter(.data$VARIABLE %>% grepl("ORGAN", .)) %>% + dplyr::pull(.data$DATAVALUE) PlantWoodIni <- @@ -134,8 +134,8 @@ Read.IC.info.BADM <-function(lat, long){ } else if (type == "*SOIL") { val <- Gdf %>% - dplyr::filter(VARIABLE %>% grepl("SOIL_STOCK_C_ORG", .)) %>% #"SOIL_STOCK_C_ORG" - dplyr::pull(DATAVALUE) %>% + dplyr::filter(.data$VARIABLE %>% grepl("SOIL_STOCK_C_ORG", .)) %>% #"SOIL_STOCK_C_ORG" + dplyr::pull(.data$DATAVALUE) %>% as.numeric() if (length(val) > 0) diff --git a/modules/data.land/R/InventoryGrowthFusion.R b/modules/data.land/R/InventoryGrowthFusion.R index 49a8ce58708..e7cebfb4c4f 100644 --- a/modules/data.land/R/InventoryGrowthFusion.R +++ b/modules/data.land/R/InventoryGrowthFusion.R @@ -404,8 +404,8 @@ model{ ## JAGS initial conditions init <- list() - if(is.mcmc.list(restart)){ - init <- mcmc.list2init(restart) + if(coda::is.mcmc.list(restart)){ + init <- PEcAn.utils::mcmc.list2init(restart) nchain <- length(init) } else { nchain <- 3 @@ -438,7 +438,7 @@ model{ } PEcAn.logger::logger.info("RUN MCMC") - load.module("dic") + rjags::load.module("dic") for(k in avail.chunks){ ## determine whether to sample states @@ -457,17 +457,17 @@ model{ save(jags.out,file=ofile) ## update restart - if(!is.null(restart) & ((is.logical(restart) && restart) || is.mcmc.list(restart))){ + if(!is.null(restart) & ((is.logical(restart) && restart) || coda::is.mcmc.list(restart))){ ofile <- paste("IGF",model,"RESTART.RData",sep=".") - jags.final <- coda.samples(model = j.model, variable.names = c("x",out.variables), n.iter = 1) + jags.final <- rjags::coda.samples(model = j.model, variable.names = c("x",out.variables), n.iter = 1) k_restart = k + 1 ## finished k, so would restart at k+1 save(jags.final,k_restart,file=ofile) } ## check for convergence and break from loop early - D <- as.mcmc.list(lapply(jags.out,function(x){x[,'deviance']})) + D <- coda::as.mcmc.list(lapply(jags.out,function(x){x[,'deviance']})) gbr <- coda::gelman.diag(D)$psrf[1,1] - trend <- mean(sapply(D,function(x){coef(lm(x~seq_len(n.chunk)))[2]})) + trend <- mean(sapply(D,function(x){stats::coef(stats::lm(x~seq_len(n.chunk)))[2]})) if(gbr < 1.005 & abs(trend) < 0.5) break } diff --git a/modules/data.land/R/InventoryGrowthFusionDiagnostics.R b/modules/data.land/R/InventoryGrowthFusionDiagnostics.R index cea71e30855..21d4114c92e 100644 --- a/modules/data.land/R/InventoryGrowthFusionDiagnostics.R +++ b/modules/data.land/R/InventoryGrowthFusionDiagnostics.R @@ -9,13 +9,13 @@ InventoryGrowthFusionDiagnostics <- function(jags.out, combined=NULL) { out <- as.matrix(jags.out) x.cols <- which(substr(colnames(out), 1, 1) == "x") if(length(x.cols) > 0){ - ci <- apply(out[, x.cols], 2, quantile, c(0.025, 0.5, 0.975)) + ci <- apply(out[, x.cols], 2, stats::quantile, c(0.025, 0.5, 0.975)) ci.names <- parse.MatrixNames(colnames(ci), numeric = TRUE) ### DBH par(mfrow=c(3,2)) if(length(x.cols) > 0){ - layout(matrix(1:8, 4, 2, byrow = TRUE)) - ci <- apply(out[, x.cols], 2, quantile, c(0.025, 0.5, 0.975)) + graphics::layout(matrix(1:8, 4, 2, byrow = TRUE)) + ci <- apply(out[, x.cols], 2, stats::quantile, c(0.025, 0.5, 0.975)) ci.names <- parse.MatrixNames(colnames(ci), numeric = TRUE) smp <- sample.int(data$ni, min(8, data$ni)) @@ -26,19 +26,19 @@ InventoryGrowthFusionDiagnostics <- function(jags.out, combined=NULL) { plot(data$time, ci[2, sel], type = "n", ylim = range(rng), ylab = "DBH (cm)", main = i) PEcAn.visualization::ciEnvelope(data$time, ci[1, sel], ci[3, sel], col = "lightBlue") - points(data$time, data$z[i, ], pch = "+", cex = 1.5) + graphics::points(data$time, data$z[i, ], pch = "+", cex = 1.5) # lines(data$time,z0[i,],lty=2) ## growth sel <- which(ci.names$row == i) inc.mcmc <- apply(out[, x.cols[sel]], 1, diff) - inc.ci <- apply(inc.mcmc, 1, quantile, c(0.025, 0.5, 0.975)) * 5 + inc.ci <- apply(inc.mcmc, 1, stats::quantile, c(0.025, 0.5, 0.975)) * 5 # inc.names = parse.MatrixNames(colnames(ci),numeric=TRUE) plot(data$time[-1], inc.ci[2, ], type = "n", ylim = range(inc.ci, na.rm = TRUE), ylab = "Ring Increment (mm)") PEcAn.visualization::ciEnvelope(data$time[-1], inc.ci[1, ], inc.ci[3, ], col = "lightBlue") - points(data$time, data$y[i, ] * 5, pch = "+", cex = 1.5, type = "b", lty = 2) + graphics::points(data$time, data$y[i, ] * 5, pch = "+", cex = 1.5, type = "b", lty = 2) } } } @@ -46,9 +46,9 @@ InventoryGrowthFusionDiagnostics <- function(jags.out, combined=NULL) { if (FALSE) { ## check a DBH plot(out[, which(colnames(out) == "x[3,31]")]) - abline(h = z[3, 31], col = 2, lwd = 2) - hist(out[, which(colnames(out) == "x[3,31]")]) - abline(v = z[3, 31], col = 2, lwd = 2) + graphics::abline(h = z[3, 31], col = 2, lwd = 2) + graphics::hist(out[, which(colnames(out) == "x[3,31]")]) + graphics::abline(v = z[3, 31], col = 2, lwd = 2) } ## process model @@ -59,105 +59,105 @@ InventoryGrowthFusionDiagnostics <- function(jags.out, combined=NULL) { grep("alpha",colnames(out)), grep("deviance",colnames(out)))] - par(mfrow = c(1, 1)) + graphics::par(mfrow = c(1, 1)) for (i in vars) { - hist(out[, i], main = colnames(out)[i]) - abline(v=0,lwd=3) + graphics::hist(out[, i], main = colnames(out)[i]) + graphics::abline(v=0,lwd=3) } if (length(vars) > 1 && length(vars) < 10) { - pairs(out[, vars]) + graphics::pairs(out[, vars]) } if("deviance" %in% colnames(out)){ - hist(out[,"deviance"]) + graphics::hist(out[,"deviance"]) vars <- c(vars,which(colnames(out)=="deviance")) } ## rebuild coda for just vars - var.out <- as.mcmc.list(lapply(jags.out,function(x){ x[,vars]})) + var.out <- coda::as.mcmc.list(lapply(jags.out,function(x){ x[,vars]})) ## convergence - gelman.diag(var.out) + coda::gelman.diag(var.out) #### Diagnostic plots plot(var.out) if("deviance" %in% colnames(out)){ - hist(out[,"deviance"]) + graphics::hist(out[,"deviance"]) vars <- c(vars,which(colnames(out)=="deviance")) } ## rebuild coda for just vars - var.out <- as.mcmc.list(lapply(jags.out,function(x){ x[,vars]})) + var.out <- coda::as.mcmc.list(lapply(jags.out,function(x){ x[,vars]})) ## convergence - gelman.diag(var.out) + coda::gelman.diag(var.out) #### Diagnostic plots plot(var.out) ## Standard Deviations layout(matrix(c(1,2,3,3),2,2,byrow=TRUE)) - par(mfrow = c(2, 3)) + graphics::par(mfrow = c(2, 3)) prec <- out[, grep("tau", colnames(out))] for (i in seq_along(colnames(prec))) { - hist(1 / sqrt(prec[, i]), main = colnames(prec)[i]) + graphics::hist(1 / sqrt(prec[, i]), main = colnames(prec)[i]) } - cor(prec) + stats::cor(prec) # pairs(prec) ### alpha - par(mfrow = c(1, 1)) + graphics::par(mfrow = c(1, 1)) alpha.cols <- grep("alpha", colnames(out)) if (length(alpha.cols) > 0) { alpha.ord <- 1:length(alpha.cols) - ci.alpha <- apply(out[, alpha.cols], 2, quantile, c(0.025, 0.5, 0.975)) + ci.alpha <- apply(out[, alpha.cols], 2, stats::quantile, c(0.025, 0.5, 0.975)) plot(alpha.ord, ci.alpha[2, ], type = "n", ylim = range(ci.alpha, na.rm = TRUE), ylab = "Random Effects") PEcAn.visualization::ciEnvelope(alpha.ord, ci.alpha[1, ], ci.alpha[3, ], col = "lightBlue") - lines(alpha.ord, ci.alpha[2, ], lty = 1, lwd = 2) - abline(h = 0, lty = 2) + graphics::lines(alpha.ord, ci.alpha[2, ], lty = 1, lwd = 2) + graphics::abline(h = 0, lty = 2) } - par(mfrow = c(1, 1)) + graphics::par(mfrow = c(1, 1)) ### alpha alpha.cols <- grep("alpha", colnames(out)) if (length(alpha.cols) > 0) { alpha.ord <- 1:length(alpha.cols) - ci.alpha <- apply(out[, alpha.cols], 2, quantile, c(0.025, 0.5, 0.975)) + ci.alpha <- apply(out[, alpha.cols], 2, stats::quantile, c(0.025, 0.5, 0.975)) plot(alpha.ord, ci.alpha[2, ], type = "n", ylim = range(ci.alpha, na.rm = TRUE), ylab = "Random Effects") PEcAn.visualization::ciEnvelope(alpha.ord, ci.alpha[1, ], ci.alpha[3, ], col = "lightBlue") - lines(alpha.ord, ci.alpha[2, ], lty = 1, lwd = 2) - abline(h = 0, lty = 2) + graphics::lines(alpha.ord, ci.alpha[2, ], lty = 1, lwd = 2) + graphics::abline(h = 0, lty = 2) } ### YEAR year.cols <- grep("year", colnames(out)) if (length(year.cols > 0)) { - ci.yr <- apply(out[, year.cols], 2, quantile, c(0.025, 0.5, 0.975)) + ci.yr <- apply(out[, year.cols], 2, stats::quantile, c(0.025, 0.5, 0.975)) plot(data$time, ci.yr[2, ], type = "n", ylim = range(ci.yr, na.rm = TRUE), ylab = "Year Effect") PEcAn.visualization::ciEnvelope(data$time, ci.yr[1, ], ci.yr[3, ], col = "lightBlue") - lines(data$time, ci.yr[2, ], lty = 1, lwd = 2) - abline(h = 0, lty = 2) + graphics::lines(data$time, ci.yr[2, ], lty = 1, lwd = 2) + graphics::abline(h = 0, lty = 2) } ### INDIV ind.cols <- which(substr(colnames(out), 1, 3) == "ind") if (length(ind.cols) > 0 & !is.null(combined)) { - boxplot(out[, ind.cols], horizontal = TRUE, outline = FALSE, col = as.factor(combined$PLOT)) - abline(v = 0, lty = 2) + graphics::boxplot(out[, ind.cols], horizontal = TRUE, outline = FALSE, col = as.factor(combined$PLOT)) + graphics::abline(v = 0, lty = 2) tapply(apply(out[, ind.cols], 2, mean), combined$PLOT, mean) table(combined$PLOT) spp <- combined$SPP # boxplot(out[order(spp),ind.cols],horizontal=TRUE,outline=FALSE,col=spp[order(spp)]) - boxplot(out[, ind.cols], horizontal = TRUE, outline = FALSE, col = spp) - abline(v = 0, lty = 2) + graphics::boxplot(out[, ind.cols], horizontal = TRUE, outline = FALSE, col = spp) + graphics::abline(v = 0, lty = 2) spp.code <- levels(spp)[table(spp) > 0] - legend("bottomright", legend = rev(spp.code), col = rev(which(table(spp) > 0)), lwd = 4) + graphics::legend("bottomright", legend = rev(spp.code), col = rev(which(table(spp) > 0)), lwd = 4) tapply(apply(out[, ind.cols], 2, mean), combined$SPP, mean) } } # InventoryGrowthFusionDiagnostics diff --git a/modules/data.land/R/extract_FIA.R b/modules/data.land/R/extract_FIA.R index 595d2f5d226..bc91dcd3216 100644 --- a/modules/data.land/R/extract_FIA.R +++ b/modules/data.land/R/extract_FIA.R @@ -20,7 +20,7 @@ extract_FIA <- function(lon, lat, start_date, end_date, gridres = 0.075, dbparms veg_info <- list() fia.con <- PEcAn.DB::db.open(dbparms$fia) - on.exit(db.close(fia.con), add = TRUE) + on.exit(PEcAn.DB::db.close(fia.con), add = TRUE) lonmin <- lon - gridres lonmax <- lon + gridres @@ -49,7 +49,7 @@ extract_FIA <- function(lon, lat, start_date, end_date, gridres = 0.075, dbparms " AND p.lat <= ", latmax, " AND p.measyear >= ", min.year, " AND p.measyear <= ", max.year, " GROUP BY p.cn") - plot.info <- db.query(query, con = fia.con) + plot.info <- PEcAn.DB::db.query(query, con = fia.con) if (nrow(plot.info) == 0) { PEcAn.logger::logger.severe("No plot data found on FIA.") } @@ -97,7 +97,7 @@ extract_FIA <- function(lon, lat, start_date, end_date, gridres = 0.075, dbparms " and p.lon < ", lonmax, " and p.lat >= ", latmin, " and p.lat < ", latmax) - tree.info <- db.query(query, con = fia.con) + tree.info <- PEcAn.DB::db.query(query, con = fia.con) names(tree.info) <- tolower(names(tree.info)) if (nrow(tree.info) == 0) { diff --git a/modules/data.land/R/extract_soil_nc.R b/modules/data.land/R/extract_soil_nc.R index 2869e1aafea..fd42aa53b2b 100644 --- a/modules/data.land/R/extract_soil_nc.R +++ b/modules/data.land/R/extract_soil_nc.R @@ -82,13 +82,13 @@ extract_soil_gssurgo<-function(outdir, lat, lon, size=1, radius=500, depths=c(0. "soil_depth"), function(x) x / 100)) - soilprop.new <- soilprop.new[ complete.cases(soilprop.new) , ] + soilprop.new <- soilprop.new[ stats::complete.cases(soilprop.new) , ] #converting it to list soil.data.gssurgo <- names(soilprop.new)[1:4] %>% purrr::map(function(var) { soilprop.new[, var] }) %>% - setNames(names(soilprop.new)[1:4]) + stats::setNames(names(soilprop.new)[1:4]) #This ensures that I have at least one soil ensemble in case the modeling part failed all.soil.ens <-c(all.soil.ens, list(soil.data.gssurgo)) @@ -105,7 +105,7 @@ extract_soil_gssurgo<-function(outdir, lat, lon, size=1, radius=500, depths=c(0. depth.levs[depth.levs>length(depths)] <-length(depths) soilprop.new.grouped<-soilprop.new %>% - mutate(DepthL=depths[depth.levs]) + dplyr::mutate(DepthL=depths[depth.levs]) # let's fit dirichlet for each depth level separately simulated.soil.props<-soilprop.new.grouped %>% @@ -123,7 +123,7 @@ extract_soil_gssurgo<-function(outdir, lat, lon, size=1, radius=500, depths=c(0. # # using the simulated sand/silt/clay to generate soil ensemble simulated.soil<-simulated.soil %>% as.data.frame %>% - mutate(DepthL=rep(DepthL.Data[1,6], size), + dplyr::mutate(DepthL=rep(DepthL.Data[1,6], size), mukey=rep(DepthL.Data[1,5], size)) %>% `colnames<-`(c("fraction_of_sand_in_soil", "fraction_of_silt_in_soil", @@ -141,8 +141,8 @@ extract_soil_gssurgo<-function(outdir, lat, lon, size=1, radius=500, depths=c(0. # estimating the proportion of areas for those mukeys which are modeled mukey_area <- mukey_area %>% - filter(mukeys %in% simulated.soil.props$mukey) %>% - mutate(Area=Area/sum(Area)) + dplyr::filter(mukeys %in% simulated.soil.props$mukey) %>% + dplyr::mutate(Area=mukey_area$Area/sum(mukey_area$Area)) #--- Mixing the depths soil.profiles<-simulated.soil.props %>% @@ -166,7 +166,7 @@ extract_soil_gssurgo<-function(outdir, lat, lon, size=1, radius=500, depths=c(0. purrr::map(function(var){ SEns[,var] })%>% - setNames(names(SEns)) + stats::setNames(names(SEns)) })%>% c(all.soil.ens,.) @@ -203,7 +203,7 @@ extract_soil_gssurgo<-function(outdir, lat, lon, size=1, radius=500, depths=c(0. purrr::discard(is.null) out.ense<-out.ense%>% - setNames(rep("path", length(out.ense))) + stats::setNames(rep("path", length(out.ense))) return(out.ense) } @@ -244,8 +244,8 @@ extract_soil_nc <- function(in.file,outdir,lat,lon){ soil.lon <- ncdf4::ncvar_get(nc, lon.dim) ## check in range - dlat <- abs(median(diff(soil.lat))) - dlon <- abs(median(diff(soil.lon))) + dlat <- abs(stats::median(diff(soil.lat))) + dlon <- abs(stats::median(diff(soil.lon))) if(lat < (min(soil.lat)-dlat) | lat > (max(soil.lat)+dlat)){ PEcAn.logger::logger.error("site lat out of bounds",lat,range(soil.lat)) } diff --git a/modules/data.land/R/fia2ED.R b/modules/data.land/R/fia2ED.R index c4d7c0e14d5..56695b0ad10 100644 --- a/modules/data.land/R/fia2ED.R +++ b/modules/data.land/R/fia2ED.R @@ -82,7 +82,7 @@ fia.to.psscss <- function(settings, pfts <- PEcAn.DB::db.query(query, con = con) # Convert PFT names to ED2 Numbers - data(pftmapping) + utils::data(pftmapping) for (pft.i in settings$pfts) { pft.number <- NULL pft.number <- pft.i$constants$num @@ -110,7 +110,7 @@ fia.to.psscss <- function(settings, names(symbol.table) <- tolower(names(symbol.table)) # grab the names where we have bad spcds in the symbol.table, exclude NAs - name.list <- na.omit(symbol.table$symbol[symbol.table$spcd %in% bad]) + name.list <- stats::na.omit(symbol.table$symbol[symbol.table$spcd %in% bad]) PEcAn.logger::logger.severe(paste0("The following species are found in multiple PFTs: ", paste(name.list[1:min(10, length(name.list))], collapse = ", "), @@ -232,7 +232,7 @@ fia.to.psscss <- function(settings, symbol.table <- PEcAn.DB::db.query("SELECT spcd, \"Symbol\" FROM species where spcd IS NOT NULL", con = con) names(symbol.table) <- tolower(names(symbol.table)) } - name.list <- na.omit(symbol.table$symbol[symbol.table$spcd %in% pft.only]) + name.list <- stats::na.omit(symbol.table$symbol[symbol.table$spcd %in% pft.only]) PEcAn.logger::logger.warn(paste0("The selected PFTs contain the following species for which the FIA database ", "contains no data at ", lat, " and ", lon, ": ", paste(name.list[1:min(10, length(name.list))], collapse = ", "), ".")) @@ -247,7 +247,7 @@ fia.to.psscss <- function(settings, symbol.table <- PEcAn.DB::db.query("SELECT spcd, \"Symbol\" FROM species where spcd IS NOT NULL", con = con) names(symbol.table) <- tolower(names(symbol.table)) } - name.list <- na.omit(symbol.table$symbol[symbol.table$spcd %in% fia.only]) + name.list <- stats::na.omit(symbol.table$symbol[symbol.table$spcd %in% fia.only]) name.list <- name.list[name.list != "DEAD"] if (length(name.list) > 0) { PEcAn.logger::logger.warn(paste0("The FIA database expects the following species at ", lat, " and ", lon, @@ -273,7 +273,7 @@ fia.to.psscss <- function(settings, css$time[is.na(css$time)] <- 1 css$cohort[is.na(css$cohort)] <- 1:sum(is.na(css$cohort)) css$dbh[is.na(css$dbh)] <- 1 # assign nominal small dbh to missing - density.median <- median(css$n[which(css$n > 0)]) + density.median <- stats::median(css$n[which(css$n > 0)]) css$n[is.na(css$n) | css$n == 0] <- density.median css$hite <- css$bdead <- css$balive <- css$lai <- rep(0, n.cohort) @@ -319,8 +319,8 @@ fia.to.psscss <- function(settings, site.file.local <- file.path(out.dir.local, paste0(prefix.site, ".site")) dir.create(out.dir.local, showWarnings = F, recursive = T) - write.table(pss, pss.file.local, quote = FALSE, row.names = FALSE) - write.table(css, css.file.local, quote = FALSE, row.names = FALSE) + utils::write.table(pss, pss.file.local, quote = FALSE, row.names = FALSE) + utils::write.table(css, css.file.local, quote = FALSE, row.names = FALSE) site.file.con <- file(site.file.local) writeLines(site, site.file.con) @@ -344,7 +344,7 @@ fia.to.psscss <- function(settings, # Insert into DB for(i in seq_along(files)) { - dbfile.input.insert( + PEcAn.DB::dbfile.input.insert( in.path = dirname(files[i]), in.prefix = basename(files[i]), siteid = settings$run$site$id, diff --git a/modules/data.land/R/get_veg_module.R b/modules/data.land/R/get_veg_module.R index 7171b46b8c3..348bf4f8e98 100644 --- a/modules/data.land/R/get_veg_module.R +++ b/modules/data.land/R/get_veg_module.R @@ -79,7 +79,7 @@ get_veg_module <- function(input_veg, write = TRUE, overwrite = overwrite, # fcn specific args - new_site = new.site, + new_site = new_site, source_id = source.id, format_name = input_veg$match.format, dbparms = dbparms, diff --git a/modules/data.land/R/ic_process.R b/modules/data.land/R/ic_process.R index 086beac0f75..92256f6fe0d 100644 --- a/modules/data.land/R/ic_process.R +++ b/modules/data.land/R/ic_process.R @@ -47,7 +47,7 @@ ic_process <- function(settings, input, dir, overwrite = FALSE){ # set up bety connection con <- PEcAn.DB::db.open(dbparms$bety) - on.exit(db.close(con), add = TRUE) + on.exit(PEcAn.DB::db.close(con), add = TRUE) #grab site lat and lon info latlon <- PEcAn.data.atmosphere::db.site.lat.lon(site$id, con = con) diff --git a/modules/data.land/R/matchInventoryRings.R b/modules/data.land/R/matchInventoryRings.R index 7abb370a03a..0a9bf4a6399 100644 --- a/modules/data.land/R/matchInventoryRings.R +++ b/modules/data.land/R/matchInventoryRings.R @@ -25,7 +25,7 @@ matchInventoryRings <- function(trees, rings, extractor = "TreeCode", nyears = 3 mch <- match(tree.ID, ring.ID) cored <- apply(!is.na(trees[, grep("DATE_CORE_COLLECT", names(trees))]), 1, any) unmatched <- which(cored & is.na(mch)) - write.table(tree.ID[unmatched], file = "unmatched.txt") + utils::write.table(tree.ID[unmatched], file = "unmatched.txt") mch[duplicated(mch)] <- NA ## if there's multiple stems, match the first ## combine data into one table diff --git a/modules/data.land/R/match_species_id.R b/modules/data.land/R/match_species_id.R index 30708c348f8..eae0583abe0 100644 --- a/modules/data.land/R/match_species_id.R +++ b/modules/data.land/R/match_species_id.R @@ -67,7 +67,7 @@ match_species_id <- function(input_codes, format_name = 'custom', bety = NULL, t 'be appended with ".translation_table" for disambiguation') } bety_species <- dplyr::tbl(bety, 'species') %>% - dplyr::filter(id %in% !!translation_table[['bety_species_id']]) %>% + dplyr::filter(.data$id %in% !!translation_table[['bety_species_id']]) %>% dplyr::select(bety_species_id = "id", "genus", "species") %>% dplyr::collect() translation <- dplyr::left_join(translation_table, bety_species, diff --git a/modules/data.land/R/plot2AGB.R b/modules/data.land/R/plot2AGB.R index d545d191526..d2f956c59d4 100644 --- a/modules/data.land/R/plot2AGB.R +++ b/modules/data.land/R/plot2AGB.R @@ -49,7 +49,7 @@ plot2AGB <- function(combined, out, outfolder, allom.stats, unit.conv = 0.02) { biomass_thoc2 <- array(NA, c(mplot, nrep, nt)) ## sample over tree chronologies - pb <- txtProgressBar(min = 0, max = nrep, style = 3) + pb <- utils::txtProgressBar(min = 0, max = nrep, style = 3) for (g in seq_len(nrep)) { ## Draw allometries @@ -72,7 +72,7 @@ plot2AGB <- function(combined, out, outfolder, allom.stats, unit.conv = 0.02) { ## diff to get NPP NPP[j, g, ] <- diff(AGB[j, g, ]) } - setTxtProgressBar(pb, g) + utils::setTxtProgressBar(pb, g) } mAGB <- sAGB <- matrix(NA, mplot, nt) @@ -84,34 +84,34 @@ plot2AGB <- function(combined, out, outfolder, allom.stats, unit.conv = 0.02) { mbiomass_thoc2 <- sbiomass_thoc2 <- matrix(NA, mplot, nt) for (i in seq_len(mplot)) { - mNPP[i, ] <- apply(NPP[i, , ], 2, mean, na.rm = TRUE) - sNPP[i, ] <- apply(NPP[i, , ], 2, sd, na.rm = TRUE) - mAGB[i, ] <- apply(AGB[i, , ], 2, mean, na.rm = TRUE) - sAGB[i, ] <- apply(AGB[i, , ], 2, sd, na.rm = TRUE) + mNPP[i, ] <- apply(NPP[i, , ], 2, stats::mean, na.rm = TRUE) + sNPP[i, ] <- apply(NPP[i, , ], 2, stats::sd, na.rm = TRUE) + mAGB[i, ] <- apply(AGB[i, , ], 2, stats::mean, na.rm = TRUE) + sAGB[i, ] <- apply(AGB[i, , ], 2, stats::sd, na.rm = TRUE) - mbiomass_tsca[i, ] <- apply(biomass_tsca[i, , ], 2, mean, na.rm = TRUE) - sbiomass_tsca[i, ] <- apply(biomass_tsca[i, , ], 2, sd, na.rm = TRUE) - mbiomass_acsa3[i, ] <- apply(biomass_acsa3[i, , ], 2, mean, na.rm = TRUE) - sbiomass_acsa3[i, ] <- apply(biomass_acsa3[i, , ], 2, sd, na.rm = TRUE) - mbiomass_beal2[i, ] <- apply(biomass_beal2[i, , ], 2, mean, na.rm = TRUE) - sbiomass_beal2[i, ] <- apply(biomass_beal2[i, , ], 2, sd, na.rm = TRUE) - mbiomass_thoc2[i, ] <- apply(biomass_thoc2[i, , ], 2, mean, na.rm = TRUE) - sbiomass_thoc2[i, ] <- apply(biomass_thoc2[i, , ], 2, sd, na.rm = TRUE) + mbiomass_tsca[i, ] <- apply(biomass_tsca[i, , ], 2, stats::mean, na.rm = TRUE) + sbiomass_tsca[i, ] <- apply(biomass_tsca[i, , ], 2, stats::sd, na.rm = TRUE) + mbiomass_acsa3[i, ] <- apply(biomass_acsa3[i, , ], 2, stats::mean, na.rm = TRUE) + sbiomass_acsa3[i, ] <- apply(biomass_acsa3[i, , ], 2, stats::sd, na.rm = TRUE) + mbiomass_beal2[i, ] <- apply(biomass_beal2[i, , ], 2, stats::mean, na.rm = TRUE) + sbiomass_beal2[i, ] <- apply(biomass_beal2[i, , ], 2, stats::sd, na.rm = TRUE) + mbiomass_thoc2[i, ] <- apply(biomass_thoc2[i, , ], 2, stats::mean, na.rm = TRUE) + sbiomass_thoc2[i, ] <- apply(biomass_thoc2[i, , ], 2, stats::sd, na.rm = TRUE) } - pdf(file.path(outfolder, "plot2AGB.pdf")) - par(mfrow = c(2, 1)) + grDevices::pdf(file.path(outfolder, "plot2AGB.pdf")) + graphics::par(mfrow = c(2, 1)) for (i in seq_len(mplot)) { up <- mNPP[i, ] + sNPP[i, ] * 1.96 low <- mNPP[i, ] - sNPP[i, ] * 1.96 - plot(yrvec[-1], mNPP[i, ], ylim = range(c(up, low)), ylab = "Mg/ha/yr", xlab = "year") - lines(yrvec[-1], up) - lines(yrvec[-1], low) + graphics::plot(yrvec[-1], mNPP[i, ], ylim = range(c(up, low)), ylab = "Mg/ha/yr", xlab = "year") + graphics::lines(yrvec[-1], up) + graphics::lines(yrvec[-1], low) upA <- mAGB[i, ] + sAGB[i, ] * 1.96 lowA <- mAGB[i, ] - sAGB[i, ] * 1.96 - plot(yrvec, mAGB[i, ], ylim = range(c(upA, lowA)), ylab = "Mg/ha", xlab = "year") - lines(yrvec, upA) - lines(yrvec, lowA) + graphics::plot(yrvec, mAGB[i, ], ylim = range(c(upA, lowA)), ylab = "Mg/ha", xlab = "year") + graphics::lines(yrvec, upA) + graphics::lines(yrvec, lowA) } grDevices::dev.off() diff --git a/modules/data.land/R/read.plot.R b/modules/data.land/R/read.plot.R index 74cfadb7e05..56e8f274ac0 100644 --- a/modules/data.land/R/read.plot.R +++ b/modules/data.land/R/read.plot.R @@ -8,7 +8,7 @@ #------------------------------------------------------------------------------- read.plot <- function(file) { - dat <- read.csv(file) + dat <- utils::read.csv(file) plot <- dat[, which(toupper(names(dat)) == "PLOT")] tree <- dat[, which(toupper(names(dat)) == "TREE")] spp <- as.character(dat[, which(toupper(names(dat)) == "SPECIES")]) diff --git a/modules/data.land/R/read.velmex.R b/modules/data.land/R/read.velmex.R index e71f3c594b3..af030fc53c8 100644 --- a/modules/data.land/R/read.velmex.R +++ b/modules/data.land/R/read.velmex.R @@ -5,7 +5,7 @@ read.velmex <- function(folder) { filenames <- dir(folder, pattern = ".txt$", full.names = TRUE) filedata <- list() for (file in filenames) { - dat <- read.fwf(file, c(1, 12, 3, 128), header = FALSE) + dat <- utils::read.fwf(file, c(1, 12, 3, 128), header = FALSE) notes <- which(!is.na(dat[, 4])) if (length(notes) == 0) { notes <- nrow(dat) + 1 diff --git a/modules/data.land/R/soil_process.R b/modules/data.land/R/soil_process.R index b1f62482762..59c4dab6b26 100644 --- a/modules/data.land/R/soil_process.R +++ b/modules/data.land/R/soil_process.R @@ -100,7 +100,7 @@ soil_process <- function(settings, input, dbfiles, overwrite = FALSE,run.local=T # retrieve model type info if(is.null(model)){ - modeltype_id <- db.query(paste0("SELECT modeltype_id FROM models where id = '", settings$model$id, "'"), con)[[1]] + modeltype_id <- PEcAn.DB::db.query(paste0("SELECT modeltype_id FROM models where id = '", settings$model$id, "'"), con)[[1]] model <- db.query(paste0("SELECT name FROM modeltypes where id = '", modeltype_id, "'"), con)[[1]] } diff --git a/modules/data.land/R/soil_utils.R b/modules/data.land/R/soil_utils.R index b89025c072f..f166faeba37 100644 --- a/modules/data.land/R/soil_utils.R +++ b/modules/data.land/R/soil_utils.R @@ -20,16 +20,38 @@ #' @return list of soil hydraulic and thermal parameters #' @export #' @importFrom rlang %||% - # null-filling operator: A %||% B == "B if A is null, A in all other cases" +# null-filling operator: A %||% B == "B if A is null, A in all other cases" #' @examples #' sand <- c(0.3, 0.4, 0.5) #' clay <- c(0.3, 0.3, 0.3) #' soil_params(sand=sand,clay=clay) soil_params <- function(soil_type=NULL, sand=NULL, silt=NULL, clay=NULL, bulk=NULL){ ## load soil parameters - load(system.file("data/soil_class.RData",package = "PEcAn.data.land")) + soil_data <- new.env() + load(system.file("data/soil_class.RData",package = "PEcAn.data.land"), envir = soil_data) mysoil <- list() - + soil.name <- soil_data$soil.name + xsand.def <- soil_data$xsand.def + xclay.def <- soil_data$xclay.def + fieldcp.K <- soil_data$fieldcp.K + soilcp.MPa <- soil_data$soilcp.MPa + grav <- soil_data$grav + soilwp.MPa <- soil_data$soilwp.MPa + sand.hcap <- soil_data$sand.hcap + silt.hcap <- soil_data$silt.hcap + clay.hcap <- soil_data$clay.hcap + air.hcap <- soil_data$air.hcap + ksand <- soil_data$ksand + sand.cond <- soil_data$sand.cond + ksilt <- soil_data$ksilt + silt.cond <- soil_data$silt.cond + kclay <- soil_data$kclay + clay.cond <- soil_data$clay.cond + kair <- soil_data$kair + air.cond <- soil_data$air.cond + h2o.cond <- soil_data$h2o.cond + texture <- soil_data$texture + #---------------------------------------------------------------------------------------# # Find soil class and sand, silt, and clay fractions. # #---------------------------------------------------------------------------------------# @@ -44,27 +66,27 @@ soil_params <- function(soil_type=NULL, sand=NULL, silt=NULL, clay=NULL, bulk=NU mysoil$soil_n <- which(toupper(soil.name) == toupper(soil_type)) sand <- xsand.def[soil_type] clay <- xclay.def[soil_type] - + } else { - + if (any(c(sand, silt, clay) > 2)) { # assume values reported in % not proportion sand <- if (is.null(sand)) { NULL } else { sand / 100 } silt <- if (is.null(silt)) { NULL } else { silt / 100 } clay <- if (is.null(clay)) { NULL } else { clay / 100 } } - + # compute up to one missing value (>1 missing was handled above) sand <- sand %||% (1-silt-clay) silt <- silt %||% (1-sand-clay) clay <- clay %||% (1-sand-silt) - + #normalize stot <- sand + silt + clay sand <- sand / stot silt <- silt / stot clay <- clay / stot - + mysoil$soil_n <- sclass(sand,clay) mysoil$soil_type <- soil.name[mysoil$soil_n] } @@ -119,14 +141,14 @@ soil_params <- function(soil_type=NULL, sand=NULL, silt=NULL, clay=NULL, bulk=NU # Hydraulic conductivity at saturation [ m/s ] mysoil$soil_hydraulic_conductivity_at_saturation[z] <- PEcAn.utils::ud_convert(10.^(-0.60 + 1.26*mysoil$fraction_of_sand_in_soil[z] - 0.64*mysoil$fraction_of_clay_in_soil[z]), - "inch/hour","meters/second") + "inch/hour","meters/second") # Soil moisture at saturation [ m^3/m^3 ] mysoil$volume_fraction_of_water_in_soil_at_saturation[z] <- (50.5 - 14.2*mysoil$fraction_of_sand_in_soil[z] - 3.7*mysoil$fraction_of_clay_in_soil[z]) / 100. # Soil field capacity[ m^3/m^3 ] mysoil$volume_fraction_of_water_in_soil_at_field_capacity[z] <- mysoil$volume_fraction_of_water_in_soil_at_saturation[z] * ( fieldcp.K/mysoil$soil_hydraulic_conductivity_at_saturation[z])^ (1. / (2.*mysoil$soil_hydraulic_b[z]+3.)) - + } ## end primary properties #---------------------------------------------------------------------------------------# @@ -178,20 +200,20 @@ soil_params <- function(soil_type=NULL, sand=NULL, silt=NULL, clay=NULL, bulk=NU # # #---------------------------------------------------------------------------------------# mysoil$thcond0 <- ( ksand * mysoil$fraction_of_sand_in_soil * ( 1. - mysoil$volume_fraction_of_water_in_soil_at_saturation ) * sand.cond - + ksilt * mysoil$fraction_of_silt_in_soil * ( 1. - mysoil$volume_fraction_of_water_in_soil_at_saturation ) * silt.cond - + kclay * mysoil$fraction_of_clay_in_soil * ( 1. - mysoil$volume_fraction_of_water_in_soil_at_saturation ) * clay.cond - + kair * mysoil$volume_fraction_of_water_in_soil_at_saturation * air.cond ) + + ksilt * mysoil$fraction_of_silt_in_soil * ( 1. - mysoil$volume_fraction_of_water_in_soil_at_saturation ) * silt.cond + + kclay * mysoil$fraction_of_clay_in_soil * ( 1. - mysoil$volume_fraction_of_water_in_soil_at_saturation ) * clay.cond + + kair * mysoil$volume_fraction_of_water_in_soil_at_saturation * air.cond ) mysoil$thcond1 <- rep(h2o.cond - kair * air.cond,length=length(mysoil$thcond0)) mysoil$thcond2 <- ( ksand * mysoil$fraction_of_sand_in_soil * ( 1. - mysoil$volume_fraction_of_water_in_soil_at_saturation ) - + ksilt * mysoil$fraction_of_silt_in_soil * ( 1. - mysoil$volume_fraction_of_water_in_soil_at_saturation ) - + kclay * mysoil$fraction_of_clay_in_soil * ( 1. - mysoil$volume_fraction_of_water_in_soil_at_saturation ) - + kair * mysoil$volume_fraction_of_water_in_soil_at_saturation ) + + ksilt * mysoil$fraction_of_silt_in_soil * ( 1. - mysoil$volume_fraction_of_water_in_soil_at_saturation ) + + kclay * mysoil$fraction_of_clay_in_soil * ( 1. - mysoil$volume_fraction_of_water_in_soil_at_saturation ) + + kair * mysoil$volume_fraction_of_water_in_soil_at_saturation ) mysoil$thcond3 <- rep(1. - kair,length=length(mysoil$thcond0)) ## default soil thermal conductivity = dry mysoil$soil_thermal_conductivity <- ( mysoil$thcond0 + mysoil$thcond1 * mysoil$volume_fraction_of_condensed_water_in_dry_soil) / - ( mysoil$thcond2 + mysoil$thcond3 * mysoil$volume_fraction_of_condensed_water_in_dry_soil) + ( mysoil$thcond2 + mysoil$thcond3 * mysoil$volume_fraction_of_condensed_water_in_dry_soil) mysoil$soil_thermal_conductivity_at_saturation <- ( mysoil$thcond0 + mysoil$thcond1 * mysoil$volume_fraction_of_water_in_soil_at_saturation) / - ( mysoil$thcond2 + mysoil$thcond3 * mysoil$volume_fraction_of_water_in_soil_at_saturation) + ( mysoil$thcond2 + mysoil$thcond3 * mysoil$volume_fraction_of_water_in_soil_at_saturation) #---------------------------------------------------------------------------------------# @@ -203,11 +225,11 @@ soil_params <- function(soil_type=NULL, sand=NULL, silt=NULL, clay=NULL, bulk=NU } for(z in which(!(mysoil$soil_n > 13))){ ## if lack class-specific values, use across-soil average - mysoil$soil_albedo[z] <- median(texture$albdry) - if(is.null(bulk)) mysoil$soil_bulk_density[z] <- median(texture$xrobulk) - mysoil$slden[z] <- median(texture$slden) + mysoil$soil_albedo[z] <- stats::median(texture$albdry) + if(is.null(bulk)) mysoil$soil_bulk_density[z] <- stats::median(texture$xrobulk) + mysoil$slden[z] <- stats::median(texture$slden) } - + ## Conversions to standard variables mysoil$soil_thermal_capacity <- mysoil$slcpd / mysoil$soil_bulk_density ## J/m3/K / [kg m-3] -> J/kg/K @@ -218,7 +240,7 @@ soil_params <- function(soil_type=NULL, sand=NULL, silt=NULL, clay=NULL, bulk=NU #mysoil$slcpd <- NULL return(mysoil) - }#end function +}#end function #==========================================================================================# #==========================================================================================# @@ -226,7 +248,7 @@ soil_params <- function(soil_type=NULL, sand=NULL, silt=NULL, clay=NULL, bulk=NU - + #' This function determines the soil class number based on the fraction of sand, clay, and silt #' #' @param sandfrac From 756b1dab9990c4f7ca7bf3f01bcc9f8674402e52 Mon Sep 17 00:00:00 2001 From: Shashank Singh Date: Fri, 3 Nov 2023 07:08:49 +0000 Subject: [PATCH 02/17] revert stats namespace --- modules/data.land/R/plot2AGB.R | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/data.land/R/plot2AGB.R b/modules/data.land/R/plot2AGB.R index d2f956c59d4..786adc3969b 100644 --- a/modules/data.land/R/plot2AGB.R +++ b/modules/data.land/R/plot2AGB.R @@ -84,18 +84,18 @@ plot2AGB <- function(combined, out, outfolder, allom.stats, unit.conv = 0.02) { mbiomass_thoc2 <- sbiomass_thoc2 <- matrix(NA, mplot, nt) for (i in seq_len(mplot)) { - mNPP[i, ] <- apply(NPP[i, , ], 2, stats::mean, na.rm = TRUE) + mNPP[i, ] <- apply(NPP[i, , ], 2, mean, na.rm = TRUE) sNPP[i, ] <- apply(NPP[i, , ], 2, stats::sd, na.rm = TRUE) - mAGB[i, ] <- apply(AGB[i, , ], 2, stats::mean, na.rm = TRUE) + mAGB[i, ] <- apply(AGB[i, , ], 2, mean, na.rm = TRUE) sAGB[i, ] <- apply(AGB[i, , ], 2, stats::sd, na.rm = TRUE) - mbiomass_tsca[i, ] <- apply(biomass_tsca[i, , ], 2, stats::mean, na.rm = TRUE) + mbiomass_tsca[i, ] <- apply(biomass_tsca[i, , ], 2, mean, na.rm = TRUE) sbiomass_tsca[i, ] <- apply(biomass_tsca[i, , ], 2, stats::sd, na.rm = TRUE) - mbiomass_acsa3[i, ] <- apply(biomass_acsa3[i, , ], 2, stats::mean, na.rm = TRUE) + mbiomass_acsa3[i, ] <- apply(biomass_acsa3[i, , ], 2, mean, na.rm = TRUE) sbiomass_acsa3[i, ] <- apply(biomass_acsa3[i, , ], 2, stats::sd, na.rm = TRUE) - mbiomass_beal2[i, ] <- apply(biomass_beal2[i, , ], 2, stats::mean, na.rm = TRUE) + mbiomass_beal2[i, ] <- apply(biomass_beal2[i, , ], 2, mean, na.rm = TRUE) sbiomass_beal2[i, ] <- apply(biomass_beal2[i, , ], 2, stats::sd, na.rm = TRUE) - mbiomass_thoc2[i, ] <- apply(biomass_thoc2[i, , ], 2, stats::mean, na.rm = TRUE) + mbiomass_thoc2[i, ] <- apply(biomass_thoc2[i, , ], 2, mean, na.rm = TRUE) sbiomass_thoc2[i, ] <- apply(biomass_thoc2[i, , ], 2, stats::sd, na.rm = TRUE) } From 1514fa7aee7c13d71e655eb0d008c5dd08753490 Mon Sep 17 00:00:00 2001 From: Shashank Singh <73598347+moki1202@users.noreply.github.com> Date: Sun, 3 Dec 2023 14:39:47 +0530 Subject: [PATCH 03/17] Update modules/data.land/R/extract_soil_nc.R Co-authored-by: Chris Black --- modules/data.land/R/extract_soil_nc.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/data.land/R/extract_soil_nc.R b/modules/data.land/R/extract_soil_nc.R index fd42aa53b2b..78150480e4f 100644 --- a/modules/data.land/R/extract_soil_nc.R +++ b/modules/data.land/R/extract_soil_nc.R @@ -142,7 +142,7 @@ extract_soil_gssurgo<-function(outdir, lat, lon, size=1, radius=500, depths=c(0. # estimating the proportion of areas for those mukeys which are modeled mukey_area <- mukey_area %>% dplyr::filter(mukeys %in% simulated.soil.props$mukey) %>% - dplyr::mutate(Area=mukey_area$Area/sum(mukey_area$Area)) + dplyr::mutate(Area=.data$Area/sum(.data$Area)) #--- Mixing the depths soil.profiles<-simulated.soil.props %>% From 1e0bc67ef300eb5217a345b6d89085b9b9c02c7f Mon Sep 17 00:00:00 2001 From: Shashank Singh <73598347+moki1202@users.noreply.github.com> Date: Sun, 3 Dec 2023 14:39:56 +0530 Subject: [PATCH 04/17] Update modules/data.land/R/soil_utils.R Co-authored-by: Chris Black --- modules/data.land/R/soil_utils.R | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/modules/data.land/R/soil_utils.R b/modules/data.land/R/soil_utils.R index f166faeba37..2a731b65597 100644 --- a/modules/data.land/R/soil_utils.R +++ b/modules/data.land/R/soil_utils.R @@ -30,27 +30,27 @@ soil_params <- function(soil_type=NULL, sand=NULL, silt=NULL, clay=NULL, bulk=NU soil_data <- new.env() load(system.file("data/soil_class.RData",package = "PEcAn.data.land"), envir = soil_data) mysoil <- list() - soil.name <- soil_data$soil.name - xsand.def <- soil_data$xsand.def - xclay.def <- soil_data$xclay.def + air.cond <- soil_data$air.cond + air.hcap <- soil_data$air.hcap + clay.cond <- soil_data$clay.cond + clay.hcap <- soil_data$clay.hcap fieldcp.K <- soil_data$fieldcp.K - soilcp.MPa <- soil_data$soilcp.MPa grav <- soil_data$grav - soilwp.MPa <- soil_data$soilwp.MPa - sand.hcap <- soil_data$sand.hcap - silt.hcap <- soil_data$silt.hcap - clay.hcap <- soil_data$clay.hcap - air.hcap <- soil_data$air.hcap + h2o.cond <- soil_data$h2o.cond + kair <- soil_data$kair + kclay <- soil_data$kclay ksand <- soil_data$ksand - sand.cond <- soil_data$sand.cond ksilt <- soil_data$ksilt + sand.cond <- soil_data$sand.cond + sand.hcap <- soil_data$sand.hcap silt.cond <- soil_data$silt.cond - kclay <- soil_data$kclay - clay.cond <- soil_data$clay.cond - kair <- soil_data$kair - air.cond <- soil_data$air.cond - h2o.cond <- soil_data$h2o.cond + silt.hcap <- soil_data$silt.hcap + soil.name <- soil_data$soil.name + soilcp.MPa <- soil_data$soilcp.MPa + soilwp.MPa <- soil_data$soilwp.MPa texture <- soil_data$texture + xclay.def <- soil_data$xclay.def + xsand.def <- soil_data$xsand.def #---------------------------------------------------------------------------------------# # Find soil class and sand, silt, and clay fractions. # From 43274a511a71d4c406abac30a32e196a839b3555 Mon Sep 17 00:00:00 2001 From: Shashank Singh <73598347+moki1202@users.noreply.github.com> Date: Sun, 3 Dec 2023 14:41:52 +0530 Subject: [PATCH 05/17] Update modules/data.land/R/soil_utils.R Co-authored-by: Chris Black --- modules/data.land/R/soil_utils.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/data.land/R/soil_utils.R b/modules/data.land/R/soil_utils.R index 2a731b65597..39901edec1d 100644 --- a/modules/data.land/R/soil_utils.R +++ b/modules/data.land/R/soil_utils.R @@ -140,7 +140,10 @@ soil_params <- function(soil_type=NULL, sand=NULL, silt=NULL, clay=NULL, bulk=NU mysoil$soil_water_potential_at_saturation[z] <- -0.01 * (10.^(2.17 - 0.63*mysoil$fraction_of_clay_in_soil[z] - 1.58*mysoil$fraction_of_sand_in_soil[z])) # Hydraulic conductivity at saturation [ m/s ] - mysoil$soil_hydraulic_conductivity_at_saturation[z] <- PEcAn.utils::ud_convert(10.^(-0.60 + 1.26*mysoil$fraction_of_sand_in_soil[z] - 0.64*mysoil$fraction_of_clay_in_soil[z]), + mysoil$soil_hydraulic_conductivity_at_saturation[z] <- PEcAn.utils::ud_convert( + 10.^(-0.60 + + 1.26*mysoil$fraction_of_sand_in_soil[z] + - 0.64*mysoil$fraction_of_clay_in_soil[z]), "inch/hour","meters/second") # Soil moisture at saturation [ m^3/m^3 ] From 4e4eff50c9beea3561b2c20bd746b43d732f4d8a Mon Sep 17 00:00:00 2001 From: Shashank Singh <73598347+moki1202@users.noreply.github.com> Date: Sun, 3 Dec 2023 14:42:07 +0530 Subject: [PATCH 06/17] Update modules/data.land/R/soil_utils.R Co-authored-by: Chris Black --- modules/data.land/R/soil_utils.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/data.land/R/soil_utils.R b/modules/data.land/R/soil_utils.R index 39901edec1d..0121dc42402 100644 --- a/modules/data.land/R/soil_utils.R +++ b/modules/data.land/R/soil_utils.R @@ -144,7 +144,8 @@ soil_params <- function(soil_type=NULL, sand=NULL, silt=NULL, clay=NULL, bulk=NU 10.^(-0.60 + 1.26*mysoil$fraction_of_sand_in_soil[z] - 0.64*mysoil$fraction_of_clay_in_soil[z]), - "inch/hour","meters/second") + "inch/hour", + "meters/second") # Soil moisture at saturation [ m^3/m^3 ] mysoil$volume_fraction_of_water_in_soil_at_saturation[z] <- (50.5 - 14.2*mysoil$fraction_of_sand_in_soil[z] - 3.7*mysoil$fraction_of_clay_in_soil[z]) / 100. From 0b1fff18cf216aec619e4db696522256e2880286 Mon Sep 17 00:00:00 2001 From: Chris Black Date: Thu, 8 Feb 2024 15:38:27 -0800 Subject: [PATCH 07/17] silence some roxygen gripes --- modules/data.land/R/Soilgrids_SoilC_prep.R | 1 - modules/data.land/R/download_NEON_soilmoisture.R | 6 ++---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/modules/data.land/R/Soilgrids_SoilC_prep.R b/modules/data.land/R/Soilgrids_SoilC_prep.R index 516a8842e90..37ccca49860 100644 --- a/modules/data.land/R/Soilgrids_SoilC_prep.R +++ b/modules/data.land/R/Soilgrids_SoilC_prep.R @@ -10,7 +10,6 @@ #' @return A data frame containing AGB median and sd for each site and each time step. #' @export #' -#' @examples #' @author Dongchen Zhang #' @importFrom magrittr %>% Soilgrids_SoilC_prep <- function(site_info, start_date, end_date, time_points, diff --git a/modules/data.land/R/download_NEON_soilmoisture.R b/modules/data.land/R/download_NEON_soilmoisture.R index 78ae44326d1..c84bb563c7b 100644 --- a/modules/data.land/R/download_NEON_soilmoisture.R +++ b/modules/data.land/R/download_NEON_soilmoisture.R @@ -1,5 +1,3 @@ -##' @name download_NEON_soilmoist -##' @description: ##' Download NEON Soil Water Content and Soil Salinity data by date and site name ##' ##' @param site four letter NEON site code name(s). If no site is specified, it will download all of them (chr) (e.g "BART" or c("SRER", "KONA", "BART")) @@ -17,8 +15,8 @@ ##' ##' @author Juliette Bateman ##' -##' @example -##' \run{ +##' @examples +##' \dontrun{ ##' test <- download_NEON_soilmoisture( ##' site = c("SRER", "BART", "KONA"), ##' avg = 30, From b65eee62403fc1e694b57c8b72b04b01efae8f59 Mon Sep 17 00:00:00 2001 From: Chris Black Date: Thu, 8 Feb 2024 15:39:52 -0800 Subject: [PATCH 08/17] RPostgreSQL -> RPostgres --- docker/depends/pecan_package_dependencies.csv | 1 - modules/data.land/DESCRIPTION | 1 - modules/data.land/tests/testthat/test.PFT_consistency.R | 3 +-- modules/data.land/tests/testthat/test.match_species_id.R | 7 ++++--- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/docker/depends/pecan_package_dependencies.csv b/docker/depends/pecan_package_dependencies.csv index 89c1d5f6d46..e4787fb562b 100644 --- a/docker/depends/pecan_package_dependencies.csv +++ b/docker/depends/pecan_package_dependencies.csv @@ -479,7 +479,6 @@ "RPostgres","*","base/db","Suggests",FALSE "RPostgreSQL","*","base/db","Suggests",FALSE "RPostgreSQL","*","models/biocro","Suggests",FALSE -"RPostgreSQL","*","modules/data.land","Suggests",FALSE "Rpreles","*","models/preles","Suggests",FALSE "RSQLite","*","base/db","Suggests",FALSE "sf","*","modules/assim.sequential","Suggests",FALSE diff --git a/modules/data.land/DESCRIPTION b/modules/data.land/DESCRIPTION index eb187ac1667..7681f3fc94c 100644 --- a/modules/data.land/DESCRIPTION +++ b/modules/data.land/DESCRIPTION @@ -61,7 +61,6 @@ Suggests: PEcAn.settings, redland, raster, - RPostgreSQL, testthat (>= 1.0.2) License: BSD_3_clause + file LICENSE Copyright: Authors diff --git a/modules/data.land/tests/testthat/test.PFT_consistency.R b/modules/data.land/tests/testthat/test.PFT_consistency.R index df9fd04abd1..d183be193d2 100644 --- a/modules/data.land/tests/testthat/test.PFT_consistency.R +++ b/modules/data.land/tests/testthat/test.PFT_consistency.R @@ -6,14 +6,13 @@ library(PEcAn.utils) library(PEcAn.settings) library(PEcAn.DB) -library(RPostgreSQL) betyparms <- PEcAn.DB::get_postgres_envvars( host = "localhost", dbname = "bety", user = "bety", password = "bety", - driver = "PostgreSQL", + driver = "Postgres", write = FALSE) fiaparms <- betyparms fiaparms$dbname <- "fia5data" diff --git a/modules/data.land/tests/testthat/test.match_species_id.R b/modules/data.land/tests/testthat/test.match_species_id.R index dd3ab8c4acc..c692058861e 100644 --- a/modules/data.land/tests/testthat/test.match_species_id.R +++ b/modules/data.land/tests/testthat/test.match_species_id.R @@ -24,14 +24,15 @@ test_that("Species matching works", { dbname = "bety", user = "bety", password = "bety", - host = "localhost") + host = "localhost", + driver = "Postgres") con <- PEcAn.DB::db.open(db_params) test_merge(c('ACRU', 'TSCA'), 'usda', con) - test_merge(c(316, 261), 'fia', con) + test_merge(c(316L, 261L), 'fia', con) test_merge(c('Acer rubrum', 'Tsuga canadensis'), 'latin_name', con) - test_table <- data.frame(bety_species_id = c(30, 1419), + test_table <- data.frame(bety_species_id = c(30L, 1419L), input_code = c('AceRub', 'TsuCan')) test_merge(input_codes = test_table$input_code, format_name = 'custom', bety = con, From 89018493404985dc66f93db1b38117274216ea5f Mon Sep 17 00:00:00 2001 From: Chris Black Date: Fri, 9 Feb 2024 02:22:54 -0800 Subject: [PATCH 09/17] update ref check result --- modules/data.land/tests/Rcheck_reference.log | 247 ++----------------- 1 file changed, 21 insertions(+), 226 deletions(-) diff --git a/modules/data.land/tests/Rcheck_reference.log b/modules/data.land/tests/Rcheck_reference.log index beeca4c7797..a8e01f2b3a0 100644 --- a/modules/data.land/tests/Rcheck_reference.log +++ b/modules/data.land/tests/Rcheck_reference.log @@ -1,19 +1,13 @@ -* using log directory ‘/tmp/Rtmp9ipF88/PEcAn.data.land.Rcheck’ -* using R version 4.0.2 (2020-06-22) +* using log directory ‘/tmp/RtmpBGazJV/PEcAn.data.land.Rcheck’ +* using R version 4.1.3 (2022-03-10) * using platform: x86_64-pc-linux-gnu (64-bit) * using session charset: UTF-8 -* using options ‘--no-manual --as-cran’ +* using options ‘--no-tests --no-manual --as-cran’ * checking for file ‘PEcAn.data.land/DESCRIPTION’ ... OK * checking extension type ... Package -* this is package ‘PEcAn.data.land’ version ‘1.7.1’ +* this is package ‘PEcAn.data.land’ version ‘1.7.2.9000’ * package encoding: UTF-8 * checking package namespace information ... OK -* checking package dependencies ... WARNING - -Imports includes 33 non-default packages. -Importing from so many packages makes the package vulnerable to any of -them becoming unavailable. Move as many as possible to Suggests and -use conditionally. * checking package dependencies ... NOTE Imports includes 33 non-default packages. Importing from so many packages makes the package vulnerable to any of @@ -26,18 +20,12 @@ use conditionally. * checking for portable file names ... OK * checking for sufficient/correct file permissions ... OK * checking serialization versions ... OK -* checking whether package ‘PEcAn.data.land’ can be installed ... WARNING -Found the following significant warnings: - Note: possible error in 'write_veg(outfolder, ': unused argument (source) -See ‘/tmp/Rtmp9ipF88/PEcAn.data.land.Rcheck/00install.out’ for details. -Information on the location(s) of code generating the ‘Note’s can be -obtained by re-running with environment variable R_KEEP_PKG_SOURCE set -to ‘yes’. +* checking whether package ‘PEcAn.data.land’ can be installed ... OK * checking installed package size ... NOTE installed size is 13.4Mb sub-directories of 1Mb or more: - data 9.4Mb FIA_allometry 2.7Mb + data 9.4Mb * checking package directory ... OK * checking for future file timestamps ... OK * checking DESCRIPTION meta-information ... OK @@ -60,206 +48,38 @@ Non-standard file/directory found at top level: * checking replacement functions ... OK * checking foreign function calls ... OK * checking R code for possible problems ... NOTE -ens_veg_module: no visible global function definition for ‘db.close’ -ens_veg_module: no visible global function definition for ‘db.query’ -ens_veg_module: no visible global function definition for - ‘convert.input’ -EPA_ecoregion_finder: no visible global function definition for - ‘as_Spatial’ -extract_FIA: no visible global function definition for ‘db.close’ -extract_FIA: no visible global function definition for ‘db.query’ -extract_soil_gssurgo: no visible global function definition for ‘as’ -extract_soil_gssurgo: no visible global function definition for - ‘complete.cases’ -extract_soil_gssurgo: no visible global function definition for - ‘setNames’ -extract_soil_gssurgo: no visible global function definition for - ‘mutate’ +InventoryGrowthFusionDiagnostics: no visible binding for global + variable ‘data’ +Read.IC.info.BADM: no visible binding for global variable ‘.’ +Read.IC.info.BADM : : no visible binding for global variable + ‘.’ extract_soil_gssurgo : : no visible binding for global variable ‘.’ -extract_soil_gssurgo : : no visible global function - definition for ‘mutate’ -extract_soil_gssurgo: no visible global function definition for - ‘filter’ -extract_soil_gssurgo: no visible binding for global variable ‘Area’ extract_soil_gssurgo: no visible binding for global variable ‘.’ extract_soil_gssurgo : : : no visible binding for global variable ‘.’ -extract_soil_gssurgo : : no visible global function - definition for ‘setNames’ -extract_soil_nc: no visible global function definition for ‘median’ -extract_veg: possible error in write_veg(outfolder, start_date, - end_date, veg_info = veg_info, source): unused argument (source) -fia.to.psscss: no visible global function definition for ‘data’ fia.to.psscss: no visible binding for global variable ‘pftmapping’ -fia.to.psscss: no visible global function definition for ‘na.omit’ -fia.to.psscss: no visible global function definition for ‘median’ -fia.to.psscss: no visible global function definition for ‘write.table’ -fia.to.psscss: no visible global function definition for - ‘dbfile.input.insert’ -get_veg_module: no visible global function definition for - ‘convert.input’ get_veg_module: no visible binding for global variable ‘input’ -get_veg_module: no visible binding for global variable ‘new.site’ -ic_process: no visible global function definition for ‘db.close’ -ic_process: no visible global function definition for ‘db.query’ -id_resolveable: no visible binding for global variable ‘doi1’ -InventoryGrowthFusion: no visible global function definition for - ‘is.mcmc.list’ -InventoryGrowthFusion: no visible global function definition for - ‘mcmc.list2init’ -InventoryGrowthFusion: no visible global function definition for - ‘runif’ -InventoryGrowthFusion: no visible global function definition for ‘var’ -InventoryGrowthFusion: no visible global function definition for - ‘load.module’ -InventoryGrowthFusion: no visible global function definition for - ‘coda.samples’ -InventoryGrowthFusion: no visible global function definition for - ‘as.mcmc.list’ -InventoryGrowthFusion : : no visible global function - definition for ‘coef’ -InventoryGrowthFusion : : no visible global function - definition for ‘lm’ -InventoryGrowthFusionDiagnostics: no visible binding for global - variable ‘quantile’ -InventoryGrowthFusionDiagnostics: no visible global function definition - for ‘layout’ -InventoryGrowthFusionDiagnostics: no visible binding for global - variable ‘data’ -InventoryGrowthFusionDiagnostics: no visible global function definition - for ‘points’ -InventoryGrowthFusionDiagnostics: no visible global function definition - for ‘par’ -InventoryGrowthFusionDiagnostics: no visible global function definition - for ‘hist’ -InventoryGrowthFusionDiagnostics: no visible global function definition - for ‘abline’ -InventoryGrowthFusionDiagnostics: no visible global function definition - for ‘pairs’ -InventoryGrowthFusionDiagnostics: no visible global function definition - for ‘as.mcmc.list’ -InventoryGrowthFusionDiagnostics: no visible global function definition - for ‘gelman.diag’ -InventoryGrowthFusionDiagnostics: no visible global function definition - for ‘cor’ -InventoryGrowthFusionDiagnostics: no visible global function definition - for ‘lines’ -InventoryGrowthFusionDiagnostics: no visible global function definition - for ‘boxplot’ -InventoryGrowthFusionDiagnostics: no visible global function definition - for ‘legend’ is.land: no visible binding for global variable ‘met.nc’ -match_species_id: no visible binding for global variable ‘id’ -match_species_id: no visible binding for global variable ‘genus’ -match_species_id: no visible binding for global variable ‘species’ -matchInventoryRings: no visible global function definition for - ‘combine.rwl’ -matchInventoryRings: no visible global function definition for - ‘write.table’ -plot2AGB: no visible global function definition for ‘txtProgressBar’ -plot2AGB: no visible global function definition for ‘setTxtProgressBar’ -plot2AGB: no visible binding for global variable ‘sd’ -plot2AGB: no visible global function definition for ‘pdf’ -plot2AGB: no visible global function definition for ‘par’ -plot2AGB: no visible global function definition for ‘lines’ -put_veg_module: no visible global function definition for ‘db.close’ -put_veg_module: no visible global function definition for ‘db.query’ -put_veg_module: no visible global function definition for - ‘convert.input’ -Read.IC.info.BADM: no visible global function definition for ‘read.csv’ -Read.IC.info.BADM: no visible binding for global variable ‘NA_L2CODE’ -Read.IC.info.BADM: no visible binding for global variable ‘VARIABLE’ -Read.IC.info.BADM: no visible binding for global variable ‘.’ -Read.IC.info.BADM: no visible binding for global variable ‘SITE_ID’ -Read.IC.info.BADM: no visible binding for global variable ‘GROUP_ID’ -Read.IC.info.BADM: no visible binding for global variable - ‘VARIABLE_GROUP’ -Read.IC.info.BADM: no visible binding for global variable ‘DATAVALUE’ -Read.IC.info.BADM: no visible binding for global variable ‘NA_L1CODE’ -Read.IC.info.BADM : : no visible binding for global variable - ‘VARIABLE’ -Read.IC.info.BADM : : no visible binding for global variable - ‘.’ -Read.IC.info.BADM : : no visible binding for global variable - ‘DATAVALUE’ -read.plot: no visible global function definition for ‘read.csv’ -read.velmex: no visible global function definition for ‘read.fwf’ -sample_ic: no visible global function definition for ‘complete.cases’ -soil_params: no visible binding for global variable ‘soil.name’ -soil_params: no visible binding for global variable ‘xsand.def’ -soil_params: no visible binding for global variable ‘xclay.def’ -soil_params: no visible binding for global variable ‘fieldcp.K’ -soil_params: no visible binding for global variable ‘soilcp.MPa’ -soil_params: no visible binding for global variable ‘grav’ -soil_params: no visible binding for global variable ‘soilwp.MPa’ -soil_params: no visible binding for global variable ‘sand.hcap’ -soil_params: no visible binding for global variable ‘silt.hcap’ -soil_params: no visible binding for global variable ‘clay.hcap’ -soil_params: no visible binding for global variable ‘air.hcap’ -soil_params: no visible binding for global variable ‘ksand’ -soil_params: no visible binding for global variable ‘sand.cond’ -soil_params: no visible binding for global variable ‘ksilt’ -soil_params: no visible binding for global variable ‘silt.cond’ -soil_params: no visible binding for global variable ‘kclay’ -soil_params: no visible binding for global variable ‘clay.cond’ -soil_params: no visible binding for global variable ‘kair’ -soil_params: no visible binding for global variable ‘air.cond’ -soil_params: no visible binding for global variable ‘h2o.cond’ -soil_params: no visible binding for global variable ‘texture’ -soil_params: no visible global function definition for ‘median’ soil_process: no visible global function definition for ‘db.query’ write_ic: no visible binding for global variable ‘input_veg’ Undefined global functions or variables: - . abline air.cond air.hcap Area as as_Spatial as.mcmc.list - bagitFile boxplot clay.cond clay.hcap coda.samples coef - combine.rwl complete.cases comppct_r convert.input cor DATAVALUE - db.close db.query dbfile.input.insert doi1 fieldcp.K - filter gelman.diag genus grav GROUP_ID h2o.cond hist - hzdept_r id input input_veg is.mcmc.list kair kclay ksand ksilt - layout legend lines lm load.module mcmc.list2init median met.nc mn - mnId mutate NA_L1CODE NA_L2CODE na.omit new.site newdir_D1 - pairs par pdf pftmapping points quantile read.csv read.fwf - resource_map runif sand.cond sand.hcap sd setNames settings - setTxtProgressBar silt.cond silt.hcap SITE_ID soil.name soilcp.MPa - soilwp.MPa species texture txtProgressBar var VARIABLE - VARIABLE_GROUP write.table xclay.def xsand.def zip_contents + . data db.query input input_veg met.nc pftmapping Consider adding - importFrom("graphics", "abline", "boxplot", "hist", "layout", "legend", - "lines", "pairs", "par", "points") - importFrom("grDevices", "pdf") - importFrom("methods", "as") - importFrom("stats", "coef", "complete.cases", "cor", - "filter", "lm", "median", "na.omit", "quantile", - "runif", "sd", "setNames", "var") - importFrom("utils", "read.csv", "read.fwf", - "setTxtProgressBar", "txtProgressBar", "write.table") -to your NAMESPACE file (and ensure that your DESCRIPTION Imports field -contains 'methods'). + importFrom("utils", "data") to your NAMESPACE file. - -Found the following calls to data() loading into the global environment: -File ‘PEcAn.data.land/R/fia2ED.R’: - data(pftmapping) -See section ‘Good practice’ in ‘?data’. * checking Rd files ... OK * checking Rd metadata ... OK -* checking Rd line widths ... NOTE -Rd file 'dataone_download.Rd': - \examples lines wider than 100 characters: - dataone_download(id = "doi:10.6073/pasta/63ad7159306bc031520f09b2faefcf87", filepath = "/fs/data1/pecan.data/dbfiles") - -These lines will be truncated in the PDF manual. +* checking Rd line widths ... OK * checking Rd cross-references ... WARNING Missing link or links in documentation object 'EPA_ecoregion_finder.Rd': ‘https://www.epa.gov/eco-research/ecoregions’ See section 'Cross-references' in the 'Writing R Extensions' manual. - * checking for missing documentation entries ... WARNING Undocumented data sets: - ‘BADM’ ‘.extract.nc.module’ ‘.getRunSettings’ ‘.met2model.module’ - ‘.Random.seed’ ‘air.cond’ ‘air.hcap’ ‘clay.cond’ ‘clay.hcap’ + ‘BADM’ ‘.Random.seed’ ‘.extract.nc.module’ ‘.getRunSettings’ + ‘.met2model.module’ ‘air.cond’ ‘air.hcap’ ‘clay.cond’ ‘clay.hcap’ ‘clay.now’ ‘fieldcp.K’ ‘grav’ ‘h2o.cond’ ‘kair’ ‘kclay’ ‘ksand’ ‘ksilt’ ‘n’ ‘nstext.lines’ ‘nstext.polygon’ ‘sand.cond’ ‘sand.hcap’ ‘sand.now’ ‘silt.cond’ ‘silt.hcap’ ‘soil.key’ ‘soil.name’ @@ -283,13 +103,6 @@ Undocumented arguments in documentation object 'Read_Tucson' Undocumented arguments in documentation object 'extract.stringCode' ‘x’ ‘extractor’ -Undocumented arguments in documentation object 'extract_FIA' - ‘lon’ ‘lat’ ‘start_date’ ‘end_date’ ‘gridres’ ‘dbparms’ - -Undocumented arguments in documentation object 'extract_veg' - ‘new_site’ ‘start_date’ ‘end_date’ ‘source’ ‘gridres’ ‘format_name’ - ‘machine_host’ ‘dbparms’ ‘outfolder’ ‘overwrite’ ‘...’ - Undocumented arguments in documentation object 'fia.to.psscss' ‘settings’ ‘lat’ ‘lon’ ‘year’ ‘gridres’ ‘min.year’ ‘max.year’ ‘overwrite’ @@ -302,11 +115,6 @@ Undocumented arguments in documentation object 'from.Tag' Undocumented arguments in documentation object 'from.TreeCode' ‘x’ -Undocumented arguments in documentation object 'ic_process' - ‘input’ ‘dir’ -Documented arguments not in \usage in documentation object 'ic_process': - ‘dbfiles’ - Undocumented arguments in documentation object 'load_veg' ‘new_site’ ‘start_date’ ‘end_date’ ‘source_id’ ‘source’ ‘icmeta’ ‘format_name’ ‘machine_host’ ‘dbparms’ ‘outfolder’ ‘overwrite’ ‘...’ @@ -314,9 +122,6 @@ Undocumented arguments in documentation object 'load_veg' Undocumented arguments in documentation object 'matchInventoryRings' ‘trees’ ‘rings’ ‘extractor’ ‘nyears’ ‘coredOnly’ -Undocumented arguments in documentation object 'match_pft' - ‘query’ - Undocumented arguments in documentation object 'match_species_id' ‘...’ @@ -332,12 +137,6 @@ Undocumented arguments in documentation object 'netcdf.writer.BADM' Undocumented arguments in documentation object 'plot2AGB' ‘allom.stats’ -Undocumented arguments in documentation object 'pool_ic_list2netcdf' - ‘ens’ - -Undocumented arguments in documentation object 'sample_ic' - ‘...’ - Undocumented arguments in documentation object 'soil_process' ‘run.local’ @@ -347,10 +146,6 @@ Undocumented arguments in documentation object 'to.Tag' Undocumented arguments in documentation object 'to.TreeCode' ‘SITE’ ‘PLOT’ ‘SUBPLOT’ ‘TAG’ -Undocumented arguments in documentation object 'write_ic' - ‘in.path’ ‘in.name’ ‘start_date’ ‘end_date’ ‘outfolder’ ‘model’ - ‘new_site’ ‘pfts’ ‘source’ ‘overwrite’ ‘...’ - Functions with \usage entries need to have the appropriate \alias entries, and all their arguments documented. The \usage entries must correspond to syntactically valid R code. @@ -1274,14 +1069,14 @@ Please remove it. soil_class.RData 117Kb 18Kb xz * checking examples ... OK * checking for unstated dependencies in ‘tests’ ... OK -* checking tests ... - Running ‘testthat.R’ - OK +* checking tests ... SKIPPED * checking for non-standard things in the check directory ... OK * checking for detritus in the temp directory ... OK * DONE -Status: 7 WARNINGs, 5 NOTEs +Status: 7 WARNINGs, 4 NOTEs See - ‘/tmp/Rtmp9ipF88/PEcAn.data.land.Rcheck/00check.log’ + ‘/tmp/RtmpBGazJV/PEcAn.data.land.Rcheck/00check.log’ for details. + + From 61289af8bda7159ce30f08ae86d9df18028270df Mon Sep 17 00:00:00 2001 From: Chris Black Date: Fri, 9 Feb 2024 02:27:40 -0800 Subject: [PATCH 10/17] test fixups --- ...T_consistency.R => test-PFT_consistency.R} | 12 ++--- .../tests/testthat/test-soil_params.R | 2 - .../tests/testthat/test.match_species_id.R | 45 ++++++++++--------- 3 files changed, 27 insertions(+), 32 deletions(-) rename modules/data.land/tests/testthat/{test.PFT_consistency.R => test-PFT_consistency.R} (78%) diff --git a/modules/data.land/tests/testthat/test.PFT_consistency.R b/modules/data.land/tests/testthat/test-PFT_consistency.R similarity index 78% rename from modules/data.land/tests/testthat/test.PFT_consistency.R rename to modules/data.land/tests/testthat/test-PFT_consistency.R index d183be193d2..e2c3d677de4 100644 --- a/modules/data.land/tests/testthat/test.PFT_consistency.R +++ b/modules/data.land/tests/testthat/test-PFT_consistency.R @@ -3,9 +3,6 @@ # # @author Anthony Cohen # ---------------------------------------------------------------------------------------------------------- -library(PEcAn.utils) -library(PEcAn.settings) -library(PEcAn.DB) betyparms <- PEcAn.DB::get_postgres_envvars( host = "localhost", @@ -16,13 +13,12 @@ betyparms <- PEcAn.DB::get_postgres_envvars( write = FALSE) fiaparms <- betyparms fiaparms$dbname <- "fia5data" -if (db.exists(params = betyparms) && db.exists(fiaparms)) { +if (PEcAn.DB::db.exists(params = betyparms) && PEcAn.DB::db.exists(fiaparms)) { - context("Testing consistency of FIA PFTs") test_that("PFTs don't overlap species", { - overlapping.pfts <- read.settings("dup_species.xml") #settings list + overlapping.pfts <- PEcAn.settings::read.settings("dup_species.xml") #settings list #expect_output(fia.to.psscss(overlapping.pfts), "ERROR \\[.*\\] : There are [0123456789]+ spcd entries that are duplicated. Please remove overlapping PFTs.") expect_error(fia.to.psscss(overlapping.pfts)) @@ -31,14 +27,14 @@ if (db.exists(params = betyparms) && db.exists(fiaparms)) { test_that("User is warned if PFTs have extra species not suggested by FIA", { - extra.pft <- read.settings("wrong_pft.xml") + extra.pft <- PEcAn.settings::read.settings("wrong_pft.xml") expect_error(fia.to.psscss(extra.pft)) }) test_that("PFTs encompass all species suggested by FIA", { - insufficient.pft <- read.settings("wrong_pft.xml") + insufficient.pft <- PEcAn.settings::read.settings("wrong_pft.xml") expect_error(fia.to.psscss(insufficient.pft)) }) diff --git a/modules/data.land/tests/testthat/test-soil_params.R b/modules/data.land/tests/testthat/test-soil_params.R index 9b567cca49c..331112c1815 100644 --- a/modules/data.land/tests/testthat/test-soil_params.R +++ b/modules/data.land/tests/testthat/test-soil_params.R @@ -1,6 +1,4 @@ -context("soil_params") - test_that("accepts 2-component textures", { sand <- c(0.3, 0.4, 0.5) clay <- c(0.2, 0.3, 0.3) diff --git a/modules/data.land/tests/testthat/test.match_species_id.R b/modules/data.land/tests/testthat/test.match_species_id.R index c692058861e..ae3ba6dafb3 100644 --- a/modules/data.land/tests/testthat/test.match_species_id.R +++ b/modules/data.land/tests/testthat/test.match_species_id.R @@ -1,23 +1,20 @@ - -context("Species matching") - test_that("Species matching works", { + test_merge <- function(input_codes, format_name, bety, ...) { - dat_merge <- match_species_id(input_codes = input_codes, - format_name = format_name, - bety = bety, - ...) - test_that(paste0('Species match works for format: ', format_name), - { - expect_equal(dat_merge[1, 'genus'], 'Acer') - expect_equal(dat_merge[1, 'species'], 'rubrum') - expect_equal(dat_merge[2, 'genus'], 'Tsuga') - expect_equal(dat_merge[2, 'species'], 'canadensis') - expect_equal(nrow(dat_merge), length(input_codes)) - expect_false(any(is.na(dat_merge$bety_species_id))) - expect_false(any(duplicated(dat_merge))) - }) - return(dat_merge) + dat_merge <- match_species_id( + input_codes = input_codes, + format_name = format_name, + bety = bety, + ...) + expect_equal(dat_merge[1, 'genus'], 'Acer') + expect_equal(dat_merge[1, 'species'], 'rubrum') + expect_equal(dat_merge[2, 'genus'], 'Tsuga') + expect_equal(dat_merge[2, 'species'], 'canadensis') + expect_equal(nrow(dat_merge), length(input_codes)) + expect_false(any(is.na(dat_merge$bety_species_id))) + expect_false(any(duplicated(dat_merge))) + + return(dat_merge) } db_params <- PEcAn.DB::get_postgres_envvars( @@ -32,9 +29,13 @@ test_that("Species matching works", { test_merge(c(316L, 261L), 'fia', con) test_merge(c('Acer rubrum', 'Tsuga canadensis'), 'latin_name', con) - test_table <- data.frame(bety_species_id = c(30L, 1419L), - input_code = c('AceRub', 'TsuCan')) + test_table <- data.frame( + bety_species_id = c(30L, 1419L), + input_code = c('AceRub', 'TsuCan')) - test_merge(input_codes = test_table$input_code, format_name = 'custom', bety = con, - translation_table = test_table) + test_merge( + input_codes = test_table$input_code, + format_name = 'custom', + bety = con, + translation_table = test_table) }) From ee18be0058dd31bb6616ffbe618b227bd5d204da Mon Sep 17 00:00:00 2001 From: Chris Black Date: Fri, 9 Feb 2024 02:30:18 -0800 Subject: [PATCH 11/17] rename --- .../testthat/{test.match_species_id.R => test-match_species_id.R} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename modules/data.land/tests/testthat/{test.match_species_id.R => test-match_species_id.R} (100%) diff --git a/modules/data.land/tests/testthat/test.match_species_id.R b/modules/data.land/tests/testthat/test-match_species_id.R similarity index 100% rename from modules/data.land/tests/testthat/test.match_species_id.R rename to modules/data.land/tests/testthat/test-match_species_id.R From 3abab3698d0ea8683c46f9f0d89510ce9d7b2cf3 Mon Sep 17 00:00:00 2001 From: Chris Black Date: Fri, 9 Feb 2024 02:32:59 -0800 Subject: [PATCH 12/17] roxygen no longer skips this one --- .../data.land/man/download_NEON_soilmoist.Rd | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 modules/data.land/man/download_NEON_soilmoist.Rd diff --git a/modules/data.land/man/download_NEON_soilmoist.Rd b/modules/data.land/man/download_NEON_soilmoist.Rd new file mode 100644 index 00000000000..2ce60df1737 --- /dev/null +++ b/modules/data.land/man/download_NEON_soilmoist.Rd @@ -0,0 +1,52 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/download_NEON_soilmoisture.R +\name{download_NEON_soilmoist} +\alias{download_NEON_soilmoist} +\title{Download NEON Soil Water Content and Soil Salinity data by date and site name} +\usage{ +download_NEON_soilmoist( + site, + avg = "all", + var = "all", + startdate = NA, + enddate = NA, + outdir +) +} +\arguments{ +\item{site}{four letter NEON site code name(s). If no site is specified, it will download all of them (chr) (e.g "BART" or c("SRER", "KONA", "BART"))} + +\item{avg}{averaging interval (minutes): 1, 30, or both ("all") . default returns both} + +\item{var}{variable of interest: "SWC" (soil water content) or "SIC" (soil ion content) or both ("all") default returns both. +Both variables will be saved in outdir automatically (chr)} + +\item{startdate}{start date as YYYY-mm. If left empty, all data available will be downloaded (chr)} + +\item{enddate}{start date as YYYY-mm. If left empty, all data available will be downloaded (chr)} + +\item{outdir}{out directory to store the following data: +.rds list files of SWC and SIC data for each site and sensor position, +sensor positions .csv for each site, +variable description .csv file, +readme .csv file} +} +\value{ +List of specified variable(s) AND prints the path to output folder +} +\description{ +Download NEON Soil Water Content and Soil Salinity data by date and site name +} +\examples{ +\dontrun{ +test <- download_NEON_soilmoisture( + site = c("SRER", "BART", "KONA"), + avg = 30, + var = "SWC", + startdate = "2019-01", + enddate = "2020-01", + outdir = getwd())} +} +\author{ +Juliette Bateman +} From 8c2bc162a07acba5a56756339dd2df7a19190af1 Mon Sep 17 00:00:00 2001 From: Chris Black Date: Fri, 9 Feb 2024 03:54:52 -0800 Subject: [PATCH 13/17] flailing at isFALSE --- base/db/DESCRIPTION | 2 +- docker/depends/pecan_package_dependencies.csv | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/base/db/DESCRIPTION b/base/db/DESCRIPTION index f8d67075ad2..519ff68123b 100644 --- a/base/db/DESCRIPTION +++ b/base/db/DESCRIPTION @@ -65,7 +65,7 @@ Suggests: bit64, data.table, here, - knitr, + knitr (>= 1.42), mockery (>= 0.4.3), RPostgreSQL, RPostgres, diff --git a/docker/depends/pecan_package_dependencies.csv b/docker/depends/pecan_package_dependencies.csv index e4787fb562b..18ee54afc48 100644 --- a/docker/depends/pecan_package_dependencies.csv +++ b/docker/depends/pecan_package_dependencies.csv @@ -110,13 +110,13 @@ "IDPmisc","*","modules/assim.batch","Imports",FALSE "jsonlite","*","base/remote","Imports",FALSE "jsonlite","*","modules/data.atmosphere","Imports",FALSE -"knitr","*","base/db","Suggests",FALSE "knitr","*","base/qaqc","Suggests",FALSE "knitr","*","modules/allometry","Suggests",FALSE "knitr","*","modules/assim.batch","Suggests",FALSE "knitr","*","modules/meta.analysis","Suggests",FALSE "knitr","*","modules/photosynthesis","Suggests",FALSE "knitr","*","modules/rtm","Suggests",FALSE +"knitr",">= 1.42","base/db","Suggests",FALSE "lattice","*","modules/meta.analysis","Imports",FALSE "linkages","*","models/linkages","Suggests",FALSE "lqmm","*","modules/assim.batch","Imports",FALSE From 14299cd39d481b3ea277823b3bbc9558710e77c7 Mon Sep 17 00:00:00 2001 From: Chris Black Date: Tue, 13 Feb 2024 14:09:26 -0800 Subject: [PATCH 14/17] whitespace --- modules/data.land/R/soil_utils.R | 6 ------ 1 file changed, 6 deletions(-) diff --git a/modules/data.land/R/soil_utils.R b/modules/data.land/R/soil_utils.R index 0121dc42402..68d9d4d599e 100644 --- a/modules/data.land/R/soil_utils.R +++ b/modules/data.land/R/soil_utils.R @@ -66,27 +66,22 @@ soil_params <- function(soil_type=NULL, sand=NULL, silt=NULL, clay=NULL, bulk=NU mysoil$soil_n <- which(toupper(soil.name) == toupper(soil_type)) sand <- xsand.def[soil_type] clay <- xclay.def[soil_type] - } else { - if (any(c(sand, silt, clay) > 2)) { # assume values reported in % not proportion sand <- if (is.null(sand)) { NULL } else { sand / 100 } silt <- if (is.null(silt)) { NULL } else { silt / 100 } clay <- if (is.null(clay)) { NULL } else { clay / 100 } } - # compute up to one missing value (>1 missing was handled above) sand <- sand %||% (1-silt-clay) silt <- silt %||% (1-sand-clay) clay <- clay %||% (1-sand-silt) - #normalize stot <- sand + silt + clay sand <- sand / stot silt <- silt / stot clay <- clay / stot - mysoil$soil_n <- sclass(sand,clay) mysoil$soil_type <- soil.name[mysoil$soil_n] } @@ -152,7 +147,6 @@ soil_params <- function(soil_type=NULL, sand=NULL, silt=NULL, clay=NULL, bulk=NU # Soil field capacity[ m^3/m^3 ] mysoil$volume_fraction_of_water_in_soil_at_field_capacity[z] <- mysoil$volume_fraction_of_water_in_soil_at_saturation[z] * ( fieldcp.K/mysoil$soil_hydraulic_conductivity_at_saturation[z])^ (1. / (2.*mysoil$soil_hydraulic_b[z]+3.)) - } ## end primary properties #---------------------------------------------------------------------------------------# From 6bc04beb8ac789dd53cc95997575482bc011e60d Mon Sep 17 00:00:00 2001 From: Chris Black Date: Tue, 13 Feb 2024 14:10:15 -0800 Subject: [PATCH 15/17] move explanation of %||% --- modules/data.land/R/soil_utils.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/data.land/R/soil_utils.R b/modules/data.land/R/soil_utils.R index 68d9d4d599e..5d78dfa87d1 100644 --- a/modules/data.land/R/soil_utils.R +++ b/modules/data.land/R/soil_utils.R @@ -20,7 +20,7 @@ #' @return list of soil hydraulic and thermal parameters #' @export #' @importFrom rlang %||% -# null-filling operator: A %||% B == "B if A is null, A in all other cases" + # `A %||% B` is a null-filling operator: "B if A is null, A in all other cases" #' @examples #' sand <- c(0.3, 0.4, 0.5) #' clay <- c(0.3, 0.3, 0.3) @@ -74,6 +74,7 @@ soil_params <- function(soil_type=NULL, sand=NULL, silt=NULL, clay=NULL, bulk=NU clay <- if (is.null(clay)) { NULL } else { clay / 100 } } # compute up to one missing value (>1 missing was handled above) + # %||% is a null-filling operator: A %||% B == "B if A is null, A in all other cases" sand <- sand %||% (1-silt-clay) silt <- silt %||% (1-sand-clay) clay <- clay %||% (1-sand-silt) From 4fdb509b95f41da85378ff51c37530f46d0fcfb3 Mon Sep 17 00:00:00 2001 From: Chris Black Date: Tue, 13 Feb 2024 14:10:55 -0800 Subject: [PATCH 16/17] no really --- modules/data.land/R/soil_utils.R | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/data.land/R/soil_utils.R b/modules/data.land/R/soil_utils.R index 5d78dfa87d1..d35831c95ec 100644 --- a/modules/data.land/R/soil_utils.R +++ b/modules/data.land/R/soil_utils.R @@ -20,7 +20,6 @@ #' @return list of soil hydraulic and thermal parameters #' @export #' @importFrom rlang %||% - # `A %||% B` is a null-filling operator: "B if A is null, A in all other cases" #' @examples #' sand <- c(0.3, 0.4, 0.5) #' clay <- c(0.3, 0.3, 0.3) From 9efc927b14ff1f53dfb7714590d4b5f2d717f66b Mon Sep 17 00:00:00 2001 From: Chris Black Date: Tue, 13 Feb 2024 14:12:42 -0800 Subject: [PATCH 17/17] remove confusing pipe --- modules/data.land/R/IC_BADM_Utilities.R | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/data.land/R/IC_BADM_Utilities.R b/modules/data.land/R/IC_BADM_Utilities.R index 18c62ef277e..700a7b20ab1 100644 --- a/modules/data.land/R/IC_BADM_Utilities.R +++ b/modules/data.land/R/IC_BADM_Utilities.R @@ -32,7 +32,7 @@ Read.IC.info.BADM <-function(lat, long){ biomass.df <- U.S.SB %>% dplyr::filter( .data$NA_L2CODE == Code_Level, - .data$VARIABLE %>% grepl("ROOT_|AG_BIOMASS|SOIL_STOCK|SOIL_CHEM", .) + grepl("ROOT_|AG_BIOMASS|SOIL_STOCK|SOIL_CHEM", .data$VARIABLE) ) %>% dplyr::select("SITE_ID", "GROUP_ID", "VARIABLE_GROUP", "VARIABLE", "DATAVALUE") @@ -44,7 +44,7 @@ Read.IC.info.BADM <-function(lat, long){ biomass.df <- U.S.SB %>% dplyr::filter( .data$NA_L1CODE == Code_Level, - .data$VARIABLE %>% grepl("ROOT_|AG_BIOMASS|SOIL_STOCK|SOIL_CHEM", .) + grepl("ROOT_|AG_BIOMASS|SOIL_STOCK|SOIL_CHEM", .data$VARIABLE) ) %>% dplyr::select("SITE_ID", "GROUP_ID", "VARIABLE_GROUP", "VARIABLE", "DATAVALUE") } @@ -54,7 +54,7 @@ Read.IC.info.BADM <-function(lat, long){ if (nrow(biomass.df) < 3) { Code_Level <- "ALL" biomass.df <- U.S.SB %>% - dplyr::filter(.data$VARIABLE %>% grepl("ROOT_|AG_BIOMASS|SOIL_STOCK|SOIL_CHEM", .)) %>% + dplyr::filter(grepl("ROOT_|AG_BIOMASS|SOIL_STOCK|SOIL_CHEM", .data$VARIABLE)) %>% dplyr::select("SITE_ID", "GROUP_ID", "VARIABLE_GROUP", "VARIABLE", "DATAVALUE") } @@ -94,7 +94,7 @@ Read.IC.info.BADM <-function(lat, long){ type <- type[-which(type == "*_BIOMASS")] #----------------- Unit conversion unit.in <- Gdf %>% - dplyr::filter(.data$VARIABLE %>% grepl("UNIT", .)) %>% + dplyr::filter(grepl("UNIT", .data$VARIABLE)) %>% dplyr::pull(.data$DATAVALUE) %>% as.character() @@ -113,7 +113,7 @@ Read.IC.info.BADM <-function(lat, long){ unit.ready <- "kg/m^2" Date.in <- Gdf %>% - dplyr::filter(.data$VARIABLE %>% grepl("DATE", .)) %>% + dplyr::filter(grepl("DATE", .data$VARIABLE)) %>% dplyr::pull(.data$DATAVALUE) %>% as.Date() @@ -124,7 +124,7 @@ Read.IC.info.BADM <-function(lat, long){ # if it's biomass if (type == "*_BIOMASS") { Oregan.in <- Gdf %>% - dplyr::filter(.data$VARIABLE %>% grepl("ORGAN", .)) %>% + dplyr::filter(grepl("ORGAN", .data$VARIABLE)) %>% dplyr::pull(.data$DATAVALUE) @@ -134,7 +134,7 @@ Read.IC.info.BADM <-function(lat, long){ } else if (type == "*SOIL") { val <- Gdf %>% - dplyr::filter(.data$VARIABLE %>% grepl("SOIL_STOCK_C_ORG", .)) %>% #"SOIL_STOCK_C_ORG" + dplyr::filter(grepl("SOIL_STOCK_C_ORG", .data$VARIABLE)) %>% dplyr::pull(.data$DATAVALUE) %>% as.numeric()