Skip to content

Commit df4c809

Browse files
committed
get_colors_from_NASIS_db: deprecate mixColors and add method argument
- use "none" for long format phcolor output
1 parent 1977c94 commit df4c809

4 files changed

+28
-8
lines changed

NEWS.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
- `fetchNASIS()` and `get_site_data_from_NASIS_db()` now return Ecological Site State and Community Phase information (ecostatename, ecostateid, commphasename, commphaseid columns) from Site Observation table
33
- `createStaticNASIS()` removed workaround for {odbc}/nanoodbc VARCHAR(MAX) columns; now can directly use `DBI::dbReadTable()` for all tables via NASIS ODBC connection
44
- `fetchNASIS()` changed default behavior to `mixColors = FALSE` which returns dominant condition for each moisture state rather than mixing LAB color coordinates
5+
- `get_colors_from_NASIS_db()` deprecate `mixColors` argument, add `method` argument with options "dominant", "mixed", and "none". New aggregation method `"none"` returns long format representation of color data from phcolor table with no aggregation applied.
56

67
# soilDB 2.8.5 (2024-11-04)
78
- `fetchLDM()` add support for `area_type` argument with local database connections (`dsn` argument)

R/fetchNASIS_pedons.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
rmHzErrors = FALSE,
77
nullFragsAreZero = TRUE,
88
soilColorState = 'moist',
9-
mixColors = TRUE,
9+
mixColors = FALSE,
1010
lab = FALSE,
1111
stringsAsFactors = NULL,
1212
dsn = NULL
@@ -28,7 +28,7 @@
2828
# these fail gracefully when no data in local DB | selected set
2929
site_data <- get_site_data_from_NASIS_db(SS = SS, dsn = dsn)
3030
hz_data <- get_hz_data_from_NASIS_db(SS = SS, fill = fill, dsn = dsn)
31-
color_data <- get_colors_from_NASIS_db(SS = SS, mixColors = mixColors, dsn = dsn)
31+
color_data <- get_colors_from_NASIS_db(SS = SS, method = ifelse(isTRUE(mixColors), "mixed", "dominant"), dsn = dsn)
3232

3333
## ensure there are enough data to create an SPC object
3434
ds <- ifelse(SS, "NASIS selected set", "NASIS local database")

R/get_colors_from_NASIS_db.R

+16-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
#'
1010
#' @param SS fetch data from Selected Set in NASIS or from the entire local
1111
#' database (default: `TRUE`)
12-
#' @param mixColors should mixed colors be calculated (Default: `TRUE`) where multiple colors are populated for the same moisture state in a horizon? `FALSE` takes the dominant color based on `colorpct` or first record based on horizon ID (`phiid`) sorting for "moist" and "dry" state. Pedon Horizon Color records without a moisture state populated are ignored.
12+
#' @param method Aggregation method to handle multiple colors per horizon and moisture state. Default `"dominant"` for dominant condition (or first record) within moisture state. Other options include `"mixed"` to calculate mixture using `simplifyColorData()` and `"none"` to do no aggregation (returns a long format representation that may have multiple values per horizon and moisture state)
13+
#' @param mixColors Deprecated. See `method`. Should mixed colors be calculated where multiple colors are populated for the same moisture state in a horizon? Default `FALSE` takes the dominant color based on `colorpct` or first record based on horizon ID (`phiid`) sorting for "moist" and "dry" state. Pedon Horizon Color records without a moisture state populated are ignored.
1314
#' @param dsn Optional: path to local SQLite database containing NASIS
1415
#' table structure; default: `NULL`
1516
#' @return A data.frame with the results.
@@ -19,8 +20,17 @@
1920
#' \code{\link{get_site_data_from_NASIS_db}}
2021
#' @keywords manip
2122
#' @export get_colors_from_NASIS_db
22-
get_colors_from_NASIS_db <- function(SS = TRUE, mixColors = TRUE, dsn = NULL) {
23+
get_colors_from_NASIS_db <- function(SS = TRUE, method = "dominant", mixColors = FALSE, dsn = NULL) {
2324

25+
if (!missing(mixColors)) {
26+
.Deprecated(msg = "`mixColors` argument is deprecated, see `method` argument for additional aggregation options")
27+
if (isTRUE(mixColors)) {
28+
method <- "mixed"
29+
}
30+
}
31+
32+
method <- match.arg(method, c("dominant", "mixed", "none"))
33+
2434
# unique-ness enforced via peiid (pedon-level) and phiid (horizon-level)
2535
# TODO: is alias of colorpct necessary?
2636
q <- "SELECT peiid, phiid, colormoistst, colorpct as pct, colorhue, colorvalue, colorchroma
@@ -53,11 +63,13 @@ get_colors_from_NASIS_db <- function(SS = TRUE, mixColors = TRUE, dsn = NULL) {
5363
d$colorchroma <- as.numeric(as.character(d$colorchroma))
5464

5565
# sanity check, only attempt to simplify colors if there are > 1 rows
56-
if (nrow(d) > 1 && mixColors) {
66+
if (nrow(d) > 1 && (method == "mixed")) {
5767
# mix colors as-needed, mixing done in CIE LAB space
5868
d.final <- simplifyColorData(d, id.var = 'phiid', wt = 'pct')
59-
} else {
69+
} else if (method == "dominant") {
6070
d.final <- .dominantColors(d)
71+
} else {
72+
d.final <- d
6173
}
6274

6375
# done

man/get_colors_from_NASIS_db.Rd

+9-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)