6

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))
Guz
  • 387
  • 3
  • 21
  • 2
    The `fmdates` package has an `equinox` function: https://www.rdocumentation.org/packages/fmdates/versions/0.1.4/topics/equinox, it's calculating the date using an algorithm though, I'm not sure if that always matches the actual date. – Marius Feb 14 '19 at 00:54
  • Don't know much about equinoxes but FWIW that package says it uses the same algorithms as OP's table, so probably suffices – Calum You Feb 14 '19 at 01:25
  • 3
    Please bear in mind that date to season realtionship varies by latitude, so if such a package exists, then the function will need at least date and latitude to produce a season result – PavoDive Feb 14 '19 at 01:45
  • @PavoDive you are right, that can be seen here: https://www.timeanddate.com/calendar/seasons.html. I will edit the question! – Guz Feb 14 '19 at 02:25

0 Answers0