1- #
2- # Center of Buoyancy Frequency
3- # Author: Jordan S Read <jread@usgs.gov>
4- #
1+ # ' @title Calculates the center of buoyancy.
2+ # '
3+ # ' @description Calculate the center of buoyancy using buoyancy frequency with a center of
4+ # ' mass analysis. Brunt-Vaisala frequency is used for a temperature profile.
5+ # ' Negative values for N2 are set to 0 (as they represent transient
6+ # ' instabilities or sensor calibration issues) for this calculation.
7+ # '
8+ # '
9+ # ' @param wtr a numeric vector of water temperature in degrees C
10+ # ' @param depths a numeric vector corresponding to the depths (in m) of the wtr
11+ # ' measurements
12+ # ' @return Returns a value for the center of buoyancy.
13+ # ' @seealso \code{buoyancy.freq}, \code{ts.buoyancy.freq},
14+ # ' \code{center.buoyancy}
15+ # ' @keywords arith
16+ # ' @examples
17+ # '
18+ # '
19+ # ' # A vector of water temperatures
20+ # ' wtr = c(22.51, 22.42, 22.4, 22.4, 22.4, 22.36, 22.3, 22.21, 22.11, 21.23, 16.42,
21+ # ' 15.15, 14.24, 13.35, 10.94, 10.43, 10.36, 9.94, 9.45, 9.1, 8.91, 8.58, 8.43)
22+ # '
23+ # ' #A vector defining the depths
24+ # ' depths = c(0, 0.5, 1, 1.5, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
25+ # ' 17, 18, 19, 20)
26+ # '
27+ # ' c.b = center.buoyancy(wtr, depths)
28+ # '
29+ # ' @export
530center.buoyancy <- function (wtr , depths ){
631
732 if (depths [2 ] - depths [1 ] < 0 ){stop(' depths must be in descending order' )}
@@ -23,6 +48,48 @@ center.buoyancy <- function(wtr, depths){
2348}
2449
2550
51+
52+
53+ # ' @title Calculates the center of buoyancy for multiple temperature profiles.
54+ # '
55+ # ' @description Function for simplifying the calculation of the center of buoyancy. Can
56+ # ' usually be called directly on data loaded directly using
57+ # ' \code{\link{load.ts}} and \code{\link{load.bathy}}.
58+ # '
59+ # '
60+ # ' @param wtr A data frame of water temperatures (in Celsius). Loaded using
61+ # ' \code{\link{load.ts}}
62+ # ' @param na.rm Boolean indicated if step-by-step removal of NA's should be
63+ # ' tried. If false, a timestep with any NA values will return an NA value. If
64+ # ' true, best effort will be made to calculate indices despite NA values.
65+ # ' @return Returns a data frame with the timeseries of the center of buoyancy
66+ # ' frequency. Includes a \sQuote{datetime} column.
67+ # ' @seealso \code{center.buoyancy}, \code{load.bathy}, \code{load.ts}
68+ # ' @references Imberger, J., Patterson, J.C., 1990. \emph{Physical limnology}.
69+ # ' Advances in Applied Mechanics 27, 353-370.
70+ # ' @keywords arith
71+ # ' @examples
72+ # '
73+ # '
74+ # ' #Get the path for the package example file included
75+ # ' wtr.path <- system.file('extdata', 'Sparkling.daily.wtr', package="rLakeAnalyzer")
76+ # '
77+ # ' #Load data for example lake, Sparkilng Lake, Wisconsin.
78+ # ' sp.wtr = load.ts(wtr.path)
79+ # '
80+ # ' #calculate and plot the thermocline depth
81+ # ' t.d = ts.thermo.depth(sp.wtr)
82+ # '
83+ # ' center.N2 = ts.center.buoyancy(sp.wtr)
84+ # '
85+ # ' plot(center.N2, type='l', ylab='Depth (m)', xlab='Date', ylim=c(19,0), lwd = 1.5)
86+ # ' lines(t.d, type='l', col='red', lwd = 1.5)
87+ # ' legend(x = t.d[3,1], y = .25,
88+ # ' c('center of buoyancy','thermocline depth'),
89+ # ' lty=c(1,1),
90+ # ' lwd=c(1.5,1.5),col=c("black","red"), bty = "n")
91+ # '
92+ # ' @export
2693ts.center.buoyancy <- function (wtr , na.rm = FALSE ){
2794
2895 depths = get.offsets(wtr )
0 commit comments