diff --git a/R/calcFunctions.R b/R/calcFunctions.R index 548a72f..ea96845 100644 --- a/R/calcFunctions.R +++ b/R/calcFunctions.R @@ -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 @@ -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) diff --git a/R/getSunlightTimes.R b/R/getSunlightTimes.R index 9cd4890..48c23ba 100644 --- a/R/getSunlightTimes.R +++ b/R/getSunlightTimes.R @@ -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 @@ -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() diff --git a/README.md b/README.md index 636a06d..df12adf 100644 --- a/README.md +++ b/README.md @@ -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