Drop #416 (2024-02-08): When The 🌕 Hits Your Eye In A Cool CLI

astral; geodate; sun

Ephemerides, at their core, are astronomical almanacs that detail the positions of celestial bodies — such as planets, moons, and stars — in the sky at given times. These positions are typically presented in tabular form, making them invaluable tools for astronomers, navigators, and even astrologers. The term itself originates from Greek and Latin, meaning ‘diary’ or ‘journal’, which aptly describes their function as logs of celestial movements.

Today, we cover some useful libraries and CLI tools, all centered around ephemerides.

TL;DR

This is an AI-generated summary of today’s edition.

  • The Go astral library and it’s Python counterpart provide means to calculate times for various positions of the sun and moon, such as dawn, sunrise, noon, sunset, and dusk, as well as the moon phase, solar azimuth, and elevation at specific latitudes and longitudes. The Go version ships with a handy CLI tool.
  • The geodate crate in Rust, based on Jean Meeus’s algorithms, allows for precise time calculations for sun and moon events, aiding in the creation of lunisolar calendars, which consider both solar and lunar cycles for various applications Rust’s geodate crate.
  • Legacy C libraries for ephemeris calculations are also mentioned, with a highlight on Paul Schlyter’s sunriset library and its CLI tool, which calculates various sun positions and twilight durations, demonstrating the enduring utility of such tools in modern computing Paul Schlyter’s sunriset.

astral

If you happen to be celestial mechanics-curious, you might have stumbled upon the Python astral (GH) library, a package that’s fairly popular for calculating various aspects of the sun and moon. Folks who are trying to use more resilient ecosystems will also be glad to know there’s a faithful Go port. We’ll be focusing mostly on the latter, as I recently added astral to my weather station console project.

Go’s astral library (like it’s Python progenitor) provides a means to calculate times for various positions of the sun, such as dawn, sunrise, noon, sunset, and dusk, as well as the moon phase, solar azimuth, and elevation at specific latitudes and longitudes.

The original Python astral library is a comprehensive package that includes a geocoder with a local database of cities, enabling folks to easily look up location and time zone data for a wide range of places around the globe. This functionality is quite useful for applications that need to adjust calculations based on the observer’s location, such as weather apps, photography tools (e.g., for the golden hour), and even religious observance calculations.

The Go library has a concept of an “observer”, which marks the x/y/z location of the calculation:

observer = astral.Observer{
  Latitude:  latitude, // all three are float64’s
  Longitude: longitude,
  Elevation: elevation,
}

This is used in all the straightforward function calls:

astral.Sunrise(observer, time.Now())
astral.Sunset(observer, time.Now())
…

A slick feature of the Golang port is the accompanying CLI, example output of which can be found in the section header.

geodate

Photo by Pixabay on Pexels.com

Go and Python are far from the only environments with ephemeris libraries and tools.

Rust’s geodate crate (GH) implements a fair number of the algorithms described in Astronomical Algorithms by Jean Meeus. With it, we can calculate the precise time of any sunrise, solstice, and new moon required to create a lunisolar calendar.

Traditional calendars and timekeeping are based on the Earth’s rotation and orbit around the Sun, but they often ignore the Moon’s influence. The geodate crate takes into account both the Sun and the Moon, (i.e., the aforementioned lunisolar calendar system). This can be particularly useful for applications that require synchronization with natural cycles, such as agriculture, astronomy, and even certain cultural and religious practices.

Like Go’s astralgeodate, too, has a CLI:

$ cargo install geodate
$ geodate --ephem 43.266998932 -70.856996572
Moonrise:            01:24:00:28:26:81
Sunrise:             01:24:00:28:28:77
Current:             01:24:00:28:38:21
Moonset:             01:24:00:28:64:22
Sunset:              01:24:00:28:71:22

sun

Photo by Timo C. Dinger on Unsplash

Back in my day, we had C libraries and C-based CLI tools, and we liked them.

One fav, “legacy” ephemeris library is Paul Schlyter’s sunriset.

Joachim Wiberg (@troglobit@fosstodon.org) wrapped Paul’s plain C file into a proper library and accompany CLI tool:

$ git clone git@github.com:troglobit/sun.git
$ cd sun
$ ./autogen.sh
$ ./configure
$ make
$ ./sun -a 43.266998932 -70.856996572
Day length:                 10.22 hours
With civil twilight         11.21 hours
With nautical twilight      12.33 hours
With astronomical twilight  13.44 hours
Length of twilight: civil    0.49 hours
                  nautical   1.06 hours
              astronomical   1.61 hours
Sun at south 11:57 EST
Sun rises 06:50, sets 17:04 EST
Civil twilight starts 06:21, ends 17:33 EST
Nautical twilight starts 05:47, ends 18:07 EST
Astronomical twilight starts 05:14, ends 18:40 EST

For R folks, I’ve had a dev-mode package, {daybreak}, around for a few years that wraps Paul’s OG library, which I even featured in my mini-SwiftR tome.

It’s hard to believe Paul’s homepage is still kickin’ and sporting the classic “Geocities” look.

FIN

Remember, you can follow and interact with the full text of The Daily Drop’s free posts on Mastodon via @dailydrop.hrbrmstr.dev@dailydrop.hrbrmstr.dev ☮️

One response to “Drop #416 (2024-02-08): When The 🌕 Hits Your Eye In A Cool CLI”

  1. Drop #418 (2024-02-09): Weekend Project Edition – hrbrmstr's Daily Drop Avatar

    […] well, time, this week; specifically, times of various ephemeris. While each of the sections in Drop #416 had a CLI component, we don’t need to settle for someone else’s vision of how things should […]

    Like

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.