From e0cf11b13643c96e5c74fefc2b8086df13e9dc4d Mon Sep 17 00:00:00 2001 From: clnsmth Date: Mon, 24 Aug 2020 14:26:14 -0700 Subject: [PATCH 1/2] Change sun.rise.set() output from matrix to data.frame MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fix maintains the index order of returned sunrise/sunset values and the associated POSIX classes while adding the column names ‘sunrise’ and ‘sunset’. A search of the code base reveals this function is used by is.day() and add.night(), which index values according to order, therefore this fix does not break any linked processes within LakeMetabolizer. Additionally, the calculation methods imply returned values in standard time. The function metadata now explicitly states this. --- DESCRIPTION | 5 +++-- R/sun.rise.set.R | 8 ++------ man/calc.lw.net.Rd | 13 ++++++------- man/calc.zeng.Rd | 7 +++---- man/get.Ts.Rd | 7 +++---- man/get.vars.Rd | 7 +++---- man/getSchmidt.Rd | 7 +++---- man/has.vars.Rd | 7 +++---- man/is.day.Rd | 7 +++---- man/is.night.Rd | 7 +++---- man/k.read.Rd | 15 +++++++-------- man/k.read.base.Rd | 15 +++++++-------- man/k600.2.kGAS.Rd | 7 +++---- man/load.all.data.Rd | 7 +++---- man/load.meta.Rd | 7 +++---- man/metab.Rd | 7 +++---- man/metab.bayesian.Rd | 7 +++---- man/metab.bookkeep.Rd | 7 +++---- man/metab.kalman.Rd | 7 +++---- man/metab.mle.Rd | 7 +++---- man/metab.ols.Rd | 7 +++---- man/o2.at.sat.Rd | 21 ++++++++++++--------- man/par.to.sw.Rd | 7 +++---- man/rmv.vars.Rd | 7 +++---- man/sun.rise.set.Rd | 9 ++++----- man/sw.to.par.Rd | 7 +++---- man/temp.kalman.Rd | 7 +++---- man/var.indx.Rd | 7 +++---- man/wind.scale.Rd | 7 +++---- tests/testthat.R | 4 ++++ tests/testthat/test_sun.rise.set.R | 22 ++++++++++++++++++++++ 31 files changed, 133 insertions(+), 133 deletions(-) create mode 100644 tests/testthat.R create mode 100644 tests/testthat/test_sun.rise.set.R diff --git a/DESCRIPTION b/DESCRIPTION index f39a277..251c53a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -10,9 +10,10 @@ Imports: plyr, methods Suggests: - R2jags + R2jags, + testthat Depends: R (>= 2.15.0), rLakeAnalyzer (>= 1.4) Repository: http://github.com/GLEON/LakeMetabolizer -RoxygenNote: 5.0.1 +RoxygenNote: 7.1.0 diff --git a/R/sun.rise.set.R b/R/sun.rise.set.R index 435b9fa..eafdaba 100644 --- a/R/sun.rise.set.R +++ b/R/sun.rise.set.R @@ -58,7 +58,7 @@ is.night <- function(datetimes, lat){ #'@param datetimes Vector of dates as \code{POSIXct} or \code{POSIXlt} (see \code{\link{DateTimeClasses}}) format #'@param lat Single latitude value of site. South should be negative, north positive #' -#'@return A 2-column matrix, first column sunrise, second column sunset, as \link{POSIXct} format. +#'@return A 2-column data frame, first column sunrise, second column sunset, as \link{POSIXct} format in standard time. #'Value is NA when there is no defined sunrise or sunset for that day (winter/summer at high and low latitudes). #'@references #'Iqbal, Muhammad. 1983. An Introduction to Solar Radiation. Elsevier. @@ -103,10 +103,6 @@ sun.rise.set <- function(datetimes, lat){ rise <- trunc(datetimes, 'day') + sr*60*60 set <- trunc(datetimes, 'day') + ss*60*60 - ##Note, this does weird things. It *is* a matrix, but it doesn't print like one because it is viewed - # as POSIXct. I will leave it this way for now, though if someone knows how to get it to show up as - # a matrix *and* a POSIXct value, that would be super cool. - - return(as.POSIXct(matrix(c(rise, set), ncol=2), origin='1970-01-01')) + return(data.frame(sunrise = rise, sunset = set)) } diff --git a/man/calc.lw.net.Rd b/man/calc.lw.net.Rd index 80e077f..f638e6b 100644 --- a/man/calc.lw.net.Rd +++ b/man/calc.lw.net.Rd @@ -67,12 +67,6 @@ lat = sp.data$metadata$latitude lwnet = calc.lw.net(ts.data, lat, atm.press) plot(lwnet$datetime, lwnet$lwnet) -} -\author{ -R Iestyn Woolway -Jordan S. Read -Hilary Dugan -Luke Winslow } \references{ Crawford, T.M., and Duchon, C.E. 1999. \emph{An improved parameterization for @@ -82,6 +76,11 @@ downwelling longwave radiation}. Journal of Applied Meteorology 38: 474-480. \seealso{ \code{\link{k.read}} and \code{\link{k.macIntyre}} } +\author{ +R Iestyn Woolway +Jordan S. Read +Hilary Dugan +Luke Winslow +} \keyword{math} \keyword{methods} - diff --git a/man/calc.zeng.Rd b/man/calc.zeng.Rd index ff9817e..80f5ded 100644 --- a/man/calc.zeng.Rd +++ b/man/calc.zeng.Rd @@ -41,9 +41,6 @@ atm.press <- 1013 wnd.z <- 2 calc.zeng(dateTime,Ts,airT,Uz,RH,atm.press,wnd.z) } -\author{ -R. Iestyn. Woolway -} \references{ Zeng, X., M. Zhao., and Dickinson, R.E. 1998. \emph{Intercomparison of bulk aerodynamic algorithms for the computation of sea surface fluxes using TOGA COARE and TAO data}. Journal of Climate 11: 2628-2644. @@ -51,6 +48,8 @@ for the computation of sea surface fluxes using TOGA COARE and TAO data}. Journa \seealso{ \link{k.read} } +\author{ +R. Iestyn. Woolway +} \keyword{math} \keyword{methods} - diff --git a/man/get.Ts.Rd b/man/get.Ts.Rd index 720e91f..d7ec4df 100644 --- a/man/get.Ts.Rd +++ b/man/get.Ts.Rd @@ -17,13 +17,12 @@ An object of class data.frame \description{ grabs best available data for surface water temperature } -\author{ -Jordan S. Read -} \seealso{ \link{has.vars} \link{get.vars} \link{rmv.vars} } +\author{ +Jordan S. Read +} \keyword{methods} - diff --git a/man/get.vars.Rd b/man/get.vars.Rd index d0b24d9..27941f2 100644 --- a/man/get.vars.Rd +++ b/man/get.vars.Rd @@ -17,12 +17,11 @@ An object of class data.frame \description{ subsets \code{data} according to header names } -\author{ -Luke A. Winslow -} \seealso{ \link{has.vars} \link{rmv.vars} } +\author{ +Luke A. Winslow +} \keyword{methods} - diff --git a/man/getSchmidt.Rd b/man/getSchmidt.Rd index 40f28b7..1740948 100644 --- a/man/getSchmidt.Rd +++ b/man/getSchmidt.Rd @@ -24,14 +24,13 @@ Temperature range is only valid from 4-35 deg Celsius \examples{ getSchmidt(temperature=12, gas="O2") } -\author{ -Jordan S. Read -} \references{ Raymond, Peter A., Christopher J. Zappa, David Butman, Thomas L. Bott, Jody Potter, Patrick Mulholland, Andrew E. Laursen, William H. McDowell, and Denis Newbold. \emph{Scaling the gas transfer velocity and hydraulic geometry in streams and small rivers}. Limnology & Oceanography: Fluids & Environments 2 (2012): 41-53. } +\author{ +Jordan S. Read +} \keyword{math} \keyword{methods} - diff --git a/man/has.vars.Rd b/man/has.vars.Rd index 58682c3..07119e5 100644 --- a/man/has.vars.Rd +++ b/man/has.vars.Rd @@ -17,12 +17,11 @@ a boolean vector of same length as \code{var.names} \description{ tests \code{data} for data column names } -\author{ -Luke A. Winslow -} \seealso{ \link{get.vars} \link{rmv.vars} } +\author{ +Luke A. Winslow +} \keyword{methods} - diff --git a/man/is.day.Rd b/man/is.day.Rd index 5e312b3..bb56d16 100644 --- a/man/is.day.Rd +++ b/man/is.day.Rd @@ -17,12 +17,11 @@ a boolean vector of same length as \code{datetimes} \description{ determines if measurement was taken during the daytime } -\author{ -Luke A. Winslow -} \seealso{ \link{is.night} \link{sun.rise.set} } +\author{ +Luke A. Winslow +} \keyword{methods} - diff --git a/man/is.night.Rd b/man/is.night.Rd index b427964..2cae9da 100644 --- a/man/is.night.Rd +++ b/man/is.night.Rd @@ -17,12 +17,11 @@ a boolean vector of same length as \code{datetimes} \description{ determines if measurement was taken during the nighttime } -\author{ -Luke A. Winslow -} \seealso{ \link{is.day} \link{sun.rise.set} } +\author{ +Luke A. Winslow +} \keyword{methods} - diff --git a/man/k.read.Rd b/man/k.read.Rd index 8419d33..57082a1 100644 --- a/man/k.read.Rd +++ b/man/k.read.Rd @@ -1,13 +1,13 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/k.read.R \name{k.read} -\alias{k.cole} -\alias{k.crusius} -\alias{k.heiskanen} -\alias{k.macIntyre} \alias{k.read} \alias{k.read.soloviev} +\alias{k.cole} +\alias{k.macIntyre} +\alias{k.crusius} \alias{k.vachon} +\alias{k.heiskanen} \title{Returns a timeseries of gas exchange velocity} \usage{ k.cole(ts.data) @@ -91,9 +91,6 @@ atm.press=atm.press, lat=lat, lake.area=lake.area) k600_macIntyre = k.macIntyre(ts.data, wnd.z=wnd.z, Kd=kd, atm.press=atm.press) } } -\author{ -Hilary Dugan, Jake Zwart, Luke Winslow, R. Iestyn. Woolway, Jordan S. Read -} \references{ Cole, J., J. Nina, and F. Caraco. \emph{Atmospheric exchange of carbon dioxide in a low-wind oligotrophic lake measured by the addition of SF~ 6}. @@ -129,6 +126,8 @@ velocity from remote sensing data}. Journal of Marine Systems 66, (2007): 182-19 \link{k.vachon} \link{k.heiskanen} } +\author{ +Hilary Dugan, Jake Zwart, Luke Winslow, R. Iestyn. Woolway, Jordan S. Read +} \keyword{math} \keyword{methods} - diff --git a/man/k.read.base.Rd b/man/k.read.base.Rd index 6f21d98..63ebb50 100644 --- a/man/k.read.base.Rd +++ b/man/k.read.base.Rd @@ -1,13 +1,13 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/k.read.R \name{k.read.base} -\alias{k.cole.base} -\alias{k.crusius.base} -\alias{k.heiskanen.base} -\alias{k.macIntyre.base} \alias{k.read.base} \alias{k.read.soloviev.base} +\alias{k.cole.base} +\alias{k.macIntyre.base} +\alias{k.crusius.base} \alias{k.vachon.base} +\alias{k.heiskanen.base} \title{Returns a timeseries of gas exchange velocity} \usage{ k.cole.base(wnd) @@ -101,9 +101,6 @@ atm.press, dateTime, Ts, z.aml, airT, wnd, RH, sw, lwnet) k600_macInytre <- k.macIntyre.base(wnd.z, Kd, atm.press, dateTime, Ts, z.aml, airT, wnd, RH, sw, lwnet) -} -\author{ -R. Iestyn. Woolway, Hilary Dugan, Luke Winslow, Jordan S Read, GLEON fellows } \references{ Cole, J., J. Nina, and F. Caraco. \emph{Atmospheric exchange of carbon dioxide @@ -141,6 +138,8 @@ velocity from remote sensing data}. Journal of Marine Systems 66, (2007): 182-19 \link{k.vachon} \link{k.heiskanen} } +\author{ +R. Iestyn. Woolway, Hilary Dugan, Luke Winslow, Jordan S Read, GLEON fellows +} \keyword{math} \keyword{methods} - diff --git a/man/k600.2.kGAS.Rd b/man/k600.2.kGAS.Rd index 86e0324..86592d8 100644 --- a/man/k600.2.kGAS.Rd +++ b/man/k600.2.kGAS.Rd @@ -45,10 +45,9 @@ ts.data = merge(k600, ts.data) k.gas = k600.2.kGAS(ts.data, 'O2') } -\author{ -Jordan S. Read -} \seealso{ \link{k.read} and \link{k.read.base} for functions that calculate k600 estimates } - +\author{ +Jordan S. Read +} diff --git a/man/load.all.data.Rd b/man/load.all.data.Rd index 1b4d6d6..31206e9 100644 --- a/man/load.all.data.Rd +++ b/man/load.all.data.Rd @@ -23,13 +23,12 @@ Loads and returns all the data available in the specified directory for a given All timeseries data are merged by \dQuote{datetime} into a single \link{data.frame}. Data are identified by the column header information. } -\author{ -Luke A. Winslow -} \seealso{ \link{load.ts} \link{load.meta} } +\author{ +Luke A. Winslow +} \keyword{IO} \keyword{file} - diff --git a/man/load.meta.Rd b/man/load.meta.Rd index f4360e8..292960a 100644 --- a/man/load.meta.Rd +++ b/man/load.meta.Rd @@ -16,13 +16,12 @@ A list with the metadata parsed from the file. Parses a formatted metadata file. Useful for site-specific metadata that is not contained in the timeseries files. } -\author{ -Luke A Winslow -} \seealso{ \link{load.ts} \link{load.all.data} } +\author{ +Luke A Winslow +} \keyword{IO} \keyword{file} - diff --git a/man/metab.Rd b/man/metab.Rd index c58fd80..fde3cab 100644 --- a/man/metab.Rd +++ b/man/metab.Rd @@ -91,9 +91,6 @@ attr(m.ols, "mod") \dontrun{names(attributes(m.bay))} \dontrun{attr(m.bay, "model")} -} -\author{ -Ryan D. Batt } \seealso{ Metabolism models: \link{metab.bookkeep}, \link{metab.ols}, \link{metab.mle}, \link{metab.kalman}, \link{metab.bayesian} @@ -106,5 +103,7 @@ To calculate k.gas: \link{k600.2.kGAS} To calculate k600 values for k.gas: \link{k.cole}, \link{k.crusius}, \link{k.macIntyre}, \link{k.read} } +\author{ +Ryan D. Batt +} \keyword{metabolism} - diff --git a/man/metab.bayesian.Rd b/man/metab.bayesian.Rd index cf8a764..3a4464d 100644 --- a/man/metab.bayesian.Rd +++ b/man/metab.bayesian.Rd @@ -70,9 +70,6 @@ metab.bayesian(irr=irr[,2], z.mix=rep(1, length(k.gas)), k.gas=k.gas, do.obs=doobs[,2]) } } -\author{ -Ryan Batt, Luke A. Winslow -} \references{ Holtgrieve, Gordon W., Daniel E. Schindler, Trevor a. Branch, and Z. Teresa A'mar. 2010. \emph{Simultaneous Quantification of Aquatic Ecosystem Metabolism and Reaeration @@ -83,4 +80,6 @@ http://www.aslo.org/lo/toc/vol_55/issue_3/1047.html. \seealso{ \link{metab.mle}, \link{metab.bookkeep}, \link{metab.kalman} } - +\author{ +Ryan Batt, Luke A. Winslow +} diff --git a/man/metab.bookkeep.Rd b/man/metab.bookkeep.Rd index 832949e..1abb220 100644 --- a/man/metab.bookkeep.Rd +++ b/man/metab.bookkeep.Rd @@ -58,9 +58,6 @@ irr = as.integer(is.day(doobs[,1], 45)) metab.bookkeep(doobs[,2], do.sat, k.gas, z.mix=1, irr, datetime=doobs$datetime) } -\author{ -R. Iestyn Woolway, Hilary Dugan, Luke A Winslow, Ryan Batt, Jordan S Read, GLEON fellows -} \references{ Cole, Jonathan J., Michael L. Pace, Stephen R. Carpenter, and James F. Kitchell. 2000. \emph{Persistence of Net Heterotrophy in Lakes during Nutrient Addition and Food Web Manipulations}. @@ -69,4 +66,6 @@ Limnology and Oceanography 45 (8): 1718-1730. doi:10.4319/lo.2000.45.8.1718. \seealso{ \link{metab.bayesian}, \link{metab.mle}, \link{metab.kalman} } - +\author{ +R. Iestyn Woolway, Hilary Dugan, Luke A Winslow, Ryan Batt, Jordan S Read, GLEON fellows +} diff --git a/man/metab.kalman.Rd b/man/metab.kalman.Rd index de9b8b2..aef0769 100644 --- a/man/metab.kalman.Rd +++ b/man/metab.kalman.Rd @@ -97,9 +97,6 @@ metab.kalman(irr=irr[,2], z.mix=rep(1, length(k.gas)), do.sat=do.sat, wtr=wtr[,2], k.gas=k.gas, do.obs=doobs[,2]) } -\author{ -Ryan Batt, Luke A. Winslow -} \references{ Batt, Ryan D. and Stephen R. Carpenter. 2012. \emph{Free-water lake metabolism: addressing noisy time series with a Kalman filter}. Limnology and Oceanography: Methods 10: 20-30. doi: 10.4319/lom.2012.10.20 @@ -107,4 +104,6 @@ addressing noisy time series with a Kalman filter}. Limnology and Oceanography: \seealso{ \link{temp.kalman}, \link{watts.in}, \link{metab}, \link{metab.bookkeep}, \link{metab.ols}, \link{metab.mle}, \link{metab.bayesian} } - +\author{ +Ryan Batt, Luke A. Winslow +} diff --git a/man/metab.mle.Rd b/man/metab.mle.Rd index b6b3014..5c62ead 100644 --- a/man/metab.mle.Rd +++ b/man/metab.mle.Rd @@ -91,9 +91,6 @@ do.sat = o2.at.sat.base(wtr[,3], altitude=300) metab.mle(doobs[,2], do.sat, k.gas, z.mix[,2], irr[,2], wtr[,3]) } -\author{ -Luke A Winslow, Ryan Batt, GLEON Fellows -} \references{ Hanson, PC, SR Carpenter, N Kimura, C Wu, SP Cornelius, TK Kratz. 2008 \emph{Evaluation of metabolism models for free-water dissolved oxygen in lakes}. @@ -108,4 +105,6 @@ Limnology and Oceanography 58 (3): 849:866. doi:10.4319/lo.2013.58.3.0849. \seealso{ \link{metab}, \link{metab.bookkeep}, \link{metab.ols}, \link{metab.kalman}, \link{metab.bayesian} } - +\author{ +Luke A Winslow, Ryan Batt, GLEON Fellows +} diff --git a/man/metab.ols.Rd b/man/metab.ols.Rd index a8e5320..48a4e35 100644 --- a/man/metab.ols.Rd +++ b/man/metab.ols.Rd @@ -59,10 +59,9 @@ do.sat = o2.at.sat.base(wtr[,3], altitude=300) metab.ols(doobs[,2], do.sat, k.gas, z.mix[,2], irr[,2], wtr[,3]) } -\author{ -Luke A Winslow, Ryan Batt, GLEON Fellows -} \seealso{ \link{metab}, \link{metab.bookkeep}, \link{metab.mle}, \link{metab.kalman}, \link{metab.bayesian}, } - +\author{ +Luke A Winslow, Ryan Batt, GLEON Fellows +} diff --git a/man/o2.at.sat.Rd b/man/o2.at.sat.Rd index d51aff9..084f299 100644 --- a/man/o2.at.sat.Rd +++ b/man/o2.at.sat.Rd @@ -6,11 +6,15 @@ \title{Calculates the equilibrium saturation concentration of oxygen in water at the supplied conditions} \usage{ -o2.at.sat(ts.data, baro, altitude = 0, salinity = 0, - model = "garcia-benson") - -o2.at.sat.base(temp, baro, altitude = 0, salinity = rep(0, length(temp)), - model = "garcia-benson") +o2.at.sat(ts.data, baro, altitude = 0, salinity = 0, model = "garcia-benson") + +o2.at.sat.base( + temp, + baro, + altitude = 0, + salinity = rep(0, length(temp)), + model = "garcia-benson" +) } \arguments{ \item{ts.data}{Object of class data.frame with two named columns @@ -59,9 +63,6 @@ plot(temp.range, o2.at.sat.base(temp.range), xlab='Temperature (C)', ylab='Oxygen Saturation (mg/L)') plot(o2.at.sat.base(rep(20,25), salinity=sal.range), xlab='Salinity (PSU)', ylab='') -} -\author{ -Luke A Winslow } \references{ Colt, John. \emph{1 - Solubility of Atmospheric Gases in Freshwater.} In @@ -101,6 +102,8 @@ doi:10.1016/0011-7471(70)90037-9 \seealso{ \link{water.density}, \link{o2.at.sat.base} } +\author{ +Luke A Winslow +} \keyword{math,} \keyword{methods} - diff --git a/man/par.to.sw.Rd b/man/par.to.sw.Rd index 90a59c3..0f5240e 100644 --- a/man/par.to.sw.Rd +++ b/man/par.to.sw.Rd @@ -35,9 +35,6 @@ Returns incoming shortwave radiation by converting PAR measuremt. par <- 800 par.to.sw.base(par) } -\author{ -LakeMetabolizer -} \references{ Britton, C. M., and J. D. Dodd. \emph{Relationships of photosynthetically active radiation and shortwave irradiance.} Agricultural Meteorology 17, no. 1 (1976): 1-7. @@ -45,6 +42,8 @@ Agricultural Meteorology 17, no. 1 (1976): 1-7. \seealso{ \link{sw.to.par} } +\author{ +LakeMetabolizer +} \keyword{math} \keyword{methods} - diff --git a/man/rmv.vars.Rd b/man/rmv.vars.Rd index 1147c31..01dc349 100644 --- a/man/rmv.vars.Rd +++ b/man/rmv.vars.Rd @@ -21,12 +21,11 @@ An object of class data.frame \description{ subsets \code{data} according to header names. Excludes all matches to \code{var.name} } -\author{ -Luke A. Winslow -} \seealso{ \link{has.vars} \link{get.vars} } +\author{ +Luke A. Winslow +} \keyword{methods} - diff --git a/man/sun.rise.set.Rd b/man/sun.rise.set.Rd index f0241e1..af82d32 100644 --- a/man/sun.rise.set.Rd +++ b/man/sun.rise.set.Rd @@ -12,7 +12,7 @@ sun.rise.set(datetimes, lat) \item{lat}{Single latitude value of site. South should be negative, north positive} } \value{ -A 2-column matrix, first column sunrise, second column sunset, as \link{POSIXct} format. +A 2-column data frame, first column sunrise, second column sunset, as \link{POSIXct} format in standard time. Value is NA when there is no defined sunrise or sunset for that day (winter/summer at high and low latitudes). } \description{ @@ -21,9 +21,6 @@ Calculates the time of sunrise and sunset based on latitude and date. \examples{ sun.rise.set(lat=40.75,datetimes=as.POSIXlt('2013-03-31')) } -\author{ -Luke A. Winslow -} \references{ Iqbal, Muhammad. 1983. An Introduction to Solar Radiation. Elsevier. } @@ -31,5 +28,7 @@ Iqbal, Muhammad. 1983. An Introduction to Solar Radiation. Elsevier. \link{is.night} \link{is.day} } +\author{ +Luke A. Winslow +} \keyword{methods} - diff --git a/man/sw.to.par.Rd b/man/sw.to.par.Rd index 6820257..ff665ea 100644 --- a/man/sw.to.par.Rd +++ b/man/sw.to.par.Rd @@ -36,9 +36,6 @@ Returns PAR by converting incoming shortwave radiation measuremt. sw <- 800 sw.to.par.base(sw) -} -\author{ -Luke Winslow and others } \references{ Britton, C. M., and J. D. Dodd. \emph{Relationships of photosynthetically active radiation and shortwave irradiance.} @@ -47,6 +44,8 @@ Agricultural Meteorology 17, no. 1 (1976): 1-7. \seealso{ \link{par.to.sw} } +\author{ +Luke Winslow and others +} \keyword{math} \keyword{methods} - diff --git a/man/temp.kalman.Rd b/man/temp.kalman.Rd index 2d91273..1ce92d7 100644 --- a/man/temp.kalman.Rd +++ b/man/temp.kalman.Rd @@ -24,9 +24,6 @@ Smoothes a temperature time series uses a Kalman filter/ smoother. \details{ basic model process is \code{x[t] = beta*x[t-1] + c1*watts[t-1]} } -\author{ -Ryan Batt -} \references{ Batt, Ryan D. and Stephen R. Carpenter. 2012. \emph{Free-water lake metabolism: addressing noisy time series with a Kalman filter}. Limnology and @@ -35,4 +32,6 @@ Oceanography: Methods 10: 20-30. doi: 10.4319/lom.2012.10.20 \seealso{ \link{watts.in} \link{metab.kalman} } - +\author{ +Ryan Batt +} diff --git a/man/var.indx.Rd b/man/var.indx.Rd index d9e879c..35c484d 100644 --- a/man/var.indx.Rd +++ b/man/var.indx.Rd @@ -17,13 +17,12 @@ a boolean vector with same length as \code{var.names} \description{ returns index of column matches for \code{data} according to header names matches with \code{var.names}. } -\author{ -Luke A. Winslow -} \seealso{ \link{has.vars} \link{get.vars} \link{rmv.vars} } +\author{ +Luke A. Winslow +} \keyword{methods} - diff --git a/man/wind.scale.Rd b/man/wind.scale.Rd index 4bb5236..deb019c 100644 --- a/man/wind.scale.Rd +++ b/man/wind.scale.Rd @@ -41,13 +41,12 @@ wndHeight <- 2 wind.scale.base(wndSpeed, wndHeight) } -\author{ -Aline Jaimes, Luke A. Winslow -} \references{ Saucier, W. 2003. \emph{Principles of Meteorological Analysis}. Dover Publications. New York. p433 } \seealso{ Models of gas flux \link{k.cole}, \link{k.crusius}, \link{k.macIntyre}, & \link{k.read}. } - +\author{ +Aline Jaimes, Luke A. Winslow +} diff --git a/tests/testthat.R b/tests/testthat.R new file mode 100644 index 0000000..444e8a5 --- /dev/null +++ b/tests/testthat.R @@ -0,0 +1,4 @@ +library(testthat) +library(LakeMetabolizer) + +test_check("LakeMetabolizer") diff --git a/tests/testthat/test_sun.rise.set.R b/tests/testthat/test_sun.rise.set.R new file mode 100644 index 0000000..13588a2 --- /dev/null +++ b/tests/testthat/test_sun.rise.set.R @@ -0,0 +1,22 @@ +context("sun.rise.set()") +library(LakeMetabolizer) + +testthat::test_that("Return object class and format", { + + # Run sun.rise.set() with test data + dates <- as.POSIXlt( + c("2020-08-22", "2020-08-23", "2020-08-24"), + tz = "America/Chicago") + r <- sun.rise.set(dates, lat = 41.8781) + + # Returned object is a data frame + expect_equal(class(r), "data.frame") + + # Index order is preserved from original implmentation + expect_equal("sunrise", colnames(r)[1]) + expect_equal("sunset", colnames(r)[2]) + + # Input time zone attribute is returned + expect_true(attr(r$sunrise, "tzone") == "America/Chicago") + +}) From 44a3643db1d1e3ea276eaea17a06aaaea56d87f0 Mon Sep 17 00:00:00 2001 From: jzwart Date: Tue, 29 Sep 2020 14:02:58 -0400 Subject: [PATCH 2/2] updating to work with new data.frame output from sun.rise.set() function --- demo/fig_k600.R | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/demo/fig_k600.R b/demo/fig_k600.R index cfaa86c..f54f39d 100644 --- a/demo/fig_k600.R +++ b/demo/fig_k600.R @@ -56,7 +56,7 @@ models <- list( list('name'="Soloviev", data = k600_soloviev, col = cols[5], lty = 6, lwd = 1.7), list('name'="Heiskanen", data = k600_heiskanen, col = cols[6], lty = 1, lwd = 1.2), list('name'="Crusius", data = k600_crusius, col = cols[7], lty = 1, lwd = 1.2)) - + add_axes <- function(xlim, ylim, ylabel = pretty(ylim,10), panel.txt){ prc_x = 0.1 # position for text relative to axes prc_y = 0.07 @@ -75,8 +75,8 @@ add_axes <- function(xlim, ylim, ylabel = pretty(ylim,10), panel.txt){ } add_night <- function(xlim, ylim){ rise.set = sun.rise.set(xlim[1]+43200, lat) # add mid-day - polygon(x = c(xlim[1], rise.set[1], rise.set[1], xlim[1]), y = c(ylim[1],ylim[1],ylim[2],ylim[2]), col = night_col,border = NA) - polygon(x = c(xlim[2], rise.set[2], rise.set[2], xlim[2]), y = c(ylim[1],ylim[1],ylim[2],ylim[2]), col = night_col,border = NA) + polygon(x = c(xlim[1], rise.set$sunrise, rise.set$sunrise, xlim[1]), y = c(ylim[1],ylim[1],ylim[2],ylim[2]), col = night_col,border = NA) + polygon(x = c(xlim[2], rise.set$sunset, rise.set$sunset, xlim[2]), y = c(ylim[1],ylim[1],ylim[2],ylim[2]), col = night_col,border = NA) } moving_ave <- function(df, window = 18){ out <- df[,2]*NA @@ -98,17 +98,17 @@ add_models <- function(models){ } add_legend <- function(models, xlim, ylim, prc_x = 0.26, prc_y = 0.06){ - + y_strt <- ylim[2]-(ylim[2] - ylim[1])*prc_y y_spc <- (ylim[2] - ylim[1])*0.05 x_len <- (xlim[2] - xlim[1])*0.16 x <- c((xlim[2] - xlim[1])*prc_x+xlim[1], (xlim[2] - xlim[1])*prc_x+xlim[1] + x_len) - + for (i in 1:length(models)){ y = y_strt-(i-1)*y_spc - lines(x, c(y,y), - col =models[[i]]$col, - lty = models[[i]]$lty, + lines(x, c(y,y), + col =models[[i]]$col, + lty = models[[i]]$lty, lwd = models[[i]]$lwd) text(x[2],y, models[[i]]$name, pos = 4, cex = 0.65) } @@ -136,10 +136,10 @@ layout(matrix(c(rep(1,10),rep(2,9)),nrow=1)) # 55% on the left panel par(mai=c(b_mar,l_mar,t_mar,0), omi = c(0,0,0,r_mar),xpd=FALSE, mgp = c(1.15,.05,0)) -plot(c(0,NA),c(0,NA), type='l', +plot(c(0,NA),c(0,NA), type='l', axes = FALSE, xaxs = 'i', yaxs = 'i', - ylim=ylim, + ylim=ylim, ylab=expression(k[600]~(m~day^-1)), xlab=strftime(mean(xlim[1:2]), '%d %b %Y'), xlim=xlim[1:2]) @@ -150,10 +150,10 @@ add_axes(xlim[1:2], ylim, panel.txt = 'a)') par(mai=c(b_mar,gapper,t_mar,0)) -plot(c(0,NA),c(0,NA), type='l', +plot(c(0,NA),c(0,NA), type='l', axes = FALSE, xaxs = 'i', yaxs = 'i', - ylim=ylim, + ylim=ylim, ylab=NA, xlab=strftime(mean(xlim[3:4]), '%d %b %Y'), xlim=xlim[3:4])