-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimeInfo.Rd
135 lines (111 loc) · 4.62 KB
/
timeInfo.Rd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/timeInfo.R
\name{timeInfo}
\alias{timeInfo}
\title{Get time related information}
\usage{
timeInfo(time = NULL, longitude = NULL, latitude = NULL, timezone = NULL)
}
\arguments{
\item{time}{POSIXct vector with specified timezone,}
\item{longitude}{Longitude of the location of interest.}
\item{latitude}{Latitude of the location of interest.}
\item{timezone}{Olson timezone at the location of interest.}
}
\value{
A dataframe with times and masks.
}
\description{
Calculate the local time at the target location, as well as
sunrise, sunset and solar noon times, and create several temporal masks.
The returned dataframe will have as many rows as the length of the incoming
UTC \code{time} vector and will contain the following columns:
\itemize{
\item{\code{localStdTime_UTC} -- UTC representation of local \strong{standard} time}
\item{\code{daylightSavings} -- logical mask = TRUE if daylight savings is in effect}
\item{\code{localTime} -- local clock time}
\item{\code{sunrise} -- time of sunrise on each localTime day}
\item{\code{sunset} -- time of sunset on each localTime day}
\item{\code{solarnoon} -- time of solar noon on each localTime day}
\item{\code{day} -- logical mask = TRUE between sunrise and sunset}
\item{\code{morning} -- logical mask = TRUE between sunrise and solarnoon}
\item{\code{afternoon} -- logical mask = TRUE between solarnoon and sunset}
\item{\code{night} -- logical mask = opposite of day}
}
}
\details{
NOAA used the reference below to develop their Sunrise/Sunset
\url{https://gml.noaa.gov/grad/solcalc/sunrise.html} and Solar
Position
\url{https://gml.noaa.gov/grad/solcalc/azel.html}
Calculators. The algorithms include corrections for atmospheric
refraction effects.
Input can consist of one location and at least one POSIXct times, or one
POSIXct time and at least one location. \var{solarDep} is recycled as
needed.
Do not use the daylight savings time zone string for supplying
\var{dateTime}, as many OS will not be able to properly set it to
standard time when needed.
The \code{localStdTime_UTC} column in the returned dataframe is primarily for
internal use and provides an important tool for creating LST daily averages
and LST axis labeling.
}
\note{
NOAA notes that “for latitudes greater than 72 degrees N and S,
calculations are accurate to within 10 minutes. For latitudes less than +/-
72 degrees accuracy is approximately one minute.”
}
\section{Attribution}{
Internal functions used for ephemerides calculations were copied verbatim
from the now deprecated \strong{maptools} package source
code in an effort to reduce the number of package dependencies.
}
\section{Warning}{
Compared to NOAA's original Javascript code, the sunrise and sunset estimates
from this translation may differ by +/- 1 minute, based on tests using
selected locations spanning the globe. This translation does not include
calculation of prior or next sunrises/sunsets for locations above the Arctic
Circle or below the Antarctic Circle.
}
\section{Local Standard Time}{
US EPA regulations mandate that daily averages be calculated
based on "Local Standard Time" (LST) (\emph{i.e. never shifting to daylight
savings}). To ease work in a regulatory context, LST times are included in the
returned dataframe.
}
\section{References}{
Meeus, J. (1991) Astronomical Algorithms. Willmann-Bell, Inc.
}
\examples{
library(MazamaTimeSeries)
Carmel <-
Carmel_Valley \%>\%
mts_filterDate(20160801, 20160810)
# Create timeInfo object for this monitor
ti <- timeInfo(
Carmel$data$datetime,
Carmel$meta$longitude,
Carmel$meta$latitude,
Carmel$meta$timezone
)
t(ti[6:9,])
# Subset the data based on day/night masks
data_day <- Carmel$data[ti$day,]
data_night <- Carmel$data[ti$night,]
# Build two monitor objects
Carmel_day <- list(meta = Carmel$meta, data = data_day)
Carmel_night <- list(meta = Carmel$meta, data = data_night)
# Plot them
plot(Carmel_day$data, pch = 8, col = 'goldenrod')
points(Carmel_night$data, pch = 16, col = 'darkblue')
}
\author{
Sebastian P. Luque \email{[email protected]}, translated from
Greg Pelletier's \email{[email protected]} VBA code (available from
\url{https://ecology.wa.gov/Research-Data/Data-resources/Models-spreadsheets/Modeling-the-environment/Models-tools-for-TMDLs}), who in turn
translated it from original Javascript code by NOAA (see Details).
Roger Bivand \email{[email protected]} adapted the code to work with
\strong{sp} classes. Jonathan Callahan \email{[email protected]}
adapted the source code from the \strong{maptools} package to work with
\href{https://mazamascience.github.io/MazamaTimeSeries/}{MazmaTimeSeries} classes.
}