Space Science Blog

Bringing You The Future Of Science and Technology

EARTH'S ATMOSPHERE


In this tutorial we will use Python and Matplotlib to calculate aerodynamic variables for various-sized flying objects through Earth's atmosphere at various altitudes, velocities.

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


Categories

Art and Web Design

Contact me for information about rates and availability.


Latest Articles


Earth's Atmosphere (current levels)

CO2 = 399.5 ppm
CH4 = 1834 ppb
N2O = 328 ppb
O3 = 237 ppb
CFC-11 = 232 ppt
CFC-12 = 516 ppt


Earth's Atmosphere (pre-1750)

CO2 = 280 ppm
CH4 = 722 ppb
N2O = 270 ppb
O3 = 237 ppb
CFC-11 = 0
CFC-12 = 0

**Globally averaged atmospheric gas records provided by: Ed Dlugokencky and Pieter Tans, NOAA/ESRL (www.esrl.noaa.gov/gmd/ccgg/trends/)


Vertical Total Electron Content (external link)



 Earth's Atmosphere



In this multi-part tutorial we will use Python and Matplotlib to calculate various atmospheric and aerodynamic variables that an object flying through Earth's atmosphere at various altitudes and velocities will encounter. Before we get into the Python code, let's take a look at the different layers of Earth's atmosphere.

With most of Earth's atmospheric gases located in the lowest layer of the atmosphere, the troposphere, the air becomes more dense as an object flies (or falls) at lower altitudes. Atmospheric gases are affected by incident solar radiation coming in from above and terrestrial drivers, such as hurricanes and tropical storms, forest fires, volcanic erruptions and nuclear detonations, coming up from below.

As the sun rotates along its axis, the side of the planet facing the sun receives far more radiation than the night-side of the planet. As radiation strikes the gases in the upper atmosphere, electrons are stripped from their nuclei, creating a forth state of matter - plasma. This layer of plasma creates an additional atmospheric layer, known as the ionosphere.

Earth's atmosphere will expand or contract based on variations in solar activity. Ionized gases in the upper atmosphere can cause atmospheric drag on satellites operating below 1000 km. This drag will affect spacecraft operating below 130 km or 81 miles altitude, by pulling them back down to earth. Between 130 km and and 600 km (81 mi - 375 mi), drag will be affected by variations in the upper atmosphere. Far below the ionosphere, in the thin layer of dense air covering the earth's surface known as the troposhere, heated gases rising from the oceans and irregular land masses drive heat and moisture into the air, where the warm moist air cools and then falls back down to earth as snow, rain, or hail in a never-ending loop known as the hydrologic cycle.

In the following tutorial, we will build a simple modle of Earth's atmosphere using Python and MatPlotLib to create visual graphics to help us better understand the past trends in solar or space weather and earth and near-earth weather. Before we begin building our model, we must first collect some data. For temperature, pressure and density data, I used an old textbook titled, Fundamentals of Aerodynamics, Fifth Edition, by John D. Anderson, Jr.

This tutorial requires Python3 and MatPlotLib. All of the math is pretty basic, however, we will be using Numpy later in this tutorial. You can download the source code from my Github page. Begin by opening python3 and importing matplotlib and numpy.

>>> import matplotlib.pyplot as plt
>>> import numpy as np

 Aerodynamic Variables


For the speed of sound, I used data from another old textbook to confirm that our calculations are correct, Aerodunamics for Naval Aviators, by the Naval Air Systems Command, United States Navy. In this textbook, Figure 1.1. Standard Altitude Table, lists the variations of temperature and the speed of sound with altitude at the standard atmosphere. This table provides the average temperature along with the related speed of sound, which is measured in knots, from sea level (0 ft) to an altitude of 100000 ft.

Altitude
The standard altitude table lists the altitude in feet and for our purposes we prefer our data to me in meters or kilometers. We will enter the altitude in feet, as listed in the Standard Altitude Table and then later we can convert it to meters by multiplying each element of the list by 0.3048.

>>> # Altitude (in feet) - from sea level to 100000 ft as a list
>>> altitude = [0, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 15000, 20000, 25000, 30000, 35000, 40000, 45000, 50000, 55000, 60000, 65000, 70000, 75000, 80000, 85000, 90000, 95000, 100000]

Temperature
The rest of our data will come from Anderson's Fundamentals of Aerodynamics, Appendix D. We will continue by creating a list of the coresponding temperatures for each altitude. You will notice, that the temperature is provided in Celcius, which is fine, but for some of our calculations we will need this to be converted to Kelvin.

>>> # Temperature in degrees Ceslsius from sea level to 100000 ft
>>> temperature = [15.0, 13.0, 11.0, 9.1, 7.1, 5.1, 3.1, 1.1, -0.9, -2.8, -4.8, -14.7, -24.6, -34.5, -44.4, -54.3, -56.5, -56.5, -56.5, -56.5, -56.5, -56.5, -56.5, -56.5, -56.5, -53.8, -49.2, -44.6, -40.1]

For temperatures, we prefer to do our calculations in degrees Kelvin. You can easliy convert from Celcuis to Kelvin by simply adding 273 to your temperature.

>>> # To convert the temperature from degrees Celcius to Kelvin and add to a new list
>>> temp_kelvin = [x + 273.15 for x in temperature]
>>> # Each element in the temperature list is converted from Celcius to Kelvin and stored in a new list named temp_kelvin
>>> temp_kelvin
[288.0, 286.0, 284.0, 282.1, 280.1, 278.1, 276.1, 274.1, 272.1, 270.2, 268.2, 258.3, 248.4, 238.5, 228.6, 218.7, 216.5, 216.5, 216.5, 216.5, 216.5, 216.5, 216.5, 216.5, 216.5, 219.2, 223.8, 228.4, 232.9]

Once we have the temperature from sea-level to 100,000 ft, in Kelvin, we can calculate the temperature ratio, or the ratio between the current temperature and the temperature at sea-level.

>>> temp_sea_level = temp_kelvin[0]
>>> temp_ratio = [x / temp_sea_level for x in temp_kelvin]

Pressure
Pressure decreases in altitude, with the greatest air pressure at or below sea. Air pressure is listed in Newtons per meter squared (N/m2).

>>> # Atmospheric pressure, measured in bars from sea level to 100000 ft
>>> pressure = [101325, 97773, 94322, 90971, 87718, 84560, 81494, 78520, 75634, 72835, 70121, 57752, 46575, 37757, 30346, 24163, 18799, 14854, 11737, 9132, 7218, 5705, 4440, 3566, 2776, 2163, 1746, 1374, 1086]

Density
Air density also decreases with altitude, and is measured in kilograms per meter cubed (kg/m).

>>> # Density of air from sea level to 100000 ft
>>> density = [1.2250, 1.1901, 1.1560, 1.1226, 1.09, 1.0581, 1.0269, 0.9965, 0.9667, 0.9377, 0.9093, 0.777, 0.6528, 0.5508, 0.4615, 0.3837, 0.3023, 0.2388, 0.1887, 0.1468, 0.1161, 0.092, 0.071, 0.057, 0.045, 0.034, 0.0272, 0.02097, 0.0162]

Speed of Sound
The Speed of Sound, like air pressure and density, is dependant of the temperature of the air and therefore the speed of sound also decreases with altitude. The speed of sound represents the speed at which sound travels and is measured in knots. Because gas molecules move more slowly at decreased temperatures, the speed of sound moves more slowly; sounds move faster through warmer air. From this we conclude that thee speed required to break the sound barrier decreases at higher altitudes, where temperatures are colder.

As scientists, we are interested in the speed of sound because it indicates the speed of transmitting a sound wave through the atmosphere. The propagation of a sound wave is caused when gas molecules hit each other, and the type of gas will affect the speed at which sound travels. The speed of sound is known as Mach 1, and to break the speed of sound means that you are travelling faster than the sound barrier.

We will calculate the speed of sound (a) for each layer in earth's atmosphere using the following equation a = sqrt(γ * R * T)

γ = ratio of specific heats (1.4 for air at STP)
R = gas constant (286 m2/s2/K for air)
T = absolute temperature (273.15 + C)

We must avoid using gamma when namming our variables in Python, especially when using SciPy, as gamma is function name. Therefore, instead of calling it γ, or gamma, we shall call it by it's namesake (g). Using Python we can calculate the speed of sound at any altitude, using the temp_kelvin list created earlier. Also note that the results are in meters per second and must be converted to knots.

>>> T = temp_kelvin
>>> g = 1.4
>>> R = 286
>>> a = math.sqrt(g * R * T[0])
>>> a
339.66933921094494

We can repeat the above code for each layer of atmosphere and combine the results to form a new list, called a_mps, which will contain the speed of sound (in meters per second) for each layer of the atmosphere, from sea-level to 100,000 ft).

>>> a_mps = [339.67, 338.49, 337.30, 336.17, 334.98, 333.78, 332.58, 331.38, 330.16, 329.01, 327.79, 321.69, 315.47, 309.12, 302.64, 296.02, 294.53, 294.53, 294.53, 294.53, 294.53, 294.53, 294.53, 294.53, 294.53, 296.36, 299.45, 302.51, 305.47]

Now we can convert the speed of sound from meters per second to knots by multiplying each element in a_mps by 1.94384.

>>> # Speed of sound, measured in knots, from sea level to 100000 ft (1 mps = 1.94384 knots)
>>> a_knot = a * 1.94384
>>> a_knot
660.2628483318032

We will repeat the above steps until we get the speed of sound for each layer of atmosphere. To do this, we will create a new list based on a_mps.

>>> a_knot = [x * 1.94384 for x in a_mps]
>>> a_knot
[660.2641328000001, 657.9704016000001, 655.657232, 653.4606928000001, 651.1475232, 648.8149152, 646.4823071999999, 644.1496992, 641.7782144, 639.5427984, 637.1713136000001, 625.3138896, 613.2232048000001, 600.8798208000001, 588.2837376, 575.4155168, 572.5191951999999, 572.5191951999999, 572.5191951999999, 572.5191951999999, 572.5191951999999, 572.5191951999999, 572.5191951999999, 572.5191951999999, 572.5191951999999, 576.0764224000001, 582.082888, 588.0310383999999, 593.7848048000001]

You may have noticed that there are way too many digits following the decimal. We can round this to two decimal places by calling the round() function. Note that we could easily round it to any decimal point (including zero).

>>> speed_sound = [round(x,2) for x in a_knot]
>>> speed_sound
[660.26, 657.98, 655.66, 653.47, 651.15, 648.82, 646.49, 644.14, 641.79, 639.54, 637.17, 625.31, 613.22, 600.88, 588.29, 575.41, 572.52, 572.52, 572.52, 572.52, 572.52, 572.52, 572.52, 572.52, 572.52, 576.07, 582.08, 588.03, 593.79]

A simple way to clean this up would be to copy and paste the results printed above into a new list.

>>> speed_sound = [660.26, 657.98, 655.66, 653.47, 651.15, 648.82, 646.49, 644.14, 641.79, 639.54, 637.17, 625.31, 613.22, 600.88, 588.29, 575.41, 572.52, 572.52, 572.52, 572.52, 572.52, 572.52, 572.52, 572.52, 572.52, 576.07, 582.08, 588.03, 593.79]

 Atmospheric Gases and the Atmosphere


Water (H2O), carbon dioxide (CO2), oxygen (O2), ozone (O3) and nitrous oxide (N2O) affect the transmission of electromagnetic energy, especially solar radiation, through the atmosphere. It is important to understand how different gases in the atmosphere interacts with various wavelengths of the electromagnetic spectrum.

Absorption and scattering are often combined with air to create what is known as an extinction coefficient. The transmission of radiant energy through the atmosphere is inversely proportional to the extinction coefficient, multiplied by the thickness of the atmospheric layer. Note that certain wavelengths of radiation are more affected by atmospheric absorption rather than by scattering. Infrared radiation and shorter-wavelength radio waves, such as microwaves, are affected more by atmospheric absorption than higher-wavelength visible light and ultra-violet light. Combined with atmospheric scattering and reflectance (from cloud tops), absorption dramatically reduces the amount of solar radiation that reaches Earth's surface.

>>> atmospheric_gases = ['N2', 'O2', 'H2O', 'Ar', 'CO2', 'Ne', 'He', 'CH4', 'Kr', 'H2', 'N2O', 'Xe', 'O3', 'Particles', 'I2', 'NO2', 'Chlorofluorocarbons']
>>> atmospheric_percent_volume = [78.08, 20.95, 4, 0.93, 0.036, 0.0018, 0.0005, 0.00017, 0.00014, 0.00005, 0.00003, 0.000009, 0.000004, 0.000001, 0.000002, 0.00000002]

A quick glance at the above list tells us that there are only five gases that make up a majority of Earth's atmosphere (nitrogen, oxygen, water vapor, argon, and carbon dioxide). The remaining gases are too minute and are considered insignificant when considering their effects on the incident and exitant solar flux. We will then create three new lists (to represent the max, mid and minimum for each gas) by slicing only the elements from each list that we want to represent. We will use these new lists to create a simple bar graph with MatPlotLib, showing the distribution of each atmospheric gas (by percentage per volume).

>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> atmospheric_gases_most = atmospheric_gases[0:5]
>>> atmospheric_gases_percentages_most = atmospheric_percent_volume[0:5]
>>> y_pos = np.arange(len(atmospheric_gases_most))
>>> plt.figure('Atmospheric Gases')
>>> plt.subplot(311)
>>> plt.title('Atmospheric Gases')
>>> plt.bar(y_pos, atmospheric_gases_percentages_most, align='center', alpha=0.5)
>>> plt.xticks(y_pos, atmospheric_gases_most)
>>> plt.grid(True)
>>> atmospheric_gases_mid = atmospheric_gases[5:11]
>>> atmospheric_gases_percentages_mid = [0.0018, 0.0005, 0.00017, 0.00014, 0.00005, 0.00003]
>>> y_pos = np.arange(len(atmospheric_gases_mid))
>>> plt.subplot(312)
>>> plt.bar(y_pos, atmospheric_gases_percentages_mid, align='center', alpha=0.5)
>>> plt.xticks(y_pos, atmospheric_gases_mid)
>>> plt.ylabel('Percentage by volume')
>>> plt.grid(True)
>>> atmospheric_gases_least = atmospheric_gases[11:17]
>>> atmospheric_gases_percentages_least = atmospheric_percent_volume[11:17]
>>> y_pos = np.arange(len(atmospheric_gases_least))
>>> plt.subplot(313)
>>> plt.bar(y_pos, atmospheric_gases_percentages_least, align='center', alpha=0.5)
>>> plt.grid(True)
>>> plt.xticks(y_pos, atmospheric_gases_least)
>>> plt.show()


Or we could simply chart the most abundant gases in Earth's atmosphere.

>>> plt.figure('Atmospheric Gases - most abundant')
>>> plt.title('Atmospheric Gases')
>>> plt.bar(y_pos, atmospheric_gases_percentages_most_abundant, align='center', alpha=0.5)
>>> plt.xticks(y_pos, atmospheric_gases_most_abundant)
>>> plt.grid(True)


Next we will plot out the speed of sound against temperature and then compare air pressure and density with altitutde.

>>> import matplotlib.pyplot as plt
>>> # Figure 1: Standard Altitude Parameters
>>> plt.figure(1)
>>> plt.subplot(211)
>>> plt.title('Standard Altitude')
>>> plt.plot(temperature, altitude)
>>> plt.ylabel('Altitude (ft)')
>>> plt.xlabel('Temperature (C)')
>>> plt.grid(True)
>>> plt.subplot(212)
>>> plt.ylabel('Altitude (ft)')
>>> plt.xlabel('Speed of Sound (Knots)')
>>> plt.plot(speed_sound, altitude)
>>> plt.grid(True)
>>> # Mach Number is calculated by dividing the object's velocity by the speed of sound
>>> plt.figure(2)
>>> plt.subplot(211)
>>> plt.title('Mach Number Vs Temperature Ratio')
>>> plt.plot(mach_number, altitude)
>>> plt.ylabel('Altitude (ft)')
>>> plt.xlabel('Mach Number')
>>> plt.grid(True)
>>> plt.subplot(212)
>>> plt.plot(temp_ratio, altitude)
>>> plt.ylabel('Altitude (ft)')
>>> plt.xlabel('Temperature Ratio')
>>> plt.grid(True)
>>> # Air pressure and density decreases with altitude
>>> plt.figure(3)
>>> plt.subplot(211)
>>> plt.title('Pressure Vs Density')
>>> plt.plot(pressure, altitude)
>>> plt.ylabel('Altitude (ft)')
>>> plt.xlabel('Pressure (Pa)')
>>> plt.grid(True)
>>> plt.subplot(212)
>>> plt.plot(density, altitude)
>>> plt.ylabel('Altitude (ft)')
>>> plt.xlabel('Density')
>>> plt.grid(True)
>>> plt.show()





We can now use Python and MatPlotLib to build a simple scale-model of the Earth's atmosphere. This allows us to better understand the unique properties of each layer. We will begin by creating a big green circle, representing Earth's surface, and then add a series of circles, from dark blue to light blue, to represent each layer of the atmosphere. Then we will add labels for each layer, identifying each layer by their temperature-associated names: thermosphere, mesosphere, stratosphere and troposphere. Each sphere is terminated by a boundary layer, usually marked by a temperature inversion. These boundary layers are known as the thermopause, mesopause, stratopause and tropopause.

>>> import matplotlib.pyplot as plt
>>> # Atmospheric layers
>>> fig = plt.figure('Atmospheric Layers')
>>> ax = fig.add_subplot(111)
>>> plt.axes()
>>> plt.title('Standard Atmospheric Layers')
>>> # Earth - thermosphere
>>> thermosphere = plt.Circle((0, 0), radius=6903800, fc='lightskyblue')
>>> plt.gca().add_patch(thermosphere)
>>> # Earth - mesosphere
>>> mesosphere = plt.Circle((0, 0), radius=6473800, fc='deepskyblue')
>>> plt.gca().add_patch(mesosphere)
>>> # Earth - stratosphere
>>> stratosphere = plt.Circle((0, 0), radius=6423800, fc='mediumblue')
>>> plt.gca().add_patch(stratosphere)
>>> # Earth - mesosphere
>>> troposphere = plt.Circle((0, 0), radius=6393800, fc='darkblue')
>>> plt.gca().add_patch(troposphere)
>>> # Earth - planet
>>> earth = plt.Circle((0, 0), radius=6378800, fc='green')
>>> plt.gca().add_patch(earth)
>>> plt.ylabel('distance in km')
>>> plt.axis('scaled')
>>> plt.show()



In this tutorial, we will draw a series of circles (representing the Earth and each layer of the earth's atmosphere) using Python and MatPlotLib. We will also learn how to set the color for each circle, to represent each layer within the atmosphere.

Note: In order to have our atmosphere start at sea-level (altitude - 0) we will need to offset the y-axis by -6378000 meters, as this is the approximate radius of the Earth in meters.

>>> import matplotlib.pyplot as plt
>>> # Atmospheric layers
>>> fig = plt.figure('Atmospheric Layers')
>>> ax = fig.add_subplot(111)
>>> plt.axes()
>>> plt.title('Standard Atmospheric Layers')
>>> # Earth - thermosphere
>>> thermosphere = plt.Circle((0, -6378000), radius=6903800, fc='lightskyblue')
>>> plt.gca().add_patch(thermosphere)
>>> # Earth - mesosphere
>>> mesosphere = plt.Circle((0, -6378000), radius=6473800, fc='deepskyblue')
>>> plt.gca().add_patch(mesosphere)
>>> # Earth - stratosphere
>>> stratosphere = plt.Circle((0, -6378000), radius=6423800, fc='mediumblue')
>>> plt.gca().add_patch(stratosphere)
>>> # Earth - mesosphere
>>> troposphere = plt.Circle((0, -6378000), radius=6393800, fc='darkblue')
>>> plt.gca().add_patch(troposphere)
>>> # Earth - planet
>>> earth = plt.Circle((0, -6378000), radius=6378800, fc='green')
>>> plt.gca().add_patch(earth)
>>> plt.ylabel('distance in km')
>>> plt.axis('scaled')
>>> plt.show()


And then we can add some labels, to help identify each layer of the atmosphere, along with their respective boundary layers.

>>> import matplotlib.pyplot as plt
>>> # Atmospheric layers
>>> fig = plt.figure('Atmospheric Layers')
>>> ax = fig.add_subplot(111)
>>> plt.axes()
>>> plt.title('Standard Atmospheric Layers
>>> # Earth - thermosphere
>>> thermosphere = plt.Circle((0, -6378000), radius=6903800, fc='lightskyblue')
>>> plt.gca().add_patch(thermosphere)
>>> thermopause_label = ax.annotate('Thermopause', xy=(0, 0), xytext=(0, 500000), horizontalalignment='right')
>>> thermosphere_label = ax.annotate('Thermosphere', xy=(0, 0), xytext=(10000, 150000), horizontalalignment='left')
>>> # Earth - mesosphere
>>> mesosphere = plt.Circle((0, -6378000), radius=6473800, fc='deepskyblue')
>>> plt.gca().add_patch(mesosphere)
>>> mesopause_label = ax.annotate('Mesopause', xy=(0, 0), xytext=(0, 92000), horizontalalignment='right')
>>> mesosphere_label = ax.annotate('Mesosphere', xy=(0, 0), xytext=(10000, 70000), horizontalalignment='left')
>>> # Earth - stratosphere
>>> stratosphere = plt.Circle((0, -6378000), radius=6423800, fc='mediumblue')
>>> plt.gca().add_patch(stratosphere)
>>> stratopause_label = ax.annotate('Stratopause', xy=(0, 0), xytext=(0, 42000), horizontalalignment='right')
>>> stratosphere_label = ax.annotate('Stratosphere', xy=(0, 0), xytext=(10000, 34000), horizontalalignment='left')
>>> # Earth - mesosphere
>>> troposphere = plt.Circle((0, -6378000), radius=6393800, fc='darkblue')
>>> plt.gca().add_patch(troposphere)
>>> tropopause_label = ax.annotate('Tropopause', xy=(0, 0), xytext=(0, 12000), horizontalalignment='right')
>>> troposphere_label = ax.annotate('Troposphere', xy=(0, 0), xytext=(7000, 10000), horizontalalignment='left')
>>> # Earth - planet
>>> earth = plt.Circle((0, -6378000), radius=6378800, fc='green')
>>> plt.gca().add_patch(earth)
>>> plt.ylabel('distance in meters')
>>> plt.axis('scaled')
>>> plt.show()


Next, we will further explore the atmosphere from the perspective of a flying object, such as an airplane or alien spacecraft as it flies through the atmosphere at various altitudes.


 Effects of Air Density on a Flying Object


In this section, we will take a closer look at the effects of air density on a flying object. We will create a script that will automatically calculate the average air temperature, density and air pressure at any altitude, it will tell us the speed of sound at the altitude of a flying object and may even tell us what types of clouds, if any, are present in the atmosphere near our flying object.

In the above examples, we have plotted the air pressure, density and temperature for each layer of the atmosphere from sea-level to the exosphere. We will now build on those data sets to create a script that will automatically calculate these variables (and more) based on the altitude and velocity of a flying object.

You can fork or download the complete code (written in Python) from my GitHub page. Or...simply create a new python file named standard-altitude.py then copy and paste the below text into this file, save and run.


################################################################################
#                                                                              #
#                        Aerodynamic Variable Calculator                       #
#                         Written by Johnathan Nicolosi                        #
#                             Created June 9, 2018                             #
#                                                                              #
################################################################################

import matplotlib.pyplot as plt
import numpy as np

################################################################################
#                                                                              #
#           Variables and constants used for aerodynamic calculations          #
#                                                                              #
################################################################################

# Altitude in feet from sea level to 100000 ft
altitude = [0, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000,
            10000, 15000, 20000, 25000, 30000, 35000, 40000, 45000,
            50000, 55000, 60000, 65000, 70000, 75000, 80000,
            85000, 90000, 95000, 100000]

# Temperature in degrees Ceslsius from sea level to 100000 ft
temperature = [15.0, 13.0, 11.0, 9.1, 7.1, 5.1, 3.1, 1.1, -0.9, -2.8,
               -4.8, -14.7, -24.6, -34.5, -44.4, -54.3, -56.5, -56.5,
               -56.5, -56.5, -56.5, -56.5, -56.5, -56.5, -56.5,
               -53.8, -49.2, -44.6, -40.1]

# Temperature in degrees Kelvin from sea level to 100000 ft
temp_kelvin = [288.15, 286.15, 284.15, 282.25, 280.25, 278.25, 276.25, 274.25, 272.25, 270.35, 268.35, 258.45, 248.55,
               238.65, 228.75, 218.85, 216.65, 216.65, 216.65, 216.65, 216.65, 216.65, 216.65, 216.65, 216.65, 219.35,
               223.96, 228.55, 233.05]

# Atmospheric pressure, measured in bars from sea level to 100000 ft
pressure = [101325, 97773, 94322, 90971, 87718, 84560, 81494, 78520, 75634, 72835, 70121, 57752, 46575, 37757, 30346,
            24163, 18799, 14854, 11737, 9132, 7218, 5705, 4440, 3566, 2776, 2163, 1746, 1374, 1086]

# Density of air from sea level to 100000 ft
density = [1.2250, 1.1901, 1.1560, 1.1226, 1.09, 1.0581, 1.0269, 0.9965, 0.9667, 0.9377, 0.9093, 0.777, 0.6528, 0.5508,
           0.4615, 0.3837, 0.3023, 0.2388, 0.1887, 0.1468, 0.1161, 0.092, 0.071, 0.057, 0.045, 0.034, 0.0272, 0.02097,
           0.0162]

# Speed of sound, measured in knots, from sea level to 100000 ft
speed_sound = [661.7, 659.5, 657.2, 654.9, 652.6, 650.3, 647.9, 645.6, 643.3, 640.9, 638.6, 626.7, 614.6, 602.2, 589.5,
               576.6, 573.8, 573.8, 573.8, 573.8, 573.8, 573.8, 573.8, 573.8, 573.8, 577.4, 583.4, 589.3, 595.2]

temp_sea_level = temp_kelvin[0]
temp_ratio = [x / temp_sea_level for x in temp_kelvin]

atmospheric_gases = ['Nitrogen', 'Oxygen', 'Water', 'Argon', 'Carbon Dioxide', 'Neon', 'Helium', 'Methane', 'Krypton',
                     'Hydrogen', 'Nitrous Oxide', 'Xenon', 'Ozone', 'Particles', 'Iodine', 'Nitrogen Dioxide',
                     'Chlorofluorocarbons']
atmospheric_gases_percentages = [78.08, 20.95, 4.0, 0.93, 0.036, 0.0018, 0.0005, 0.00017, 0.00014, 0.00005, 0.00003,
                                 0.000009, 0.000004, 0.000001, 0.000001, 0.000002, 0.00000002]

print("""
####################################################################################################
#                                                                                                  #
#                                 Aerodynamic Variable Calculator                                  #
#                                  Written by Johnathan Nicolosi                                   #
#                                       Created June 9, 2018                                       #
#                                                                                                  #
####################################################################################################
""")

# User input data
mps = int(input("Enter velocity of flying object (meters per second): "))
user_altitude = int(input("Enter altitude of flying object (meters): "))
altitude_meters = user_altitude

meters_knots = mps * 1.94384
true_airspeed = meters_knots
mach_number = [true_airspeed / x for x in speed_sound]
mach = mach_number
regimes = ['Subsonic', 'Transonic', 'Supersonic', 'Hypersonic']
meter_foot_conversion = altitude_meters * 3.28084 # Converts from meters to feet
mps_mph_conversion = mps * 2.23694 # Converts from mps to mph
mps_knots_conversion = mps * 1.94384 # Converts from mps to knots

master_list = [
    ["Altitude", "Temperature", "Pressure   ", "Density ", "Speed of Sound", "Mach Number" ],
    [meter_foot_conversion, "(ft)", temp_kelvin[0], "(K)", pressure[0], "(Pa)", density[0], "(d)", speed_sound[0], "(a)", "%.1f" % mach_number[0], "(M)"],
    [meter_foot_conversion, "(ft)", temp_kelvin[1], "(K)", pressure[1], "(Pa)", density[1], "(d)", speed_sound[1], "(a)", "%.1f" % mach_number[1], "(M)"],
    [meter_foot_conversion, "(ft)", temp_kelvin[2], "(K)", pressure[2], "(Pa)", density[2], "(d)", speed_sound[2], "(a)", "%.1f" % mach_number[2], "(M)"],
    [meter_foot_conversion, "(ft)", temp_kelvin[3], "(K)", pressure[3], "(Pa)", density[3], "(d)", speed_sound[3], "(a)", "%.1f" % mach_number[3], "(M)"],
    [meter_foot_conversion, "(ft)", temp_kelvin[4], "(K)", pressure[4], "(Pa)", density[4], "(d)", speed_sound[4], "(a)", "%.1f" % mach_number[4], "(M)"],
    [meter_foot_conversion, "(ft)", temp_kelvin[5], "(K)", pressure[5], "(Pa)", density[5], "(d)", speed_sound[5], "(a)", "%.1f" % mach_number[5], "(M)"],
    [meter_foot_conversion, "(ft)", temp_kelvin[6], "(K)", pressure[6], "(Pa)", density[6], "(d)", speed_sound[6], "(a)", "%.1f" % mach_number[6], "(M)"],
    [meter_foot_conversion, "(ft)", temp_kelvin[7], "(K)", pressure[7], "(Pa)", density[7], "(d)", speed_sound[7], "(a)", "%.1f" % mach_number[7], "(M)"],
    [meter_foot_conversion, "(ft)", temp_kelvin[8], "(K)", pressure[8], "(Pa)", density[8], "(d)", speed_sound[8], "(a)", "%.1f" % mach_number[8], "(M)"],
    [meter_foot_conversion, "(ft)", temp_kelvin[9], "(K)", pressure[9], "(Pa)", density[9], "(d)", speed_sound[9], "(a)", "%.1f" % mach_number[9], "(M)"],
    [meter_foot_conversion, "(ft)", temp_kelvin[10], "(K)", pressure[10], "(Pa)", density[10], "(d)", speed_sound[10], "(a)", "%.1f" % mach_number[10], "(M)"],
    [meter_foot_conversion, "(ft)", temp_kelvin[11], "(K)", pressure[11], "(Pa)", density[11], "(d)", speed_sound[11], "(a)", "%.1f" % mach_number[11], "(M)"],
    [meter_foot_conversion, "(ft)", temp_kelvin[12], "(K)", pressure[12], "(Pa)", density[12], "(d)", speed_sound[12], "(a)", "%.1f" % mach_number[12], "(M)"],
    [meter_foot_conversion, "(ft)", temp_kelvin[13], "(K)", pressure[13], "(Pa)", density[13], "(d)", speed_sound[13], "(a)", "%.1f" % mach_number[13], "(M)"],
    [meter_foot_conversion, "(ft)", temp_kelvin[14], "(K)", pressure[14], "(Pa)", density[14], "(d)", speed_sound[14], "(a)", "%.1f" % mach_number[14], "(M)"],
    [meter_foot_conversion, "(ft)", temp_kelvin[15], "(K)", pressure[15], "(Pa)", density[15], "(d)", speed_sound[15], "(a)", "%.1f" % mach_number[15], "(M)"],
    [meter_foot_conversion, "(ft)", temp_kelvin[16], "(K)", pressure[16], "(Pa)", density[16], "(d)", speed_sound[16], "(a)", "%.1f" % mach_number[16], "(M)"],
    [meter_foot_conversion, "(ft)", temp_kelvin[17], "(K)", pressure[17], "(Pa)", density[17], "(d)", speed_sound[17], "(a)", "%.1f" % mach_number[17], "(M)"],
    [meter_foot_conversion, "(ft)", temp_kelvin[18], "(K)", pressure[18], "(Pa)", density[18], "(d)", speed_sound[18], "(a)", "%.1f" % mach_number[18], "(M)"],
    [meter_foot_conversion, "(ft)", temp_kelvin[19], "(K)", pressure[19], "(Pa)", density[19], "(d)", speed_sound[19], "(a)", "%.1f" % mach_number[19], "(M)"],
    [meter_foot_conversion, "(ft)", temp_kelvin[20], "(K)", pressure[20], "(Pa)", density[20], "(d)", speed_sound[20], "(a)", "%.1f" % mach_number[20], "(M)"],
    [meter_foot_conversion, "(ft)", temp_kelvin[21], "(K)", pressure[21], "(Pa)", density[21], "(d)", speed_sound[21], "(a)", "%.1f" % mach_number[21], "(M)"],
    [meter_foot_conversion, "(ft)", temp_kelvin[22], "(K)", pressure[22], "(Pa)", density[22], "(d)", speed_sound[22], "(a)", "%.1f" % mach_number[22], "(M)"],
    [meter_foot_conversion, "(ft)", temp_kelvin[23], "(K)", pressure[23], "(Pa)", density[23], "(d)", speed_sound[23], "(a)", "%.1f" % mach_number[23], "(M)"],
    [meter_foot_conversion, "(ft)", temp_kelvin[24], "(K)", pressure[24], "(Pa)", density[24], "(d)", speed_sound[24], "(a)", "%.1f" % mach_number[24], "(M)"],
    [meter_foot_conversion, "(ft)", temp_kelvin[25], "(K)", pressure[25], "(Pa)", density[25], "(d)", speed_sound[25], "(a)", "%.1f" % mach_number[25], "(M)"],
    [meter_foot_conversion, "(ft)", temp_kelvin[26], "(K)", pressure[26], "(Pa)", density[26], "(d)", speed_sound[26], "(a)", "%.1f" % mach_number[26], "(M)"],
    [meter_foot_conversion, "(ft)", temp_kelvin[27], "(K)", pressure[27], "(Pa)", density[27], "(d)", speed_sound[27], "(a)", "%.1f" % mach_number[27], "(M)"],
    [meter_foot_conversion, "(ft)", temp_kelvin[28], "(K)", pressure[28], "(Pa)", density[28], "(d)", speed_sound[28], "(a)", "%.1f" % mach_number[28], "(M)"]
]

atmospheric_layers = ['Exosphere', 'Thermosphere', 'Mesosphere', 'Stratosphere', 'Troposphere']
cloud_type = ['Cirrocumulus', 'Cirrostratus', 'Cirrus', 'Altostratus', 'Altocumulus', 'Nimbostratus', 'Cumulonimbus',
              'Cumulus', 'Stratus', 'no']
atmospheric_layers_gases = [
    [atmospheric_gases[9], atmospheric_gases[6], atmospheric_gases[4], atmospheric_gases[1], atmospheric_gases[0]],
    [atmospheric_gases[1], atmospheric_gases[0], atmospheric_gases[6], atmospheric_gases[9]],
    [atmospheric_gases[1], atmospheric_gases[0], atmospheric_gases[6], atmospheric_gases[9]],
    [atmospheric_gases[1], atmospheric_gases[0], atmospheric_gases[6], atmospheric_gases[9], atmospheric_gases[12],
     atmospheric_gases[16]],
    [atmospheric_gases[1], atmospheric_gases[0], atmospheric_gases[6], atmospheric_gases[9], atmospheric_gases[2],
     atmospheric_gases[13], atmospheric_gases[3], atmospheric_gases[4]],
]
ionospheric_layer = ['F Layer', 'E Layer', 'D Layer']
f_layer = [150000, 500000]
e_layer = [88000, 144000]
d_layer = [40000, 87000]

precipitation_type = [
    'None', 'Light Rain', 'Heavy Rain', 'Light Snow', 'Heavy Snow', 'Hail'
]
################################################################################
#                                                                              #
#                         Display aerodynamic variables                        #
#                                                                              #
################################################################################
print("")
print("""
####################################################################################################
#                                                                                                  #
#                                       Aerodynamic Variables                                      #
#                                                                                                  #
####################################################################################################
    """)

print("Altitude: ", "%.0f" % user_altitude, "meters (", "%.0f" % meter_foot_conversion, "ft )")
print("Velocity: ", "%.0f" % mps, "meters per second (", "%.0f" % mps_mph_conversion, "mph,",
      "%.0f" % mps_knots_conversion, "knots)")
print("")

print("""
####################################################################################################
#                                                                                                  #
#                                       Atmospheric Variables                                      #
#                                                                                                  #
####################################################################################################
    """)

print("")
if meter_foot_conversion >= 100000:
    print("Altitude:", "%.0f" % user_altitude, "meters (", meter_foot_conversion, "ft )")
    print("Temperature:", "%.0f" % temp_kelvin[28], "K")
    print("Pressure:", "%.0f" % pressure[28], "Pa")
    print("Density:", "%.4f" % density[28], "d")
    print("Speed of Sound:", "%.1f" % speed_sound[28], "a")
    print("Mach Number:", "%.1f" % mach_number[28], "M")

elif meter_foot_conversion >= 95000:
    print("Altitude:", "%.0f" % user_altitude, "meters (", meter_foot_conversion, "ft )")
    print("Temperature:", "%.0f" % temp_kelvin[27], "K")
    print("Pressure:", "%.0f" % pressure[27], "Pa")
    print("Density:", "%.4f" % density[27], "d")
    print("Speed of Sound:", "%.1f" % speed_sound[27], "a")
    print("Mach Number:", "%.1f" % mach_number[27], "M")

elif meter_foot_conversion >= 90000:
    print("Altitude: ",  " % .0f" % user_altitude, "meters (", meter_foot_conversion, "ft )")
    print("Temperature:", "%.0f" % temp_kelvin[26], "K")
    print("Pressure:", "%.0f" % pressure[26], "Pa")
    print("Density:", "%.4f" % density[26], "d")
    print("Speed of Sound:", "%.1f" % speed_sound[26], "a")
    print("Mach Number:", "%.1f" % mach_number[26], "M")

elif meter_foot_conversion >= 85000:
    print("Altitude:", "%.0f" % user_altitude, "meters (", meter_foot_conversion, "ft )")
    print("Temperature:", "%.0f" % temp_kelvin[25], "K")
    print("Pressure:", "%.0f" % pressure[25], "Pa")
    print("Density:", "%.4f" % density[25], "d")
    print("Speed of Sound:", "%.1f" % speed_sound[25], "a")
    print("Mach Number:", "%.1f" % mach_number[25], "M")

elif meter_foot_conversion >= 80000:
    print("Altitude:", "%.0f" % user_altitude, "meters (", meter_foot_conversion, "ft )")
    print("Temperature:", "%.0f" % temp_kelvin[24], "K")
    print("Pressure:", "%.0f" % pressure[24], "Pa")
    print("Density:", "%.4f" % density[24], "d")
    print("Speed of Sound:", "%.1f" % speed_sound[24], "a")
    print("Mach Number:", "%.1f" % mach_number[24], "M")

elif meter_foot_conversion >= 75000:
    print("Altitude: ",  " %.0f" % user_altitude, "meters (", meter_foot_conversion, "ft )")
    print("Temperature:", "%.0f" % temp_kelvin[23], "K")
    print("Pressure:", "%.0f" % pressure[23], "Pa")
    print("Density:", "%.4f" % density[23], "d")
    print("Speed of Sound:", "%.1f" % speed_sound[23], "a")
    print("Mach Number:", "%.1f" % mach_number[23], "M")

elif meter_foot_conversion >= 70000:
    print("Altitude:", "%.0f" % user_altitude, "meters (", meter_foot_conversion, "ft )")
    print("Temperature:", "%.0f" % temp_kelvin[22], "K")
    print("Pressure:", "%.0f" % pressure[22], "Pa")
    print("Density:", "%.4f" % density[22], "d")
    print("Speed of Sound:", "%.1f" % speed_sound[22], "a")
    print("Mach Number:", "%.1f" % mach_number[22], "M")

elif meter_foot_conversion >= 65000:
    print("Altitude:", "%.0f" % user_altitude, "meters (", meter_foot_conversion, "ft )")
    print("Temperature:", "%.0f" % temp_kelvin[21], "K")
    print("Pressure:", "%.0f" % pressure[21], "Pa")
    print("Density:", "%.4f" % density[21], "d")
    print("Speed of Sound:", "%.1f" % speed_sound[21], "a")
    print("Mach Number:", "%.1f" % mach_number[21], "M")

elif meter_foot_conversion >= 60000:
    print("Altitude:", "%.0f" % user_altitude, "meters (", meter_foot_conversion, "ft )")
    print("Temperature:", "%.0f" % temp_kelvin[20], "K")
    print("Pressure:", "%.0f" % pressure[20], "Pa")
    print("Density:", "%.4f" % density[20], "d")
    print("Speed of Sound:", "%.1f" % speed_sound[20], "a")
    print("Mach Number:", "%.1f" % mach_number[20], "M")

elif meter_foot_conversion >= 55000:
    print("Altitude:", "%.0f" % user_altitude, "meters (", meter_foot_conversion, "ft )")
    print("Temperature:", "%.0f" % temp_kelvin[19], "K")
    print("Pressure:", "%.0f" % pressure[19], "Pa")
    print("Density:", "%.4f" % density[19], "d")
    print("Speed of Sound:", "%.1f" % speed_sound[19], "a")
    print("Mach Number:", "%.1f" % mach_number[19], "M")

elif meter_foot_conversion >= 50000:
    print("Altitude:", "%.0f" % user_altitude, "meters (", meter_foot_conversion, "ft )")
    print("Temperature:", "%.0f" % temp_kelvin[18], "K")
    print("Pressure:", "%.0f" % pressure[18], "Pa")
    print("Density:", "%.4f" % density[18], "d")
    print("Speed of Sound:", "%.1f" % speed_sound[18], "a")
    print("Mach Number:", "%.1f" % mach_number[18], "M")

elif meter_foot_conversion >= 45000:
    print("Altitude:", "%.0f" % user_altitude, "meters (", meter_foot_conversion, "ft )")
    print("Temperature:", "%.0f" % temp_kelvin[17], "K")
    print("Pressure:", "%.0f" % pressure[17], "Pa")
    print("Density:", "%.4f" % density[17], "d")
    print("Speed of Sound:", "%.1f" % speed_sound[17], "a")
    print("Mach Number:", "%.1f" % mach_number[17], "M")

elif meter_foot_conversion >= 40000:
    print("Altitude:", "%.0f" % user_altitude, "meters (", meter_foot_conversion, "ft )")
    print("Temperature:", "%.0f" % temp_kelvin[16], "K")
    print("Pressure:", "%.0f" % pressure[16], "Pa")
    print("Density:", "%.4f" % density[16], "d")
    print("Speed of Sound:", "%.1f" % speed_sound[17], "a")
    print("Mach Number:", "%.1f" % mach_number[16], "M")

elif meter_foot_conversion >= 35000:
    print("Altitude:", "%.0f" % user_altitude, "meters (", meter_foot_conversion, "ft )")
    print("Temperature:", "%.0f" % temp_kelvin[15], "K")
    print("Pressure:", "%.0f" % pressure[15], "Pa")
    print("Density:", "%.4f" % density[15], "d")
    print("Speed of Sound:", "%.1f" % speed_sound[15], "a")
    print("Mach Number:", "%.1f" % mach_number[15], "M")

elif meter_foot_conversion >= 30000:
    print("Altitude:", "%.0f" % user_altitude, "meters (", meter_foot_conversion, "ft )")
    print("Temperature:", "%.0f" % temp_kelvin[14], "K")
    print("Pressure:", "%.0f" % pressure[14], "Pa")
    print("Density:", "%.4f" % density[14], "d")
    print("Speed of Sound:", "%.1f" % speed_sound[14], "a")
    print("Mach Number:", "%.1f" % mach_number[14], "M")

elif meter_foot_conversion >= 25000:
    print("Altitude:", "%.0f" % user_altitude, "meters (", meter_foot_conversion, "ft )")
    print("Temperature:", "%.0f" % temp_kelvin[13], "K")
    print("Pressure:", "%.0f" % pressure[13], "Pa")
    print("Density:", "%.4f" % density[13], "d")
    print("Speed of Sound:", "%.1f" % speed_sound[13], "a")
    print("Mach Number:", "%.1f" % mach_number[13], "M")

elif meter_foot_conversion >= 20000:
    print("Altitude:", "%.0f" % user_altitude, "meters (", meter_foot_conversion, "ft )")
    print("Temperature:", "%.0f" % temp_kelvin[12], "K")
    print("Pressure:", "%.0f" % pressure[12], "Pa")
    print("Density:", "%.4f" % density[12], "d")
    print("Speed of Sound:", "%.1f" % speed_sound[12], "a")
    print("Mach Number:", "%.1f" % mach_number[12], "M")

elif meter_foot_conversion >= 15000:
    print("Altitude:", "%.0f" % user_altitude, "meters (", meter_foot_conversion, "ft )")
    print("Temperature:", "%.0f" % temp_kelvin[11], "K")
    print("Pressure:", "%.0f" % pressure[11], "Pa")
    print("Density:", "%.4f" % density[11], "d")
    print("Speed of Sound:", "%.1f" % speed_sound[11], "a")
    print("Mach Number:", "%.1f" % mach_number[11], "M")

elif meter_foot_conversion >= 10000:
    print("Altitude:", "%.0f" % user_altitude, "meters (", meter_foot_conversion, "ft )")
    print("Temperature:", "%.0f" % temp_kelvin[10], "K")
    print("Pressure:", "%.0f" % pressure[10], "Pa")
    print("Density:", "%.4f" % density[10], "d")
    print("Speed of Sound:", "%.1f" % speed_sound[10], "a")
    print("Mach Number:", "%.1f" % mach_number[10], "M")

elif meter_foot_conversion >= 9000:
    print("Altitude:", "%.0f" % user_altitude, "meters (", meter_foot_conversion, "ft )")
    print("Temperature:", "%.0f" % temp_kelvin[9], "K")
    print("Pressure:", "%.0f" % pressure[9], "Pa")
    print("Density:", "%.4f" % density[9], "d")
    print("Speed of Sound:", "%.1f" % speed_sound[9], "a")
    print("Mach Number:", "%.1f" % mach_number[9], "M")

elif meter_foot_conversion >= 8000:
    print("Altitude:", "%.0f" % user_altitude, "meters (", meter_foot_conversion, "ft )")
    print("Temperature:", "%.0f" % temp_kelvin[8], "K")
    print("Pressure:", "%.0f" % pressure[8], "Pa")
    print("Density:", "%.4f" % density[8], "d")
    print("Speed of Sound:", "%.1f" % speed_sound[8], "a")
    print("Mach Number:", "%.1f" % mach_number[8], "M")

elif meter_foot_conversion >= 7000:
    print("Altitude:", "%.0f" % user_altitude, "meters (", meter_foot_conversion, "ft )")
    print("Temperature:", "%.0f" % temp_kelvin[7], "K")
    print("Pressure:", "%.0f" % pressure[7], "Pa")
    print("Density:", "%.4f" % density[7], "d")
    print("Speed of Sound:", "%.1f" % speed_sound[7], "a")
    print("Mach Number:", "%.1f" % mach_number[7], "M")

elif meter_foot_conversion >= 6000:
    print("Altitude:", "%.0f" % user_altitude, "meters (", meter_foot_conversion, "ft )")
    print("Temperature:", "%.0f" % temp_kelvin[6], "K")
    print("Pressure:", "%.0f" % pressure[6], "Pa")
    print("Density:", "%.4f" % density[6], "d")
    print("Speed of Sound:", "%.1f" % speed_sound[6], "a")
    print("Mach Number:", "%.1f" % mach_number[6], "M")

elif meter_foot_conversion >= 5000:
    print("Altitude:", "%.0f" % user_altitude, "meters (", meter_foot_conversion, "ft )")
    print("Temperature:", "%.0f" % temp_kelvin[5], "K")
    print("Pressure:", "%.0f" % pressure[5], "Pa")
    print("Density:", "%.4f" % density[5], "d")
    print("Speed of Sound:", "%.1f" % speed_sound[5], "a")
    print("Mach Number:", "%.1f" % mach_number[5], "M")

elif meter_foot_conversion >= 4000:
    print("Altitude:", "%.0f" % user_altitude, "meters (", meter_foot_conversion, "ft )")
    print("Temperature:", "%.0f" % temp_kelvin[4], "K")
    print("Pressure:", "%.0f" % pressure[4], "Pa")
    print("Density:", "%.4f" % density[4], "d")
    print("Speed of Sound:", "%.1f" % speed_sound[4], "a")
    print("Mach Number:", "%.1f" % mach_number[4], "M")

elif meter_foot_conversion >= 3000:
    print("Altitude:", "%.0f" % user_altitude, "meters (", meter_foot_conversion, "ft )")
    print("Temperature:", "%.0f" % temp_kelvin[3], "K")
    print("Pressure:", "%.0f" % pressure[3], "Pa")
    print("Density:", "%.4f" % density[3], "d")
    print("Speed of Sound:", "%.1f" % speed_sound[3], "a")
    print("Mach Number:", "%.1f" % mach_number[3], "M")

elif meter_foot_conversion >= 2000:
    print("Altitude:", "%.0f" % user_altitude, "meters (", meter_foot_conversion, "ft )")
    print("Temperature:", "%.0f" % temp_kelvin[2], "K")
    print("Pressure:", "%.0f" % pressure[2], "Pa")
    print("Density:", "%.4f" % density[2], "d")
    print("Speed of Sound:", "%.1f" % speed_sound[2], "a")
    print("Mach Number:", "%.1f" % mach_number[2], "M")

elif meter_foot_conversion >= 1000:
    print("Altitude:", "%.0f" % user_altitude, "meters (", meter_foot_conversion, "ft )")
    print("Temperature:", "%.0f" % temp_kelvin[1], "K")
    print("Pressure:", "%.0f" % pressure[1], "Pa")
    print("Density:", "%.4f" % density[1], "d")
    print("Speed of Sound:", "%.1f" % speed_sound[1], "a")
    print("Mach Number:", "%.1f" % mach_number[1], "M")

elif meter_foot_conversion >= 0:
    print("Altitude:", "%.0f" % user_altitude, "meters (", meter_foot_conversion, "ft )")
    print("Temperature:", "%.0f" % temp_kelvin[0], "K")
    print("Pressure:", "%.0f" % pressure[0], "Pa")
    print("Density:", "%.4f" % density[0], "d")
    print("Speed of Sound:", "%.1f" % speed_sound[0], "a")
    print("Mach Number:", "%.1f" % mach_number[0], "M")
    print("")

# This section will display the atmospheric layer the flying object is located in (based on user input)
if user_altitude < 190000000 and user_altitude >= 525000:
    print("The object is currently located in the", atmospheric_layers[0])
    print("Atmospheric gases at this altitude consist of:", atmospheric_layers_gases[0])
elif user_altitude < 525000 and user_altitude >= 80000:
    print("The object is currently located in the", atmospheric_layers[1])
    print("Atmospheric gases at this altitude consist of:", atmospheric_layers_gases[1])
elif user_altitude < 80000 and user_altitude >= 50000:
    print("The object is currently located in the", atmospheric_layers[2])
    print("Atmospheric gases at this altitude consist of:", atmospheric_layers_gases[2])
elif user_altitude < 50000 and user_altitude >= 13000:
    print("The object is currently located in the", atmospheric_layers[3])
    print("Atmospheric gases at this altitude consist of:", atmospheric_layers_gases[3])
elif user_altitude < 13000 and user_altitude > 0:
    print("The object is currently located in the", atmospheric_layers[4])
    print("Atmospheric gases at this altitude consist of:", atmospheric_layers_gases[4])
else:
    print("The object is not located within Earth's atmosphere")

# This section will list the types of clouds appearing at this altitude
if user_altitude >= 46000:
    print("There are", cloud_type[9], "clouds at this altitude.")
elif user_altitude >= 45000:
    print("At this altitude there are", cloud_type[0], "clouds,", cloud_type[1], "clouds and", cloud_type[2], "clouds.")
elif user_altitude >= 16500:
    print("At this altitude there are", cloud_type[3], "clouds.")
elif user_altitude >= 15000:
    print("At this altitude there are", cloud_type[4], "clouds.")
elif user_altitude >= 10000:
    print("At this altitude there are", cloud_type[5], "clouds,", cloud_type[6], "clouds, and", cloud_type[7], "clouds.")
elif user_altitude >= 3000:
    print("At this altitude there are", cloud_type[8], "clouds.")
elif user_altitude < 3000:
    print("Cloud formation does not occur at this altitude.")

# Display ionospheric layer
if user_altitude >= 500000:
    print("At this altitude there are no gas molecules to ionize")
elif user_altitude < 500000 and user_altitude >= 150000:
    print("The uppermost layer of the ionosphere (", ionospheric_layer[0], ") is divided into two layers: F1 and F2 Layers.")
elif user_altitude <= 444000 and user_altitude >= 88000:
    print("The second layer of the ionosphere (", ionospheric_layer[1], ") reflects radio waves with little to no cost "
                                                                          "and is vital for long-distance communications.")
elif user_altitude < 87000 and user_altitude > 40000:
    print("The bottom-most layer of the ionosphere (", ionospheric_layer[2], ") is characterized by relatively weak ionization.")
else:
    print("Molecules are too densly packed for ionization to occur at this altitude.")

# Include the Van Allen radiation belts
radiation_belts = ['Outer Radiation Belt', 'Inner Radiation Belt']
if user_altitude > 15000000 and user_altitude < 24400000:
    print("The object is currently located within the", radiation_belts[0])
elif user_altitude > 1000000 and user_altitude < 4500000:
    print("The object is currently located within the", radiation_belts[1])
else:
    print("")


Johnathan Nicolosi - 20 Sep 2018