diff --git a/R/AAAA.R b/R/AAAA.R index 425ac532..6d77f4db 100644 --- a/R/AAAA.R +++ b/R/AAAA.R @@ -6,18 +6,18 @@ soilDB.env <- new.env(hash=TRUE, parent = parent.frame()) .onLoad <- function(libname, pkgname) { # deprecated: soilDB 2.5.9 CRAN release - options(.soilDB_testNetworkFunctions=TRUE) - + options(.soilDB_testNetworkFunctions = TRUE) + # function verbosity - options(soilDB.verbose=FALSE) - + options(soilDB.verbose = FALSE) + # set default local nasis authentication - options(soilDB.NASIS.credentials="DSN=nasis_local;UID=NasisSqlRO;PWD=nasisRe@d0n1y") - + options(soilDB.NASIS.credentials = "DSN=nasis_local;UID=NasisSqlRO;PWD=nasisRe@d0n1y") + # update according to win 7 or 10 si <- Sys.info() - if( grepl('windows', si['sysname'], ignore.case = TRUE) & grepl('8|10', si['release'], ignore.case = TRUE) ) { - options(soilDB.NASIS.credentials="DSN=nasis_local;UID=NasisSqlRO;PWD=nasisRe@d0n1y365") + if (grepl('windows', si['sysname'], ignore.case = TRUE) & grepl('8|10', si['release'], ignore.case = TRUE)) { + options(soilDB.NASIS.credentials = "DSN=nasis_local;UID=NasisSqlRO;PWD=nasisRe@d0n1y365") } } diff --git a/R/get_extended_data_from_NASIS_db.R b/R/get_extended_data_from_NASIS_db.R index 71e14389..3aae3527 100644 --- a/R/get_extended_data_from_NASIS_db.R +++ b/R/get_extended_data_from_NASIS_db.R @@ -520,19 +520,21 @@ LEFT OUTER JOIN ( # summarize rock fragment data if (nrow(d.rf.data) > 0) { # keep track of UNIQUE original phiids so that we can optionally fill NA with 0 in a second pass - all.ids <- unique(d.rf.data[, 'phiid', drop=FALSE]) + all.ids <- unique(d.rf.data[, 'phiid', drop = FALSE]) # left join d.rf.summary <- merge(all.ids, d.rf.summary, by = 'phiid', sort = FALSE, all.x = TRUE, incomparables = NA) ## basic checks for problematic data + # 2022/05/18: removed this QC warning, the "change" to 75mm was a typographical error + # recent NSSH changes to gravel/cobble threshold 76mm -> 75mm - qc.idx <- which(d.rf.data$fragsize_h == 76) - if(length(qc.idx) > 0) { - msg <- sprintf('-> QC: some fragsize_h values == 76mm, may be mis-classified as cobbles [%i / %i records]', length(qc.idx), nrow(d.rf.data)) - message(msg) - } + # qc.idx <- which(d.rf.data$fragsize_h == 76) + # if (length(qc.idx) > 0) { + # msg <- sprintf('-> QC: some fragsize_h values == 75mm, may be mis-classified as cobbles [%i / %i records]', length(qc.idx), nrow(d.rf.data)) + # message(msg) + # } } @@ -552,15 +554,9 @@ LEFT OUTER JOIN ( if (nrow(d.art.data) > 0) { - art.all.ids <- unique(d.art.data[, 'phiid', drop=FALSE]) + art.all.ids <- unique(d.art.data[, 'phiid', drop = FALSE]) d.art.summary <- merge(art.all.ids, d.art.summary, by = 'phiid', sort = FALSE, all.x = TRUE, incomparables = NA) - # recent NSSH changes to gravel/cobble threshold 76mm -> 75mm - qc.idx <- which(d.art.data$huartsize_h == 76) - if (length(qc.idx) > 0) { - msg <- sprintf('-> QC: some huartsize_h values == 76mm, may be mis-classified as cobbles [%i / %i records]', length(qc.idx), nrow(d.art.data)) - message(msg) - } } if (nullFragsAreZero) { @@ -578,8 +574,7 @@ LEFT OUTER JOIN ( # if (nullFragsAreZero == TRUE) { # d.rf.data.v2[idx] <- lapply(d.rf.data.v2[idx], function(x) ifelse(is.na(x), 0, x)) # } - - + # return a list of results return(list(ecositehistory = d.ecosite, siteaoverlap = d.siteaoverlap, diff --git a/R/simplfyFragmentData.R b/R/simplfyFragmentData.R index 348c2348..2572d448 100644 --- a/R/simplfyFragmentData.R +++ b/R/simplfyFragmentData.R @@ -1,52 +1,52 @@ ## TODO: generalize, export, and make sieve sizes into an argument - -# latest NSSH part 618 -# https://directives.sc.egov.usda.gov/OpenNonWebContent.aspx?content=44371.wba +## 2022 I propose we move .sieve to aqp and export it there, see updates --agb # internally-used function to test size classes # diameter is in mm # NA diameter results in NA class -.sieve <- function(diameter, flat=FALSE, para=FALSE, new.names = NULL) { - - # flat fragments - if(flat == TRUE) - sieves <- c(channers=150, flagstones=380, stones=600, boulders=10000000000) - - # non-flat fragments - if(flat == FALSE) - sieves <- c(fine_gravel=5, gravel=75, cobbles=250, stones=600, boulders=10000000000) - - if(!is.null(new.names)) +.sieve <- function(diameter, flat = FALSE, para = FALSE, + sieves = c(fine_gravel = 5, gravel = 76, cobbles = 250, stones = 600, boulders = 1e10), + new.names = NULL) { + + if (flat && missing(sieves)) { + sieves <- c(channers = 150, flagstones = 380, stones = 600, boulders = 1e10) + } + + if (!is.null(new.names)) { names(sieves) <- new.names + } # test for NA, and filter-out - res <- vector(mode='character', length = length(diameter)) + res <- vector(mode = 'character', length = length(diameter)) res[which(is.na(diameter))] <- NA no.na.idx <- which(!is.na(diameter)) # only assign classes to non-NA diameters - if(length(no.na.idx) > 0) { + if (length(no.na.idx) > 0) { # pass diameters "through" sieves # 2020: latest part 618 uses '<' for all upper values of class range + # 2022: adjusted gravel upper threshold to 76 mm classes <- t(sapply(diameter[no.na.idx], function(i) i < sieves)) # determine largest passing sieve name res[no.na.idx] <- names(sieves)[apply(classes, 1, which.max)] # change names if we are working with parafrags - if(para == TRUE) + + if (para == TRUE) { res[no.na.idx] <- paste0('para', res[no.na.idx]) + } } return(res) } - -## TODO: this is NASIS-specific for now, generalize this to any data # x: uncoded contents of the phfrags table -.rockFragmentSieve <- function(x, vol.var = "fragvol", prefix = "frag") { +# vol.var: column name in x containing fragment volume (default (`"fragvol"`)) +# prefix: prefix used in common with hardness and shape var (default `"frag"`) +# ...: additional arguments to .sieve +.rockFragmentSieve <- function(x, vol.var = "fragvol", prefix = "frag", ...) { - xvar <- vol.var hardvar <- paste0(prefix, "hard") shpvar <- paste0(prefix, "shp") sizevar <- paste0(paste0(prefix, "size"), c("_l","_r","_h")) @@ -79,7 +79,6 @@ idx <- grep('strong|indurated', x[[hardvar]], ignore.case = TRUE, invert = TRUE) parafrags <- x[idx, ] - ## split flat / non-flat # frags idx <- which(frags[[shpvar]] == 'nonflat') @@ -97,18 +96,18 @@ ## sieve # non-flat fragments - frags.nonflat$class <- .sieve(frags.nonflat[[sizevar[2]]], flat = FALSE) + frags.nonflat$class <- .sieve(frags.nonflat[[sizevar[2]]], flat = FALSE, ...) # non-flat parafragments - parafrags.nonflat$class <- .sieve(parafrags.nonflat[[sizevar[2]]], flat = FALSE, para = TRUE) + parafrags.nonflat$class <- .sieve(parafrags.nonflat[[sizevar[2]]], flat = FALSE, para = TRUE, ...) # flat fragments - frags.flat$class <- .sieve(frags.flat[[sizevar[2]]], flat = TRUE) + frags.flat$class <- .sieve(frags.flat[[sizevar[2]]], flat = TRUE, ...) # flat parafragments - parafrags.flat$class <- .sieve(parafrags.flat[[sizevar[2]]], flat = TRUE, para = TRUE) + parafrags.flat$class <- .sieve(parafrags.flat[[sizevar[2]]], flat = TRUE, para = TRUE, ...) - # combine pieces, note may contain RF classes == NA + # combine pieces, note may contain RF classes == NA res <- rbind(frags.nonflat, frags.flat, parafrags.nonflat, parafrags.flat) # what does an NA fragment class mean? @@ -119,7 +118,7 @@ # keep track of these for QC in an 'unspecified' column # but only when there is a fragment volume specified idx <- which(is.na(res$class) & !is.na(res[[vol.var]])) - if( length(idx) > 0 ) { + if (length(idx) > 0) { res$class[idx] <- 'unspecified' } @@ -127,12 +126,6 @@ return(res) } - -# rf: un-coded contents of the phfrags table -# id.var: id column name -# nullFragsAreZero: convert NA to 0? - - #' Simplify Coarse Fraction Data #' #' Simplify multiple coarse fraction (>2mm) records by horizon. @@ -158,10 +151,12 @@ #' @param prefix a character vector prefix for input #' @param nullFragsAreZero should fragment volumes of NULL be interpreted as 0? (default: `TRUE`), see details #' @param msg Identifier of data being summarized. Default is `"rock fragment volume"` but this routine is also used for `"surface fragment cover"` +#' @param ... Additional arguments passed to sieving function (e.g. `sieves` a named numeric containing sieve size thresholds with class name) #' @author D.E. Beaudette, A.G Brown #' @keywords manip #' @export simplifyFragmentData -simplifyFragmentData <- function(rf, id.var, vol.var = "fragvol", prefix = "frag", nullFragsAreZero = TRUE, msg = "rock fragment volume") { +simplifyFragmentData <- function(rf, id.var, vol.var = "fragvol", prefix = "frag", + nullFragsAreZero = TRUE, msg = "rock fragment volume", ...) { fragvol <- NULL @@ -177,7 +172,7 @@ simplifyFragmentData <- function(rf, id.var, vol.var = "fragvol", prefix = "frag if (nrow(rf[which(!is.na(rf[[vol.var]])),]) == 0) { message(sprintf('NOTE: all records are missing %s', msg)) dat <- as.data.frame(t(rep(NA, length(result.columns)))) - for(i in 1:length(rf[[id.var]])) { + for (i in 1:length(rf[[id.var]])) { dat[i,] <- dat[1,] dat[i,which(result.columns == id.var)] <- rf[[id.var]][i] } @@ -195,14 +190,16 @@ simplifyFragmentData <- function(rf, id.var, vol.var = "fragvol", prefix = "frag ## NOTE: this is performed on the data, as-is: not over all possible classes as enforced by factor levels # sum volume by id and class # class cannot contain NA - rf.sums <- aggregate(rf.classes[[vol.var]], by=list(rf.classes[[id.var]], rf.classes[['class']]), FUN=sum, na.rm=TRUE) - # fix defualt names from aggregate() + rf.sums <- aggregate(rf.classes[[vol.var]], + by = list(rf.classes[[id.var]], rf.classes[['class']]), + FUN = sum, na.rm = TRUE) + # fix default names from aggregate() names(rf.sums) <- c(id.var, 'class', 'volume') ## NOTE: we set factor levels here because the reshaping (long->wide) needs to account for all possible classes ## NOTE: this must include all classes that related functions return # set levels of classes - rf.sums$class <- factor(rf.sums$class, levels=frag.classes) + rf.sums$class <- factor(rf.sums$class, levels = frag.classes) # convert to wide format if (nrow(rf.sums) == 0) { @@ -219,23 +216,19 @@ simplifyFragmentData <- function(rf, id.var, vol.var = "fragvol", prefix = "frag id.col.idx <- which(names(rf.wide) == id.var) ## optionally convert NULL frags -> 0 - if(nullFragsAreZero & ncol(rf.wide) > 1) { + if (nullFragsAreZero & ncol(rf.wide) > 1) { rf.wide <- as.data.frame( - cbind(rf.wide[, id.col.idx, drop=FALSE], + cbind(rf.wide[, id.col.idx, drop = FALSE], lapply(rf.wide[, -id.col.idx], function(i) ifelse(is.na(i), 0, i)) ), stringsAsFactors = FALSE) } - # final sanity check: are there any fractions or the total >= 100% - # note: sapply() was previously used here - # 1 row in rf.wide --> result is a vector - # >1 row in rf.wide --> result is a matrix - # solution: keep as a list + # are there any fractions or the total >= 100% gt.100 <- lapply(rf.wide[, -id.col.idx, drop = FALSE], FUN = function(i) i >= 100) # check each size fraction and report id.var if there are any - gt.100.matches <- sapply(gt.100, any, na.rm=TRUE) - if(any(gt.100.matches)) { + gt.100.matches <- sapply(gt.100, any, na.rm = TRUE) + if (any(gt.100.matches)) { # search within each fraction class.idx <- which(gt.100.matches) idx <- unique(unlist(lapply(gt.100[class.idx], which))) @@ -244,19 +237,16 @@ simplifyFragmentData <- function(rf, id.var, vol.var = "fragvol", prefix = "frag warning(sprintf("%s >= 100%%\n%s:\n%s", msg, id.var, paste(flagged.ids, collapse = "\n")), call. = FALSE) } - ## TODO: 0 is returned when all NA and nullFragsAreZero=FALSE - ## https://github.com/ncss-tech/soilDB/issues/57 # compute total fragments - # trap no frag condition - # includes unspecified class - if(ncol(rf.wide) > 1) { - # calculate another column for total RF, ignoring parafractions + if (ncol(rf.wide) > 1) { + # calculate another column for total RF, ignoring "parafractions" # index of columns to ignore, para* - idx.pf <- grep(names(rf.wide), pattern="para") + idx.pf <- grep(names(rf.wide), pattern = "para") + # also remove ID column idx <- c(id.col.idx, idx.pf) # this could result in an error if all fragments are para* - rf.wide$total_frags_pct_nopf <- rowSums(rf.wide[, -idx], na.rm=TRUE) + rf.wide$total_frags_pct_nopf <- rowSums(rf.wide[, -idx], na.rm = TRUE) # calculate total fragments (including para) # excluding ID and last columns @@ -264,12 +254,9 @@ simplifyFragmentData <- function(rf, id.var, vol.var = "fragvol", prefix = "frag rf.wide$total_frags_pct <- rowSums(rf.wide[, -idx], na.rm = TRUE) } - ## TODO: 0 is returned when all NA and nullFragsAreZero=FALSE - ## https://github.com/ncss-tech/soilDB/issues/57 - # corrections: # 1. fine gravel is a subset of gravel, therefore: gravel = gravel + fine_gravel rf.wide$gravel <- rowSums(cbind(rf.wide$gravel, rf.wide$fine_gravel), na.rm = TRUE) - rf.wide$paragravel <- rowSums(cbind(rf.wide$paragravel, rf.wide$parafine_gravel), na.rm=TRUE) + rf.wide$paragravel <- rowSums(cbind(rf.wide$paragravel, rf.wide$parafine_gravel), na.rm = TRUE) # done return(rf.wide) diff --git a/R/simplifyArtifactData.R b/R/simplifyArtifactData.R index e6b4c138..829ac93b 100644 --- a/R/simplifyArtifactData.R +++ b/R/simplifyArtifactData.R @@ -1,30 +1,25 @@ -## TODO: convert commentary from source material (fragments) and add manual page, thanks +# code for dealing with human artifacts; see simplifyFragmentData.R -# code for dealing with human artifacts - -.artifactSieve <- function(x, vol.var = "huartvol") { - # convert to lower case: NASIS metadata usese upper for labels, lower for values +.artifactSieve <- function(x, vol.var = "huartvol", ...) { x$huartco <- tolower(x$huartco) x$huartshp <- tolower(x$huartshp) ## assumptions - # missing hardness = rock fragment + # missing huartco = cohesive x$huartco[which(is.na(x$huartco))] <- 'cohesive' - # missing shape = Nonflat + + # missing huartshp = irregular x$huartshp[which(is.na(x$huartshp))] <- 'irregular' - ## the RV size is likely the safest estimate, - ## given the various upper bounds for GR (74mm, 75mm, 76mm) - # calculate if missing + ## the RV size is likely the safest estimate x$huartsize_r <- ifelse( is.na(x$huartsize_r), (x$huartsize_l + x$huartsize_h) / 2, x$huartsize_r ) - ## split flat/nonflat - idx <- grep('^flat', x$huartshp, ignore.case = TRUE, invert=TRUE) + idx <- grep('^flat', x$huartshp, ignore.case = TRUE, invert = TRUE) arts <- x[idx, ] idx <- grep('^flat', x$huartshp, ignore.case = TRUE) @@ -32,24 +27,14 @@ ## sieve using RV sizes # non-flat fragments - arts$class <- .sieve(arts$huartsize_r, new.names = c('art_fgr', 'art_gr', 'art_cb', - 'art_st', 'art_by')) + arts$class <- .sieve(arts$huartsize_r, new.names = c('art_fgr', 'art_gr', 'art_cb', 'art_st', 'art_by'), ...) # flat artifacts - farts$class <- .sieve(farts$huartsize_r, flat = TRUE, new.names = c('art_ch','art_fl', 'art_st', 'art_by')) + farts$class <- .sieve(farts$huartsize_r, flat = TRUE, new.names = c('art_ch','art_fl', 'art_st', 'art_by'), ...) - # combine pieces, note may contain RF classes == NA res <- rbind(arts, farts) - - # what does an NA fragment class mean? - # - # typically, fragment size missing - # or, worst-case, .sieve() rules are missing criteria - # - # keep track of these for QC in an 'unspecified' column - # but only when there is a fragment volume specified idx <- which(is.na(res$class) & !is.na(res[[vol.var]])) - if( length(idx) > 0 ) { + if (length(idx) > 0) { res$class[idx] <- 'art_unspecified' } @@ -60,14 +45,10 @@ #' @param art a \code{data.frame} object, typically returned from NASIS, see details #' @rdname simplifyFragmentData #' @export simplifyArtifactData -simplifyArtifactData <- function(art, id.var, vol.var = "huartvol", nullFragsAreZero = nullFragsAreZero) { - - huartvol <- NULL +simplifyArtifactData <- function(art, id.var, vol.var = "huartvol", nullFragsAreZero = nullFragsAreZero, ...) { # artifact size classes, using fragment breaks, are used in this function - # note that we are adding a catch-all for those strange phfrags records missing fragment size art.classes <- c('art_fgr', 'art_gr', 'art_cb', 'art_st', 'art_by', 'art_ch', 'art_fl', 'art_unspecified') - result.columns <- c(id.var, art.classes, "total_art_pct", "huartvol_cohesive", "huartvol_penetrable", "huartvol_innocuous", "huartvol_persistent") # warn the user and remove the NA records @@ -76,9 +57,9 @@ simplifyArtifactData <- function(art, id.var, vol.var = "huartvol", nullFragsAre if (nrow(art[which(!is.na(art[[vol.var]])),]) == 0) { message('NOTE: all records are missing artifact volume') dat <- as.data.frame(t(rep(NA, length(result.columns)))) - for(i in 1:length(art[[id.var]])) { - dat[i,] <- dat[1,] - dat[i,which(result.columns == id.var)] <- art[[id.var]][i] + for (i in 1:length(art[[id.var]])) { + dat[i, ] <- dat[1, ] + dat[i, which(result.columns == id.var)] <- art[[id.var]][i] } colnames(dat) <- result.columns return(dat) @@ -89,16 +70,14 @@ simplifyArtifactData <- function(art, id.var, vol.var = "huartvol", nullFragsAre # extract classes # note: these will put any fragments without fragsize into an 'unspecified' class - artifact.classes <- .artifactSieve(art, vol.var = vol.var) + artifact.classes <- .artifactSieve(art, vol.var = vol.var, ...) # sum volume by id and class - # class cannot contain NA - art.sums <- aggregate(artifact.classes[[vol.var]], by=list(artifact.classes[[id.var]], artifact.classes[['class']]), FUN=sum, na.rm=TRUE) - # fix defualt names from aggregate() + art.sums <- aggregate(artifact.classes[[vol.var]], + by = list(artifact.classes[[id.var]], artifact.classes[['class']]), + FUN = sum, na.rm = TRUE) names(art.sums) <- c(id.var, 'class', 'volume') - ## NOTE: we set factor levels here because the reshaping (long->wide) needs to account for all possible classes - ## NOTE: this must include all classes that related functions return # set levels of classes art.sums$class <- factor(art.sums$class, levels = art.classes) @@ -110,23 +89,17 @@ simplifyArtifactData <- function(art, id.var, vol.var = "huartvol", nullFragsAre id.col.idx <- which(names(art.wide) == id.var) ## optionally convert NULL frags -> 0 - if(nullFragsAreZero & ncol(art.wide) > 1) { + if (nullFragsAreZero & ncol(art.wide) > 1) { art.wide <- as.data.frame( - cbind(art.wide[, id.col.idx, drop=FALSE], + cbind(art.wide[, id.col.idx, drop = FALSE], lapply(art.wide[, -id.col.idx], function(i) ifelse(is.na(i), 0, i)) - ), stringsAsFactors=FALSE) + ), stringsAsFactors = FALSE) } - - # final sanity check: are there any fractions or the total >= 100% - # note: sapply() was previously used here - # 1 row in rf.wide --> result is a vector - # >1 row in rf.wide --> result is a matrix - # solution: keep as a list - gt.100 <- lapply(art.wide[, -id.col.idx, drop=FALSE], FUN=function(i) i >= 100) - - # check each size fraction and report id.var if there are any - gt.100.matches <- sapply(gt.100, any, na.rm=TRUE) - if(any(gt.100.matches)) { + + # are there any fractions or the total >= 100% + gt.100 <- lapply(art.wide[, -id.col.idx, drop = FALSE], FUN = function(i) i >= 100) + gt.100.matches <- sapply(gt.100, any, na.rm = TRUE) + if (any(gt.100.matches)) { # search within each fraction class.idx <- which(gt.100.matches) idx <- unique(unlist(lapply(gt.100[class.idx], which))) @@ -135,11 +108,7 @@ simplifyArtifactData <- function(art, id.var, vol.var = "huartvol", nullFragsAre warning(sprintf("artifact volume >= 100%%\n%s:\n%s", id.var, paste(flagged.ids, collapse = "\n")), call. = FALSE) } - ## TODO: 0 is returned when all NA and nullFragsAreZero=FALSE - ## https://github.com/ncss-tech/soilDB/issues/57 - # compute total fragments - # trap no frag condition - # includes unspecified class + # compute total artifacts if (ncol(art.wide) > 1) { # calculate another column for total RF, ignoring parafractions # index of columns to ignore, para* @@ -147,11 +116,9 @@ simplifyArtifactData <- function(art, id.var, vol.var = "huartvol", nullFragsAre # also remove ID column idx <- c(id.col.idx)#, idx.pf) # this could result in an error if all fragments are para* - art.wide$total_art_pct <- rowSums(art.wide[, -idx], na.rm=TRUE) + art.wide$total_art_pct <- rowSums(art.wide[, -idx], na.rm = TRUE) } - - ## TODO: 0 is returned when all NA and nullFragsAreZero=FALSE - ## https://github.com/ncss-tech/soilDB/issues/57 + # corrections: # 1. fine gravel is a subset of gravel, therefore: gravel = gravel + fine_gravel art.wide$art_gr <- rowSums(cbind(art.wide$art_gr, art.wide$art_fgr), na.rm = TRUE) @@ -161,12 +128,15 @@ simplifyArtifactData <- function(art, id.var, vol.var = "huartvol", nullFragsAre art.wide$huartvol_cohesive <- as.numeric(lapply(split(art, art[[id.var]]), function(art.sub) { sum(art.sub[[vol.var]][art.sub$huartco == "cohesive"], na.rm = TRUE) })) + art.wide$huartvol_penetrable <- as.numeric(lapply(split(art, art[[id.var]]), function(art.sub) { sum(art.sub[[vol.var]][art.sub$huartpen == "penetrable"], na.rm = TRUE) })) + art.wide$huartvol_noxious <- as.numeric(lapply(split(art, art[[id.var]]), function(art.sub) { sum(art.sub[[vol.var]][art.sub$huartsafety == "noxious artifacts"], na.rm = TRUE) })) + art.wide$huartvol_persistent <- as.numeric(lapply(split(art, art[[id.var]]), function(art.sub) { sum(art.sub[[vol.var]][art.sub$huartper == "persistent"], na.rm = TRUE) })) diff --git a/data-raw/NASIS_SoilProfileCollections.R b/data-raw/NASIS_SoilProfileCollections.R index 7605792f..9fa9491e 100644 --- a/data-raw/NASIS_SoilProfileCollections.R +++ b/data-raw/NASIS_SoilProfileCollections.R @@ -10,13 +10,13 @@ data("mineralKing", package = "soilDB") # # create CSVs (requires NASIS setup) # # query CA630 and CA792 w/ R08 PEDON/SITE by SSA ID or similar # # load source data sets (CA630 and CA792 pedons) -# nasis_pedons <- fetchNASIS(rmHzErrors = FALSE, SS = FALSE) -# -# p <- rebuildSPC(subset(nasis_pedons, siteiid %in% as.double(c(loafercreek, gopheridge, mineralKing)$siteiid))) -# write.csv(horizons(p), "data-raw/spc-horizons.csv", row.names = FALSE) -# write.csv(site(p), "data-raw/spc-site.csv", row.names = FALSE) -# write.csv(diagnostic_hz(p), "data-raw/spc-diagnostic_hz.csv", row.names = FALSE) -# write.csv(restrictions(p), "data-raw/spc-restrictions.csv", row.names = FALSE) +nasis_pedons <- fetchNASIS(rmHzErrors = FALSE, SS = FALSE) + +p <- rebuildSPC(subset(nasis_pedons, siteiid %in% as.double(c(loafercreek, gopheridge, mineralKing)$siteiid))) +write.csv(horizons(p), "data-raw/spc-horizons.csv", row.names = FALSE) +write.csv(site(p), "data-raw/spc-site.csv", row.names = FALSE) +write.csv(diagnostic_hz(p), "data-raw/spc-diagnostic_hz.csv", row.names = FALSE) +write.csv(restrictions(p), "data-raw/spc-restrictions.csv", row.names = FALSE) recent1822a <- read.csv("data-raw/spc-horizons.csv") depths(recent1822a) <- peiid ~ hzdept + hzdepb diff --git a/data-raw/spc-horizons.csv b/data-raw/spc-horizons.csv index 6391d992..1dd95a11 100644 --- a/data-raw/spc-horizons.csv +++ b/data-raw/spc-horizons.csv @@ -860,7 +860,7 @@ "2977026","640607","Bt1","Bt1",6,39,"clear","smooth",17,49,34,10,"L","l",NA,NA,"none",NA,"slightly hard","friable",NA,"slightly sticky","slightly plastic",NA,"l","12533",NA,NA,NA,NA,NA,NA,NA,0.488397126185639,0.349362062820934,0.229243737407669,"7.5YR",4,4,NA,"#7D593A",NA,"#7D593A",0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,10,10,0,0,0,0,0,0,0,0,0,0,0,0,0 "2977027","640607","Bt2","Bt2",39,54,"clear","wavy",21,44,35,40,"GR-L","l",NA,NA,"none",NA,"slightly hard","friable",NA,"moderately sticky","moderately plastic",NA,"l","12534",NA,NA,NA,NA,NA,NA,NA,0.634523149830161,0.438851858628477,0.247247510397254,"7.5YR",5,6,NA,"#A2703F",NA,"#A2703F",0,20,10,0,0,0,0,0,10,0,0,0,0,0,0,30,40,0,0,0,0,0,0,0,0,0,0,0,0,0 "2977028","640607","Cr","Cr",54,79,NA,NA,NA,NA,NA,0,"BR",NA,"br",NA,NA,NA,NA,NA,NA,NA,NA,NA,"br","12535",NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 -"2977037","640610","A","A",0,5,"clear","smooth",14,40,46,5,"L","l",NA,NA,"none",NA,"soft","friable",NA,"slightly sticky","slightly plastic",NA,"l","12544",NA,NA,NA,NA,NA,NA,NA,0.337643309877762,0.264793407575455,0.213042579872497,"7.5YR",3,2,NA,"#564436",NA,"#564436",0,0,5,0,0,0,0,0,0,0,0,0,0,0,0,5,5,0,0,0,0,0,0,0,0,0,0,0,0,0 +"2977037","640610","A","A",0,5,"clear","smooth",14,40,46,5,"L","l",NA,NA,"none",NA,"soft","friable",NA,"slightly sticky","slightly plastic",NA,"l","12544",NA,NA,NA,NA,NA,NA,NA,0.337643309877762,0.264793407575455,0.213042579872497,"7.5YR",3,2,NA,"#564436",NA,"#564436",0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,5,5,0,0,0,0,0,0,0,0,0,0,0,0,0 "2977038","640610","Bt1","Bt1",5,34,"clear","smooth",18,40,42,5,"L","l",NA,NA,"none",NA,"slightly hard","friable",NA,"slightly sticky","slightly plastic",NA,"l","12545",NA,NA,NA,NA,NA,NA,NA,0.358300526259172,0.258532492699209,0.181154944486718,"7.5YR",3,3,NA,"#5B422E",NA,"#5B422E",0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,5,5,0,0,0,0,0,0,0,0,0,0,0,0,0 "2977039","640610","Bt2","Bt2",34,49,"clear","smooth",23,36,41,10,"L","l",NA,NA,"none",NA,"slightly hard","firm",NA,"moderately sticky","moderately plastic",NA,"l","12546",NA,NA,NA,NA,NA,NA,NA,0.358300526259172,0.258532492699209,0.181154944486718,"7.5YR",3,3,NA,"#5B422E",NA,"#5B422E",0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,10,10,0,0,0,0,0,0,0,0,0,0,0,0,0 "2977040","640610","Bt3","Bt2",49,89,"abrupt","smooth",28,34,38,0,"CL","cl",NA,NA,"none",NA,"moderately hard","firm",NA,"moderately sticky","moderately plastic",NA,"cl","12547",NA,NA,NA,NA,NA,NA,NA,0.467514082120659,0.355962289511748,0.265795247113725,"7.5YR",4,3,NA,"#775B44",NA,"#775B44",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 diff --git a/data/loafercreek.rda b/data/loafercreek.rda index 19a2fa35..8fa203c6 100644 Binary files a/data/loafercreek.rda and b/data/loafercreek.rda differ diff --git a/man/simplifyFragmentData.Rd b/man/simplifyFragmentData.Rd index aa9e79a6..9d1032a5 100644 --- a/man/simplifyFragmentData.Rd +++ b/man/simplifyFragmentData.Rd @@ -12,14 +12,16 @@ simplifyFragmentData( vol.var = "fragvol", prefix = "frag", nullFragsAreZero = TRUE, - msg = "rock fragment volume" + msg = "rock fragment volume", + ... ) simplifyArtifactData( art, id.var, vol.var = "huartvol", - nullFragsAreZero = nullFragsAreZero + nullFragsAreZero = nullFragsAreZero, + ... ) } \arguments{ @@ -37,6 +39,8 @@ that is unique among all horizons in \code{rf}} \item{msg}{Identifier of data being summarized. Default is \code{"rock fragment volume"} but this routine is also used for \code{"surface fragment cover"}} +\item{...}{Additional arguments passed to sieving function (e.g. \code{sieves} a named numeric containing sieve size thresholds with class name)} + \item{art}{a \code{data.frame} object, typically returned from NASIS, see details} } \description{ diff --git a/misc/run-all-NASIS-get-methods.R b/misc/run-all-NASIS-get-methods.R index bd218663..3dda4278 100644 --- a/misc/run-all-NASIS-get-methods.R +++ b/misc/run-all-NASIS-get-methods.R @@ -38,13 +38,13 @@ library(soilDB) # path to data source (NULL = use ODBC to local nasis, # otherwise path to SQLite) -dsn <- "misc/testStatic.sqlite" - -# RUN IF NEEDED: # dsn <- "misc/testStatic.sqlite" -createStaticNASIS(tables = c(get_NASIS_table_name_by_purpose(SS = TRUE), - get_NASIS_table_name_by_purpose(SS = FALSE)), - dsn = NULL, output_path = dsn) +# +# # RUN IF NEEDED: +# # dsn <- "misc/testStatic.sqlite" +# createStaticNASIS(tables = c(get_NASIS_table_name_by_purpose(SS = TRUE), +# get_NASIS_table_name_by_purpose(SS = FALSE)), +# dsn = NULL, output_path = dsn) # Function to load all function names in package, run them using SS and dsn as specified test_local_NASIS <- function(SS = FALSE, dsn = NULL) { @@ -67,11 +67,11 @@ test_local_NASIS <- function(SS = FALSE, dsn = NULL) { TESTFUN <- get(FUN, envir = as.environment("package:soilDB")) # handle special cases -- all functions tested take an SS argument except local_NASIS_defined - switch (FUN, - "local_NASIS_defined" = try(TESTFUN(dsn = dsn)), - "get_soilseries_from_NASIS" = try(TESTFUN(dsn = dsn)), - "get_soilseries_from_NASISWebReport" = NULL, - try(TESTFUN(SS = SS, dsn = dsn)) ) + switch(FUN, + "local_NASIS_defined" = try(TESTFUN(dsn = dsn)), + "get_soilseries_from_NASIS" = try(TESTFUN(dsn = dsn)), + "get_soilseries_from_NASISWebReport" = NULL, + try(TESTFUN(SS = SS, dsn = dsn)) ) }) })