ctdTrim(x, method, inferWaterDepth=TRUE,
removeDepthInversions=FALSE, parameters, debug=getOption("oceDebug"))
ctd
object, e.g. as read by read.ctd
.method
is not provided,
"downcast"
is assumed. See TRUE
if the water depth
(metadata$water.depth
) is to be determined from the maximum of the trimmed pressure.
(This is ignored if the original data file contained the water depth in the header.)ctdDecimate
class
"ctd"
, with data having been trimmed in some way.ctdTrim
with method="downcast"
, although it is almost always best to use
plotScan
to investigate the data, and then use the method="index"
method
based on visual inspection of the data. The details methods are as follows.
method[1]
is"downcast"
then an attempt is made to only data for
which the CTD is descending. This is done in stages, with variants based onmethod[1]
, if
supplied.Step 1.The pressure data are despiked with a smooth() filter with method "3R".
This removes wild spikes that arise from poor instrument connections, etc.Step 2.If noparameters
are given, then any data with negative pressures are deleted. If there is a
parameter namedpmin
, then that pressure (in decibars) is used instead as the lower limit.
This is a commonly-used setup, e.g.ctdTrim(ctd, parameters=list(pmin=1))
removes the top
decibar (roughly 1m) from the data. Specifyingpmin
is a simple way to remove near-surface
data, such as a shallow equilibration phase, and if specified will causectdTrim
to skip
step 4 below.Step 3.The maximum pressure is determined, and data acquired subsequent to
that point are deleted. This removes the upcast and any subsequent data.Step 4.If thepmin
parameter is not specified, an attempt is made to remove an initial equilibrium phase
by a regression of pressure on scan number. There are three variants to this, depending on the
value of the secondmethod
element. If it is"A"
(or not given), the procedure is to
calloptim
to minimize the mismatch between observed pressure and a linear model
with respect toscan
that is set toNA
above a fitted value ofscan
. The
value of pressure at the cutoffscan
is taken as the top of the downcast. If the submethod
is"B"
, a similar procedure is used in a model that retains the pressures in the upper
portion, but that takes the pressure to be (a fitted) constant there. Case"C"
is the same,
except that the pressure in the surface region is taken to be zero.method="index"
then each column of data is subsetted according to the
value of parameters
. If the latter is a logical vector of length matching data column
length, then it is used directly for subsetting. If parameters
is a numerical vector with
two elements, then the integers between those values (if positive) are used for subsetting. The
two-element method is probably the most useful, with the values being determined by visual
inspection of the results of plotScan
. While this may take a minute or two, the
analyst should bear in mind that a deep-water CTD profile might take 6 hours, corresponding to
ship-time costs exceeding a week of salary.method="range"
then data are selected based on the value of the column named
parameters$item
. This may be by range or by critical value. By range: select values
between parameters$from
(the lower limit) and parameters$to
(the upper limit) By
critical value: select if the named column exceeds the value. For example, ctd2 <-
ctdTrim(ctd, "range", parameters=list(item="scan", from=5))
starts at scan number 5 and
continues to the end, while
ctdTrim(ctd,"range",parameters=list(item="scan",from=5,to=100))
also starts at scan 5,
but extends only to scan 100. method
is a function, then it must return a vector of logical
values, computed based on two arguments: data
, which is set to x@data
(a
list
), and parameters
as supplied to ctdTrim
. Both
inferWaterDepth
and removeInversions
are ignored in the function case. See
ctd-class
explains the structure
of CTD objects, and also outlines the other functions dealing with them.library(oce)
data(ctdRaw)
plot(ctdRaw) # barely recognizable, due to pre- and post-cast junk
plot(ctdTrim(ctdRaw)) # looks like a real profile ...
plot(ctdDecimate(ctdTrim(ctdRaw),method="boxcar")) # ... smoothed
# Demonstrate use of a function. The scan limits were chosen
# by using locator(2) on a graph made by plotScan(ctdRaw).
trimByIndex <- function(data, parameters) {
parameters[1] < data$scan & data$scan < parameters[2]
}
trimmed <- ctdTrim(ctdRaw, trimByIndex, parameters=c(130, 380))
plot(trimmed)
Run the code above in your browser using DataLab