NB: to learn how to directly wrap within python the Fortran routine call_mcd compiled with f2py, look at the folder test_mcd
In [1]:
# This line configures matplotlib to show figures embedded in the notebook.
%matplotlib inline
In [2]:
from mcd import mcd
Step 2 create your request
In [3]:
req = mcd()
Step 3 set the coordinates for your request (for instance, let us choose Curiosity landing site)
In [4]:
req.lat = -4.6 # latitude
req.lon = 137.4 # longitude
req.loct = 15. # local time
req.xz = 1. # vertical coordinate
req.xdate = 150.6 # areocentric longitude
Step 4 retrieve fields from the Mars Climate Database (all fields are stored in the req object)
In [5]:
req.update()
Step 5 print requested results
In [6]:
req.printcoord()
In [7]:
req.printmeanvar()
req.printmcd() is equivalent to the three previous commands in a row (update+printcoord+printmeanvar)
In [8]:
req.printmcd()
In [9]:
req.printextvar(22)
In [10]:
req.printextvar("tsurf")
In [11]:
req.printallextvar()
Request 1D plot of diurnal cycle for one variable ...
In [12]:
req.diurnal()
req.plot1d("t")
... and for several variables
In [13]:
req.plot1d(["t","p","u","v"])
Request seasonal cycle (this takes a longer time)
req.seasonal()
req.plot1d(["tsurf","u","v"])
1D slicing also works for vertical profiles. Start and end of profile can be set easily
--- as well as the kind of vertical coordinate through the zkey variable (as in MCD Fortran routines)
In [14]:
req.xzs = -3500.
req.xze = 15000.
req.zkey = 2
req.lat = 25.
req.lon = 195.
req.loct = 4.2
req.xdate = 140.
req.profile(nd=50)
req.plot1d("t")
It is a good place here to remind you that any field stored in the Mars Climate Database is inside the req object.
This allows you to work out further calculations, e.g. to combine several variables to obtain new diagnostics.
Here is for instance a calculation for potential temperature
In [15]:
tpot = req.temptab*((610./req.prestab)**(1.0/3.9))
print tpot
In [16]:
req = mcd()
req.diurnal()
req.getascii("t",filename="diurnal.txt")
%cat diurnal.txt ; rm -rf diurnal.txt
Simple 2D longitude-latitude map with default cylindrical view. Map projections can be used, provided basemap is installed -- for instance, for Robinson projection add proj="robin" to the map2d call below.
In [17]:
test = mcd()
test.loct = 15.
test.xz = 10000.
test.map2d("t")
You can also use the method htmlmap2d that will create a PNG file with your figure in it. This is the function actually used in the online MCD interface.
In [18]:
test.htmlmap2d("t")
Adding wind vectors can be done with the incwind argument.
In [19]:
test.map2d("t",incwind=True)
NB: map2d works with several variables
In [20]:
test.map2d(["t","u"])
import matplotlib.pyplot as mpl
mpl.savefig("temp.png",dpi=85,bbox_inches='tight',pad_inches=0.25)
To obtain a name corresponding to the request
In [21]:
figname = test.getnameset()+'.png'
print figname