oce (version 0.9-23)

handleFlags,argo-method: Handle Flags in ARGO Objects

Description

Data-quality flags are stored in the metadata slot of oce-class 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 core data based on the data-quality flags. For example, a common operation is to replace suspicious or erroneous data with NA.

If metadata$flags in the object supplied as the first argument is empty, then that object is returned, unaltered. Otherwise, handleFlags analyses the data-quality flags within the object, in relation to the flags argument, and interprets the action argument to select an action to be applied to matched data.

Reasonable defaults are used if flags and actions are not supplied (see ‘Details’), but different schemes are used in different data archives, so it is risky to rely on these defaults. It is usually necessary to tailor flags and actions to the data and the analysis goals.

Usage

# S4 method for argo
handleFlags(object, flags = list(), actions = list(),
  debug = integer())

Arguments

object

An object of argo-class.

flags

An optional list containing (a) items with names of entries in the data slot of object, or (b) a single unnamed item. In the first case, the attention is focussed on the named items, while in the second case the all the data in the object's data slot are examined. Each element in the list must be set to an integer or vector of integers, specifying conditions to be met before actions are to be taken. See “Details” for the default that is used if flags is not supplied.

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.

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 use ARGO flags [1], in which the value 1 indicates good data, and other values indicate either unchecked, suspicious, or bad data. Any data not flagged as good are set to NA in the returned value. Since Argo flag codes run from 0 to 9, with 1 indicating the highest level of confidence in the data, the defaults are flags=list(c(0,2:9)) and actions=list("NA").

References

1. http://www.argo.ucsd.edu/Argo_date_guide.html#dmodedata

See Also

Other functions that handle data-quality flags: handleFlags,ctd-method, handleFlags,section-method, handleFlags

Other things related to argo data: [[,argo-method, [[<-,argo-method, argo-class, argoGrid, argoNames2oceNames, argo, as.argo, plot,argo-method, read.argo, subset,argo-method, summary,argo-method

Examples

Run this code
# NOT RUN {
library(oce)
data(argo)
# 1. Default: anything not flagged as 1 is set to NA, to focus
# solely on 'good', in the Argo scheme.
argoNew <- handleFlags(argo)
# demonstrate replacement, looking at the second profile
f <- argo[["salinityFlag"]][,2] # first column with a flag=4 entry
df <- data.frame(flag=f, orig=argo[["salinity"]][,2], new=argoNew[["salinity"]][,2])
df[11:15,]
##    flag   orig    new
## 11    1 35.207 35.207
## 12    1 35.207 35.207
## 13    4 35.209     NA
## 14    1 35.207 35.207
## 15    1 35.207 35.207

# 2. A less restrictive case: include also 'questionable' data,
# and only apply this action to salinity.
argoNew <- handleFlags(argo, flags=list(salinity=4))
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab