In this example, we will go through one possible use of the
nasapy library by extracting a decade of fireball data from the NASA API and visualizing it on a map.
A fireball, as defined by the Center for Near Earth Object Studies (CNEOS), is:
A fireball is an unusually bright meteor that reaches a visual magnitude of -3 or brighter when seen at the observer’s zenith. Objects causing fireball events can exceed one meter in size. Fireballs that explode in the atmosphere are technically referred to as bolides, although the terms fireballs and bolides are often used interchangeably.
During the atmospheric entry phase, an impacting object is both slowed and heated by atmospheric friction. In front of it, a bow shock develops where atmospheric gases are compressed and heated. Some of this energy is radiated to the object causing it to ablate, and in most cases, to break apart. Fragmentation increases the amount of atmosphere intercepted, and so enhances ablation and atmospheric braking. The object catastrophically disrupts when the force from the unequal pressures on the front and back sides exceeds its tensile strength.
Before getting started, import the needed packages that we will be using. The data analysis library pandas will be used to wrangle the data, while folium and seaborn are used for plotting the data. The magic command
%matplotlib inline is loaded to display the generated plots.
import nasapy import pandas as pd import numpy as np import folium from folium.plugins import HeatMap import matplotlib.pyplot as plt import seaborn as sns %matplotlib inline
nasapy library, we can extract the last 10 years of fireball data as a pandas
DataFrame by calling the
fireballs function. The
fireballs method does not require authentication to the NASA API, so we can go straight to getting the data.
fb = nasapy.fireballs(date_min='2010-01-01', date_max='2019-12-31', return_df=True)
Before plotting the data, we will do a few cleanup and pre-processing steps to get the data ready. The first step is to remove any duplicate records from the results using the
dropna method. Afterward, we will convert the necessary data points to a
float data type to ensure the data is of a sufficient type to plot. This conversion can be accomplished by using the
fb.dropna(inplace=True) fb['lat'] = fb['lat'].astype(float) fb['lon'] = fb['lon'].astype(float) fb['energy'] = fb['energy'].astype(float)
impact-e are specified in Joules, which is a unit of energy defined as kilograms times velocity squared,
kg * (m/s)^2.
We are now ready to plot the data! The
folium map that will be displayed is initialized using the
Map object, and then for each data point in the extracted and processed data from earlier, we add a point to the map with the data we are interested in displaying.
m = folium.Map(zoom_start=4) for i in range(0, len(fb)): folium.Circle( location=[fb.iloc[i]['lat'], fb.iloc[i]['lon']], tooltip=['Date: ' + fb.iloc[i]['date'], '\nLat/Lon: ' + str(fb.iloc[i]['lat']) + ', ' + str(fb.iloc[i]['lon'])], radius=fb.iloc[i]['energy'] * 10, color='red', fill=True, fill_color='red' ).add_to(m) m
Interestingly, it seems two fireball events are much larger than the others. Let's investigate further by plotting the energy values of the fireballs using the
seaborn library. First, we will extract the date from the
datetime column in the data and sort the data ascending by energy value to prepare it for plotting.
fb['datetime'] = fb['date'] fb['date'] = fb['datetime'].apply(lambda x: x.split(' ')) fb.sort_values('energy', ascending=False, inplace=True)
With the data prepped accordingly, we can use the seaborn
barplot function to plot the fireball energy values by date.
plt.figure(figsize=(16, 6)) p = sns.barplot(x='date', y='energy', data=fb[0:20]) p = p.set_xticklabels(fb['date'], rotation=45, ha='right')
As we suspected, two fireballs had much higher energy values than others! The highest energy value is almost two times as much as the next fireball, which itself is many times more powerful than the next. To get a better representation of the overall data, let's cut these points out and plot the points on a map again.
fb2 = fb[fb['energy'] < 5000] m = folium.Map(zoom_start=0.1) for i in range(0, len(fb2)): folium.Circle( location=[fb2.iloc[i]['lat'], fb2.iloc[i]['lon']], tooltip=['Date: ' + fb2.iloc[i]['date'], '\nLat/Lon: ' + str(fb2.iloc[i]['lat']) + ', ' + str(fb2.iloc[i]['lon'])], radius=fb2.iloc[i]['energy'] * 100, color='red', fill=True, fill_color='red' ).add_to(m) m
- Analyzing the Next Decade of Earth Close-Approaching Objects with nasapy
- Get All NASA Astronomy Pictures of the Day from 2019
- From Intake to Outcome: Analyzing the Austin Animal Center's Intake and Outcomes Datasets
- Austin Animal Center Intakes Exploratory Data Analysis with Python, Pandas and Seaborn
- Extract and Analyze the Seattle Pet Licenses Dataset