How to Track and Map the International Space Station with Python - It's All in a Rest API Call
Introduction
Let's keep exploring interesting and socially impactful data sets. But instead of looking down, let's turn our gaze upwards towards the sky! Welcome to 5 Minutes for data science.
Code
from IPython.display import Image
Image(filename='viralml-iss-tracking.png', width='60%')
Space Station Mapping¶
Let's keep exploring insteresting and socially impactful data sets. But instead of looking down, let's look up! If you have young ones, this may be of interest to them and may work as an interesting bridge to leure young ones, if you have kids, to the power of python using the magic of space. It is certainly fascinating to me and to my friends. But, am still working on it with my own kids and I'll keep trying...
It's actually really easy to get the position of the International Space Station, it is available through a REST API call, that simple - and that API yields even more than just that i.
International Space Station Current Location¶
http://open-notify.org/Open-Notify-API/ISS-Location-Now/
The ISS programme is a joint project between five participating space agencies: NASA (United States), Roscosmos (Russia), JAXA (Japan), ESA (Europe), and CSA (Canada). The ownership and use of the space station is established by intergovernmental treaties and agreements.
The ISS serves as a microgravity and space environment research laboratory in which crew members conduct experiments in biology, physics, astronomy, and other fields.
This is all from Wikipedia.
Interesting facts
- It was lauched over 2 decadeas on November 20th, 1998
- It will operate up to 2030
- It has two bathrooms, a gymnasium and a 360-degree bay window - wouldn't we all love to take a peek!
- it orbits 15.5 perday... It flies at 4.791 miles per second. That's fast enough to go to the Moon and back in about a day.
- Some 230 people have visited it,
Welcome to the ViralML show and 5 mintues for data sceince.
- it has a capactity for 6 people on board... they have to exercise some two hours a day to keep their muscles from atrophiating, oh and who are they?
GO TO: http://open-notify.org/¶
### Who is in space right now?
import requests
r = requests.get(url='http://api.open-notify.org/astros.json')
r.json()
import pandas as pd
# http://www.satsig.net/lat_long.htm
Image(filename='satsig_explanation.png', width='60%')
# take a lat lon and return a pixel coordinate
# http://www.satsig.net/lat_long.htm
def translate_geo_to_pixels(longitude, latitude, max_x_px, max_y_px):
# y = -90 to 90
# x = -180 to 180
scale_x = (((longitude + 180) / 360) * max_x_px)
scale_y = (((latitude - 90) / 180) * max_y_px)
return scale_x, scale_y
translate_geo_to_pixels(20,90, 500, 250)
# get international space station geo location
# http://open-notify.org/Open-Notify-API/ISS-Location-Now/
def get_space_station_location():
r = requests.get(url='http://api.open-notify.org/iss-now.json')
space_station_location = (r.json())
space_station_longitude = float(space_station_location['iss_position']['longitude'])
print('space_station_longitude', space_station_longitude)
space_station_latitude = float(space_station_location['iss_position']['latitude'])
print('space_station_latitude', space_station_latitude)
return (space_station_longitude, space_station_latitude)
# you will need to pip install Basemap - https://matplotlib.org/basemap/users/installing.html
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
get_space_station_location()
# Set the dimension of the figure
plt.figure(figsize=(16, 8))
# Make the background map
m=Basemap(llcrnrlon=-180, llcrnrlat=-65,urcrnrlon=180,urcrnrlat=80)
m.drawmapboundary(fill_color='#A6CAE0', linewidth=0)
m.fillcontinents(color='grey', alpha=0.3)
m.drawcoastlines(linewidth=0.1, color="white")
# Add a point per position
space_station_longitude, space_station_latitude = get_space_station_location()
m.scatter(space_station_longitude, space_station_latitude, s=200, alpha=0.4,color='blue')
plt.title('Internation Space Station Location' , fontsize=30)
# Let's Build
# ISS Icom: https://icons-for-free.com/color-space+station-131994932307187327/
# http://www.satsig.net/lat_long.htm
print(space_station_longitude, space_station_latitude)
# figure out translation of space_station_longitude/space_station_latitude to screen pixels
# imagine 0,0 to 300,100
translate_geo_to_pixels(space_station_longitude, space_station_latitude, 300, 100)
Show Notes
(pardon typos and formatting -these are the notes I use to make the videos)
Let's keep exploring interesting and socially impactful data sets. But instead of looking down, let's turn our gaze upwards towards the sky! Welcome to 5 Minutes for data science.