A Python CLI tool that retrieves, analyzes, and visualizes Near-Earth Object (NEO) data using NASA's NeoWs API.
.. . . .. . .. .. .. . .. .
.-+:.... ... .. . .. . . .. .. .. .. . .
.. :*####++=:++: .... .. .. .... . .. . .. . ..
.=*####+++**+==+: .--:..:..
..-**#**+=######*=+=++===+=::::. ...
:-:+**##**#*+:::-++=----====-==-----.
. .. ... ==:==+==+=:.:++==:..:---:::---=:-. .. . .
.. . . .. ...:-=--==:.:+***+-.......:-*%#+=*+-+. .. ..
. .. ... .. . ..-:=-..:--+=-:. .=##*#%%#=+-::. .
.. . . .. . .. ..::=---.:-+++:.*##+# +%%#+%**--:. ..
. .. ... .. . .. . .-=++++-=-=\**--**#%%%##%%%+=#%*=#==.
.. . .. .. . .. ... :---+===++\**#%%%%%%%%%#***#*#%-=-...
. . .:-==-=-+##%%%%%%%%%%#*+=**=-
..:::-:-+\**#%%%%%%%%%%%%=+**+.
..:--:-#%%%%%%%%%#%%%#**
. .. ... .. . .. . .. .. ...:+*#%%%%###%%%%%%%
.. . .. .. . .. .. .. . .. .. =##*##%#%%#%=....
. . .. .. . . .. . . .. .. ... . .
NASA NEO Tracker is a command-line Python project that uses NASA's Near Earth Object Web Service (NeoWs) API to retrieve asteroid data for a selected date range.
The project started as a simple API-based asteroid tracker and evolved into a data-analysis and visualization project using Pandas and Matplotlib.
Version 3.0 โ Data Visualization with Matplotlib
- ๐ญ Search for Near-Earth Objects using a custom date range
- ๐ชจ Display asteroid names and estimated diameters
โ ๏ธ Identify potentially hazardous asteroids- ๐ Find the largest asteroid in the selected date range
- ๐ Find the smallest asteroid in the selected date range
- ๐ Find the closest asteroid based on miss distance
- ๐ Display the closest approach date
- ๐ Calculate average asteroid diameter
โ ๏ธ Calculate the percentage of potentially hazardous asteroids- ๐ Display the top 5 largest asteroids
- ๐ Group potentially hazardous asteroids by date
- ๐ข Sort asteroid data by estimated diameter
- โ Validate date formats and date ranges
- ๐ก๏ธ Handle API request errors
- ๐ป Simple command-line interface
- ๐ ASCII art splash screen
- โจ Improved CLI formatting and presentation
- ๐ Visualize the top 5 largest asteroids using a bar chart
- ๐ Generate graphical representations of asteroid data
- ๐ฅ๏ธ Access visualizations through the CLI menu
- Python
- NASA NeoWs API
- Requests
- Pandas
- Matplotlib
- python-dotenv
- Git & GitHub
Pandas is used to organize the API response into a DataFrame and perform operations such as filtering, sorting, grouping, and calculating statistics.
Matplotlib is used to visualize asteroid data through charts and graphs.
Before running the project, make sure you have:
- Python 3.x
- A NASA API key
- Internet connection
The required Python packages are listed in requirements.txt.
git clone https://github.com/TheCreatorJJ/Nasa-asteroid-tracker.gitcd Nasa-asteroid-trackerpip install -r requirements.txtThis project uses a NASA API key to access the NeoWs API.
Create a file named .env in the project folder:
NASA_API_KEY=your_nasa_api_key_hereYour project structure should look similar to:
Nasa-asteroid-tracker/
โ
โโโ main.py
โโโ art.py
โโโ README.md
โโโ requirements.txt
โโโ .gitignore
โโโ .env
Run the program with:
python main.pyThe program will display the NASA NEO Tracker menu:
======================================
NASA NEO TRACKER
Near-Earth Object (NEO) Data Analyzer
======================================
1. Search asteroids
2. Show top 5 Largest
3. Exit
Select option:
1
Enter a start date:
Enter the start date (YYYY-MM-DD):
Then enter an end date:
Enter the end date (YYYY-MM-DD):
Example:
Enter the start date (YYYY-MM-DD): 2026-01-01
Enter the end date (YYYY-MM-DD): 2026-01-07
The program retrieves Near-Earth Object data from NASA and analyzes the results using Pandas.
After searching for asteroid data, select:
2
The program displays a Matplotlib bar chart showing the top 5 largest asteroids from the searched date range.
โน๏ธ Asteroid data must be loaded using option 1 before the visualization can be displayed.
Version 2 introduced Pandas to make the project more than just an API data viewer.
The program currently performs analysis such as:
Finds the asteroid with the largest estimated maximum diameter.
Finds the asteroid with the smallest estimated maximum diameter.
Finds the asteroid with the smallest recorded miss distance.
Calculates the average estimated maximum diameter of the retrieved asteroids.
Counts the number of potentially hazardous asteroids and calculates their percentage of the total results.
Sorts the asteroid DataFrame by diameter and displays the five largest asteroids.
Groups potentially hazardous asteroids by their close-approach date.
Version 3.0 introduced Matplotlib for visualizing the analyzed asteroid data.
The current visualization allows the user to view the top 5 largest asteroids in a bar chart.
The chart displays:
- Asteroid names
- Estimated maximum diameter
- Formatted data labels
- Rotated x-axis labels for improved readability
The visualization feature is accessed through the CLI.
Users must first search for asteroid data before viewing the available visualization.
Example results from a previous search:
================================
ASTEROID SUMMARY
================================
Total Asteroids: 36
Potentially Hazardous: 7
Hazardous Percentage: 19.44%
Largest Asteroid: 418265 (2008 EA32)
Diameter: 2,992.54 meters
Smallest Asteroid: (2018 TV5)
Diameter: 7.48 meters
Closest Asteroid: (2014 AF16)
Miss Distance: 3,071,593.48 km
Approach Date: 2026-01-04
Average Diameter: 285.73 meters
================================
================================
TOP 5 LARGEST ASTEROIDS
================================
1. 418265 (2008 EA32) - 2,992.54 meters
2. 26663 (2000 XK47) - 1,412.67 meters
3. 620103 (2018 LC3) - 1,042.41 meters
4. (2018 LC3) - 1,032.86 meters
5. 367390 (2008 MB5) - 924.78 meters
================================
================================
HAZARDOUS BY DATE
================================
2026-01-01: 3
2026-01-02: 1
2026-01-04: 1
2026-01-05: 1
2026-01-07: 1
Note: The values above are example results. Results will vary depending on the selected date range and the data returned by NASA's API.
This project is part of my Python learning journey.
While building it, I practiced:
- Working with APIs
- Making HTTP requests with
requests - Using environment variables
- Working with JSON data
- Working with dictionaries and lists
- Using loops
- Using conditional statements
- Creating functions
- Working with dates using
datetime - Handling errors with
tryandexcept - Building a CLI application
- Creating Pandas DataFrames
- Filtering DataFrames
- Sorting DataFrame data
- Finding maximum and minimum values
- Calculating averages
- Grouping and counting data
- Iterating through DataFrame rows
- Formatting numerical output
- Creating data visualizations
- Using Matplotlib
- Creating bar charts
- Formatting chart labels
- Improving chart readability
- Using Git
- Using GitHub
- Managing project dependencies
Nasa-asteroid-tracker/
โ
โโโ main.py # Main application
โโโ art.py # ASCII art
โโโ README.md # Project documentation
โโโ requirements.txt # Python dependencies
โโโ .gitignore # Files excluded from Git
โโโ .env # Private NASA API key
.envis intentionally excluded from GitHub.
The first version focused on learning how to work with an external API.
- NASA NeoWs API integration
- Custom date-range search
- Basic asteroid information
- Hazardous asteroid identification
- Largest asteroid detection
- Closest asteroid detection
- Close-approach date
- Date validation
- API error handling
- Basic Command Line Interface
The second version expanded the project into a small data-analysis application.
- Added Pandas
- Added DataFrame-based analysis
- Added smallest asteroid detection
- Added average diameter calculation
- Added hazardous asteroid percentage
- Added top 5 largest asteroid ranking
- Added hazardous asteroids grouped by date
- Added sorting and filtering
- Improved numerical formatting
- Improved CLI layout
- Added ASCII art
- Improved project documentation
The third version introduced data visualization using Matplotlib.
- Added Matplotlib
- Added Top 5 largest asteroid bar chart
- Added formatted chart data labels
- Added rotated x-axis labels for readability
- Added visualization option to the CLI
- Added Matplotlib to project dependencies
- Improved graphical presentation of analyzed data
- Visualizes the top 5 largest asteroids
- Displays asteroid names and estimated diameters
Possible improvements for future versions:
- ๐ฅ๏ธ Add a Pandas-based CLI data viewer
- ๐ Allow users to select different visualization types
- ๐ Add histogram visualizations
- ๐ Add scatter plot visualizations
- ๐ Add line charts for asteroid activity by date
- ๐ Add an option to display all visualizations
- ๐ Add CSV export
- ๐ Add more detailed asteroid filtering
- ๐ Add additional statistics
- ๐ฅ๏ธ Further improve the CLI
- ๐ Eventually build a web-based dashboard
- ๐ Expand the project for NASA Space Apps Challenge
Asteroid data is provided by NASA's Near Earth Object Web Service (NeoWs) API.
NASA API:
This project was created as a hands-on Python learning project.
The goal is to gradually develop the project while learning new programming and data-analysis concepts rather than building everything at once.
V1 โ API Integration
V2 โ Pandas & Data Analysis
V3 โ Data Visualization with Matplotlib
V4 โ Data Exploration & Advanced CLI
Future โ More advanced data science
Created by TheCreatorJJ as a Python and Data Science learning project.
โญ If you find the project interesting, feel free to explore the code and follow its development.