Daytime length variations with latitude and season (2/3)

In the previous post of this series:

  1. a simple grid consisting of points on the surface of a sphere was built step by step to approximate Earth.
  2. the basics of matrix rotations were reviewed to obtain:
    • the tilt of the rotational axis.
    • the changes in the orientation of the tilt relative to the Sun as Earth revolves around it over the year.

The closing figure in the first post is copied here as it summarizes visually all the relevant results and describes the starting point on top of which this post will build the calculation of the daytime by latitude througthout the year. This post will also cover how to prepare the data so that it can be easily plotted.

Figure 1: Orientation of the rotational axis relative to the Sun over a year

Daytime calculation

As already anticipated, the simple model that emerges from approximating Earth as a sphere, the Earth’s orbit around the Sun as a circumference and sunlight as parallel, simplifies by a great deal the calculation of the daytime.

At any time, half of the Earth is illuminated by the Sun and the other half is at night. During a day (24 hours), every point completes a rotation around the tilted axis, subject to experience the daynight cycle. It is beyond the scope of this model to calculate the location of a point at a particular time, meaning whether a point at a given latitude is on the illuminated area or not at a specific time. For this reason, how the surface is splitted in two halves (bright and dark) is irrelevant as long as the plane cutting the sphere in half is perpedincular to the Earth’s orbit and the sunlight. For simplicity’s sake, all points laying on the negative y-axis are considered illuminated and the those laying on the positive at dark.

The following function determines whether it is day or night based on the y-coordinate.

1is_day_or_night <- function(y) {
2    daynight <- y < 0 
3    daynight[daynight] <- 'day'
4    daynight[daynight==FALSE] <- 'night'
5    return(daynight)
6}

Now, the revolution of Earth around the Sun results in changes in the orientation of the tilted axis. These changes impact on how long the points at different latitudes are on the illuminated or the dark half as Earth spins about its axis.

The function is applied to each point in the grid. The grid comprises all the points representing the Earth’s surface (latitude, longitude) on different days in the year. There are as many spheres as days are used to sample the Earth’s orbit around the Sun.

1library(knitr)
2df <- df %>% mutate(daynight = is_day_or_night(yp))
3kable(head(df,5), caption = 'First 5 rows of the grid of points and measures')
Table 1: First 5 rows of the grid of points and measures
xp yp zp lon_pt day latitude daynight
0.0512145 -0.3944778 -0.9174771 1 1 -90 day
0.0512145 -0.3944778 -0.9174771 2 1 -90 day
0.0512145 -0.3944778 -0.9174771 3 1 -90 day
0.0512145 -0.3944778 -0.9174771 4 1 -90 day
0.0512145 -0.3944778 -0.9174771 5 1 -90 day
Note

An offset was added in the previous post so that the relative orientation on the day 1 coincides with the orientation on January 1st, winter in the northern hemisphere. As a result, the North Pole is away from the Sun.

1scene = list(camera = list(eye = list(x = 2, y = 0, z = 0)))
2fig3d <- plot_ly() %>%  config(displayModeBar = FALSE, scrollZoom = FALSE)
3fig3d <- fig3d %>% add_trace(data = df, x = ~xp, y = ~yp, z = ~zp, frame = ~ day,  color =~ daynight,type ='scatter3d', mode='markers', size=1, colors = c('#FFEA46FF','#00204DFF') ) %>% layout(scene = scene)
4fig3d

Figure 2: Bright and dark halves due to the orientation of the tilted axis over a year

Assuming that the change in the Earth’s orbit in 24 hours is negligible when compared to the rotation about its axis over the same time, then the calculation can be simplified even further by taking a snapshot at any time on a given day and count how many points at each latitude are illuminated and how many points are not.

The total number of points at a particular latitude corresponds to a 24-hour cycle. The proportion of points on the illuminated area represent the daytime and the proportion of points on the dark area, the nightime. For any given latitude, daytime and nightime always add up to 24 hours.

The following code groups the points by latitude and day in the year, counts the number of points that are “day” and turns the count into the number of daylight hours.

1hdnl <- df %>% group_by(latitude, day) %>% summarize(day_hours = (sum(daynight == 'day')  * 24 / num_lon_pts))
Table 2: First 5 rows of daylight hours by latitude and day in the year
latitude day day_hours
-90 1 24
-90 16 24
-90 31 24
-90 46 24
-90 61 24

Data preparation

Now the calculations are complete and it is just a matter of reshaping the data so that the daytime can be easily plotted by latitude and day in the year.

From the previous table 2 with columns (latitude, day, day_hour), the data are casted into a table 3 with a row for each latitude and a column for each day representing the axis orientation in Earth’s orbit around the Sun with value, the number of daylight hours on that day.

1cast_hdnl <- acast(hdnl, latitude~day, value.var ='day_hours' )
2kable(head(cast_hdnl,5), caption = 'First 3 rows of casted daylight hours by latitude and day in the year')
Table 3: First 3 rows of casted daylight hours by latitude and day in the year
1 16 31 46 61 76 91 106 121 136 151 166 181 196 211 226 241 256 271 286 301 316 331 346 361
-90 24.0 24.0 24.0 24.0 24.0 24.0 0.0 0 0.0 0.0 0 0 0.0 0.0 0.0 0.0 0.0 0.0 24.0 24.0 24 24.0 24.0 24.0 24.0
-80 24.0 24.0 24.0 24.0 20.5 14.5 10.0 5 0.0 0.0 0 0 0.0 0.0 0.0 0.0 0.0 8.5 13.0 18.0 24 24.0 24.0 24.0 24.0
-70 24.0 24.0 21.0 18.0 15.5 13.5 11.0 9 6.5 4.0 0 0 0.0 0.0 2.5 5.5 8.0 10.5 12.5 15.0 17 19.5 24.0 24.0 24.0
-60 18.5 17.5 16.5 15.5 14.5 12.5 11.5 10 9.0 7.5 6 6 5.5 6.0 7.0 8.5 9.5 11.0 12.0 13.5 15 16.5 17.5 18.5 18.5
-50 16.5 15.5 15.0 14.5 13.5 12.5 11.5 11 10.0 9.0 8 8 8.0 8.5 8.5 9.5 10.5 11.0 12.0 13.0 14 14.5 15.5 16.0 16.0

Daytime visualisation

The 3 dimensions (latitude, day and day_hours) are represented in a countour plot using plotly (Sievert 2020).

The latitude is represented in the y-axis, the day in the x-axis and the day_hours are represented by the slices coloured according to their value.

 1m <- list(
 2  l = 0,
 3  r = 0,
 4  b = 0,
 5  t = 0,
 6  pad = 4
 7)
 8
 9figcon <- plot_ly(width = 900, height = 700, z= cast_hdnl, type='contour',
10                  autocontour = F,
11                  colors = viridis_pal(direction = 1, option = 'cividis')(16),
12                  contours = list(
13                    start =1,
14                    end =  24,
15                    size = 1,
16                    showlabels = TRUE
17                  ),
18                  line = list(smoothing = 0.85)
19                  )  %>%  config(displayModeBar = FALSE, scrollZoom = FALSE)
20figcon <- figcon %>% colorbar(title = '# daylight hours')
21labels <- lat_pts
22labels[labels %% 10 != 0] <- ''
23labels <- as.character(labels)
24figcon <- figcon %>%
25  layout(
26        yaxis = list (
27            tickvals = seq( from = 0, to = (num_lat_pts - 1) , by  = 1),
28            ticktext = labels,
29            title = 'Latitude'
30        ),
31           xaxis = list (
32             tickvals = seq( from = 0, to = (num_year_pts - 1) , by  = 1),
33             ticktext = colnames(cast_hdnl),
34            title = 'Day in the year'
35        )
36      )
37figcon <- figcon %>% layout(margin = m)
38figcon

Figure 3: Daylength by latitude and day in the year (lat_step = 10, lon_step =1, year_step = 15)

The contour plot allows to quickly recognise a few well-known facts:

  • The 6-month daynight cicle on both poles. For the North Pole, 6-month night in Winter and 6 month-day in Summer. In the South Pole the other way around. This is the cause of a breathtaking sight, the midnight sun (Wikipedia, n.d.).
  • The day- and nighttime at the Equator are approx. 12 hours throughout the year.
  • In the Spring and Autumn equinoxes, the day- and nighttime are approx. 12 hours at any latitude on Earth.

References

Sievert, Carson. 2020. Interactive Web-Based Data Visualization with r, Plotly, and Shiny. Chapman; Hall/CRC. https://plotly-r.com.
Wikipedia. n.d. “Midnight Sun.” https://en.wikipedia.org/wiki/Midnight_sun.

Posts in this Series

comments powered by Disqus