Fun with NASA's Open Data Portal

Getting started with an API example using NASA's Near Earth Object Web Service

Favorited Favorite 2

NASA Open Data

One of the most powerful tools available to tinkerers and prototypers is the Application Program Interface. An API is the structure by which two computer programs talk to each other – think of it as a traffic cop for information traveling between two applications.

In a workshop at SXSW EDU last year, I encountered NASA's open data platform. My mind was blown by the fact that a good percentage of NASA's projects reveal their data and code through an open API, and it's all fairly well supported and reasonably easy to get started with.

To begin, I navigated to the cover page for the Open Data Portal. From there I selected the data catalog; I'm pretty into the asteroid thing these days, so I used the Near Earth Object database.

Asteroids section of the NeoWs API

From here I clicked on the API button:

API access button

This brought me to the opening page for the NeoWs.

alt text

If you go to the Getting Started documents, it will ask you to sign up for a development key. You don't necessarily need one; you can browse the API catalog and pull out example URLs and use them at will without a key. I chose object 2018GG – there's a nifty visual of this house-sized space rock here.

After pulling out the URL for the data on 2018GG, I put together a simple Python script that I ran in Trinket.

import urllib.request
contents = urllib.request.urlopen("").read()

When I ran this, I actually got a return in the console matching all the data available for 2018GG:

data for object 2018GG

I called in the urllib library and used the request method. Next, I created a variable and stored the return coming from the URL connected to 2018GG. Finally, I printed out what's stored in the variable. That’s a lot of data for this simple call. We can simplify things by loading everything into a Json object using the code below.

import urllib.request
import json
contents = urllib.request.urlopen("").read()
varab = json.loads(contents)

This gave me a value and an object notation connected to the value, all comma-separated.

value and object notation

I wanted to find out what the key titles associated with each element of data are, so I wrote a short script that separates out and prints just the keys.

import urllib.request
import json
contents = urllib.request.urlopen("").read()
varab = json.loads(contents)

The printout now shows a whole list of the keys I can work with.

list of keys

Continuing to narrow things down, I picked out a single element from my list of keys and added some text to it and built a small, very specific printout. I separated out the element line I really wanted by a set of asterisks for readability.

import urllib.request
import json
contents = urllib.request.urlopen("").read()
varab = json.loads(contents)
print('*' * 79)
print(('object 3802394 is: ')+varab['close_approach_data'][0]['miss_distance']['miles']+(" miles away!!!"))
print('*' * 79)

smaller printout with isolated element

The fun part of all this is that not only can this be implemented in the Trinket environment like I've used here, but it's a great project for Python on the Raspberry Pi. Further steps might include a warning light or buzzer if an object got too close for comfort. This example would employ the GPIO pins on the Raspberry Pi and give a great overview of connected data through an API and physical computing. Many thanks to Cameron here at SFE for wisdom and help in getting this all going!

I hope you have fun with this and happy hacking.

Comments 7 comments

  • viliamklein / about 6 years ago / 2

    For more fun, check out NASA openMCT

    I'd be fun to see an AVC project use NASA mission control software to visualize performance!

    • Miskatonic / about 6 years ago / 1

      Oh man, this is great!!! I am digging into this, Thanks !!!

  • Member #1459709 / about 6 years ago / 1

    Thanks, this is awesome.

  • l0gikG8 / about 6 years ago / 1

    The link to above that's broken due to an extra space character probably didn't help out Clark either.

    <a href="">Trinket</a>

  • Member #134773 / about 6 years ago / 1

    Maybe I shouldn't read blog posts before I've even finished my first cup of coffee in the morning... it took me a bit to figure out that you weren't referring to the Adafruit Trinket...

Related Posts

Recent Posts


All Tags