DiveFreedom
DiveFreedom

Reputation: 122

How to convert time of day into radians with 0/2Pi = sunrise and Pi=sunset?

I have a big dataset (continuous across months), and I need to perform circular statistics to assess a potential effect of diel cycles.

For this, I converted all cyclic data into radians. I need now to do the same with the time of the day. The problem that I am facing is the following: I do not want 0/2Pi to correspond to 0h/24h and Pi to noon. I need my data to be standardised, considering that sunrise/sunset time varies through the year.

Instead, I would need to set 0/2Pi to be sunrise and Pi to be sunset times. I've been looking everywhere and couldn't find any solution. A scientific paper uses this method, I contacted one of the authors but no answer so far. Here is a sentence from the paper:

"To standardise daylight, radian values were calculated. The values 0 and 2Pi represent dawn, while Pi represents dusk." Zein et al., 2019

I should mentioned that I am a marine biologist, working on cetaceans. I do not have any mathematical background. And I code in R. I accessed sunset/sunrise times for everyday of my dataset using sunriset() from the Maptools package.

Thank you very much in advance.

Upvotes: 0

Views: 1578

Answers (1)

Rundmus
Rundmus

Reputation: 127

You can use getSunlightTimes in suncalc package. Here is an attempt to compute the time, setting 0 for sunrise and π for sunset.

library(suncalc)
library(hms)

#  tm = a time variable
tm <- as.hms(
  c(
    as.POSIXlt("2019-04-18 10:02:29"),
    as.POSIXlt("2019-04-18 15:10:00"),
    as.POSIXlt("2019-04-18 18:54:12")
  )
)

sun_t <- getSunlightTimes(as.Date("2019-04-18"), lat= 59.33, lon= 18.07, tz= "CET")

sunrise <- as.hms(sun_t$sunrise)
sunset <- as.hms(sun_t$sunset)

tm_pi <- as.numeric(tm - sunrise) * pi / as.numeric(sunset - sunrise)

Upvotes: 1

Related Questions