swN2(pressure, sigmaTheta=NULL, derivs, df, ...)sigmaTheta must
be provided) or an object of class ctd object (in which
case sigmaTheta is inferred from the object.smooth.spline if this
function is used for smoothing.smooth.spline, in
the case that derivs="smoothing". See ctd object, then density is is
inferred from it, and the sigmaTheta argument is ignored. The core of the method involves differentiating density with respect to
pressure, and the derivs argument is used to control how this is
done, as follows.
derivsis not supplied, the action is as though it were
given as the string"smoothing"derivsequals"simple", then the derivative of
density with respect to pressure is calculated as the ratio of
first-order derivatives of density and pressure, each calculated usingdiff. (A zero is appended at the top level.)derivsequals"smoothing", then the processing
depends on the number of data in the profile, and on whetherdfis given as an optional argument. When the number of points exceeds 4,
and whendfexceeds 1,smooth.splineis used to
calculate smoothing spline representation the variation of density as a
function of pressure, and derivatives are extracted from the spline
usingpredict. Otherwise, density is smoothed usingsmooth, and derivatives are calculated as with the"simple"method.derivsis a function taking two arguments (first
pressure, then density) then that function is called directly to
calculate the derivative, and no smoothing is done before or after that
call.Given the derivative, the square of the buoyancy frequency is calculated as $10^{-4}g^2d\sigma_\theta/dp$.
library(oce)
data(ctd)
# Illustrate effect of changing df
p <- pressure(ctd)
plot(swN2(ctd), p, ylim=rev(range(p)), xlab="N2",ylab="p", type='l')
lines(swN2(ctd, df=3), p, col="blue")
grid()Run the code above in your browser using DataLab