| Title: | Compute Sun Position, Sunlight Phases, Moon Position and Lunar Phase |
|---|---|
| Description: | Get sun position, sunlight phases (times for sunrise, sunset, dusk, etc.), moon position and lunar phase for the given location and time. Most calculations are based on the formulas given in Astronomy Answers articles about position of the sun and the planets : <https://www.aa.quae.nl/en/reken/zonpositie.html>. |
| Authors: | Benoit Thieurmel [aut, cre] (R interface), Achraf Elmarhraoui [aut] (R interface) |
| Maintainer: | Benoit Thieurmel <[email protected]> |
| License: | GPL-2 | file LICENSE |
| Version: | 0.5.3 |
| Built: | 2026-07-15 14:48:19 UTC |
| Source: | https://github.com/datastorm-open/suncalc |
Get Moon illumination
getMoonIllumination(date = Sys.Date(), keep = c("fraction", "phase", "angle"))getMoonIllumination(date = Sys.Date(), keep = c("fraction", "phase", "angle"))
date |
Single or multiple DateTime. Can be a |
keep |
|
Computes the following properties:
illuminated fraction of the moon; varies from 0.0 (new moon) to 1.0 (full moon)
moon phase; varies from 0.0 to 1.0, described below
midpoint angle in radians of the illuminated limb of the moon reckoned eastward from the north point of the disk; the moon is waxing if the angle is negative, and waning if positive
Moon phase value should be interpreted like this:
| 0 | New Moon |
| Waxing Crescent | |
| 0.25 | First Quarter |
| Waxing Gibbous | |
| 0.5 | Full Moon |
| Waning Gibbous | |
| 0.75 | Last Quarter |
| Waning Crescent | |
| 1 | New Moon |
By subtracting the parallacticAngle from the angle one can get the zenith angle of the moons bright limb (anticlockwise). The zenith angle can be used do draw the moon shape from the observers perspective (e.g. moon lying on its back).
data.frame
Other suncalc functions:
getMoonPosition(),
getMoonTimes(),
getSunlightPosition(),
getSunlightTimes()
# one date getMoonIllumination(date = Sys.Date()) # in character getMoonIllumination(date = c("2017-05-12", "2017-05-12 00:00:00"), keep = c("fraction", "phase")) # in POSIXct getMoonIllumination(date = as.POSIXct("2017-05-12 00:00:00", tz = "UTC")) getMoonIllumination(date = as.POSIXct("2017-05-12 02:00:00", tz = "CET")) date <- seq(ISOdate(2009,1,1), ISOdate(2010,1,1), "hours") date_cet <- date attr(date_cet, "tzone") <- "CET" res <- getMoonIllumination(date = date_cet)# one date getMoonIllumination(date = Sys.Date()) # in character getMoonIllumination(date = c("2017-05-12", "2017-05-12 00:00:00"), keep = c("fraction", "phase")) # in POSIXct getMoonIllumination(date = as.POSIXct("2017-05-12 00:00:00", tz = "UTC")) getMoonIllumination(date = as.POSIXct("2017-05-12 02:00:00", tz = "CET")) date <- seq(ISOdate(2009,1,1), ISOdate(2010,1,1), "hours") date_cet <- date attr(date_cet, "tzone") <- "CET" res <- getMoonIllumination(date = date_cet)
Get Moon position
getMoonPosition( date = NULL, lat = NULL, lon = NULL, data = NULL, keep = c("altitude", "azimuth", "distance", "parallacticAngle") )getMoonPosition( date = NULL, lat = NULL, lon = NULL, data = NULL, keep = c("altitude", "azimuth", "distance", "parallacticAngle") )
date |
Single or multiple DateTime. Can be a |
lat |
|
lon |
|
data |
|
keep |
|
Returns an object with the following properties:
moon altitude above the horizon in radians
moon azimuth in radians
distance to moon in kilometers
parallactic angle of the moon in radians
data.frame
Other suncalc functions:
getMoonIllumination(),
getMoonTimes(),
getSunlightPosition(),
getSunlightTimes()
# one date getMoonPosition(date = Sys.Date(), lat = 50.1, lon = 1.83) # in character getMoonPosition(date = c("2017-05-12", "2017-05-12 00:00:00"), lat = 50.1, lon = 1.83) # in POSIXct getMoonPosition(date = as.POSIXct("2017-05-12 00:00:00", tz = "UTC"), lat = 50.1, lon = 1.83) getMoonPosition(date = as.POSIXct("2017-05-12 02:00:00", tz = "CET"), lat = 50.1, lon = 1.83) # multiple date + subset getMoonPosition(date = seq.Date(Sys.Date()-9, Sys.Date(), by = 1), keep = c("altitude", "azimuth"), lat = 50.1, lon = 1.83) # multiple coordinates data <- data.frame(date = seq.Date(Sys.Date()-9, Sys.Date(), by = 1), lat = c(rep(50.1, 10), rep(49, 10)), lon = c(rep(1.83, 10), rep(2, 10))) getMoonPosition(data = data, keep = c("altitude", "azimuth"))# one date getMoonPosition(date = Sys.Date(), lat = 50.1, lon = 1.83) # in character getMoonPosition(date = c("2017-05-12", "2017-05-12 00:00:00"), lat = 50.1, lon = 1.83) # in POSIXct getMoonPosition(date = as.POSIXct("2017-05-12 00:00:00", tz = "UTC"), lat = 50.1, lon = 1.83) getMoonPosition(date = as.POSIXct("2017-05-12 02:00:00", tz = "CET"), lat = 50.1, lon = 1.83) # multiple date + subset getMoonPosition(date = seq.Date(Sys.Date()-9, Sys.Date(), by = 1), keep = c("altitude", "azimuth"), lat = 50.1, lon = 1.83) # multiple coordinates data <- data.frame(date = seq.Date(Sys.Date()-9, Sys.Date(), by = 1), lat = c(rep(50.1, 10), rep(49, 10)), lon = c(rep(1.83, 10), rep(2, 10))) getMoonPosition(data = data, keep = c("altitude", "azimuth"))
Get Moon times
getMoonTimes( date = NULL, lat = NULL, lon = NULL, data = NULL, keep = c("rise", "set", "alwaysUp", "alwaysDown"), tz = "UTC", ... )getMoonTimes( date = NULL, lat = NULL, lon = NULL, data = NULL, keep = c("rise", "set", "alwaysUp", "alwaysDown"), tz = "UTC", ... )
date |
|
lat |
|
lon |
|
data |
|
keep |
|
tz |
|
... |
Not used. (Maintenance only) |
Available variables are :
Date. moonrise time
Date. moonset time
Logical. TRUE if the moon never rises or sets and is always above the horizon during the day
Logical. TRUE if the moon is always below the horizon
data.frame
Other suncalc functions:
getMoonIllumination(),
getMoonPosition(),
getSunlightPosition(),
getSunlightTimes()
# one date getMoonTimes(date = Sys.Date(), lat = 47.21, lon = -1.557, tz = "CET") # multiple date + subset getMoonTimes(date = seq.Date(Sys.Date()-9, Sys.Date(), by = 1), keep = c("rise", "set", "alwaysUp"), lat = 47.21, lon = -1.557, tz = "CET") # multiple coordinates data <- data.frame(date = seq.Date(Sys.Date()-9, Sys.Date(), by = 1), lat = c(rep(50.1, 10), rep(49, 10)), lon = c(rep(1.83, 10), rep(2, 10))) getMoonTimes(data = data, tz = "CET")# one date getMoonTimes(date = Sys.Date(), lat = 47.21, lon = -1.557, tz = "CET") # multiple date + subset getMoonTimes(date = seq.Date(Sys.Date()-9, Sys.Date(), by = 1), keep = c("rise", "set", "alwaysUp"), lat = 47.21, lon = -1.557, tz = "CET") # multiple coordinates data <- data.frame(date = seq.Date(Sys.Date()-9, Sys.Date(), by = 1), lat = c(rep(50.1, 10), rep(49, 10)), lon = c(rep(1.83, 10), rep(2, 10))) getMoonTimes(data = data, tz = "CET")
Get Sunlight position
getSunlightPosition( date = NULL, lat = NULL, lon = NULL, data = NULL, keep = c("altitude", "azimuth") )getSunlightPosition( date = NULL, lat = NULL, lon = NULL, data = NULL, keep = c("altitude", "azimuth") )
date |
Single or multiple DateTime. Can be a |
lat |
|
lon |
|
data |
|
keep |
|
Returns an object with the following properties:
sun altitude above the horizon in radians, e.g. 0 at the horizon and PI/2 at the zenith (straight over your head)
sun azimuth in radians (direction along the horizon, measured from south to west), e.g. 0 is south and Math.PI * 3/4 is northwest
data.frame
Other suncalc functions:
getMoonIllumination(),
getMoonPosition(),
getMoonTimes(),
getSunlightTimes()
# one date getSunlightPosition(date = Sys.Date(), lat = 50.1, lon = 1.83) # in character getSunlightPosition(date = c("2017-05-12", "2017-05-12 00:00:00"), lat = 50.1, lon = 1.83) # in POSIXct getSunlightPosition(date = as.POSIXct("2017-05-12 00:00:00", tz = "UTC"), lat = 50.1, lon = 1.83) getSunlightPosition(date = as.POSIXct("2017-05-12 02:00:00", tz = "CET"), lat = 50.1, lon = 1.83) # multiple date + subset getSunlightPosition(date = seq.Date(Sys.Date()-9, Sys.Date(), by = 1), keep = c("altitude"), lat = 50.1, lon = 1.83) # multiple coordinates data <- data.frame(date = seq.Date(Sys.Date()-9, Sys.Date(), by = 1), lat = c(rep(50.1, 10), rep(49, 10)), lon = c(rep(1.83, 10), rep(2, 10))) getSunlightPosition(data = data, keep = c("altitude", "azimuth"))# one date getSunlightPosition(date = Sys.Date(), lat = 50.1, lon = 1.83) # in character getSunlightPosition(date = c("2017-05-12", "2017-05-12 00:00:00"), lat = 50.1, lon = 1.83) # in POSIXct getSunlightPosition(date = as.POSIXct("2017-05-12 00:00:00", tz = "UTC"), lat = 50.1, lon = 1.83) getSunlightPosition(date = as.POSIXct("2017-05-12 02:00:00", tz = "CET"), lat = 50.1, lon = 1.83) # multiple date + subset getSunlightPosition(date = seq.Date(Sys.Date()-9, Sys.Date(), by = 1), keep = c("altitude"), lat = 50.1, lon = 1.83) # multiple coordinates data <- data.frame(date = seq.Date(Sys.Date()-9, Sys.Date(), by = 1), lat = c(rep(50.1, 10), rep(49, 10)), lon = c(rep(1.83, 10), rep(2, 10))) getSunlightPosition(data = data, keep = c("altitude", "azimuth"))
Get Sunlight times
getSunlightTimes( 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" )getSunlightTimes( 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" )
date |
|
lat |
|
lon |
|
data |
|
keep |
|
tz |
|
Available variables are :
sunrise (top edge of the sun appears on the horizon)
sunrise ends (bottom edge of the sun touches the horizon)
morning golden hour (soft light, best time for photography) ends
solar noon (sun is in the highest position)
evening golden hour starts
sunset starts (bottom edge of the sun touches the horizon)
sunset (sun disappears below the horizon, evening civil twilight starts)
dusk (evening nautical twilight starts)
nautical dusk (evening astronomical twilight starts)
night starts (dark enough for astronomical observations)
nadir (darkest moment of the night, sun is in the lowest position)
night ends (morning astronomical twilight starts)
nautical dawn (morning nautical twilight starts)
dawn (morning nautical twilight ends, morning civil twilight starts)
data.frame
Other suncalc functions:
getMoonIllumination(),
getMoonPosition(),
getMoonTimes(),
getSunlightPosition()
# one date getSunlightTimes(date = Sys.Date(), lat = 50.1, lon = 1.83, tz = "CET") # multiple date + subset getSunlightTimes(date = seq.Date(Sys.Date()-9, Sys.Date(), by = 1), keep = c("sunrise", "sunriseEnd", "sunset", "sunsetStart"), lat = 50.1, lon = 1.83, tz = "CET") # multiple coordinates data <- data.frame(date = seq.Date(Sys.Date()-9, Sys.Date(), by = 1), lat = c(rep(50.1, 10), rep(49, 10)), lon = c(rep(1.83, 10), rep(2, 10))) getSunlightTimes(data = data, keep = c("sunrise", "sunriseEnd", "sunset", "sunsetStart"), tz = "CET")# one date getSunlightTimes(date = Sys.Date(), lat = 50.1, lon = 1.83, tz = "CET") # multiple date + subset getSunlightTimes(date = seq.Date(Sys.Date()-9, Sys.Date(), by = 1), keep = c("sunrise", "sunriseEnd", "sunset", "sunsetStart"), lat = 50.1, lon = 1.83, tz = "CET") # multiple coordinates data <- data.frame(date = seq.Date(Sys.Date()-9, Sys.Date(), by = 1), lat = c(rep(50.1, 10), rep(49, 10)), lon = c(rep(1.83, 10), rep(2, 10))) getSunlightTimes(data = data, keep = c("sunrise", "sunriseEnd", "sunset", "sunsetStart"), tz = "CET")