How Open Source Developers Can Push the Universe’s Frontier

ODSC - Open Data Science
6 min readJun 5, 2023

Editor’s note: Dr.-Ing. Thomas Albin is a speaker for ODSC Europe this June 14th-15th. Be sure to check out his talk, “Space Science with Python — Enabling Citizen Scientists,” there!

2009, a paper by Postberg et al. was published in Nature. The title: Sodium Salts in E-Ring Ice Grains from an Ocean Below the Surface of Enceladus. Liquid water on a foreign world, revolving around Saturn! A short summary is provided by ESA: https://sci.esa.int/web/cassini-huygens/-/43954-sodium-salts-point-to-subsurface-ocean-on-enceladus

The work behind this significant scientific discovery is based on so-called in-situ data from the Cassini spacecraft. And to be more precise: from the instrument Cosmic Dust Analyzer (CDA). CDA was like a “dust telescope”, attached to the NASA probe the instrument detected hundred-thousands of impacts and determined tens of thousands of mass spectra: a chemical composition analysis that shows the abundance of elements of a single dust particle.

So … how did CDA help to derive this scientific insight? Well, the picture above, an artistic impression, gives us a hint: NASA sent the Cassini probe very close to the moon Enceladus; it flew directly through the icy geysers, emerging from the world’s surface, and caught several dust particles. The chemical analysis finally came to this conclusion.

Now the question is: how do you do that? And this question does not only apply to the Cassini mission. How did scientists create this iconic picture of a black hole? How do scientists discover a new asteroid or comet? How did engineers manage to land a probe on a comet?

Astronomy and space science appear so … far away (pun maybe intended). Yet so fascinating and intriguing, considering the cosmos’ vastness and beauty.

Thankfully, as enthusiastic coders, we have THE major astronomy and space science tool to work on all these data, theories, and insights: Python! There are several Astro-related packages like astropy, skyfield, astroML, healpy, poliastro, or SunPy. Some are expert tools, some are easier to approach and work with.

And that’s where Space Science with Python tries to fill an educational gap: to give everyone a chance to learn, work and apply space-related toolkits for this scientific domain.

Learning a new domain requires a first step. And also some more consecutive ones. To derive the scientific conclusion of a liquid ocean below a moon’s surface or to compute the image of a Black Hole … well … requires some first building blocks. So let’s start with a very first and basic computation: how far away is our home planet from the Sun?

Thankfully there is one commonly unknown (but expert-wise often used) toolkit from NASA, called SPICE. This is an almost ancient tool that enables one to compute very precisely the positions of planets, the trajectory of spacecraft, or the observation direction of a camera system mounted on a satellite orbiting Mars.

In fact, SPICE does not do everything from scratch, but requires some configuration and meta files called kernels. To conduct our computation we need 2 kernels:

  • NAIF0012.tls: A kernel that contains time information (the scope of this time topic would exceed probably an entire ODSC conference)
  • de432s.bsp: A kernel that contains positional information, pre-computed by an agency or, if you get more familiar with SPICE: by yourself!

Both kernels can be either downloaded from the NASA or ESA repository. I uploaded them to my tutorial repo for easier access. You can find them here:

Additionally, we need a (virtual) Python environment. And for starters we need to install only one single package: the unofficial wrapper for SPICE:

>>> !pip install spiceypy

So first, we need to import the library and let’s set a datetime at which we want to compute Earth’s position and distance as well as the velocity as seen from our home star:

# Import the SPICE module
import spiceypy
# Import datetime and get the current time stamp
import datetime
# get today's date
date_today = datetime.datetime.today()
# convert the datetime to a string, replacing the time with midnight
date_today = date_today.strftime('%Y-%m-%dT00:00:00')
print(f"Today's date (midnight): {date_today}")

Now you need to provide the directories to both downloaded kernel files. Please replace the placeholder DIR with your directory (relative or absolute):

# Load the spice kernels for leapseconds and for the planets
spiceypy.furnsh('DIR/naif0012.tls')
spiceypy.furnsh('DIR/de432s.bsp')

SPICE “knows” now some Solar System related information. To obtain positional data we need to set a datetime. Creating and editing datetimes in Python is mostly straightforward. The only thing that one needs to consider are different time zones.

In astronomy, this topic is … an entire domain for itself. For you to know: we need the so-called Ephemeris Time (ET):

# Compute the Ephemeris Time
et_today_midnight = spiceypy.utc2et(date_today)
print(f"The Ephemeris Time: {et_today_midnight}")

And now we can compute the so-called state vector of our home planet: a 6-dimensional vector with spatial coordinates in x, y, and z directions and the corresponding velocities! The values are given in km and km/s, respectively. We conduct this computation with the function spkgeo. The function’s input (in a “human readable way”): Compute the state vector of Earth (targ=399) as seen from the Sun (targ=10) at a certain time (et=et_today_midnight) considering a dedicated reference frame (ref=”ECLIPJ2000”).

This reference frame is a “standard” reference frame of our Solar System, where the Earth is almost floating on its x-y plane. Further, the numbers 10 and 399 may appear strange, but follow the NASA guideline as can be seen here: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/req/naif_ids.html#NAIF%20Object%20ID%20numbers.

Please note: sometimes you need particular kernels to compute different positions!

# Compute the state vector of the Earth w.r.t. the Sun
earth_state_wrt_sun, earth_sun_light_time = spiceypy.spkgeo(targ=399,
et=et_today_midnight,
ref='ECLIPJ2000',
obs=10)

So … what’s next? I would suggest exploring and understanding the state vector earth_state_wrt_sun that contains the x, y, z, and velocity values. What is the distance between Earth and Sun? Does it fit with the data you find e.g., on Wikipedia? What’s the velocity? And assuming that our home planet is revolving around the Sun in a perfect circle: What is the travel distance during a year?

earth_sun_light_time contains the time the light needs to travel from the Sun to Earth. Can you estimate the lightspeed using the distance and the time?

Back to Cassini: In a virtual workshop we will take a look at the already mentioned instrument “Cosmic Dust Analyzer” (CDA) onboard Cassini. In this very first ODSC talk on space science, we will see how such an instrument is calibrated, how Python and Machine Learning can help, and what one can derive for themselves and their experiments, instruments or devices. The workshop will give a scientific and engineering background as well as coding sessions to work on the data.

A Q’n’A session at the end will provide additional space to go “beyond” CDA, calibration tasks, and so on. We will have a discussion on how the Open Source community can support astronomers and space scientists in creating next-generation Machine Learning and Data Science tools.

_________

Social Media Links:

YouTube: https://www.youtube.com/c/Astroniz

GitHub: https://github.com/ThomasAlbin/Astroniz-YT-Tutorials

Twitter: https://twitter.com/MrAstroThomas

Mastodon: https://astrodon.social/@ThomasAlbin

LinkedIn: https://www.linkedin.com/in/dr-ing-thomas-albin/

About the author/ODSC Europe speaker:

Thomas is a Senior Machine Learning engineer, working in the automotive industry since 2019. Before joining the Research & Development department of a large manufacturer he was conducting research activities in space science. In parallel to his studies in Astro- and Geo-Physics and later PhD program, he participated in 2 major missions: ESA’s comet mission Rosetta/Philae and NASA’s & ESA’s Saturn spacecraft Cassini/Huygens; always with a special focus on cosmic dust. Additionally, he applies Machine Learning algorithms to analyze astronomy- and space-related data to derive new scientific insights or to create new methods for calibrating instruments. Besides his industry work, Thomas is a guest scientist at the Free University of Berlin, where he continues working on Cassini-related datasets using Deep Learning. On his active YouTube channel Astroniz he shares his Python + Space Science + Machine Learning knowledge with a small community.

Originally posted on OpenDataScience.com

Read more data science articles on OpenDataScience.com, including tutorials and guides from beginner to advanced levels! Subscribe to our weekly newsletter here and receive the latest news every Thursday. You can also get data science training on-demand wherever you are with our Ai+ Training platform. Subscribe to our fast-growing Medium Publication too, the ODSC Journal, and inquire about becoming a writer.

--

--

ODSC - Open Data Science

Our passion is bringing thousands of the best and brightest data scientists together under one roof for an incredible learning and networking experience.