Space Exploration with Machine Learning

Spacecraft and satellites operating in deep space can generate huge amounts of data due to the complexity of their research missions.

Because of the different rotations and orbits of their host planets, these massive data packets must be transmitted to earth during specific windows of opportunity.

The role of machine learning in space exploration can be roughly divided into data transmission, visual data analytics, navigation, and rocket landing.

In this Article we will explore the space with Machine Learning using the space exploration data provided by Space X.

Lets start by importing the libraries

# IMPORTING LIBRARIES
import numpy as np
import matplotlib.pyplot as plt
from PIL import  Image
%matplotlib inline
import pandas as pd
import seaborn as sns
import itertools
from wordcloud import WordCloud,STOPWORDS
import io
import base64
from matplotlib import rc,animation
from mpl_toolkits.mplot3d import Axes3D
import folium
import folium.plugins
import plotly.offline as py
py.init_notebook_mode(connected=True)
import plotly.graph_objs as go
import plotly.tools as tls

Download Space X launch Data set

space_data = pd.read_csv("spacex_launch_data.csv")
space_data.head()

Data Information

space_data.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 57 entries, 0 to 56
Data columns (total 11 columns):
 #   Column             Non-Null Count  Dtype 
---  ------             --------------  ----- 
 0   Flight Number      57 non-null     object
 1   Date               57 non-null     object
 2   Time (UTC)         57 non-null     object
 3   Booster Version    57 non-null     object
 4   Launch Site        57 non-null     object
 5   Payload            57 non-null     object
 6   Payload Mass (kg)  55 non-null     object
 7   Orbit              57 non-null     object
 8   Customer           57 non-null     object
 9   Mission Outcome    57 non-null     object
 10  Landing Outcome    57 non-null     object
dtypes: object(11)
memory usage: 5.0+ KB

Data Dimensions

print ("Number of columns :",space_data.shape[1])
print ("Number of rows    :",space_data.shape[0])
Number of columns : 11
Number of rows    : 57
#Date manipulation
import datetime
space_data["Date"]  = pd.to_datetime(space_data["Date"],format="%Y-%m-%d")
space_data["year"]  = pd.DatetimeIndex(space_data["Date"]).year
space_data["month"] = pd.DatetimeIndex(space_data["Date"]).month
space_data["month"] = space_data["month"].map({1:"JAN",  2:"FEB",  3:"MAR",  4:"APR",  
                                               5:"MAY",  6:"JUN",
                                              7:"JUL",  8:"AUG",  9:"SEP", 10:"OCT",
                                               11:"NOV", 12:"DEC"})
space_data["hour"]  = space_data["Time (UTC)"].str.split(":").str[0]
space_data["month_year"] = space_data["month"].astype(str) + "-" + space_data["year"].astype(str)

Total Space-X launches by year

  • Space X had maximum of 18 launches in the year 2017 .
  • No launches in the year 2011.
yr = space_data.groupby("year")["Flight Number"].count().reset_index()


plt.figure(figsize=(12,7))
ax = sns.barplot("year","Flight Number",data=yr,
                 palette="jet_r",linewidth=2,
                 edgecolor=["white"]*len(yr),
                 alpha=.9)
ax.set_facecolor("k")
ax.set_ylabel("Number of launches")
plt.yticks(np.arange(0,22,2))
plt.title("Total launches by year")
plt.grid(True,alpha=.3)
plt.show()

Mission outcomes by year

  • Year 2015 have a mission failure during flight.
  • Since their first mission in June 2010, rockets from the Falcon 9 family have been launched 57 times, with 55 full mission successes, one partial failure and one total loss of spacecraft.
sy = pd.crosstab(space_data["year"],space_data["Mission Outcome"])
ax = sy.plot(kind="bar",stacked=True,figsize=(12,7),
             linewidth=1,edgecolor="w"*space_data["year"].nunique(),
             colors=["r","lawngreen","b"],alpha=0.9)

plt.yticks(np.arange(0,22,2))
plt.grid(True,alpha=.3)
plt.title("Mission outcomes by year")
plt.legend(loc="upper center",prop={"size":12})
plt.xticks(rotation=0)
ax.set_facecolor("k")
plt.show()

Mission Success rate

  • Rockets from the Falcon 9 family have been launched 57 times over 8 years, resulting in 55 full mission successes (96.5% success rate), one partial success , and one failure.
plt.figure(figsize=(8,8))
space_data["Mission Outcome"].value_counts().plot.pie(autopct="%1.1f%%",
                                                      fontsize=12,
                                                      colors = ["lawngreen","b","r"],
                                                      wedgeprops={"linewidth":3,"edgecolor":"w"},
                                                      shadow=True)
circ = plt.Circle((0,0),.7,color="white")
plt.gca().add_artist(circ)
plt.ylabel("")
plt.title("Mission Success rate")
plt.show()

Mission Failure

  • Launch performance was nominal until an overpressure incident in the second-stage LOX tank, leading to vehicle breakup at T+150 seconds.
  • Dragon capsule survived the explosion but was lost upon splashdown as its software did not contain provisions for parachute deployment on launch vehicle failure.
from IPython.display import YouTubeVideo
failure = space_data[space_data["Mission Outcome"] == "Failure  (in flight)"].transpose()[:12].reset_index()
failure.columns = ["launch_details","information"]
failure = failure.style.set_properties(**{'background-color': 'black',
                                         'color': 'lawngreen',
                                        'border-color': 'white'}).set_caption("Mission Failed")

display(failure)
YouTubeVideo("WTVkhp0MxMc",width=700,height=400)

Mission payload status unclear

The mission had been postponed by nearly two months. Following a nominal launch, the recovery of the first-stage booster marked the 17th successful recovery in a row.

Rumors appeared that the payload was lost, as the satellite might have failed to separate from the second stage, to which SpaceX announced that their rocket performed nominally.

The classified nature of the mission means that there is little confirmed information.

uc = space_data[space_data["Mission Outcome"] == "Success  (payload\xa0status unclear)"].transpose()[:12].reset_index()
uc.columns = ["launch_details","information"]
uc = uc.style.set_properties(**{"background-color":"black",
                               "color":"yellow",
                               "border-color":"white"}).set_caption("Mission payload status unclear")
uc

Launch Sites

  • Cape Canaveral Air Force Station .Cape Canaveral Air Force Station Space Launch Complex 40 (SLC-40), previously Launch Complex 40 (LC-40) is a launch pad for rockets located at the north end of Cape Canaveral, Florida.
  • Launch Complex 39 (LC-39) is a rocket launch site at the John F. Kennedy Space Center on Merritt Island in Florida, United States.
  • Space Launch Complex 4 (SLC-4) is a launch and landing site at Vandenberg Air Force Base with two pads, both of which are used by SpaceX for Falcon 9 launch operations.
space_data["Launch_site_f"] = space_data["Launch Site"].map({"CCAFS LC-40" :"Cape Canaveral Air Force Station LC-40",
                                                            "CCAFS SLC-40" :"Cape Canaveral Air Force Station LC-40",
                                                            "KSC LC-39A"   :"The John F. Kennedy Space Center LC-39A",
                                                            "VAFB SLC-4E"  :"Vandenberg Air Force Base SLC-4E"})

plt.figure(figsize=(8,6))

ax = sns.countplot(y = space_data["Launch_site_f"],palette=["b"],
                  order=space_data["Launch_site_f"].value_counts().index,
                  linewidth=2,
                  edgecolor="w"*3,
                  alpha=.9)

ax.set_facecolor("k")
plt.ylabel("")
plt.xlabel("count")
plt.yticks(color="navy",fontsize=12)
plt.title("Total number of launches by sites")

for i,j in enumerate(space_data["Launch_site_f"].value_counts().values.ravel()):
    ax.text(.7,i,j,color="w",weight="bold",fontsize=30)

plt.show()

Mission outcomes by Launching sites

lm = pd.crosstab(space_data["Launch_site_f"],space_data["Mission Outcome"])

ax = lm.plot(kind="barh",stacked=True,figsize=(8,6),
            linewidth=2,
            edgecolor="w"*3,
            alpha = .9)

plt.grid(True,alpha=.3)
plt.title("Mission outcomes by Launching sites")
plt.legend(loc="upper right",prop={"size":12})
plt.xticks(rotation=0)
plt.ylabel("")
ax.set_facecolor("k")
plt.show()

Launch sites by year

ly = pd.crosstab(space_data["year"],space_data["Launch_site_f"])
ax = ly.plot(kind="bar",stacked=True,figsize=(12,7),
             linewidth=1,
             edgecolor="w"*space_data["year"].nunique(),
             alpha  = 1)
plt.xticks(rotation=0)
plt.legend(loc="upper left",prop={"size":12})
plt.yticks(np.arange(0,22,2))
plt.grid(True,alpha=.3)
plt.title("Lauch sites by year")
ax.set_facecolor("k")
plt.show()

Rocket configurations

space_data["booster"] = space_data["Booster Version"].str.split(" ").str[1]
space_data["booster"] = "Falcon 9 " + space_data["booster"]
space_data.loc[48,"booster"] = "Falcon Heavy"

plt.figure(figsize=(12,7))
ax = space_data["booster"].value_counts().plot(kind="bar",
                                               color="Orange",
                                               linewidth=2,
                                               edgecolor="w"*space_data["booster"].nunique())
plt.xticks(rotation=0,fontsize=13,color="navy")
plt.yticks(np.arange(0,28,4))
plt.grid(True,alpha=.3)
plt.title("Rocket configurations")
ax.set_facecolor("k")
plt.show()

Rocket configurations by year

by = pd.crosstab(space_data["year"],space_data["booster"])
ax = by.plot(kind="bar",stacked=True,
             figsize=(12,7),colormap="rainbow",
             linewidth=1,edgecolor="w"*space_data["year"].nunique())
plt.xticks(rotation=0)
plt.legend(loc="upper left",prop={"size":12})
plt.yticks(np.arange(0,22,2))
plt.grid(True,alpha=.3)
plt.title("Rocket configurations  by year")
ax.set_facecolor("k")
plt.show()

Tesla Roadster Payload

  • The first-generation Tesla Roadster is an all-electric sports car. The red Roadster launched into space is one of Elon Musk’s privately owned vehicles.
  • Musk said in a 2012 interview that the Roadster was “the one I drive to work”. The car was installed in the Falcon Heavy rocket at an inclined position above the payload adapter in order to account for the mass distribution.
tes = space_data[space_data["Payload"] == "Elon Musk's Tesla Roadster"].transpose().reset_index()[:12]
tes.columns = ["launch_attribute","details"]
tes = tes.style.set_properties(**{"background-color":"red",
                                "color":"white",
                                "border-color":"white"}).set_caption("Elon Musk's Tesla Roadster")
display(tes)
YouTubeVideo("q_WQ-Ds8ZvE",width=700,heith=400)

Payload word cloud

wrds = space_data[["Payload"]]

plt.figure(figsize=(13,8))
wc = WordCloud(scale=5,background_color="black",
               colormap="cool",margin=True).generate(str(wrds))
plt.imshow(wc,interpolation="bilinear")
plt.axis("off")
plt.title("Payload word cloud")
plt.show()

Total Payload taken to space by spacecrafts every year

space_data_nl = space_data.copy()
space_data_nl = space_data_nl[(space_data_nl["Payload Mass (kg)"].notnull()) & (space_data_nl["Payload Mass (kg)"] != "Classified")]
space_data_nl["Payload Mass (kg)"] = space_data_nl["Payload Mass (kg)"].astype(int)


myp = space_data_nl.groupby("year")["Payload Mass (kg)"].sum().reset_index()

plt.figure(figsize=(12,7))
ax = sns.pointplot("year","Payload Mass (kg)",
                   data=myp,color="w")
ax.set_facecolor("k")
plt.grid(True,alpha=.3)
plt.yticks(np.arange(0,110000,10000))
plt.xticks(fontsize=15,color="navy")
plt.title("Total Payload taken to space by spacecrafts every year")
plt.show()

Launching orbits for space crafts.

  • 22 rockets are launched in GTO orbit
  • 16 rockets in LEO(ISS) orbit.
  • 8 rockets in LEO orbit.
  • 1 rocket in Heliocentric orbit.
plt.figure(figsize=(8,8))
orb = space_data["Orbit"].value_counts().reset_index()

ax  = sns.barplot("Orbit","index",
                  data=orb,
                  linewidth=2,
                  edgecolor="w"*len(orb),
                  palette = "husl")
ax.set_facecolor("k")
plt.xlabel("count")
plt.ylabel("")
plt.grid(True,alpha=.3)

for i,j in enumerate(orb["Orbit"].values):
    ax.text(.7,i,j,weight="bold",fontsize=10)

plt.title("Launching orbits for space crafts")
plt.show()

Word cloud for spaceX customers

wrds1 = space_data[["Customer"]]

plt.figure(figsize=(14,8))
wc1   = WordCloud(scale=5,background_color="black",colormap="bwr").generate(str(wrds1))
plt.imshow(wc1,interpolation="bilinear")
plt.axis("off")
plt.title("Word cloud for spaceX customers")
plt.show()
Thecleverprogrammer
Thecleverprogrammer
Articles: 76

Leave a Reply