![Python Tutorial](https://www.tutorialspoint.com/python/images/python-mini.jpg)
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How To Track ISS (International Space Station) Using Python?
Exploring the whereabouts of the International Space Station (ISS) and witnessing its real−time movements can be an exhilarating experience. The following article aims to showcase how Python can be utilized to track the ISS, utilizing the ISS API provided by Open Notify and visualizing its location on an interactive world map with the aid of the `folium` library.
Installing the Required Libraries
Before we embark on our ISS tracking journey, it is necessary to install a couple of libraries: `requests`, which facilitates API calls, and `folium`, which empowers the creation of captivating interactive maps.
pip install requests folium
Retrieving ISS Location Data
To retrieve the current location of the ISS, we shall employ the ISS API provided by Open Notify. This API furnishes us with latitude and longitude coordinates representing the ISS's position.
import requests def acquire_iss_location(): response = requests.get("http://api.open-notify.org/iss-now.json") data = response.json() latitude = float(data["iss_position"]["latitude"]) longitude = float(data["iss_position"]["longitude"]) return latitude, longitude iss_latitude, iss_longitude = acquire_iss_location() print(f"ISS's present location: Latitude: {iss_latitude}, Longitude: {iss_longitude}")
Output
ISS's present location: Latitude: 47.3335, Longitude: 49.9148
Within this code snippet, a function named `acquire_iss_location()` is defined. This function sends a GET request to Open Notify's ISS API and subsequently parses the received JSON response, extracting the latitude and longitude coordinates of the ISS. Finally, we print the current location of the ISS.
Visualizing ISS Location on an Interactive Map
To visualize the ISS's location on an interactive map, we will make use of the `folium` library. This library empowers us to create captivating world maps and plot the ISS's current position upon it.
import folium def generate_iss_map(latitude, longitude): iss_map = folium.Map(location=[latitude, longitude], zoom_start=2) folium.Marker([latitude, longitude], tooltip="ISS Location", popup="International Space Station", icon=folium.Icon(color="red", icon="info-sign")).add_to(iss_map) return iss_map iss_map = generate_iss_map(iss_latitude, iss_longitude) iss_map.save("iss_location.html")
Inside this code scrap, we characterize the work `generate_iss_map()`. This work acknowledges the scope and longitude arrangements of the ISS as inputs and continues to form an intelligent world outline, centered around the ISS's area. We incorporate a marker onto the map, accompanied by a tooltip and a popup that provide information about the ISS. Finally, we save the map as an HTML file named `iss_location.html`.
To observe the ISS's location on the map, simply open the `iss_location.html` file in your preferred web browser.
Bonus: Automating ISS Tracking
For real−time ISS tracking, we can devise a simple loop that fetches the ISS location data at regular intervals and subsequently updates the map accordingly.
import time while True: iss_latitude, iss_longitude = acquire_iss_location() print(f"ISS's present location: Latitude: {iss_latitude}, Longitude: {iss_longitude}") iss_map = generate_iss_map(iss_latitude, iss_longitude) iss_map.save("iss_location.html") time.sleep(60)
In this specific illustration, we utilize a `while` loop to ceaselessly recover the ISS's area information each 60 seconds, guaranteeing that the outline remains up to date. In any case, it is fundamental to work out caution when running this loop inconclusively, because it may expend a considerable sum of system resources. It is recommended to implement a stopping condition or a user interrupt mechanism.
The output displayed in the terminal will showcase the ISS's current location in latitude and longitude format:
ISS's present location: Latitude: -51.4142, Longitude: -179.8206
![](https://www.tutorialspoint.com/assets/questions/media/594839-1688969816.png)
Kindly note that the actual latitude and longitude values will differ depending on the ISS's real−time location at the moment the script is executed.
Conclusion
In conclusion, this article has provided a comprehensive demonstration of how Python can be harnessed to track the International Space Station. By leveraging Open Notify's ISS API and the versatile `folium` library, we were able to retrieve the ISS's location data in the form of latitude and longitude coordinates and effectively visualize its position on an interactive world map. Engaging in such a project not only enhances our understanding of the ISS and its movements but also serves as an opportunity to sharpen our Python programming skills while working with APIs and interactive maps.
- Related Articles
- What is the International Space Station?
- How to add Track-bar in OpenCV using C++?
- How to track the color in OpenCV using C++?
- How to track the eye in OpenCV using C++?
- How to add space before and after specific character using regex in Python?
- How to match tab and newline but not space using Python regular expression?
- How to match anything except space and new line using Python regular expression?
- Program to find most visited sector in a circular track using Python
- How to track the order of insertion using Java collections?
- How to check total space and available space in Linux using the terminal?
- How can RGB color space be converted to a different color space in Python?
- How to track the position of the face in OpenCV using C++?
- How to track the face in real-time in OpenCV using C++?
- Python Pandas – How to skip initial space from a DataFrame
- How to match a white space equivalent using Java RegEx?
![Tutorials Point](https://www.tutorialspoint.com/articles/images/tp-print-page-logo.png)