Space Science Blog

Bringing You The Future Of Science and Technology

ROCKET COMPARISON USING PYTHON


In this tutorial we will use the Python programming language to compare several common rockets. We will use the Matplotlib library to build simple, yet elegant bar charts to help us visualize the differences between each rocket in our comparison.

Artificial Intelligence | DIY Electronics Projects | Game Design Workshop | Random Generators | Planetary Science | Rocket Science


Categories

Art and Web Design

Contact me for information about rates and availability.


Latest Articles


Rocket Comparison

Ariane 5
-------------------------
Height (h): 46 (m)
Diameter (d): 5.4 (m)
Thrust (t): 220000 (lbf)
Mass (m): 777000 (kg)
Stages (s): 2


Atlas V
----------------------------
Height (h): 58.3 (m)
Diameter (d): 3.81 (m)
Thrust (t): 860000 (lbf)
Mass (m): 334500 (kg)
Stages (s): 2


Black Brant IV
----------------------------
Height (h): 11.06 (m)
Diameter (d): 0.44 (m)
Thrust (t): 24953 (lbf)
Mass (m): 1356 (kg)
Stages (s): 2


Delta II
----------------------------
Height (h): 37.8 (m)
Diameter (d): 2.4 (m)
Thrust (t): 237000 (lbf)
Mass (m): 151700 (kg)
Stages (s): 2


Delta IV
----------------------------
Height (h): 63 (m)
Diameter (d): 5 (m)
Thrust (t): 705000 (lbf)
Mass (m): 249500 (kg)
Stages (s): 2


Falcon 9
----------------------------
Height (h): 70 (m)
Diameter (d): 3.7 (m)
Thrust (t): 1710000 (lbf)
Mass (m): 549054 (kg)
Stages (s): 2


Saturn V
----------------------------
Height (h): 110.6 (m)
Diameter (d): 10 (m)
Thrust (t): 7891000 (lbf)
Mass (m): 2840622 (kg)
Stages (s): 3


 Rocket Comparison Using Python

In this tutorial, we will take a closer look at several past and present chemical rockets, using the Python programming language and the Matplotlib library to visualize the differences in size, mass and thrust of each rocket. We will compare the Ariane 5, Atlas V, Black Brant IV, Delta II, Delta IV, Falcon 9 and Saturn V rockets.

Before we begin programming we must collect data on each rocket, and for this purpose we will use Wikipedia to gather the necessary information. When measuring height and diameter, we will use the metric system as opposed to the imperial system (1 ft = 0.3048 m). Thrust will be measured in lbf (please note that in some cases we may need to convert from Newtons (N) or kilo Newtons (kN) to lbf (1.0 N = 0.2248089 lbf). Also note that we will only be using the thrust of the first stage rocket engine at sea level.

For our comparison, we will need to gather the following attributes: height, diamter, thrust, mass, specific impulse and the number of stages. The following table shows the relevant attributes that we will be using in our comparison.



Rocket Attributes
Rocket Height (h) Diameter (d) Thrust (t) Mass (m) Stages (s)
Ariane 5 46 m 5.4 m 220,000 lbf 777,000 kg 2
Atlas V 58.3 m 3.81 m 860,000 lbf 334,500 kg 2
Black Brant IV 11.06 m 0.44 m 24,953 lbf 1,356 kg 2
Delta II 37.8 m 2.4 m 237,000 lbf 151,700 kg 2
Delta IV 63 m 5 m 705,000 lbf 249,500 kg 2
Falcon 9 70 m 3.7 m 1,710,000 lbf 549,054 kg 2
Saturn V 110.6 m 10 m 7,891,000 lbf 2,840,622 kg 3


First we will use the information contained in the above table to create Python lists for each attribute. This will allow us to easily display the information by printing to the console. A list is simply an ordered collection of data. Lists can contain strings, numbers, boolean values or any combination of these.

To create a list in Python, start by entering the name of the list, followed by the assignment operator (=) and the square brackets. Within the square brackets list each attribute (separated by a comma) in correct order. Note that srings must be wrapped inside single, or double, quotes.

>>> rockets = ['Ariane 5', 'Atlas V', 'Black Brant IV', 'Delta II', 'Delta IV', 'Falcon 9', 'Saturn V'] >>> height = [46, 58.3, 11.06, 37.8, 63, 70, 110.6] # meters >>> diameter = [5.4, 3.81, 0.44, 2.4, 5, 3.7, 10] # meters >>> thrust = [220000, 860000, 24953, 237000, 705000, 1710000, 7891000] # lbf >>> mass = [777000, 334500, 1356, 151700, 249500, 549054, 2840622] # kg >>> stages = [2, 2, 2, 2, 2, 2, 3] >>> attributes = ['Height (h):', 'Diameter (d):', 'Thrust (t):', 'Mass (m):', 'Stages (s):']


Next we will define a function for each rocket that will allow us to easily print out the attributes that we stored in our lists above. This will make our code cleaner and easier to use. Remember, elements ina list can be accessed using zero-based indexes inside square brackets. We will define each function using def:

>>> # Ariane 5 >>> def ariane_5(): ... print(rockets[0]) ... print(attributes[0], height[0], "(m)") ... print(attributes[1], diameter[0], "(m)") ... print(attributes[2], thrust[0], "(lbf)") ... print(attributes[3], mass[0], "(kg)") ... print(attributes[4], stages[0]) ... print("") >>> ariane_5()


Which results in the following:

Ariane 5 Height (h): 46 (m) Diameter (d): 5.4 (m) Thrust (t): 220000 (lbf) Mass (m): 777000 (kg) Stages (s): 2


Now we can repeat the above code for each rocket, making sure that we change the index for each list to reflect each consecutive rocket. For example, the second element in a Python list is indexed as list[1], instead of list[2]. Therefore, for the attributes related to the Atlas V rocket, which is the second element in our lists, we would use rockets[1].

>>> # Atlas V >>> def atlas_v(): ... print(rockets[1]) ... print(attributes[0], height[1], "(m)") ... print(attributes[1], diameter[1], "(m)") ... print(attributes[2], thrust[1], "(lbf)") ... print(attributes[3], mass[1], "(kg)") ... print(attributes[4], stages[1]) ... print("") >>> atlas_v()


Which results in the following:

Atlas V Height (h): 58.3 (m) Diameter (d): 3.81 (m) Thrust (t): 860000 (lbf) Mass (m): 334500 (kg) Stages (s): 2


Lastly, we want to create a couple of bar graphs using Python and the Matplotlib library (http://matplotlib.org/). Before using Matplotlib, we must import it, which can be done with the following command:

>>> import matplotlib.pyplot as plt


This will allow us to visualize some of the differences between the rockets under investigation. Matplotlib will allow us to create simple bar charts, line charts and scatterplots. For our purposes, we will use the standard bar chart to visualize our data.

>>> ################################# >>> # Plotting Figures (Matplotlib) # >>> ################################# >>> plt.title('Rocket Comparison') >>> plt.figure(1) >>> plt.subplot(211) >>> plt.title('Diameter Vs Height') >>> plt.bar(rockets, diameter) >>> plt.ylabel('Diameter (meters)') >>> plt.subplot(212) >>> plt.bar(rockets, height) >>> plt.ylabel('Height (meters)') >>> ################################# >>> plt.figure(2) >>> plt.subplot(211) >>> plt.title('Mass Vs Thrust') >>> plt.bar(rockets, mass) >>> plt.ylabel('Mass (kg)') >>> plt.subplot(212) >>> plt.bar(rockets, thrust) >>> plt.ylabel('Thrust (lbf)') >>> # This section turns off scientific notation >>> ax = plt.gca() >>> ax.get_yaxis().get_major_formatter().set_scientific(False) >>> ################################# >>> plt.show() >>> #################################


Running the above code generates in the following bar charts:

Diameter vs Height Mass vs Thrust

 Complete Code


The Complete code for this project is listed below. You can also download this code from my GitHub page.


######################################################## # # # Rocket Comparison # # Written by Johnathan Nicolosi # # January 8, 2019 # # # ######################################################## import matplotlib.pyplot as plt ################################ # Rocket Comparison # ################################ rockets = ['Ariane 5', 'Atlas V', 'Black Brant IV', 'Delta II', 'Delta IV', 'Falcon 9', 'Saturn V'] height = [46, 58.3, 11.06, 37.8, 63, 70, 110.6] # meters diameter = [5.4, 3.81, 0.44, 2.4, 5, 3.7, 10] # meters thrust = [220000, 860000, 24953, 237000, 705000, 1710000, 7891000] # lbf mass = [777000, 334500, 1356, 151700, 249500, 549054, 2840622] # kg stages = [2, 2, 2, 2, 2, 2, 3] attributes = ['Height (h):', 'Diameter (d):', 'Thrust (t):', 'Mass (m):', 'Stages (s):'] ################################ # Ariane 5 # ################################ def ariane_5(): print(rockets[0]) print(attributes[0], height[0], "(m)") print(attributes[1], diameter[0], "(m)") print(attributes[2], thrust[0], "(lbf)") print(attributes[3], mass[0], "(kg)") print(attributes[4], stages[0]) print("") ariane_5() ################################ # Atlas V # ################################ def atlas_v(): print(rockets[1]) print(attributes[0], height[1], "(m)") print(attributes[1], diameter[1], "(m)") print(attributes[2], thrust[1], "(lbf)") print(attributes[3], mass[1], "(kg)") print(attributes[4], stages[1]) print("") atlas_v() ################################ # Black Brant IV # ################################ def black_brant_iv(): print(rockets[2]) print(attributes[0], height[2], "(m)") print(attributes[1], diameter[2], "(m)") print(attributes[2], thrust[2], "(lbf)") print(attributes[3], mass[2], "(kg)") print(attributes[4], stages[2]) print("") black_brant_iv() ################################ # Detla II # ################################ def delta_ii(): print(rockets[3]) print(attributes[0], height[3], "(m)") print(attributes[1], diameter[3], "(m)") print(attributes[2], thrust[3], "(lbf)") print(attributes[3], mass[3], "(kg)") print(attributes[4], stages[3]) print("") delta_ii() ################################ # Detla IV # ################################ def delta_iv(): print(rockets[4]) print(attributes[0], height[4], "(m)") print(attributes[1], diameter[4], "(m)") print(attributes[2], thrust[4], "(lbf)") print(attributes[3], mass[4], "(kg)") print(attributes[4], stages[4]) print("") delta_iv() ################################ # Falcon 9 # ################################ def falcon_9(): print(rockets[5]) print(attributes[0], height[5], "(m)") print(attributes[1], diameter[5], "(m)") print(attributes[2], thrust[5], "(lbf)") print(attributes[3], mass[5], "(kg)") print(attributes[4], stages[5]) print("") falcon_9() ################################ # Saturn V # ################################ def saturn_v(): print(rockets[6]) print(attributes[0], height[6], "(m)") print(attributes[1], diameter[6], "(m)") print(attributes[2], thrust[6], "(lbf)") print(attributes[3], mass[6], "(kg)") print(attributes[4], stages[6]) print("") saturn_v() ################################# # Plotting Figures (Matplotlib) # ################################# plt.title('Rocket Comparison') plt.figure(1) plt.subplot(211) plt.title('Diameter Vs Height') plt.bar(rockets, diameter) plt.ylabel('Diameter (meters)') plt.subplot(212) plt.bar(rockets, height) plt.ylabel('Height (meters)') plt.figure(2) plt.subplot(211) plt.title('Mass Vs Thrust') plt.bar(rockets, mass) plt.ylabel('Mass (kg)') plt.subplot(212) plt.bar(rockets, thrust) plt.ylabel('Thrust (lbf)') # This section turns off scientific notation ax = plt.gca() ax.get_yaxis().get_major_formatter().set_scientific(False) plt.show()


Johnathan Nicolosi - 08 Jan 2019