From 9f9bab7ebf8e3f4312adb0ae87ea1ab7cb35c96f Mon Sep 17 00:00:00 2001 From: Gabriel Date: Sat, 20 Mar 2021 10:47:36 -0400 Subject: [PATCH 1/4] Include possibility to find Sun time based on a given altitude. --- R/calcFunctions.R | 6 ++++-- R/getSunlightTimes.R | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/R/calcFunctions.R b/R/calcFunctions.R index 548a72f..d377a68 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(.getSetJ(alt * rad, lw, phi, dec, n, M, L)), + custom2 = .fromJulian(Jnoon - (.getSetJ(alt * rad, lw, phi, dec, n, M, L) - Jnoon)) ) return(result) diff --git a/R/getSunlightTimes.R b/R/getSunlightTimes.R index 9cd4890..613c5ec 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 = 7){ # 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() From 04d3c988cd191335e4b03b71ab16dc2c9df61ea5 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Sat, 20 Mar 2021 11:01:00 -0400 Subject: [PATCH 2/4] Invert order of custom1 and custom2. --- R/calcFunctions.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/calcFunctions.R b/R/calcFunctions.R index d377a68..ea96845 100644 --- a/R/calcFunctions.R +++ b/R/calcFunctions.R @@ -157,8 +157,8 @@ 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)), - custom1 = .fromJulian(.getSetJ(alt * rad, lw, phi, dec, n, M, L)), - custom2 = .fromJulian(Jnoon - (.getSetJ(alt * rad, lw, phi, dec, n, M, L) - Jnoon)) + 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) From 8e07c62637f710f047fbf37f96579e12a6acef8d Mon Sep 17 00:00:00 2001 From: Gabriel Date: Sat, 20 Mar 2021 11:01:28 -0400 Subject: [PATCH 3/4] Set 45 as the default custom altitude. --- R/getSunlightTimes.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/getSunlightTimes.R b/R/getSunlightTimes.R index 613c5ec..48c23ba 100644 --- a/R/getSunlightTimes.R +++ b/R/getSunlightTimes.R @@ -64,7 +64,7 @@ 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", "custom1", "custom2"), - tz = "UTC", alt = 7){ + tz = "UTC", alt = 45){ # data control From 4899c1830eb57db96420ebbfc66cd8bfdff99e90 Mon Sep 17 00:00:00 2001 From: tuberculo Date: Mon, 12 Apr 2021 15:03:14 -0400 Subject: [PATCH 4/4] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 36a91de..6108941 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