Welcome to this practice where, through Python programming and contextualizing this learning in the International Space Station (ISS), we will carry out a simple practice, carried out step by step for our students.

The first thing we will do is contextualize the activity in the subject that we are going to deal with, so ...

Let's get to know the ISS

  • The International Space Station is a large spacecraft in orbit around the Earth. It serves as a home where crews of astronauts and cosmonauts live.
  • The space station is also a unique scientific laboratory. Several nations worked together to build and use the space station. The space station is made of parts assembled in space by astronauts.
  • It orbits the Earth at an average altitude of about 250 miles. It travels at 17.500 mph. This means that it orbits the Earth every 90 minutes.
  • NASA is using the space station to learn more about life and work in space. These lessons will allow us to send humans into space farther than ever.

The first piece of the International Space Station was launched in November 1998. A Russian rocket launched the Russian control module Zarya (Tsar EE uh). About two weeks later, the space shuttle Endeavor encountered Zarya in orbit. The space shuttle was carrying the United States Unit node. The crew attached the Unity node to Zarya.

The space station has the volume of a five-room house or two Boeing 747 aircraft. It is capable of supporting a crew of six, plus visitors. On Earth, the space station would weigh almost a million pounds. Measured from the edges of its solar panels, the station covers the area of ​​a soccer field. Includes laboratory modules from the United States, Russia, Japan, and Europe.

The goal of our practice

The objective is to study some aspects of the international station in real time using programming and consulting external tools.

What we will do is contextualize this practice in the field of space or directly on the ISS (International station), for this we can use the information previously provided in this document. Once our students know the context of the practice, we must mark the objective that we can achieve using Python programming.

The objectives will be 3:

  • We can locate exactly where the ISS is at all times.
  • We will be able to know how many astronauts are on board the ISS and their names
  • We will be able to know when exactly you will pass through a place that we mark for you.

To achieve this objective we will use the web http://www.open-notify.org which has a API where we can obtain this data. If the students do not know what a API we can explain it here https://www.xataka.com/basics/api-que-sirve This API will return the response data in a format called JSON. What is JSON?, https://www.json.org/json-es.html We can handle this JSON format perfectly with Python as we will show later.

The code of practice (full code at the end of the article)

The first thing we must do is import the necessary libraries to perform the exercise

  • urllib.request : to capture data from a web
  • json : necessary to process the data we receive, which in this case comes in json format
  • folium : is a Python library for drawing maps.

In 2]:

import urllib.request as url
import json
import folium

Exact location of the ISS

  • Using url.Request we call the Web to get the coordinates of the ISS at this time. We will do this with the first two lines
  • Then we read the data in JSON format using the command json.loads
  • We print the data to verify it
ISS = url.Request ("http://api.open-notify.org/iss-now.json") response_ISS = url.urlopen (ISS) ISS_obj = json.loads (response_ISS.read ()) print (ISS_obj [ 'iss_position'] ['latitude']) print (ISS_obj ['iss_position'] ['longitude'])
1599500006 48.3707 166.3623

Map

To draw our map with the coordinates obtained in the previous code, we will use the library folium. First we will save the latitude and longitude data in two variables called lat and longIn [4]:

long = ISS_obj ['iss_position'] ['longitude'] lat = ISS_obj ['iss_position'] ['latitude']

We draw the map using the previous variables (lat and long) and we use the following properties:

  • zoom_starter : Zoom level to load the map preview
  • tiles : Type of map, in this case «Satellite View»
  • Icon : We give a color to the icon that will mark the position of the ISS
  • Marker : We put the icon right in that position and we put the label (tooltip) of ISS
m = folium.Map (location = [lat, long], zoom_start = 2, tiles = 'Stamen Terrain') icon = folium.Icon (color = "red") folium.Marker ([lat, long], tooltip = " ISS ", icon = icon) .add_to (m) m

The astronauts

In this second part of the practice we will use the API to know the number of astronauts aboard the ISS and their names

  • Using url.Request we call the web to get the number of astronauts and their names from the ISS at this time. We will do this with the first two lines
  • Then we read the data in JSON format using the command json.loads
  • We print the number of astronauts
astros = url.Request ("http://api.open-notify.org/astros.json") response_astros = url.urlopen (astros) astros_obj = json.loads (response_astros.read ()) print (astros_obj ['number '])
3

Now we proceed to draw the names of the astronauts. These names are in the format List what is the variable people for that reason we use the command json.dumps We use the following properties:

  • indent : We put 3 so that it marks a space of 3 in the indentation of the margin
  • sort_keys : For your order
  • separators : The separation characters that we will use between the variable and the data
astros_name = json.dumps (astros_obj, indent = 3, sort_keys =True, separators = (".", "=")) print (astros_name)
{"message" = "success". "number" = 3. "people" = [{"craft" = "ISS". "name" = "Chris Cassidy"}. {"craft" = "ISS". "name" = "Anatoly Ivanishin"}. {"craft" = "ISS". "name" = "Ivan Vagner"}]}

Show astronaut names using a loop

For this we use a FOR loop that will allow us to extract the data from that List of json and print them one by one. In the last line of the loop we introduce the data in a Python array to be able to use it if necessary (it is not the case of this activity) In [9]:

astros_list = []
for count, item in enumerate (astros_obj, start = 0): print (astros_obj ['people'] [count] ['name']) astros_list.append (astros_obj ['people'] [count] ['name'])
Chris Cassidy Anatoly Ivanishin Ivan Vagner

ISS Pitch Prediction

In this last point of the practice what we will do is provide a place on earth through the coordinates and see at what time or date the ISS will pass near that point.

We load the libraries that we need to manage time and dates

from datetime import datetime, timezone

We use three variables to send them to our API, since in this last part of the practice, our query to the API needs values ​​to calculate the response. In this case the entered values ​​are:

  • Latitude and longitude : From the place where we want to make the prediction of the passage of the ISS
  • n : Number of times we want you to tell us when passing through that place
# Latitude and Longitude of the City of Madrid (used as an example)
latitude = 40.4 longitude = -3.7 n = 5 # number of times the ISS will pass
  • Using url.Request we call the Web to get the response from the ISS step. We will do this with the first two lines
  • It is important to note that within the Web request we introduce the three previously mentioned variables (latitude, longitude and n)
  • Then we read the data in JSON format using the command json.loads
  • We print all the data, we really get the answer from the variable response
Pass = url.Request ('http://api.open-notify.org/iss-pass.json?lat={}& lon ={}& n ={}'.format (latitude, longitude, n)) response_Pass = url.urlopen (Pass) Pass_obj = json.loads (response_Pass.read ()) print (Pass_obj)
{'message': 'success', 'request': {'altitude': 100, 'datetime': 1599500116, 'latitude': 40.4, 'longitude': -3.7, 'passes': 5}, 'response': [{'duration': 431, 'risetime': 1599515475}, {'duration': 649, 'risetime': 1599521134}, {'duration': 614, 'risetime': 1599526972}, {'duration': 553, 'risetime': 1599532868}, {'duration': 597, 'risetime': 1599538715}]}

Finally we use a FOR loop to use the same structure with which we have obtained the names of the astronauts.

In the last line, we print the data converting them into real dates, since the API returns the date as risetimeIn 13]:

pass_list = []
for count, item in enumerate (Pass_obj ["response"], start = 0): pass_list.append (Pass_obj ['response'] [count] ['risetime']) print (datetime.fromtimestamp (pass_list [count]). strftime ('%d-% m-% Y% H:% M:% S '))
07-09-2020 23:51:15
08-09-2020 01:25:34
08-09-2020 03:02:52
08-09-2020 04:41:08
08-09-2020 06:18:35