I need to get the exact season (autumn, winter, spring and summer) of my dataset using a "POSIXct" "POSIXt"
datetime column.
It's important to consider that the seasons depends on equinoxes and solstices on Earth and the exact time it takes places change over years and also with latitude and longitude position. So it's not as trivial as defining the same date and time for all the equinoxes and solstices over all the years.
Here is a table that shows this change through years: http://www.astropixels.com/ephemeris/soleq2001.html.
Is there any built-in function in some R package to achieve that?
Below is a starting point:
# Load packages
library(lubridate)
library(dplyr)
# Create dummy df with datetime col
df <- data.frame(datetimes = seq(as.POSIXct("2016-01-01 00:00:00", tz = "UTC"),
as.POSIXct("2019-12-31 23:59:59", tz="UTC"),
by = "hour"))
# Calculate season in a fix position given by lon, lat pairs
df2 <-
df %>%
mutate(season = datetimeToExactSeason(datetimes))