Sunset calculations with astral

Introduction

Many of us are looking forward to spring as we all know that days are getting longer. But have you ever wondered how exactly daylight increases? Naivly, I always thought that it is a simple, steady gain of a few minutes every day. However, looking at the acutal data tells a slightly different story. Fortunatly, the Astral package in Python makes it easy to calculate exact sunrise and sunset times for a given day at a given location.

What to keep in mind?

Unlike weather forecasts, sunset times are not predictions. Instead, they can be calculated precisely from astronomical principles, taking into account latitude, longitude, and the Earth’s tilt (see https://gml.noaa.gov/grad/solcalc/calcdetails.html). Another challenge in analyzing daylight is time changes due to Daylight Saving Time (DST). When clocks shift forward in spring or backward in autumn, the local sunset time can jump by an hour overnight. While this affects our clocks, the astronomical sunset continues on its precise schedule. To avoid the sudden jump in sunset time, I used Coordinated Universal Time (UTC) and then converted it to local time.

What does the data tell us?

The increase in daylight is not fully linear. There are phases where the sunset time jumps faster from one day to the next, and phases where the gain is smaller. According to the AI, this pattern reflects the combination of the Earth’s axial tilt and its elliptical orbit. Around the solstices, the change is minimal, while in the weeks surrounding the equinoxes, the rate of change is higher.

Visualizing the daily sunset times and the rate of change (first derivative) reveals these phases: there are periods of rapid increase and periods where the gains are slower. Hence, nature does not follow all simple uniform trend, i.e., “a few minutes per day”.

Where to find the code?

The full code can be found here: https://github.com/msauerberg/sunset_with_astral




Enjoy Reading This Article?

Here are some more articles you might like to read next:

  • MCP Server - Spotify and Claude
  • Wasserstein distance - Analysis using HMD data
  • Wasserstein distance
  • Kite surfing, summer 2025
  • Sailing impressions