handleFlags-adp-method: Handle Flags in adp Objects

handleFlags,adp-methodR Documentation

Handle Flags in adp Objects

Description

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.

Usage

## S4 method for signature 'adp'
handleFlags(
  object = "oce",
  flags = NULL,
  actions = NULL,
  where = NULL,
  debug = getOption("oceDebug")
)

Arguments

object

an adp object.

flags

A list specifying flag values upon which actions will be taken. This can take two forms.

  • In the first form, the list has named elements each containing a vector of integers. For example, salinities flagged with values of 1 or 3:9 would be specified by flags=list(salinity=c(1,3:9)). Several data items can be specified, e.g. flags=list(salinity=c(1,3:9), temperature=c(1,3:9)) indicates that the actions are to take place for both salinity and temperature.

  • In the second form, flags is a list holding a single unnamed vector, and this means to apply the actions to all the data entries. For example, flags=list(c(1,3:9)) means to apply not just to salinity and temperature, but to everything within the data slot.

If flags is not provided, then defaultFlags() is called, to try to determine a reasonable default.

actions

an optional list that contains items with names that match those in the flags argument. If actions is not supplied, the default will be to set all values identified by flags to NA; this can also be specified by specifying actions=list("NA"). It is also possible to specify functions that calculate replacement values. These are provided with object as the single argument, and must return a replacement for the data item in question. See “Details” for the default that is used if actions is not supplied.

where

an optional character value that permits the function to work with objects that store flags in e.g. object@metadata$flags$where instead of in object@metadata$flags, and data within object@data$where instead of within object@data. The default value of NULL means to look withing object@metadata itself, and this is the default within oce. (The purpose of where is to make oce extensible by other packages, which may choose to store data two levels deep in the data slot.)

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 getOption("oceDebug").

Details

If flags and actions are not provided, the default is to consider a flag value of 1 to indicate bad data, and 0 to indicate good data. Note that it only makes sense to use velocity (v) flags, because other flags are, at least for some instruments, stored as raw quantities, and such quantities may not be set to NA.

See Also

Other functions relating to data-quality flags: defaultFlags(), handleFlags(), handleFlags,argo-method, handleFlags,ctd-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 adp data: [[,adp-method, [[<-,adp-method, ad2cpCodeToName(), ad2cpHeaderValue(), adp, adp-class, adpAd2cpFileTrim(), adpConvertRawToNumeric(), adpEnsembleAverage(), adpFlagPastBoundary(), adpRdiFileTrim(), adp_rdi.000, applyMagneticDeclination,adp-method, as.adp(), beamName(), beamToXyz(), beamToXyzAdp(), beamToXyzAdpAD2CP(), beamToXyzAdv(), beamUnspreadAdp(), binmapAdp(), enuToOther(), enuToOtherAdp(), is.ad2cp(), plot,adp-method, read.adp(), read.adp.ad2cp(), read.adp.nortek(), read.adp.rdi(), read.adp.sontek(), read.adp.sontek.serial(), read.aquadopp(), read.aquadoppHR(), read.aquadoppProfiler(), rotateAboutZ(), setFlags,adp-method, subset,adp-method, subtractBottomVelocity(), summary,adp-method, toEnu(), toEnuAdp(), velocityStatistics(), xyzToEnu(), xyzToEnuAdp(), xyzToEnuAdpAD2CP()

Examples

# Flag low "goodness" or high "error beam" values.
library(oce)
data(adp)
# Same as Example 2 of ?'setFlags,adp-method'
v <- adp[["v"]]
i2 <- array(FALSE, dim = dim(v))
g <- adp[["g", "numeric"]]
# Set thresholds on percent "goodness" and error "velocity".
G <- 25
V4 <- 0.45
for (k in 1:3) {
    i2[, , k] <- ((g[, , k] + g[, , 4]) < G) | (v[, , 4] > V4)
}
adpQC <- initializeFlags(adp, "v", 2)
adpQC <- setFlags(adpQC, "v", i2, 3)
adpClean <- handleFlags(adpQC, flags = list(3), actions = list("NA"))
# Demonstrate (subtle) change graphically.
par(mfcol = c(2, 1))
plot(adp, which = "u1", drawTimeRange = FALSE)
plot(adpClean, which = "u1", drawTimeRange = FALSE)
t0 <- 1214510000 # from locator()
arrows(t0, 20, t0, 35, length = 0.1, lwd = 3, col = "magenta")
mtext("Slight change above arrow", col = "magenta", font = 2)


oce documentation built on Sept. 11, 2024, 7:09 p.m.