<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 python package for the Mars Climate Database
Step1:  Step 2 create your request
Step2:  Step 3 set the coordinates for your request (for instance, let us choose Curiosity landing site)
Step3:  Step 4 retrieve fields from the Mars Climate Database (all fields are stored in the req object)
Step4:  Step 5 print requested results
Requested coordinates (for a reminder)
Step5:  Main atmospheric variables
Step6:  Shortcut
Step7:  The extvar number can also be used to inquire a specific variable (see Fortran sources).
Step8:  Another way to inquire for a specific variable is through a string.
Step9:  Print all field
Step10:  1D slices
Request 1D plot of diurnal cycle for one variable ...
Step11:  ... and for several variables
Step12:  Request seasonal cycle (this takes a longer time)
~~~python
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)
Step13:  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
Step14:  1D slices
Step15:  2D mapping
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.
Step16:  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.
Step17:  Adding wind vectors can be done with the incwind argument.
Step18:  NB
Step19:  NB
Step20:  advanced diagnostics
Hövmoller plot
Step21:  Zonal average 
Step22:  Zonal average 
Step23:  see difference with following case
<ASSISTANT_TASK:>
Python Code:
from mcd import mcd
# This line configures matplotlib to show figures embedded in the notebook.
%matplotlib inline
Explanation: python package for the Mars Climate Database: how to use?
NB: to learn how to directly wrap within python the Fortran routine call_mcd compiled with f2py, look at the folder test_mcd
General steps to follow to use the mcd class
Step 1 import mcd class from mcd package
End of explanation
req = mcd()
Explanation: Step 2 create your request
End of explanation
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
Explanation: Step 3 set the coordinates for your request (for instance, let us choose Curiosity landing site)
End of explanation
req.update()
Explanation: Step 4 retrieve fields from the Mars Climate Database (all fields are stored in the req object)
End of explanation
req.printcoord()
Explanation: Step 5 print requested results
Requested coordinates (for a reminder)
End of explanation
req.printmeanvar()
Explanation: Main atmospheric variables
End of explanation
req.printmcd()
Explanation: Shortcut: req.printmcd() is equivalent to the three previous commands in a row (update+printcoord+printmeanvar)
End of explanation
req.printextvar(22)
Explanation: The extvar number can also be used to inquire a specific variable (see Fortran sources).
End of explanation
req.printextvar("tsurf")
Explanation: Another way to inquire for a specific variable is through a string.
End of explanation
req.printallextvar()
Explanation: Print all field
End of explanation
req.diurnal()
req.plot1d("t")
Explanation: 1D slices
Request 1D plot of diurnal cycle for one variable ...
End of explanation
req.plot1d(["t","p","u","v"])
Explanation: ... and for several variables
End of explanation
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")
Explanation: Request seasonal cycle (this takes a longer time)
~~~python
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)
End of explanation
tpot = req.temptab*((610./req.prestab)**(1.0/3.9))
print tpot
Explanation: 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
End of explanation
req = mcd()
req.diurnal()
req.getascii("t",filename="diurnal.txt")
%cat diurnal.txt ; rm -rf diurnal.txt
Explanation: 1D slices: ASCII outputs
It is easy to get ASCII files containing 1D slices. Say, for instance, diurnal cycle of temperature.
End of explanation
test = mcd()
test.loct = 15.
test.xz = 10000.
test.map2d("t")
Explanation: 2D mapping
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.
End of explanation
test.htmlmap2d("t")
Explanation: 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.
End of explanation
test.map2d("t",incwind=True)
Explanation: Adding wind vectors can be done with the incwind argument.
End of explanation
test.map2d(["t","u"])
Explanation: NB: map2d works with several variables
End of explanation
figname = test.getnameset()+'.png'
print figname
Explanation: NB: to save figures
~~~python
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
End of explanation
test = mcd()
test.xz = 50000.
test.lat = 20.
test.locts = 0.
test.locte = 24.
test.lons = -180.
test.lone = +180.
test.htmlplot2d("tsurf",figname="hov.png")
Explanation: advanced diagnostics
Hövmoller plot
End of explanation
test = mcd()
test.zonmean = True
test.lats = -90.
test.late = 90.
test.htmlplot2d("u",figname="zonm.png")
Explanation: Zonal average : lat/altitude figure
End of explanation
test = mcd()
test.zonmean = True
test.lats = -90.
test.late = 90.
test.xdates = 0.
test.xdatee = 360.
test.htmlplot2d("h2ovap",figname="zonmm.png")
Explanation: Zonal average : ls/lat figure
End of explanation
test.zonmean = False
test.lon = 0.
test.htmlplot2d("h2ovap",figname="hovls.png")
Explanation: see difference with following case
End of explanation
<END_TASK>