diff --git a/R/allocate.R b/R/allocate.R index 797367c7..6e6ab0eb 100644 --- a/R/allocate.R +++ b/R/allocate.R @@ -794,6 +794,8 @@ hz_to_taxpartsize <- function(x, y, taxpartsize = "taxpartsize", clay = "clay", clay_wt_bot.1 <- NULL taxpartsize_bot.1 <- NULL + + # still needs special cases for very fine sand xy_agg <- cbind(xy_agg, xy_lag) |> within({ clay_dif = clay_wt_bot.1 - clay_wt @@ -804,9 +806,27 @@ hz_to_taxpartsize <- function(x, y, taxpartsize = "taxpartsize", clay = "clay", sc = gsub("over fine$|over very-fine$", "over clayey", sc) sc = gsub("over fine over|over very-fine over", "over clayey over", sc) sc = gsub("over sandy|over sandy-skeletal", "over sandy or sandy-skeletal", sc) - - idx_sc = sc %in% .pscs_sc - sc[idx_sc] = sc[idx_sc] + # clay over loamy + sc = ifelse( + abs(clay_dif) >= 25 & sc %in% c("clayey over fine-loamy", "clayey over coarse-loamy"), + gsub("clayey over fine-loamy|clayey over coarse-loamy", "clayey over loamy", sc), + sc + ) + # clay over loamy-skeletal + sc = ifelse( + sc == "clayey over loamy-skeletal" & abs(clay_dif) < 25, + taxpartsize, + sc + ) + # fine-silty over clayey + sc = ifelse( + sc == "fine-silty over clayey" & abs(clay_dif) < 25, + taxpartsize, + sc + ) + idx_sc = sc %in% .pscs_sc + # idx_sc = grepl("over", sc) + sc = ifelse(idx_sc, sc, taxpartsize) }) xy_lag <- NULL @@ -816,8 +836,8 @@ hz_to_taxpartsize <- function(x, y, taxpartsize = "taxpartsize", clay = "clay", n_peiid <- NULL test <- data.table::as.data.table(xy_agg)[, list( - n_sc = sum(grepl("over", sc), na.rm = TRUE), - n_peiid = length(idcol) + n_sc = sum(idx_sc, na.rm = TRUE), # sum(grepl(" over ", sc), na.rm = TRUE), + n_peiid = length(idx_sc) ), by = "idcol" ] |> @@ -828,7 +848,9 @@ hz_to_taxpartsize <- function(x, y, taxpartsize = "taxpartsize", clay = "clay", xy_res <- xy_agg |> merge(test, by = "idcol", all.x = TRUE, sort = FALSE) |> transform( - idx_sc = grepl(" over ", sc) + idx_sc = sc %in% .pscs_sc, + # idx_sc = grepl(" over ", sc), + idx_c_ov_l = sc %in% c("clayey over fine-loamy") ) xy_res <- data.table::as.data.table(xy_res)[, list( diff --git a/man/hz_to_taxpartsize.Rd b/man/hz_to_taxpartsize.Rd index 65e699a3..a2a686c5 100644 --- a/man/hz_to_taxpartsize.Rd +++ b/man/hz_to_taxpartsize.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/allocate.R \name{hz_to_taxpartsize} \alias{hz_to_taxpartsize} -\title{Allocate Particle Size Control Class for the Control Section.} +\title{Allocate Particle Size Class for the Control Section.} \usage{ hz_to_taxpartsize( x, @@ -30,7 +30,7 @@ hz_to_taxpartsize( A \code{data.frame} object containing the original idcol and aggregated particle size control section allocation. } \description{ -This function aggregates information in the horizon table and allocates it to the particle size control section. +This function aggregates information in the horizon table and allocates it to the particle size class for the control section. } \details{ This function differs from \code{\link{texture_to_taxpartsize}} in that is aggregates the results of \code{\link{texture_to_taxpartsize}}, and accounts for strongly contrasting particle size classes.