Track live position of International Space Station and people in space — using Python

Nabarun Chakraborti
4 min readFeb 15, 2021

This is a very basic but powerful python program to track the live position of ISS. My son used to run it in every 30–40 mins interval to see it’s position :-)

Prerequisites: python , IDE, install few packages — pandas, plotly, google.

Reference: We are going to use the existing API to get the location and other information in our code. Can refer to the below link incase you are curious:

http://open-notify.org/Open-Notify-API/ISS-Location-Now/

Here, you will find below file which is registering the latitude and longitude of ISS.

http://api.open-notify.org/iss-now.json

## Content of the above JSON file :

{"iss_position": {"longitude": "-41.8150", "latitude": "30.4643"}, "message": "success", "timestamp": 1613412345}

The other file contains the info of the people currently available in space station.

http://api.open-notify.org/astros.json

We are going to read these 2 files and display the content using python — as simple.

Program: It has 2 parts — i) position of ISS and ii) people in space.

Let’s describe the code step by step and then will keep the complete code for execution.

  1. First we are going to read the ISS location JSON file:
ISSurl = 'http://api.open-notify.org/iss-now.json'

ISS_Loc_DF = pd.read_json(ISSurl)
print("Basic info of ISS : ")
print(ISS_Loc_DF)

O/P:

Basic info of ISS : 
iss_position message timestamp
latitude -2.5352 success 2021-02-15 18:16:59
longitude -14.8967 success 2021-02-15 18:16:59

2) Create the latitude and longitude columns and drop unwanted columns.

# get the live latitude and longitude of ISS
ISS_Loc_DF['latitude'] = ISS_Loc_DF.loc['latitude', 'iss_position']
ISS_Loc_DF['longitude'] = ISS_Loc_DF.loc['longitude', 'iss_position']
ISS_Loc_DF.reset_index(inplace=True)

# drop unwanted columns
ISS_Loc_DF = ISS_Loc_DF.drop(['index','message'], axis=1)
print("Final position dataframe to refer : ")
print(ISS_Loc_DF)

O/P:

Final position dataframe to refer : 
iss_position timestamp latitude longitude
0 -2.5352 2021-02-15 18:16:59 -2.5352 -14.8967
1 -14.8967 2021-02-15 18:16:59 -2.5352 -14.8967

3) Show the position of the ISS in world map

# Show the position of the ISS in global map
iss_position = pe.scatter_geo(ISS_Loc_DF, lat='latitude', lon='longitude')
iss_position.show()

O/P:

Note: ISS speed is approx. 17,100 mph. So, refresh after 2–3 mins to see the movement.

4) Now Read the name of people currently available in space -

## Find the Number of people in space right now:
peopleurl = 'http://api.open-notify.org/astros.json'
People_DF = pd.read_json(peopleurl)
print(People_DF)

O/P:

message  number                                            people
0 success 7 {'craft': 'ISS', 'name': 'Sergey Ryzhikov'}
1 success 7 {'craft': 'ISS', 'name': 'Kate Rubins'}
2 success 7 {'craft': 'ISS', 'name': 'Sergey Kud-Sverchkov'}
3 success 7 {'craft': 'ISS', 'name': 'Mike Hopkins'}
4 success 7 {'craft': 'ISS', 'name': 'Victor Glover'}
5 success 7 {'craft': 'ISS', 'name': 'Shannon Walker'}
6 success 7 {'craft': 'ISS', 'name': 'Soichi Noguchi'}

5) Print their name:

print("People who are available in space now : ")
for index, row in People_DF.iterrows():
name = People_DF['people'].values[index]['name']
print(name)

O/P:

People who are available in space now : 
Sergey Ryzhikov
Kate Rubins
Sergey Kud-Sverchkov
Mike Hopkins
Victor Glover
Shannon Walker
Soichi Noguchi

6) Get some info about them

print("Let's check who are they : ")
for index, row in People_DF.iterrows():
name = People_DF['people'].values[index]['name']
print(name)
query = name+' iss'
for i in search(query, tld="co.in", num=4, stop=4, pause=2):
print(i)

O/P:

Let's check who are they : 
Sergey Ryzhikov
https://en.wikipedia.org/wiki/Sergey_Ryzhikov_(cosmonaut)
https://en.wikipedia.org/wiki/Sergey_Ryzhikov_(cosmonaut)#Cosmonaut_career
https://en.wikipedia.org/wiki/Sergey_Ryzhikov_(cosmonaut)#Expedition_49/50
https://www.nasa.gov/image-feature/expedition-64-commander-sergey-ryzhikov-of-roscosmos
Kate Rubins
http://t0.gstatic.com/images?q=tbn:ANd9GcTFLk1C2z0Tr-8CF9HPl3S2AKG1GjMPdC8rSFBxvTQGpLYMdtPurLXdEmTPkape
https://en.wikipedia.org/wiki/Kathleen_Rubins
https://en.wikipedia.org/wiki/Jeffrey_Williams_(astronaut)
https://en.wikipedia.org/wiki/Soyuz_MS-01
Sergey Kud-Sverchkov
https://en.wikipedia.org/wiki/Sergey_Kud-Sverchkov
http://t0.gstatic.com/images?q=tbn:ANd9GcQzRyC8GCNyvfiFy8jlWO-ifVywdEgvMJT2yICzYaK6PED2oZ2OcPyNpv-ZfX_d
https://www.nasa.gov/image-feature/cosmonauts-sergey-ryzhikov-and-sergey-kud-sverchkov

You can increase or decrease your search link as per your wish.

Complete code:

import pandas as pd
import plotly.express as pe
from googlesearch import search

# refer http://open-notify.org/Open-Notify-API/ISS-Location-Now/ link for more details:
ISSurl = 'http://api.open-notify.org/iss-now.json'

ISS_Loc_DF = pd.read_json(ISSurl)
print("Basic info of ISS : ")
print(ISS_Loc_DF)

# get the live latitude and longitude of ISS
ISS_Loc_DF['latitude'] = ISS_Loc_DF.loc['latitude', 'iss_position']
ISS_Loc_DF['longitude'] = ISS_Loc_DF.loc['longitude', 'iss_position']
ISS_Loc_DF.reset_index(inplace=True)
# drop unwanted columns
ISS_Loc_DF = ISS_Loc_DF.drop(['index','message'], axis=1)
print("Final position dataframe to refer : ")
print(ISS_Loc_DF)

# Show the position of the ISS in global map
iss_position = pe.scatter_geo(ISS_Loc_DF, lat='latitude', lon='longitude')
iss_position.show()

## Find the Number of people in space right now:
peopleurl = 'http://api.open-notify.org/astros.json'
People_DF = pd.read_json(peopleurl)
print(People_DF)


print("People who are available in space now : ")
for index, row in People_DF.iterrows():
name = People_DF['people'].values[index]['name']
print(name)

print("Let's check who are they : ")
for index, row in People_DF.iterrows():
name = People_DF['people'].values[index]['name']
print(name)
query = name+' iss'
for i in search(query, tld="co.in", num=4, stop=4, pause=2):
print(i)

Happy Learning !!

--

--