maxd: Detect the position of the maximum

Description Usage Arguments Value See Also Examples

View source: R/maxd.R

Description

Find the index or depth of the maximum in a (possibly smoothed) variable along a cast. Useful to find the depth of the Deep Chlorophyll Maximum (DCM) from a chlorophyll profile for example.

Usage

1
maxd(x, depth = NULL, n.smooth = 1, k = 2)

Arguments

x

vector of the variable of interest.

depth

vector of depths at which x is measured; optional.

n.smooth

integer, number of times to smooth the data before detecting the maximum (1 by default, because we are rarely interested in the absolute maximum, which often corresponds to a spike, but rather in the region of the maximum values).

k

order of the moving average used for smoothing; the window size is 2k+1. NB: when data is smoothed, it should have been recorded at approximately regular intervals for the moving average to make sense.

Value

When depth is NULL, return the index of x corresponding to the maximum, i. When depth is provided, return depth[i], the value of the depth of the maximum.

See Also

smooth() for smoothing.

Other functions computing remarkable depths: clined, mld, ze_from_chla, ze_from_par, ze_from_surface_chla

Examples

1
2
3
4
5
6
7
plot(-depth ~ chla, data=d, type="l")
# find the absolute maximum
DCM <- maxd(d$chla, d$depth, n.smooth=0)
abline(h=-DCM, col="chartreuse4", lty="dashed")
# find the region of the maximum, along a smoothed cast
DCM <- maxd(d$chla, d$depth, n.smooth=3, k=3)
abline(h=-DCM, col="chartreuse4")

jiho/castr documentation built on April 5, 2020, 2:12 p.m.