Skip to content

Instantly share code, notes, and snippets.

@jsta
Created February 28, 2017 02:53
Show Gist options
  • Save jsta/41d89d8f9173fce0deedf41ef437eafd to your computer and use it in GitHub Desktop.
Save jsta/41d89d8f9173fce0deedf41ef437eafd to your computer and use it in GitHub Desktop.
Calculate day length
#'@references \url{http://aa.usno.navy.mil/data/docs/RS_OneYear.php}
#'@return A 3 x 365 data.frame of sunrise, sunset, date where times are in GMT
#'@examples \dontrun{
#' sunsetrise_yr(year = 2015, lon_deg = 80, lon_min = 26, lat_deg = 25, lat_min = 5, tz = 5)
#' }
sunsetrise_yr <- function(year, lon_sign = -1, lon_deg, lon_min, lat_sign = 1, lat_deg, lat_min, tz, tz_sign = 1){
url <- "http://aa.usno.navy.mil"
query <- list(
ID = "JS",
year = year,
task = 0,
lon_sign = lon_sign,
lon_deg = lon_deg,
lon_min = lon_min,
lat_sign = lat_sign,
lat_deg = lat_deg,
lat_min = lat_min,
tz = tz,
tz_sign = tz_sign)
rs <- httr::GET(url, path = "cgi-bin/aa_rstablew.pl", query = query)
strsplit(httr::content(rs, "text"), "\n")[[1]][19:62]
}
@jsta
Copy link
Author

jsta commented Mar 3, 2017

This function and associated functions moved to a package at: https://github.com/jsta/twilight

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment