Get the "Applied Data Science Edge"!

The ViralML School

Fundamental Market Analysis with Python - Find Your Own Answers On What Is Going on in the Financial Markets

Web Work

Python Web Work - Prototyping Guide for Maker

Use HTML5 Templates, Serve Dynamic Content, Build Machine Learning Web Apps, Grow Audiences & Conquer the World!

Hot off the Press!

The Little Book of Fundamental Market Indicators

My New Book: "The Little Book of Fundamental Analysis: Hands-On Market Analysis with Python" is Out!

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.



If you liked it, please share it:

Code

ViralML-Space-Station-Mapping
In [1]:
from IPython.display import Image
Image(filename='viralml-iss-tracking.png', width='60%')
Out[1]:

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/

In [2]:
### Who is in space right now?

import requests
r = requests.get(url='http://api.open-notify.org/astros.json')
r.json()
    
Out[2]:
{'people': [{'name': 'Christina Koch', 'craft': 'ISS'},
  {'name': 'Alexander Skvortsov', 'craft': 'ISS'},
  {'name': 'Luca Parmitano', 'craft': 'ISS'},
  {'name': 'Andrew Morgan', 'craft': 'ISS'},
  {'name': 'Oleg Skripochka', 'craft': 'ISS'},
  {'name': 'Jessica Meir', 'craft': 'ISS'}],
 'number': 6,
 'message': 'success'}
In [3]:
import pandas as pd
In [4]:
# http://www.satsig.net/lat_long.htm
Image(filename='satsig_explanation.png', width='60%')
Out[4]:
In [ ]:
# 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)
In [5]:
# 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)

 
In [6]:
# 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
In [8]:
get_space_station_location()
space_station_longitude -74.8149
space_station_latitude 25.7436
Out[8]:
(-74.8149, 25.7436)
In [14]:
# 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) 
space_station_longitude -65.9858
space_station_latitude 15.5454
Out[14]:
Text(0.5, 1.0, 'Internation Space Station Location')
In [ ]:
# Let's Build
# ISS Icom: https://icons-for-free.com/color-space+station-131994932307187327/
# http://www.satsig.net/lat_long.htm 
In [ ]:
print(space_station_longitude, space_station_latitude)
In [ ]:
# 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.