From 4b7e59dc75373eb3200631d19f58771e44227546 Mon Sep 17 00:00:00 2001 From: Andrew Gene Brown Date: Tue, 24 Sep 2024 18:23:41 -0700 Subject: [PATCH] fetchNASIS: update QC messages by adding to soilDB.env as needed for fragments/artifacts >100% --- R/fetchNASIS_pedons.R | 15 ++++++++++++++- R/get_site_data_from_NASIS_db.R | 2 +- R/simplifyArtifactData.R | 5 ++++- R/simplifyFragmentData.R | 7 +++++-- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/R/fetchNASIS_pedons.R b/R/fetchNASIS_pedons.R index 70fa3081..9d1c428f 100644 --- a/R/fetchNASIS_pedons.R +++ b/R/fetchNASIS_pedons.R @@ -256,10 +256,23 @@ ) } } + if (exists('dup.pedon.ids', envir = get_soilDB_env())) if (length(get('dup.pedon.ids', envir = get_soilDB_env())) > 0) message("-> QC: duplicate pedons: \n\tUse `get('dup.pedon.ids', envir=get_soilDB_env())` for pedon record IDs (peiid)") - + + if (exists('rock.fragment.volume.gt100.phiid', envir = get_soilDB_env())) + if (length(get('rock.fragment.volume.gt100.phiid', envir = get_soilDB_env())) > 0) + message("-> QC: pedon horizons with rock fragment volume >=100%: \n\tUse `get('rock.fragment.volume.gt100.phiid', envir=get_soilDB_env())` for pedon horizon record IDs (phiid)") + + if (exists('artifact.volume.gt100.phiid', envir = get_soilDB_env())) + if (length(get('artifact.volume.gt100.phiid', envir = get_soilDB_env())) > 0) + message("-> QC: pedon horizons with artifact volume >=100%: \n\tUse `get('artifact.volume.gt100.phiid', envir=get_soilDB_env())` for pedon horizon record IDs (phiid)") + + if (exists('surface.fragment.cover.gt100.siteobsiid', envir = get_soilDB_env())) + if (length(get('surface.fragment.cover.gt100.siteobsiid', envir = get_soilDB_env())) > 0) + message("-> QC: pedons with surface fragment cover >=100%: \n\tUse `get('surface.fragment.cover.gt100.siteobsiid', envir=get_soilDB_env())` for site observation record IDs (siteobsiid)") + # set NASIS component specific horizon identifier if (!fill & length(filled.ids) == 0) { res <- try(hzidname(hz_data) <- 'phiid') diff --git a/R/get_site_data_from_NASIS_db.R b/R/get_site_data_from_NASIS_db.R index bbc3f4d2..d7594ebb 100644 --- a/R/get_site_data_from_NASIS_db.R +++ b/R/get_site_data_from_NASIS_db.R @@ -136,7 +136,7 @@ ORDER BY pedon_View_1.peiid ;" phs <- simplifyFragmentData( uncode(sfr, dsn = dsn), - id.var = "peiid", + id.var = "siteobsiid", vol.var = "sfragcov", prefix = "sfrag", msg = "surface fragment cover" diff --git a/R/simplifyArtifactData.R b/R/simplifyArtifactData.R index 1ccfa49c..fa23f5cf 100644 --- a/R/simplifyArtifactData.R +++ b/R/simplifyArtifactData.R @@ -102,7 +102,10 @@ simplifyArtifactData <- function(art, id.var, vol.var = "huartvol", nullFragsAre idx <- unique(unlist(lapply(gt.100[class.idx], which))) flagged.ids <- art.wide[[id.var]][idx] - message(sprintf("NOTE: artifact volume >= 100%% in %s: %s", id.var, paste(flagged.ids, collapse = ","))) + gt100nm <- paste0("artifact.volume.gt100.", id.var) + assign(gt100nm, value = flagged.ids, envir = get_soilDB_env()) + + message(sprintf("NOTE: some %s have artifact volume >= 100%%", id.var)) } # compute total artifacts diff --git a/R/simplifyFragmentData.R b/R/simplifyFragmentData.R index fbe67dba..78ab570b 100644 --- a/R/simplifyFragmentData.R +++ b/R/simplifyFragmentData.R @@ -229,8 +229,11 @@ simplifyFragmentData <- function(rf, id.var, vol.var = "fragvol", prefix = "frag class.idx <- which(gt.100.matches) idx <- unique(unlist(lapply(gt.100[class.idx], which))) flagged.ids <- rf.wide[[id.var]][idx] - - message(sprintf("NOTE: %s >= 100%% in %s: %s", msg, id.var, paste(flagged.ids, collapse = ","))) + + gt100nm <- paste0(gsub(" ", ".", msg), ".gt100.", id.var) + assign(gt100nm, value = flagged.ids, envir = get_soilDB_env()) + + message(sprintf("NOTE: some %s have %s >= 100%%", id.var, msg)) } # compute total fragments