Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions R/calcFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
}

# calculates sun times for a given date and latitude/longitude
.getTimes <- function(date, lat, lng) {
.getTimes <- function(date, lat, lng, alt) {

rad <- (pi / 180)
lw <- rad * -lng
Expand Down Expand Up @@ -156,7 +156,9 @@
nightEnd = .fromJulian(Jnoon - (.getSetJ(-18 * rad, lw, phi, dec, n, M, L) - Jnoon)),
night = .fromJulian(.getSetJ(-18 * rad, lw, phi, dec, n, M, L)),
goldenHourEnd = .fromJulian(Jnoon - (.getSetJ(6 * rad, lw, phi, dec, n, M, L) - Jnoon)),
goldenHour = .fromJulian(.getSetJ(6 * rad, lw, phi, dec, n, M, L))
goldenHour = .fromJulian(.getSetJ(6 * rad, lw, phi, dec, n, M, L)),
custom1 = .fromJulian(Jnoon - (.getSetJ(alt * rad, lw, phi, dec, n, M, L) - Jnoon)),
custom2 = .fromJulian(.getSetJ(alt * rad, lw, phi, dec, n, M, L))
)

return(result)
Expand Down
8 changes: 4 additions & 4 deletions R/getSunlightTimes.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
getSunlightTimes <- function(date = NULL, lat = NULL, lon = NULL, data = NULL,
keep = c("solarNoon", "nadir", "sunrise", "sunset", "sunriseEnd", "sunsetStart",
"dawn", "dusk", "nauticalDawn", "nauticalDusk", "nightEnd", "night",
"goldenHourEnd", "goldenHour"),
tz = "UTC"){
"goldenHourEnd", "goldenHour", "custom1", "custom2"),
tz = "UTC", alt = 45){


# data control
Expand All @@ -77,13 +77,13 @@ getSunlightTimes <- function(date = NULL, lat = NULL, lon = NULL, data = NULL,
# variable control
available_var <- c("solarNoon", "nadir", "sunrise", "sunset", "sunriseEnd", "sunsetStart",
"dawn", "dusk", "nauticalDawn", "nauticalDusk", "nightEnd", "night",
"goldenHourEnd", "goldenHour")
"goldenHourEnd", "goldenHour", "custom1", "custom2")
stopifnot(all(keep %in% available_var))

# date := lubridate::force_tz(lubridate::as_datetime(Sys.Date()) + lubridate::hours(12), Sys.timezone())
data <- data %>%
.[, date := lubridate::force_tz(lubridate::as_datetime(date) + lubridate::hours(12), Sys.timezone())] %>%
.[, (available_var) := .getTimes(date = date, lat = lat, lng = lon)] %>%
.[, (available_var) := .getTimes(date = date, lat = lat, lng = lon, alt = alt)] %>%
.[, c("date", "lat", "lon", keep), with = FALSE] %>%
.[, date := as.Date(date)] %>%
as.data.frame()
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
````
# from cran
install.packages("suncalc")
devtools::install_github("datastorm-open/suncalc") for developpement version
devtools::install_github("tuberculo/suncalc") for version from this repo.
````

# Use
Expand Down