This function returns the solar angles at a given time and location.
sun_angles(
time = lubridate::now(tzone = "UTC"),
tz = lubridate::tz(time),
geocode = tibble::tibble(lon = 0, lat = 51.5, address = "Greenwich"),
use.refraction = FALSE
)sun_angles_fast(time, tz, geocode, use.refraction)
sun_elevation(
time = lubridate::now(),
tz = lubridate::tz(time),
geocode = tibble::tibble(lon = 0, lat = 51.5, address = "Greenwich"),
use.refraction = FALSE
)
sun_zenith_angle(
time = lubridate::now(),
tz = lubridate::tz(time),
geocode = tibble::tibble(lon = 0, lat = 51.5, address = "Greenwich"),
use.refraction = FALSE
)
sun_azimuth(
time = lubridate::now(),
tz = lubridate::tz(time),
geocode = tibble::tibble(lon = 0, lat = 51.5, address = "Greenwich"),
use.refraction = FALSE
)
A "vector" of POSIXct Time, with any valid time zone (TZ) is allowed, default is current time.
character string indicating time zone to be used in output.
data frame with variables lon and lat as numeric values (degrees), nrow > 1, allowed.
logical Flag indicating whether to correct for fraction in the atmosphere.
A data.frame with variables time (in same TZ as input), TZ, solartime,
longitude, latitude, address, azimuth, and elevation. If a data frame with
multiple rows is passed to geocode
and a vector of times longer
than one is passed to time
, sun position for all combinations of
locations and times are returned are returned by sun_angles
. In
contrast, convenience functions returning a vector.
This function is an implementation of Meeus equations as used in NOAAs on-line web calculator, which are precise and valid for a very broad range of dates (years -1000 to 3000 at least). The apparent solar elevations near sunrise and sunset are affected by refraction in the atmosphere, which does in turn depend on weather conditions. The effect of refraction on the apparent position of the sun is only an estimate based on "typical" conditions for the atmosphere. The computation is not defined for latitudes 90 and -90 degrees, i.e. exactly at the poles.
In the current implementation functions sun_azimuth
,
sun_elevation
, and sun_zenith_angle
are wrappers
on sun_angles
, so if more than one angle is needed it is
preferable to directly call sun_angles
as it will be faster.
The primary source for the algorithm used is the book: Meeus, J. (1998) Astronomical Algorithms, 2 ed., Willmann-Bell, Richmond, VA, USA. ISBN 978-0943396613.
A different implementation is available at https://apps-nefsc.fisheries.noaa.gov/AstroCalc4R/ and in R paclage 'fishmethods'. In 'fishmethods' (= 1.11-0) there is a bug in function astrocalc4r() that affects sunrise and sunset times.
An interactive web page using the same algorithms is available at https://www.esrl.noaa.gov/gmd/grad/solcalc/. There are small differences in the returned times compared to our function that seem to be related to the estimation of atmospheric refraction (about 0.1 degrees).
Other astronomy related functions:
day_night()
,
format.solar_time()
,
format.tod_time()
,
is.solar_time()
,
print.solar_time()
,
print.tod_time()
,
solar_time()
# NOT RUN {
library(lubridate)
sun_angles()
sun_azimuth()
sun_elevation()
sun_zenith_angle()
sun_angles(ymd_hms("2014-09-23 12:00:00"))
sun_angles(ymd_hms("2014-09-23 12:00:00"),
geocode = data.frame(lat=60, lon=0))
sun_angles(ymd_hms("2014-09-23 12:00:00") + minutes((0:6) * 10))
# }
Run the code above in your browser using DataLab