| handleFlags,ctd-method | R Documentation |
Data-quality flags are stored in the metadata
slot of oce objects in a
list named flags.
The present function (a generic that has specialized versions
for various data classes) provides a way to
manipulate the contents of the data slot, based on
such data-quality flags. For example, a common operation is to replace
erroneous data with NA.
If the flags within object's metadata slot is empty,
then object is returned, unaltered.
Otherwise, handleFlags examines object@metadata$flags
in the context of the flags argument, and then
carries out actions that are specified by the actions argument.
By default, this sets the returned data entries to NA,
wherever the corresponding metadata$flag values
signal unreliable data. To maintain a hint as to why
data were changed, metadata$flags in the
returned value is a direct copy of the corresponding
entry in object.
## S4 method for signature 'ctd'
handleFlags(
object = "oce",
flags = NULL,
actions = NULL,
where = NULL,
debug = getOption("oceDebug")
)
object |
a ctd object. |
flags |
A list specifying flag values upon which actions will be taken. This can take two forms.
If |
actions |
an optional list that contains items with
names that match those in the |
where |
an optional character value that permits the function to work with
objects that store flags in e.g. |
debug |
An optional integer specifying the degree of debugging, with
value 0 meaning to skip debugging and 1 or higher meaning to print some
information about the arguments and the data. It is usually a good idea to set
this to 1 for initial work with a dataset, to see which flags are being
handled for each data item. If not supplied, this defaults to the value of
|
The following link used to work, but failed as of December 2020.
https://www.nodc.noaa.gov/woce/woce_v3/wocedata_1/whp/exchange/exchange_format_desc.htm
Other functions relating to data-quality flags:
defaultFlags(),
handleFlags(),
handleFlags,adp-method,
handleFlags,argo-method,
handleFlags,oce-method,
handleFlags,section-method,
initializeFlagScheme(),
initializeFlagScheme,ctd-method,
initializeFlagScheme,oce-method,
initializeFlagScheme,section-method,
initializeFlagSchemeInternal(),
initializeFlags(),
initializeFlags,adp-method,
initializeFlags,oce-method,
initializeFlagsInternal(),
setFlags(),
setFlags,adp-method,
setFlags,ctd-method,
setFlags,oce-method
Other things related to ctd data:
CTD_BCD2014666_008_1_DN.ODF.gz,
[[,ctd-method,
[[<-,ctd-method,
as.ctd(),
cnvName2oceName(),
ctd,
ctd-class,
ctd.cnv.gz,
ctdDecimate(),
ctdFindProfiles(),
ctdFindProfilesRBR(),
ctdRaw,
ctdRepair(),
ctdTrim(),
ctd_aml.csv.gz,
d200321-001.ctd.gz,
d201211_0011.cnv.gz,
initialize,ctd-method,
initializeFlagScheme,ctd-method,
oceNames2whpNames(),
oceUnits2whpUnits(),
plot,ctd-method,
plotProfile(),
plotScan(),
plotTS(),
read.ctd(),
read.ctd.aml(),
read.ctd.itp(),
read.ctd.odf(),
read.ctd.odv(),
read.ctd.saiv(),
read.ctd.sbe(),
read.ctd.ssda(),
read.ctd.woce(),
read.ctd.woce.other(),
setFlags,ctd-method,
subset,ctd-method,
summary,ctd-method,
woceNames2oceNames(),
woceUnit2oceUnit(),
write.ctd()
library(oce)
data(section)
stn <- section[["station", 100]]
# 1. Default: anything not flagged as 2 is set to NA, to focus
# solely on 'good', in the World Hydrographic Program scheme.
STN1 <- handleFlags(stn, flags = list(c(1, 3:9)))
data.frame(old = stn[["salinity"]], new = STN1[["salinity"]], salinityFlag = stn[["salinityFlag"]])
# 2. Use bottle salinity, if it is good and ctd is bad
replace <- 2 == stn[["salinityBottleFlag"]] & 2 != stn[["salinityFlag"]]
S <- ifelse(replace, stn[["salinityBottle"]], stn[["salinity"]])
STN2 <- oceSetData(stn, "salinity", S)
# 3. Use smoothed TS relationship to nudge questionable data.
f <- function(x) {
S <- x[["salinity"]]
T <- x[["temperature"]]
df <- 0.5 * length(S) # smooths a bit
sp <- smooth.spline(T, S, df = df)
0.5 * (S + predict(sp, T)$y)
}
par(mfrow = c(1, 2))
STN3 <- handleFlags(stn, flags = list(salinity = c(1, 3:9)), action = list(salinity = f))
plotProfile(stn, "salinity", mar = c(3, 3, 3, 1))
p <- stn[["pressure"]]
par(mar = c(3, 3, 3, 1))
plot(STN3[["salinity"]] - stn[["salinity"]], p, ylim = rev(range(p)))
# 4. Single-variable flags (vector specification)
data(section)
# Multiple-flag scheme: one per data item
A <- section[["station", 100]]
deep <- A[["pressure"]] > 1500
flag <- ifelse(deep, 7, 2)
for (flagName in names(A[["flags"]])) {
A[[paste(flagName, "Flag", sep = "")]] <- flag
}
Af <- handleFlags(A)
stopifnot(all.equal(is.na(Af[["salinity"]]), deep))
# 5. Single-variable flags (list specification)
B <- section[["station", 100]]
B[["flags"]] <- list(flag)
Bf <- handleFlags(B)
stopifnot(all.equal(is.na(Bf[["salinity"]]), deep))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.