PLANETS tutorial

Author: Aymeric SPIGA

This tutorial explains how to use the planets utilities written in python. This package would be useful to anyone interested in an easy way to get and manipulate planetary constants in python scripts and interactive use with ipython. Note that the planets package is inspired from one of the package in R. Pierrehumbert python suite in support of the book Principles of Planetary Climates.

NB: If you have `ipython notebook` installed on your computer, download and use this tutorial interactively with the command `ipython notebook planets_tutorial.ipynb`

First and foremost, import the planets package by the command


In [1]:
import planets

Side use: physical constants

It is always useful to have a handful of physical constants around: this is not the goal of planets - still you will appreciate this possibility in further calculations.


In [2]:
print planets.h # Planck's constant
print planets.c # Speed of light


6.62607554e-34
299792458.0

In [3]:
print planets.k # Boltzman thermodynamic constant
print planets.sigma # Boltzman thermodynamic constant
print planets.G # Gravitational constant
print planets.N_avogadro # Avogadro's number
print planets.Rstarkilo # Universal gas constant


1.38065812e-23
5.67051196e-08
6.67428e-11
6.022136736e+23
8314.51198431

Main use: planetary constants and calculations

It is pretty straightforward to import planetary constants for any planet. Let us choose Venus as an example.


In [4]:
myplanet = planets.Venus

Note that the command above + the import line can be equivalently obtained with the pretty intuitive alternative

from planets import Venus as myplanet

Nevertheless this method is less flexible than the one indicated above, in which you have access to the whole planets variables and functions.</small>

OK, now you have loaded a Planet python object named myplanet and its attributes are set to the preset Venus values. The list of parameters in each Planet object can be obtained with the show() method.


In [5]:
myplanet.show()


dryadiab 0.00985555555556 dry adiabatic lapse rate
ascend 76.68069 Longitude of ascending node (deg)
obliquity 177.36 Obliquity to orbit (degrees)
year 19414166.4 Sidereal length of year (s)
cp 900.0 Specific heat capacity (J kg-1 K-1)
albedo 0.75 Bond albedo (fraction)
Tsmax 737.0 Maximum surface temperature (K)
date_peri 2014-09-05 00:00:00 Date of perihelion
incl 3.39471 Orbit inclination (deg)
rsm 1.0821e+11 Semi-major axis of orbit about Sun (m)
M 43.34 Molecular weight (g/mol)
L 2613.9 Annual mean solar constant (current) (W/m**2)
T0 300.0 Typical atmospheric temperature (K)
Tsbar 737.0 Mean surface temperature (K)
eccentricity 0.0067 Eccentricity (unitless)
date_equi 2014-08-02 00:00:00 Date of equinox
omega 6.22886956458e-07 planetary rotation rate
day 10087200.0 Mean tropical length of day (s)
Lequinox None Longitude of equinox (degrees)
a 6051800.0 Mean radius of planet (m)
name Venus Name of the planet
g 8.87 Surface gravitational acceleration (m/s**2)
omeg 131.53298 Argument of periapsis (deg)
R 191.843839047 planetary gas constant

Now each of those parameter is easy to get from the attribute variable indicated in the left column. For instance, get the mean radius of the planet.


In [6]:
print myplanet.a


6051800.0

If you are unsure about the units, you can still get the description by typing


In [7]:
print planets.desc["a"]


Mean radius of planet (m)

So now it is fairly easy to work out a calculation ! One example. Compute the equivalent temperature $$T_{eq} = \left( \frac{(1-A)F}{4\sigma} \right)^{\frac{1}{4}}$$


In [8]:
teq = ( ( (1-myplanet.albedo)*myplanet.L ) / (4*planets.sigma) )**0.25
print teq


231.679004728

Actually this is already coded in planets because it is a quantity planetary scientists often use. Thus to compute equivalent temperature, you can simply use the method eqtemp()


In [9]:
teq = myplanet.eqtemp()
print teq


231.679004728

The additional cool point of setting up a method is that it is easy to display values for a bunch of preset planets


In [10]:
print planets.Earth.eqtemp()
print planets.Mars.eqtemp()
print planets.Venus.eqtemp()
print planets.Saturn.eqtemp()


254.336725223
210.092444789
231.679004728
81.0834977726

New methods are often added to planets. Check for the source for this. Other examples of methods available at the time of writing are


In [11]:
print myplanet.H() # atmospheric scale height
print myplanet.N2() # Brunt-Väisälä frequency


6488.51766789
0.000291395925926

Those methods have additional arguments. For instance you can change the temperature (in Kelvin) for the atmospheric scale height


In [14]:
print myplanet.H(T0=273.)


5904.55107778

This works also with an array of temperature values temp. Hence myplanet.H(T0=temp) will be an array of scale height values with the same dimensions as temp.

Customize planetary constants

The values of preset planetary constants can be modified (because, well, those are constants to a certain point, or measured with a given accuracy, or subject to change with new missions) in the text files located in the planet folder.

The use of text files to set planetary constants allows for a very flexible use. You might even set your own Planet object with your user-defined planetary constants, which a pretty useful feature in an universe in which we get to discover more and more exoplanets. Here is how to do that. Let us assume you want to create a set of planetary constant for HD189733b

1. Open a file HD189733b.txt
2. Fill it with constants (look the existing files in the `planet` folder for templates)
3. Put this file in the planet folder (or have it where you work out your computations)

The new planet is now available in planets! Simply set a Planet object (name it the way you want) and load the values for the chosen planet with the ini() method. Then you can use all the available variables and methods associated to the object.

a_hot_jupiter = Planet()
a_hot_jupiter.ini("HD189733b")
print a_hot_jupiter.L
print a_hot_jupiter.eqtemp()

Note that if one particular planetary constant is missing in the text file, it will be set to None by default.

Concluding remark

planets is still a work in progress. Should you have bug fixes - or useful txt files for missing planetary environments, please feel free to drop me an email.