photobiology (version 0.9.26)

day_night: Times for sun positions

Description

Functions for calculating the timing of solar positions by means of function sun_angles, given geographical coordinates and dates. They can be also used to find the time for an arbitrary solar elevation between 90 and -90 degrees by supplying "twilight" angle(s) as argument.

Usage

day_night(date = lubridate::now(tzone = "UTC"),
  tz = lubridate::tz(date), geocode = data.frame(lon = 0, lat = 51.5,
  address = "Greenwich"), twilight = "none", unit.out = "hours")

day_night_fast(date, tz, geocode, twilight, unit.out)

noon_time(date = lubridate::today(), tz = Sys.timezone(), geocode = data.frame(lon = 0, lat = 51.5, address = "Greenwich"), twilight = "none", unit.out = "datetime")

sunrise_time(date = lubridate::today(), tz = Sys.timezone(), geocode = data.frame(lon = 0, lat = 51.5, address = "Greenwich"), twilight = "sunlight", unit.out = "datetime")

sunset_time(date = lubridate::today(), tz = Sys.timezone(), geocode = data.frame(lon = 0, lat = 51.5, address = "Greenwich"), twilight = "sunlight", unit.out = "datetime")

day_length(date = lubridate::now(), tz = "UTC", geocode = data.frame(lon = 0, lat = 51.5, address = "Greenwich"), twilight = "sunlight", unit.out = "hours")

night_length(date = lubridate::now(), tz = "UTC", geocode = data.frame(lon = 0, lat = 51.5, address = "Greenwich"), twilight = "sunlight", unit.out = "hours")

Arguments

date

"vector" of POSIXct times or Date objects, any valid TZ is allowed, default is current date

tz

character vector indicating time zone to be used in output.

geocode

data frame with one or more rows and variables lon and lat as numeric values (degrees). If present, address will be copied to the output.

twilight

character string, one of "none", "civil", "nautical", "astronomical", or a numeric vector of length one, or two, giving solar elevation angle(s) in degrees (negative if below the horizon).

unit.out

character string, One of "datetime", "day", "hour", "minute", or "second".

Value

A data.frame with variables day, tz, twilight.rise, twilight.set, longitude, latitude, address, sunrise, noon, sunset, daylength, nightlength.

noon_time, sunrise_time and sunset_time return a vector of POSIXct times

day_length and night_length return numeric a vector giving the length in hours

Warning

Be aware that R's Date class does not save time zone metadata. This can lead to ambiguities in the current implementation as based on time instants. The argument passed to date should be of class POSIXct, in other words an instant in time, from which the correct date will be computed based on the tz argument.

Details

Twilight names are interpreted as follows. "none": solar elevation = 0 degrees. "refraction": solar elevation = 0 degrees + refraction correction. "sunlight": upper rim of solar disk corrected for refraction. "civil": -6 degrees, "naval": -12 degrees, and "astronomical": -18 degrees. Unit names for output are as follows: "hours" times for sunrise and sunset are returned as times-of-day in hours since midnight. "date" or "datetime" return the same times as datetime objects with TZ set (this is much slower than the "hours"). Day length and night length are returned as numeric values expressed in hours when `"datetime"' is passed as argument to unit.out. If twilight is a numeric vector of length two, the element with index 1 is used for sunrise and that with index 2 for sunset.

See Also

sun_angles.

Other astronomy related functions: format.solar_time, is.solar_time, print.solar_time, solar_time, sun_angles

Examples

Run this code
# NOT RUN {
library(lubridate)
my.geocode <- data.frame(lat = 60, lon = 25)
day_night(ymd("2015-05-30"), geocode = my.geocode)
day_night(ymd("2015-05-30") + days(1:10), geocode = my.geocode, twilight = "civil")
sunrise_time(ymd("2015-05-30"), geocode = my.geocode)
noon_time(ymd("2015-05-30"), geocode = my.geocode)
sunset_time(ymd("2015-05-30"), geocode = my.geocode)
day_length(ymd("2015-05-30"), geocode = my.geocode)
day_length(ymd("2015-05-30"), geocode = my.geocode, unit.out = "day")

# }

Run the code above in your browser using DataCamp Workspace