Chaotic Productions LLC

Bringing You The Future Of Design and Technology

PLANETARY SCIENCE USING PYTHON


In this tutorial we will explore the solar system using Python and popular data science libraries NumPy and Matplotlib, to perform various functions and to visualize planetary data.

Conspiracies | Game Design | Illustrations | Random Generators | Science and Technology | Secret History | Tutorials


Planetary Science Using Python

In this multi-part tutorial we will explore the solar system using Python and popular data science libraries NumPy and Matplotlib, to perform various functions and to visualize large amounts of planetary data. By the end of this tutorial, we will learn how to use Python to perform scientific calculations and hopefuly gain new insights into our eternal journey around the galactic core.

For ease of navigation, this tutorial is broken into the following sections:

Planetary Weight Calculator
Gravitational Acceleration
Effects of Gravity at Altitude
Sunspot Activity
Severe Weather Tracker

For consistincy, the calculations in this tutorial will be done using the metric system and converted to the Imperial system when necessary. If you are using the NASA Planetary Fact Sheet, don't forget to convert from diameter to radius for each celestial body.

# Calculate the radius by dividing the diameter by 2
radius_planet = diameter_planet / 2


Universal Constants

The following universal constants are used to perform various scientific calculations :

###################################################
#
# Speed of light (c) = 3 x 108 m/s
# Planck's constant (h) = 6.626 x 10-34 J - s
# Gravitational constant (G) = 6.67408 x 10-11 m3 kg3 s-2
# Gravitational parameter (μ) = 3.986 x 105 km3/s2
#
###################################################

speed_light = 3 * 10**8 # m/s
planck_constant = 6.626 * 10**-34 # J - s
gravitational_constant = 6.67408 * 10**-11 # m^3/kg^3 s^-2
gravitational_parameter_earth = 3.986 * 10**5 # km^3/s^2


Planetary Data

Planetary statistics can be found in any planetary science book or good physics book, but the internet is also a good place to search for planetary data. NASA offers planetary facts in metric and standard formats. We use the metric system for all scientific computing.

Planetary Fact Sheet
Planetary Body Mass (kg) Radius (km) Orbital Period (days) Rotation Period (hrs) Inclination (deg) Eccentricity Velocity (km/s) Mean Surface Temp (C) Distance from Sun (km)
Mercury 3.30 x 1023 2439 87.98 58.65 0 0.205 47.4 430 580 x 106
Venus 4.87 x 1024 6051 224.7 5832.24 117.4 0.007 35 480 108 x 106
Earth 5.98 x 1024 6378 365.36 24 23.5 0.017 29.8 22 150 x 106
Mars 6.42 x 1023 3393 686.98 24.56 23.98 0.094 24 -23 228 x 106
Jupiter 1.90 x 1027 71492 11.86 9.89 3.1 0.049 13.1 -150 778 x 106
Saturn 5.69 x 1026 60268 29.41 10.24 27 0.057 9.7 -80 1432 x 106
Uranus 8.68 x 1025 25559 84.04 17.25 97.9 0.046 6.8 -215 2871 x 106
Neptune 1.02 x 1026 24764 164.8 16.10 29.6 0.011 5.4 -220 4498 x 106
Sun 1.99 x 1030 696000 *** 24.47 - - 220 5600 -
Moon 7.35 x 1022 1738 27 648 6.7 0.055 1 127 (-173) **
*** Based on a distance of 30,000 light years, and travelling at a speed of 220 km/s, the Sun takes approximately 225 million years to orbit around the Milky Way.
** The Moon's average distance to Earth is 384,400 km (238,900 mi).
- Missing or incomplete data.

The above planetary data can be saved as a List or Dictionary. For example, we can save these parameters as either a list, or a list of lists. For our purposes, we will create lists of intergers, strings and lists of variables. These lists can then be used to by our scripts, displayed on the screen or plotted in bar or scatter charts using Matplotlib.

Begin by creating a list of strings, named planets to hold the names of each planet:

# List of known planets orbiting the sun
planets = ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune', 'Pluto']

Next, create a list of intergers to hold the planetary variables, such as the distance of each planet from the sun:

# Distance of planet from from sun (as list)
distance_sun = [58000000, 108000000, 150000000, 228000000, 778000000, 1432000000, 2871000000, 4498000000, 5914000000]

This data can then be visualized using the popular Matplotlib library.
import matplotlib.pyplot as plt

# List of known planets orbiting the sun
planets = ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune', 'Pluto']

# Distance of planet from from sun (as list)
distance_sun = [58000000, 108000000, 150000000, 228000000, 778000000, 1432000000, 2871000000, 4498000000, 5914000000]

plt.figure(1)
plt.barh(planets, distance_sun, color=(0.1, 0.1, 0.1, 0.1), edgecolor='blue')
plt.xlabel('Distance (km)')
plt.ylabel('Planets')
plt.title('Distance of each planet from the Sun')

######################################################
# This section turns off scientific notation from changing the xticks
######################################################
ax = plt.gca()
ax.get_xaxis().get_major_formatter().set_scientific(False)
######################################################

plt.show()



Looking at the above bar graph allows us to easily visualize the vast distances between planets. Upon closer inspection, we begin to see a pattern to the distances between the planets. It appears that a planet is missing in the spot where the Asteroid Belt is located, between Mars and Jupiter. In the next section of this tutorial we will explore different ways to calculate the weight of a spacecraft or other object on each planetary body.

Johnathan Nicolosi - 12 Jun 2018