Logo

dev-resources.site

for different kinds of informations.

Introducing Ephem

Published at
1/13/2025
Categories
ruby
astronomy
astrometry
webdev
Author
rhannequin
Categories
4 categories in total
ruby
open
astronomy
open
astrometry
open
webdev
open
Author
10 person written this
rhannequin
open
Introducing Ephem

tl;dr at the end

I am glad to announce a new Ruby gem on astronomy has been published: Ephem, a library that produces ephemerides from NASA's JPL Development Ephemeris series.

JPL DE4XX

The Jet Propulsion Laboratory (JPL) produces a series of mathematical models called Development Ephemeris (DE), which are used for spacecraft navigation and astronomy.

JPL center in Pasadena, California

Such an ephemeris is available through a SPK file, or SPICE Kernel file, a complex binary file containing mathematical parameters to compute the position of Solar System bodies based on time.

The precision delivered by these models is so high that space agencies use it to send spacecraft into space. As an order of magnitude, while the planet Mars is usually located within a range of 50 to 250 million kilometres from the Earth, they are expected to predict its location with a margin error of one kilometre.

These kernels are large and complex and follow an arbitrary format of headers, segments, and coefficients that is unfriendly to beginners. However, once the right coefficients are found and used in the right mathematical formula, barycentric Cartesian coordinates are produced.

Solar System Cartesian coordinates

While we are used to coordinates relative to one's town, country or even the Earth, a DE kernel produces a more absolute series of coordinates, relative to barycentres in the Solar System.

A [barycentre] is the centre of mass of two or more bodies. In the same way, the point of balance for two different objects on a plank depends on their mass, Solar System bodies such as planets or even the Sun are related to their barycentre.

Animation of a barycentre with two objects, one with a large mass and the other with a small mass. They both orbit the barycentre with different amplitudes based on their mass.

Also, Cartesian coordinates are a 3-D space coordinate system of three axes going through a single origin. Often named x, y, z, these are coordinates where an object is located in space relative to the origin.

Illustration of Cartesian coordinates showing 3 planes for each x,y,z axis, joined at a centre

Here is an example in more practical words: JPL DE405 enables us to compute the Earth-Moon system's (barycentre) location from the Solar System's barycentre. It can also calculate the Earth's location from the Earth-Moon barycentre. Therefore, through a simple formula, it is possible to compute the Earth's location from the Solar System's barycentre.

How to use these coordinates

Now the question is: What can we do with such raw data?

As we can see these coordinates as absolute, we can then convert them into coordinates that are useful to an observer.

Through a list of trigonometry functions, time and referential conversions and many corrections due to how complex the motion of celestial bodies is, the barycentric coordinates can be converted into topocentric coordinates, also known as geodetic coordinates or even horizontal coordinates. From Ephem's data, it is possible to calculate the altitude and azimuth of a celestial object in the sky for a given time and place on Earth.

The coordinates produced by Ephem can be used to observe the sky with extreme precision.

While Ephem remains its own gem so that the community can access raw data, it will become a dependency of Astronoby to exploit its full potential. Having access to such precise and accurate data will open the door to all possible computations of celestial events with the greatest accuracy available to the public. This will enable Astronoby to truly become a scientific library.

Usage

Here is a common use case of the library:

# Download and store the SPICE binary kernel file
Ephem::IO::Download.call(name: "de421.bsp", target: "tmp/de421.bsp")

# Load the kernel
spk = Ephem::SPK.open("tmp/de421.bsp")

# Define the center and target bodies
center = 0 # Solar system barycenter
target = 5 # Jupiter

# Get the right segment
segment = spk[center, target]

# Get the position and velocity of the target body at a given time
# The time is expressed in Julian Date TDB
time = 2460676.5 # 2025-01-01 00:00 UTC
state = segment.compute_and_differentiate(time)

# Display the position and velocity vectors
puts "Position: #{state.position}"
# => Position: Vector[157123190.6507038, 684298787.8592143, 289489366.7262833]
# The position is expressed in km

puts "Velocity: #{state.velocity}"
# => Velocity: Vector[-1117315.1437825128, 254177.26336095092, 136149.03901534996]
# The velocity is expressed in km/day
Enter fullscreen mode Exit fullscreen mode

What if I want to use it right now?

If you want to use this data immediately and not wait for Astronoby to use it, or if you don't want to rely on Astronoby at all, I got you covered. You will find here a simple Ruby script that computes the position of Saturn on a specified date and time and displays the horizontal coordinates (altitude and azimuth) for an observer on Earth.

Please be aware the results will be approximate. Many tiny corrections should be added to the calculations to compute accurate coordinates. However, for amateur purposes, you will probably find the results accurate enough.

Conclusion

Access to astronomical data with this level of precision is a first time in the Ruby ecosystem. While Ephem is only v0.1, the main usage is covered and accurate data can already be used by the community.

It will help Astronoby reach its full potential and provide more and more features while ensuring accuracy and precision.

Check out the GitHub repository for more usage information and please spread the word so that we can improve the library from feedback.

tl;dr

  • Ephem v0.1 is out: https://rubygems.org/gems/ephem
  • Supports computing Solar System's planets Cartesian coordinates
  • Based on NASA JPL Development Ephemeris files
  • Accuracy from our point of view is estimated to be below 0.1 arcseconds
  • Will be used in Astronoby to compute geocentric coordinates
  • Such accuracy allows for computing any astronomical event and data with confidence

Credit cover picture: https://www.highpointscientific.com/astronomy-hub/post/astronomy-101/8-things-you-need-to-know-about-the-8-planets-in-our-solar-system
Credit JPL center: https://www.jpl.nasa.gov/annual-report/today-tomorrow/
Credit barycenter animation: https://en.wikipedia.org/wiki/Barycenter_(astronomy)
Credit Cartesian coordinates: https://fr.m.wikiversity.org/wiki/Fichier:3D_coordinate_system.svg

ruby Article's
30 articles in total
Favicon
Ruby on Rails 8 API not allowing mobile phone connection
Favicon
ruby -run
Favicon
ruby -run, again
Favicon
Ruby on Rails: Your Service Layer is a Lie
Favicon
Die Ruby-Seite von Puppet - Teil 2 - Benutzerdefinierte Funktionen
Favicon
The Ruby side of Puppet - Part 2 - Custom Functions
Favicon
Introducing Ephem
Favicon
What Is It (in Ruby 3.4)?
Favicon
Unable to find Ruby class that definitely exists
Favicon
Devise not accepting JSON Token
Favicon
Ruby on Rails - Calculating pricing based user's purchasing power parity
Favicon
Ruby on Rails 8 - Frontend Rรกpido Usando Tailwind como um Frameworks CSS Classless
Favicon
Use cases for Turbo's Custom Events
Favicon
Meta programming with Ruby Eval: A guide (Part 1)
Favicon
Tracing a method call in Ruby
Favicon
False positives of Lint/Void in assignments
Favicon
Die Ruby-Seite von Puppet - Teil 1 - Benutzerdefinierte Fakten
Favicon
Just committed to learning ruby for sonic pi and rails https://dev.to/highcenburg/2025-roadmap-mastering-ruby-for-sonic-pi-and-rails-696 wish me luck!
Favicon
Building a GitHub Activity CLI - A Ruby Journey
Favicon
I have been thinking of moving forward from Python to Ruby to align my skills with my musicality since I like to learn SonicPi.. But I'm still thinking about it so yeah
Favicon
Task Tracker CLI
Favicon
Rails 8 CRUD: Modern Development Guide 2025
Favicon
When Controllers Take on Too Much Responsibility
Favicon
Ruby on Rails 8 - Frontend Rรกpido com Frameworks CSS Classless ou Class-Light sem CDN
Favicon
Cdg Hoodie or Eric Emanuel Hoodie: The Trend You Need Now
Favicon
Brakeman LSP Support
Favicon
Docker in development: Episode 3
Favicon
Add Invite to Rails 8 Authentication
Favicon
How to Develop an Air Quality Monitoring App with Ruby on Rails
Favicon
School

Featured ones: