Commit 0805c288 authored by Thomas Shatwell's avatar Thomas Shatwell
Browse files

Updates

parent 143fd07e
......@@ -8,7 +8,7 @@ Authors@R:
email = "tom.shatwell@ufz.de",
comment = c(ORCID = "0000-0002-4520-7916"))
Maintainer: Tom Shatwell <tom.shatwell@ufz.de>
Description: A collection of useful tools for lake research. These tools include: calculating ice and stratification phenology, reading raw data files from sondes (\code{\link{batch_read}}, \code{\link{read_bbe}}, \code{\link{read_ctm}}, \code{\link{read_ixx}}), calculating water density and leap years, calculating volume-weighted mean using hyspographic information, interpolating to fixed depth grids or daily values.
Description: A collection of useful tools for lake research. These tools include: calculating ice and stratification phenology, reading raw data files from sondes, calculating water density and leap years, calculating volume-weighted mean using hyspographic information, interpolating to fixed depth grids or daily values.
License: GPL (>= 3)
Depends: R (>= 3.5)
Encoding: UTF-8
......
......@@ -5,6 +5,7 @@ export(clean_profile)
export(delta_rho)
export(get_profile_info)
export(h2mix)
export(h3mix)
export(hmix)
export(ice_phenology)
export(leap)
......@@ -12,4 +13,5 @@ export(read_bbe)
export(read_ctm)
export(read_ixx)
export(rho_water)
export(seefo)
export(strat_phenology)
......@@ -14,7 +14,7 @@
#'
#' @author Georgiy Kirillin and Tom Shatwell
#'
#' @seealso \code{\link{hmix}}, \code{\link{delta_rho}}
#' @seealso \code{\link{hmix}}, \code{\link{h3mix}}, \code{\link{delta_rho}}
#'
#' @examples
#' \dontrun{
......
......@@ -4,19 +4,19 @@
#' more suited for manual or irregular
#' temperature data.
#'
#' @param T Temperature profile
#' @param z The depths corresponding to the temperature profile
#' @param plot Should a plot of the profile showing the estimates be shown? (logical)
#' @param thresh The threshold for the difference between top and bottom temperature to infer stratification
#' @param T Temperature profile as numeric vector.
#' @param z The depths corresponding to the temperature profile, as a numeric vector.
#' @param plot Should a plot of the profile showing the estimates be shown? (logical).
#' @param thresh The threshold for the difference between top and bottom temperature to infer stratification.
#' @param therm.dz Representative thickness of the thermocline layer. 1 m works well from experience.
#' @param min.hmix I can't really remember what this is for.
#' @param min.gradient Not used
#' @param ... Arguments passed to `plot()`, when `plot=TRUE`
#' @param min.gradient Not used.
#' @param ... Arguments passed to `plot()`, when `plot=TRUE`.
#'
#' @details
#' This function estimates the mixed depth and the thermocline depth.
#' It uses regressions to locate the kink in the profile at the bottom of
#' the mixed layer as the mixed layer, and the maximum gradient as the thermocline.
#' It uses regressions to locate the depth of the kink in the temperature profile
#' as the mixed layer depth, and the maximum gradient as the thermocline.
#' It is better suited to irregular, esp manually measured profile data.
#' It first finds the minimum curvature in the
#' profile (maximum for winter stratification) as the initial guess of the
......@@ -24,8 +24,9 @@
#' layer. Then it finds the thermocline as the depth of maximum T-gradient. It
#' estimates the mixed layer depth as the depth where the regression line through
#' the surface layer temperatures intersects with the regression line through the
#' thermocline temperatures. It performs some other checks, like whether
#' stratification exists surface-bottom temperature difference > `thresh`, and whether the thermocline
#' thermocline temperatures, extended by a window of thickness `therm.dz`. It performs some other checks, like whether
#' stratification exists according to whether the surface-bottom temperature difference > `thresh`,
#' and whether the thermocline
#' is above the surface layer, or whether the lake is completely isothermal and
#' there is no intersection (and returns `NA`). If mixed, it assumes the mixed
#' layer depth is the maximum depth. It also plots the profile if desired
......@@ -89,34 +90,34 @@ h3mix <- function(T, z, plot=FALSE, thresh = 1,
T = T[z>=z[i1]-therm.dz &
z <= z[i1+1]+therm.dz])
regs <- lm(T[1:i2]~z[1:i2]) # regression thru surface temps
regt <- lm(T~z, thermo) # regression thru thermocline
dTdz.s <- coef(regs)[2] # T gradient in surface layer
if(is.na(coef(regs)[2])) dTdz.s <- 0
regs <- stats::lm(T[1:i2]~z[1:i2]) # regression thru surface temps
regt <- stats::lm(T~z, thermo) # regression thru thermocline
dTdz.s <- stats::coef(regs)[2] # T gradient in surface layer
if(is.na(stats::coef(regs)[2])) dTdz.s <- 0
h <- (coef(regt)[1] - coef(regs)[1]) / # depth of intersection of thermocline and surface layer regression lines
(dTdz.s - coef(regt)[2])
h <- (stats::coef(regt)[1] - stats::coef(regs)[1]) / # depth of intersection of thermocline and surface layer regression lines
(dTdz.s - stats::coef(regt)[2])
if(!is.na(h) & h > z[i1+1]) h <- NA # ignore if intersection of thermocline and surface layer is below thermocline
if(i1 < i2) h <- NA # ignore if minimum curvature is below the thermocline
if(abs(Ts-Tb) < thresh) h <- max(z) # assume mixed to max(z) if Ts-Tb < thresh
if(!is.na(h) & h < 0) h <- NA
if(plot){
plot(T, z,
graphics::plot(T, z,
ylim=c(max(z),0), type="n", ...)
abline(h=0:(max(z)), col="grey")
abline(h=h)
graphics::abline(h=0:(max(z)), col="grey")
graphics::abline(h=h)
# abline(h=h2, lty=2)
# if(!c(coef(regs)[2] %in% c(0,NA) | !coef(regt)[2] %in% c(0,NA))) {
# abline(-coef(regs)[1]/coef(regs)[2], 1/coef(regs)[2], lty=2, col="red")
# abline(-coef(regt)[1]/coef(regt)[2], 1/coef(regt)[2], lty=2, col="blue")
# }
# points(coef(regs)[2] * h + coef(regs)[1], h, pch=16, col="blue", cex=1.5)
lines(T, z, type="o")
lines(T[1:i2], z[1:i2], col="red", lwd=2)
lines(T[c(i1,i1+1)], z[c(i1,i1+1)], col="blue", lwd=2)
points(T[i2+1], z[i2+1], col="red",pch=16)
box()
graphics::lines(T, z, type="o")
graphics::lines(T[1:i2], z[1:i2], col="red", lwd=2)
graphics::lines(T[c(i1,i1+1)], z[c(i1,i1+1)], col="blue", lwd=2)
graphics::points(T[i2+1], z[i2+1], col="red",pch=16)
graphics::box()
}
} else {
h <- NA
......
......@@ -17,7 +17,7 @@
#'
#' @author Georgiy Kirillin and Tom Shatwell
#'
#' @seealso \code{\link{h2mix}}, \code{\link{delta_rho}}
#' @seealso \code{\link{h2mix}}, \code{\link{h3mix}}, \code{\link{delta_rho}}
#'
#' @examples
#' \dontrun{
......
......@@ -34,7 +34,7 @@ h2mix(T,z)
}
\seealso{
\code{\link{hmix}}, \code{\link{delta_rho}}
\code{\link{hmix}}, \code{\link{h3mix}}, \code{\link{delta_rho}}
}
\author{
Georgiy Kirillin and Tom Shatwell
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/h3mix.R
\name{h3mix}
\alias{h3mix}
\title{Robust calculation of mixed layer depth}
\usage{
h3mix(
T,
z,
plot = FALSE,
thresh = 1,
therm.dz = 1,
min.hmix = 1.5,
min.gradient = 0.3,
...
)
}
\arguments{
\item{T}{Temperature profile}
\item{z}{The depths corresponding to the temperature profile}
\item{plot}{Should a plot of the profile showing the estimates be shown? (logical)}
\item{thresh}{The threshold for the difference between top and bottom temperature to infer stratification}
\item{therm.dz}{Representative thickness of the thermocline layer. 1 m works well from experience.}
\item{min.hmix}{I can't really remember what this is for.}
\item{min.gradient}{Not used}
\item{...}{Arguments passed to \code{plot()}, when \code{plot=TRUE}}
}
\value{
A vector of length 2 with the mixed layer depth \code{hmix} and the thermocline depth \code{htherm}
}
\description{
Robust calculation of the mixed layer depth and thermocline depth,
more suited for manual or irregular
temperature data.
}
\details{
This function estimates the mixed depth and the thermocline depth.
It uses regressions to locate the kink in the profile at the bottom of
the mixed layer as the mixed layer, and the maximum gradient as the thermocline.
It is better suited to irregular, esp manually measured profile data.
It first finds the minimum curvature in the
profile (maximum for winter stratification) as the initial guess of the
border of the surface mixed
layer. Then it finds the thermocline as the depth of maximum T-gradient. It
estimates the mixed layer depth as the depth where the regression line through
the surface layer temperatures intersects with the regression line through the
thermocline temperatures. It performs some other checks, like whether
stratification exists surface-bottom temperature difference > \code{thresh}, and whether the thermocline
is above the surface layer, or whether the lake is completely isothermal and
there is no intersection (and returns \code{NA}). If mixed, it assumes the mixed
layer depth is the maximum depth. It also plots the profile if desired
(\code{plot=TRUE}), marking the surface layer and inflection point in red and the
thermocline in blue.
Surface temperature is estimated as the mean of the upper 2 m, or the top two measurements,
bottom temperature is estimated as the mean of the deepest 2 m layer.
}
\examples{
\dontrun{
T <- c(25.44,25.46,25.48,25.46,25.44,24.36,20.48,18.09,15.96,13.95,11.67,
10.62,9.82,9.51,9.22,9.01,8.81,8.68,8.58,8.39,8.29,8.14,8.08,8.03,8.01,
8.05,7.94,7.93,7.85)
z <- 0:28
h3mix(T,z,plot=TRUE)
}
}
\seealso{
\code{\link{hmix}}, \code{\link{h2mix}}, \code{\link{delta_rho}}
}
\author{
Tom Shatwell
}
......@@ -19,10 +19,10 @@ Fast calculation of the upper thermocline boundary
}
\details{
Calculates mixed layer depths as the depth of the maximum temperature gradient (dT/dz).
Designed to be as fast as possible for large data sets. It doesn't do any checks at all,
and only works with regular data, so be careful.
Designed to be as fast as possible for very large data sets, like model output.
It doesn't do any checks at all, and only works with regular data, so be careful.
Choose the right vertical resolution in the temperatures to ensure a more robust result.
Use the rLakeAnalyzer functions for more robust solutions which are
Use h3mix or the rLakeAnalyzer functions for more robust solutions which are
orders of magnitude slower.
}
\examples{
......@@ -37,7 +37,7 @@ hmix(T,z)
}
\seealso{
\code{\link{h2mix}}, \code{\link{delta_rho}}
\code{\link{h2mix}}, \code{\link{h3mix}}, \code{\link{delta_rho}}
}
\author{
Georgiy Kirillin and Tom Shatwell
......
......@@ -9,15 +9,15 @@ strat_phenology(
Tb,
H_ice = NULL,
dates,
thresh = 0.1,
thresh = 1,
NH = TRUE,
bydensity = TRUE
bydensity = FALSE
)
}
\arguments{
\item{Ts}{Surface temperature (numeric vector).}
\item{Ts}{Surface temperature, as daily values (numeric vector).}
\item{Tb}{Bottom temperature (numeric vector with same length as \code{Ts}.}
\item{Tb}{Bottom temperature, as daily values (numeric vector with same length as \code{Ts}.}
\item{H_ice}{Ice thickness as numeric vector of the same length as \code{Ts}.
\code{NULL} if ice statistics should not be calculated.}
......@@ -62,6 +62,7 @@ The function determines that stratification exists when the difference
between surface (\code{Ts}) and bottom temperature (\code{Tb}) exceeds a
certain threshold (\code{thresh}). This can be defined either in terms of a
temperature difference or a density difference (\code{bydensity = TRUE}).
Commonly used thresholds are 1 degree Celsius or 0.1 kg/m2.
Density is calculated from temperature, using the formula
of Millero & Poisson (1981) for freshwater. Only summer (positive) stratification
is considered and winter (inverse) stratification is ignored because it is usually
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment