Messing about with serious software
In which we discuss setting up some spaceflight software from NASA inside a tiny webserver, inside an AWS lambda, and with Rust.
There is no reason you’d ever want to do this, but I was stuck at home sick and needed to scratch an itch: How does one know if the sun is shining on any particular part of the moon right now?
The solution is very complicated, actually.
- Is the spot occluded by, e.g., being in a crater?
- How high above the surface are you? Are you right on the surface?
- Technically the sun goes out of line of sight about 8 minutes before the light stops hitting the spot - do we take that into account?
- Does the atmosphere bend the light of the sun? Making it visible when it isn’t strictly in line of sight?
- What does “now” mean? Does it mean that when we look at this spot the light is not hitting it (e.g., the reflection of sunlight from that spot is no longer reaching our eyes).
- How do we know where the moon is relative to the sun precisely?
- Doesn’t the moon wobble?
- Suppose I wanted to plan the arrival of a spacecraft that will do distributed sensing, so now I need to know all this for future dates!
You can imagine that someone wanting to point a telescope at a spot on Mars would want to do similar calculations, lest they take a picture of a shadow-obscured region, or worse, something in darkness 1.

Lunar terminator (creative commons)
One of the things I most appreciated about working at JPL was being surrounded by smart people who could think of all these details and solve them. So, I was exposed to NAIF SPICE system. SPICE is a C library for calculating observer geometry.
Putting this up into a webservice involved the following steps:
- Figuring out if SPICE could solve this problem
- Downloading and building the software
- Finding and configuring the kernels (~180MB of them!)
- Using Rust FFI to interact with the right SPICE apis
- Configuring an API Gateway, Lambda, and domain name
- Wrapping the rust code in Axum, and deploying
I’m definitely going to write about each of those steps … right after I get some sleep
-
Actually, taking images of the terminator can yield some interesting science opportunities, so now we really want to know where the sun is! ↩︎
Comments
I have not configured comments for this site yet as there doesn't seem to be any good, free solutions. Please feel free to email, or reach out on social media if you have any thoughts or questions. I'd love to hear from you!