Skip to content

Commit

Permalink
Merge pull request #139 from clnsmth/fix_127
Browse files Browse the repository at this point in the history
Change sun.rise.set() output from matrix to data.frame
  • Loading branch information
jzwart authored Oct 9, 2020
2 parents 94e26dd + 5ef30ce commit 5e42781
Show file tree
Hide file tree
Showing 32 changed files with 145 additions and 145 deletions.
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 2 additions & 6 deletions R/sun.rise.set.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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))

}
24 changes: 12 additions & 12 deletions demo/fig_k600.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
}
Expand Down Expand Up @@ -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])
Expand All @@ -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])
Expand Down
13 changes: 6 additions & 7 deletions man/calc.lw.net.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions man/calc.zeng.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions man/get.Ts.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions man/get.vars.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions man/getSchmidt.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions man/has.vars.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions man/is.day.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions man/is.night.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 7 additions & 8 deletions man/k.read.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 7 additions & 8 deletions man/k.read.base.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions man/k600.2.kGAS.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions man/load.all.data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions man/load.meta.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions man/metab.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5e42781

Please sign in to comment.