Creates a day/night indicator for each time point. If latitude and longitude are not provided, local time is used (daylight defined by an hour threshold). Otherwise, an approximate solar zenith angle is computed to determine whether the sun is above the horizon.
day_night_flag(data, date_col = NULL, lat = NULL, lon = NULL,
threshold = 6, type = c("binary", "sun", "shade"),
local_tz = "UTC", verbose = FALSE)A vector of day/night flags.
A data frame with a time column.
Time column index or name. If NULL, the first column matching date is used.
Latitude of the location(s). Can be a scalar or a vector of length equal to the number of rows.
Longitude of the location(s). Same behavior as lat.
Hour threshold used for local-time based classification (default 6). Only used if latitude/longitude are missing.
Output type: "binary" returns 1/0, "sun" returns "day"/"night", "shade" returns "day"/"shade".
Time zone for local time calculation (default UTC).
Logical; if TRUE, prints progress message.
Chun-Sheng Liang <[email protected]>
When latitude/longitude are supplied, the function computes the solar zenith angle using a simplified astronomical formula. Values with a solar zenith angle below 90 degrees are considered day.
1. Example data is from https://smear.avaa.csc.fi/download. It includes particle number concentrations in SMEAR I Varrio forest.
day_night_flag(data[1:100, c(1, 4, 17:19)], date_col = 1, lat = 40, lon = -105)
Run the code above in your browser using DataLab