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.
Type your email…
Subscribe
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.comGo 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 astral, geodate, too, has a CLI:
$ cargo install geodate$ geodate --ephem 43.266998932 -70.856996572Moonrise: 01:24:00:28:26:81Sunrise: 01:24:00:28:28:77Current: 01:24:00:28:38:21Moonset: 01:24:00:28:64:22Sunset: 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 (@[email protected]) wrapped Paul’s plain C file into a proper library and accompany CLI tool:
$ git clone [email protected]:troglobit/sun.git$ cd sun$ ./autogen.sh$ ./configure$ make$ ./sun -a 43.266998932 -70.856996572Day length: 10.22 hoursWith civil twilight 11.21 hoursWith nautical twilight 12.33 hoursWith astronomical twilight 13.44 hoursLength of twilight: civil 0.49 hours nautical 1.06 hours astronomical 1.61 hoursSun at south 11:57 ESTSun rises 06:50, sets 17:04 ESTCivil twilight starts 06:21, ends 17:33 ESTNautical twilight starts 05:47, ends 18:07 ESTAstronomical 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.
Type your email…
Subscribe
FIN
Remember, you can follow and interact with the full text of The Daily Drop’s free posts on Mastodon via @[email protected] ☮️
https://dailydrop.hrbrmstr.dev/2024/02/08/drop-416-2024-02-08-when-the-%f0%9f%8c%95-hits-your-eye-in-a-cool-cli/
#ephemeris #sunrise #sunset