Skip to content

Commit

Permalink
BODC flag scheme added
Browse files Browse the repository at this point in the history
  • Loading branch information
dankelley committed May 12, 2018
1 parent cdf2955 commit b950cc7
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 81 deletions.
30 changes: 15 additions & 15 deletions R/AllClass.R
Original file line number Diff line number Diff line change
Expand Up @@ -776,26 +776,26 @@ initializeFlagSchemeInternal <- function(object, name=NULL, mapping=NULL, debug=
if (!is.null(object@metadata$flagScheme))
warning("cannot alter a flagScheme that is already is place")
else {
predefined <- c("WHP CTD", "WHP bottle", "argo")
predefined <- c("argo", "BODC", "WHP bottle", "WHP CTD")
if (name %in% predefined) {
if (name == "WHP CTD") {
if (!is.null(mapping))
stop("cannot redefine the mapping for existing scheme named \"WHP CTD\"")
mapping <- list(not_calibrated=1, acceptable=2, questionable=3,
bad=4, not_reported=5, interpolated=6,
despiked=7, missing=9)
if (!is.null(mapping))
stop("cannot redefine the mapping for existing scheme named \"", name, "\"")
if (name == "argo") {
mapping <- list(not_assessed=0, passed_all_tests=1, probably_good=2,
probably_bad=3, bad=4, averaged=7,
interpolated=8, missing=9)
} else if (name == "BODC") {
mapping <- list(no_quality_control=0, good=1, probably_good=2,
probably_bad=3, bad=4, changed=5, below_detection=6,
in_excess=7, interpolated=8, missing=9)
} else if (name == "WHP bottle") {
if (!is.null(mapping))
stop("cannot redefine the mapping for existing scheme named \"WHP bottle\"")
mapping <- list(no_information=1, no_problems_noted=2, leaking=3,
did_not_trip=4, not_reported=5, discrepency=6,
unknown_problem=7, did_not_trip=8, no_sample=9)
} else if (name == "argo") {
if (!is.null(mapping))
stop("cannot redefine the mapping for existing scheme named \"argo\"")
mapping <- list(not_assessed=0, passed_all_tests=1, probably_good=2,
probably_bad=3, bad=4, averaged=7,
interpolated=8, missing=9)
} else if (name == "WHP CTD") {
mapping <- list(not_calibrated=1, acceptable=2, questionable=3,
bad=4, not_reported=5, interpolated=6,
despiked=7, missing=9)
} else {
stop("internal coding error in initializeFlagSchemeInternal(); please report to developer")
}
Expand Down
48 changes: 34 additions & 14 deletions man-roxygen/initializeFlagSchemeTemplate.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,36 @@
#' The following pre-defined schemes are available (note that the
#' names are simplified from the phrases used in defining
#' documentation):
#'
#' \itemize{
#' \item \code{name="WHP CTD"} defaults \code{mapping} to
#' \code{list(not_calibrated=1, acceptable=2, questionable=3,
#' bad=4, not_reported=5, interpolated=6,
#' despiked=7, missing=9)}
#' \item \code{name="WHP bottle"} defaults \code{mapping} to
#' \code{list(no_information=1, no_problems_noted=2, leaking=3,
#' did_not_trip=4, not_reported=5, discrepency=6,
#' unknown_problem=7, did_not_trip=8, missing=9)}
#'
#' \item \code{name="argo"} defaults \code{mapping} to
#' \code{list(not_assessed=0, passed_all_tests=1, probably_good=2,
#' probably_bad=3, bad=4, averaged=7,
#' interpolated=8, missing=9)}
#' probably_bad=3, bad=4, averaged=7,
#' interpolated=8, missing=9)}.
#' See [1] for a deeper explanation of the meanings of these codes.
#'
#' \item \code{name="BODC"} defaults \code{mapping} to
#' \code{list(no_quality_control=0, good=1, probably_good=2,
#' probably_bad=3, bad=4, changed=5,
#' below_detection=6, in_excess=7, interpolated=8,
#' missing=9)}.
#' See [2] for a deeper explanation of the meanings of these codes,
#' and note that codes \code{A} and \code{Q} are not provided in
#' oce.
#'
#' \item \code{name="WHP bottle"} defaults \code{mapping} to
#' \code{list(no_information=1, no_problems_noted=2, leaking=3,
#' did_not_trip=4, not_reported=5, discrepency=6,
#' unknown_problem=7, did_not_trip=8, no_sample=9)}.
#' See [3] for a deeper explanation of the meanings of these codes.
#'
#' \item \code{name="WHP CTD"} defaults \code{mapping} to
#' \code{list(not_calibrated=1, acceptable=2, questionable=3,
#' bad=4, not_reported=5, interpolated=6,
#' despiked=7, missing=9)}.
#' See [3] for a deeper explanation of the meanings of these codes.
#'
#'}
#'
#' \strong{Specific to the <%=class%> objects:}
Expand All @@ -54,11 +71,14 @@
#' @return An object with the \code{metadata} slot containing \code{flagScheme}.
#'
#' @references
#' 1. The codes for \code{"WHP CTD"} and \code{"WHP bottle"} are defined at
#' \url{https://www.nodc.noaa.gov/woce/woce_v3/wocedata_1/whp/exchange/exchange_format_desc.htm}
#'
#' 2. The codes for \code{"Argo"} are defined at
#' 1. The codes for \code{"Argo"} are defined at
#' \url{http://www.oceannetworks.ca/data-tools/data-quality}
#'
#' 2. The codes for \code{"BODC"} are defined at
#' \url{http://seadatanet.maris2.nl/v_bodc_vocab_v2/browse.asp?order=conceptid&formname=search&screen=0&lib=l20}
#'
#' 3. The codes for \code{"WHP CTD"} and \code{"WHP bottle"} are defined at
#' \url{https://www.nodc.noaa.gov/woce/woce_v3/wocedata_1/whp/exchange/exchange_format_desc.htm}
#'
#' @family functions relating to data-quality flags

48 changes: 34 additions & 14 deletions man/initializeFlagScheme-ctd-method.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 34 additions & 14 deletions man/initializeFlagScheme-oce-method.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 34 additions & 14 deletions man/initializeFlagScheme.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 16 additions & 10 deletions tests/testthat/test_flags.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,30 @@ test_that("argument existence", {

test_that("predefined flag schemes", {
data(ctd)
a <- initializeFlagScheme(ctd, "WHP CTD")
a <- initializeFlagScheme(ctd, "argo")
expect_equal(a[["flagScheme"]],
list(name="WHP CTD",
mapping=list(not_calibrated=1, acceptable=2, questionable=3,
bad=4, not_reported=5, interpolated=6,
despiked=7, missing=9)))
list(name="argo",
mapping=list(not_assessed=0, passed_all_tests=1, probably_good=2,
probably_bad=3, bad=4, averaged=7,
interpolated=8, missing=9)))
a <- initializeFlagScheme(ctd, "BODC")
expect_equal(a[["flagScheme"]],
list(name="BODC",
mapping=list(no_quality_control=0, good=1, probably_good=2,
probably_bad=3, bad=4, changed=5, below_detection=6,
in_excess=7, interpolated=8, missing=9)))
a <- initializeFlagScheme(ctd, "WHP bottle")
expect_equal(a[["flagScheme"]],
list(name="WHP bottle",
mapping=list(no_information=1, no_problems_noted=2, leaking=3,
did_not_trip=4, not_reported=5, discrepency=6,
unknown_problem=7, did_not_trip=8, no_sample=9)))
a <- initializeFlagScheme(ctd, "argo")
a <- initializeFlagScheme(ctd, "WHP CTD")
expect_equal(a[["flagScheme"]],
list(name="argo",
mapping=list(not_assessed=0, passed_all_tests=1, probably_good=2,
probably_bad=3, bad=4, averaged=7,
interpolated=8, missing=9)))
list(name="WHP CTD",
mapping=list(not_calibrated=1, acceptable=2, questionable=3,
bad=4, not_reported=5, interpolated=6,
despiked=7, missing=9)))
})

test_that("user-created flag scheme", {
Expand Down

0 comments on commit b950cc7

Please sign in to comment.