source: trunk/UTIL/PYTHON/mcd/mcd.py @ 797

Last change on this file since 797 was 797, checked in by aslmd, 12 years ago

UTIL PYTHON: mcd interface, a more compact code. and added online handling of various vertical coordinates.

  • Property svn:executable set to *
File size: 23.4 KB
Line 
1####################################################
2### A Python Class for the Mars Climate Database ###
3### ---------------------------------------------###
4### Aymeric SPIGA 17-21/04/2012                  ###
5### ---------------------------------------------###
6### (see mcdtest.py for examples of use)         ###
7####################################################
8
9import numpy as np
10import fmcd
11import matplotlib.pyplot as mpl
12import myplot
13
14
15class mcd():
16 
17    def __repr__(self):
18    # print out a help string when help is invoked on the object
19        whatprint = 'MCD object. \"help(mcd)\" for more information\n'
20        return whatprint
21
22########################
23### Default settings ###
24########################
25
26    def __init__(self):
27    # default settings
28        ## 0. general stuff
29        self.name      = "MCD v4.3 output"
30        #self.dset      = '/home/aymeric/Science/MCD_v4.3/data/'
31        self.dset      = '/home/marshttp/MCD_v4.3/data/'
32        ## 1. spatio-temporal coordinates
33        self.lat       = 0.
34        self.lats      = None
35        self.late      = None
36        self.lon       = 0.
37        self.lons      = None
38        self.lone      = None
39        self.loct      = 0.
40        self.locts     = None
41        self.locte     = None
42        self.xdate     = 0.  # see datekey
43        self.xdates    = None
44        self.xdatee    = None
45        self.xz        = 10. # see zkey
46        self.xzs       = None
47        self.xze       = None
48        ## 1bis. related settings
49        self.zkey      = 3  # specify that xz is the altitude above surface (m)
50                            # zkey  : <integer>   type of vertical coordinate xz
51                            # 1 = radius from centre of planet (m)
52                            # 2 = height above areoid (m) (MOLA zero datum)
53                            # 3 = height above surface (m)
54                            # 4 = pressure level (Pa)
55                            # 5 = altitude above mean Mars Radius(=3396000m) (m)
56        self.datekey   = 1  # 0 = "Earth time": xdate is given in Julian days (localtime must be set to zero)
57                            # 1 = "Mars date": xdate is the value of Ls
58        ## 2. climatological options
59        self.dust      = 2  #our best guess MY24 scenario, with solar average conditions
60        self.hrkey     = 1  #set high resolution mode on (hrkey=0 to set high resolution off)
61        ## 3. additional settings for advanced use
62        self.extvarkey = 1  #extra output variables (1: yes, 0: no)
63        self.perturkey = 0  #integer perturkey ! perturbation type (0: none)
64        self.seedin    = 1  #random number generator seed (unused if perturkey=0)
65        self.gwlength  = 0. #gravity Wave wavelength (unused if perturkey=0)
66        ## outputs. just to define attributes.
67        ## --> in update
68        self.pres = None ; self.dens = None ; self.temp = None ; self.zonwind = None ; self.merwind = None ; self.meanvar = None ; self.extvar = None
69        self.seedout = None ; self.ierr = None
70        ## --> in prepare
71        self.xcoord = None ; self.ycoord = None
72        self.prestab = None ; self.denstab = None ; self.temptab = None 
73        self.zonwindtab = None ; self.merwindtab = None ; self.meanvartab = None ; self.extvartab = None
74
75    def viking1(self): self.name = "Viking 1 site. MCD v4.3 output" ; self.lat = 22.48 ; self.lon = -49.97 ; self.xdate = 97.
76    def viking2(self): self.name = "Viking 2 site. MCD v4.3 output" ; self.lat = 47.97 ; self.lon = -225.74 ; self.xdate = 117.6
77
78    def getextvarlab(self,num):
79        whichfield = { \
80        91: "Pressure (Pa)", \
81        92: "Density (kg/m3)", \
82        93: "Temperature (K)", \
83        94: "W-E wind component (m/s)", \
84        95: "S-N wind component (m/s)", \
85        1: "Radial distance from planet center (m)",\
86        2: "Altitude above areoid (Mars geoid) (m)",\
87        3: "Altitude above local surface (m)",\
88        4: "orographic height (m) (surface altitude above areoid)",\
89        5: "Ls, solar longitude of Mars (deg)",\
90        6: "LST local true solar time (hrs)",\
91        7: "Universal solar time (LST at lon=0) (hrs)",\
92        8: "Air heat capacity Cp (J kg-1 K-1)",\
93        9: "gamma=Cp/Cv Ratio of specific heats",\
94        10: "density RMS day to day variations (kg/m^3)",\
95        11: "[not defined]",\
96        12: "[not defined]",\
97        13: "scale height H(p) (m)",\
98        14: "GCM orography (m)",\
99        15: "surface temperature (K)",\
100        16: "daily maximum mean surface temperature (K)",\
101        17: "daily minimum mean surface temperature (K)",\
102        18: "surf. temperature RMS day to day variations (K)",\
103        19: "surface pressure (high resolution if hireskey=1)",\
104        20: "GCM surface pressure (Pa)",\
105        21: "atmospheric pressure RMS day to day variations (Pa)",\
106        22: "surface pressure RMS day to day variations (Pa)",\
107        23: "temperature RMS day to day variations (K)",\
108        24: "zonal wind RMS day to day variations (m/s)",\
109        25: "meridional wind RMS day to day variations (m/s)",\
110        26: "vertical wind component (m/s) >0 when downwards!",\
111        27: "vertical wind RMS day to day variations (m/s)",\
112        28: "small scale perturbation (gravity wave) (kg/m^3)",\
113        29: "q2: turbulent kinetic energy (m2/s2)",\
114        30: "[not defined]",\
115        31: "thermal IR flux to surface (W/m2)",\
116        32: "solar flux to surface (W/m2)",\
117        33: "thermal IR flux to space (W/m2)",\
118        34: "solar flux reflected to space (W/m2)",\
119        35: "surface CO2 ice layer (kg/m2)",\
120        36: "DOD: Dust column visible optical depth",\
121        37: "Dust mass mixing ratio (kg/kg)",\
122        38: "DOD RMS day to day variations",\
123        39: "DOD total standard deviation over season",\
124        40: "Water vapor column (kg/m2)",\
125        41: "Water vapor vol. mixing ratio (mol/mol)",\
126        42: "Water ice column (kg/m2)",\
127        43: "Water ice mixing ratio (mol/mol)",\
128        44: "O3 ozone vol. mixing ratio (mol/mol)",\
129        45: "[CO2] vol. mixing ratio (mol/mol)",\
130        46: "[O] vol. mixing ratio (mol/mol)",\
131        47: "[N2] vol. mixing ratio (mol/mol)",\
132        48: "[CO] vol. mixing ratio (mol/mol)",\
133        49: "R: Molecular gas constant (J K-1 kg-1)",\
134        50: "Air viscosity estimation (N s m-2)"
135        }
136        if num not in whichfield: myplot.errormess("Incorrect subscript in extvar.")
137        return whichfield[num]
138
139    def convertlab(self,num):       
140        ## a conversion from text inquiries to extvar numbers. to be completed.
141        if num == "p": num = 91
142        elif num == "rho": num = 92
143        elif num == "t": num = 93
144        elif num == "u": num = 94
145        elif num == "v": num = 95
146        elif num == "tsurf": num = 15
147        elif num == "topo": num = 4
148        elif num == "h": num = 13
149        elif num == "ps": num = 19
150        elif num == "tau": num = 36
151        elif num == "mtot": num = 40
152        elif num == "icetot": num = 42
153        elif num == "ps_ddv": num = 22
154        elif num == "h2ovap": num = 41
155        elif num == "h2oice": num = 43
156        elif num == "cp": num = 8
157        elif num == "rho_ddv": num = 10
158        elif num == "tsurfmx": num = 16
159        elif num == "tsurfmn": num = 17
160        elif num == "lwdown": num = 31
161        elif num == "swdown": num = 32
162        elif num == "lwup": num = 33
163        elif num == "swup": num = 34
164        elif num == "o3": num = 44
165        elif num == "o": num = 46
166        elif num == "co": num = 48
167        elif num == "visc": num = 50
168        elif num == "co2ice": num = 35
169        elif not isinstance(num, np.int): myplot.errormess("field reference not found.")
170        return num
171
172###################
173### One request ###
174###################
175
176    def update(self):
177    # retrieve fields from MCD (call_mcd). more info in fmcd.call_mcd.__doc__
178        (self.pres, self.dens, self.temp, self.zonwind, self.merwind, \
179         self.meanvar, self.extvar, self.seedout, self.ierr) \
180         = \
181         fmcd.call_mcd(self.zkey,self.xz,self.lon,self.lat,self.hrkey, \
182             self.datekey,self.xdate,self.loct,self.dset,self.dust, \
183             self.perturkey,self.seedin,self.gwlength,self.extvarkey )
184        ## we use the end of extvar (unused) to store meanvar. this is convenient for getextvar(lab)
185        self.extvar[90] = self.pres ; self.extvar[91] = self.dens
186        self.extvar[92] = self.temp ; self.extvar[93] = self.zonwind ; self.extvar[94] = self.merwind
187
188    def printset(self):
189    # print main settings
190        print "zkey",self.zkey,"xz",self.xz,"lon",self.lon,"lat",self.lat,"hrkey",self.hrkey, \
191              "xdate",self.xdate,"loct",self.loct,"dust",self.dust
192
193    def getnameset(self):
194    # set a name referring to settings [convenient for databases]
195        strlat = str(self.lat)+str(self.lats)+str(self.late)
196        strlon = str(self.lon)+str(self.lons)+str(self.lone)
197        strxz = str(self.xz)+str(self.xzs)+str(self.xze)
198        strloct = str(self.loct)+str(self.locts)+str(self.locte)
199        name = str(self.zkey)+strxz+strlon+strlat+str(self.hrkey)+str(self.datekey)+str(self.xdate)+strloct+str(self.dust)
200        return name
201
202    def printcoord(self):
203    # print requested space-time coordinates
204        print "LAT",self.lat,"LON",self.lon,"LOCT",self.loct,"XDATE",self.xdate
205
206    def printmeanvar(self):
207    # print mean MCD variables
208        print "Pressure = %5.3f pascals. " % (self.pres)
209        print "Density = %5.3f kilograms per cubic meter. " % (self.dens)
210        print "Temperature = %3.0f kelvins (%4.0f degrees celsius)." % (self.temp,self.temp-273.15)
211        print "Zonal wind = %5.3f meters per second." % (self.zonwind)
212        print "Meridional wind = %5.3f meters per second." % (self.merwind)
213
214    def printextvar(self,num):
215    # print extra MCD variables
216        num = self.convertlab(num)
217        print self.getextvarlab(num) + " ..... " + str(self.extvar[num-1])
218
219    def printallextvar(self):
220    # print all extra MCD variables   
221        for i in range(50): self.printextvar(i+1)
222
223    def htmlprinttabextvar(self,tabtodo):
224        print "Results from the Mars Climate Database"
225        print "<ul>"
226        for i in range(len(tabtodo)): print "<li>" ; self.printextvar(tabtodo[i]) ; print "</li>"
227        print "</ul>"
228        print "<hr>"
229        print "SETTINGS<br />"
230        self.printcoord()
231        self.printset()
232
233    def printmcd(self):
234    # 1. call MCD 2. print settings 3. print mean vars
235        self.update()
236        self.printcoord()
237        print "-------------------------------------------"
238        self.printmeanvar()
239
240########################
241### Several requests ###
242########################
243
244    def prepare(self,ndx=None,ndy=None):
245    ### prepare I/O arrays for 1d slices
246      if ndx is None:  print "No dimension in prepare. Exit. Set at least ndx." ; exit()
247      else:            self.xcoord = np.ones(ndx)
248      if ndy is None:  dashape = (ndx)     ; dashapemean = (ndx,6)     ; dashapeext = (ndx,101)     ; self.ycoord = None
249      else:            dashape = (ndx,ndy) ; dashapemean = (ndx,ndy,6) ; dashapeext = (ndx,ndy,101) ; self.ycoord = np.ones(ndy)
250      self.prestab = np.ones(dashape) ; self.denstab = np.ones(dashape) ; self.temptab = np.ones(dashape)
251      self.zonwindtab = np.ones(dashape) ; self.merwindtab = np.ones(dashape) 
252      self.meanvartab = np.ones(dashapemean) ; self.extvartab = np.ones(dashapeext)
253
254    def getextvar(self,num):
255    ### get a given var in extvartab
256      try: field=self.extvartab[:,:,num] 
257      except: field=self.extvartab[:,num]
258      return field
259
260    def definefield(self,choice):
261    ### for analysis or plot purposes, set field and field label from user-defined choice
262      choice = self.convertlab(choice)
263      field = self.getextvar(choice); fieldlab = self.getextvarlab(choice)
264      return field,fieldlab
265
266    def ininterv(self,dstart,dend,nd,start=None,end=None,yaxis=False):
267    ### user-defined start and end are used to create xcoord (or ycoord) vector
268      if start is not None and end is not None:  first, second = self.correctbounds(start,end)
269      else:                                      first, second = self.correctbounds(dstart,dend) 
270      if not yaxis: self.xcoord = np.linspace(first,second,nd)
271      else:         self.ycoord = np.linspace(first,second,nd)
272      ## here we should code the log axis for pressure
273
274    def correctbounds(self,start,end):
275      if self.zkey != 4:
276        # regular altitudes
277        if start > end: first = end ; second = start
278        else:           first = start ; second = end
279      else:
280        # pressure: reversed avis
281        if start < end: first = end ; second = start
282        else:           first = start ; second = end
283      return first, second
284
285###################
286### 1D analysis ###
287###################
288
289    def put1d(self,i):
290    ## fill in subscript i in output arrays
291    ## (arrays must have been correctly defined through prepare)
292      if self.prestab is None:  myplot.errormess("arrays must be prepared first through self.prepare")
293      self.prestab[i] = self.pres ; self.denstab[i] = self.dens ; self.temptab[i] = self.temp
294      self.zonwindtab[i] = self.zonwind ; self.merwindtab[i] = self.merwind
295      self.meanvartab[i,1:5] = self.meanvar[0:4]  ## note: var numbering according to MCD manual is kept
296      self.extvartab[i,1:100] = self.extvar[0:99] ## note: var numbering according to MCD manual is kept
297
298    def diurnal(self,nd=13):
299    ### retrieve a local time slice
300      self.xlabel = "Local time (Martian hour)"
301      self.prepare(ndx=nd) ; self.ininterv(0.,24.,nd,start=self.locts,end=self.locte) 
302      for i in range(nd): self.loct = self.xcoord[i] ; self.update() ; self.put1d(i)
303
304    def zonal(self,nd=37):
305    ### retrieve a longitude slice
306      self.xlabel = "East longitude (degrees)"
307      self.prepare(ndx=nd) ; self.ininterv(-180.,180.,nd,start=self.lons,end=self.lone)
308      for i in range(nd): self.lon = self.xcoord[i] ; self.update() ; self.put1d(i)
309
310    def meridional(self,nd=19):
311    ### retrieve a latitude slice
312      self.xlabel = "North latitude (degrees)"
313      self.prepare(ndx=nd) ; self.ininterv(-90.,90.,nd,start=self.lats,end=self.late)
314      for i in range(nd): self.lat = self.xcoord[i] ; self.update() ; self.put1d(i)
315
316    def profile(self,nd=20,tabperso=None):
317    ### retrieve an altitude slice (profile)
318      self.xlabel = "Altitude (m)"
319      if tabperso is not None: nd = len(tabperso)
320      correct = False
321      self.prepare(ndx=nd) ; self.ininterv(0.,120000.,nd,start=self.xzs,end=self.xze)
322      if tabperso is not None: self.xcoord = tabperso
323      for i in range(nd): self.xz = self.xcoord[i] ; self.update() ; self.put1d(i)
324
325    def seasonal(self,nd=12):
326    ### retrieve a seasonal slice
327      self.xlabel = "Areocentric longitude (degrees)"
328      self.prepare(ndx=nd) ; self.ininterv(0.,360.,nd,start=self.xdates,end=self.xdatee)
329      for i in range(nd): self.xdate = self.xcoord[i] ; self.update() ; self.put1d(i)
330
331    def makeplot1d(self,choice,vertplot=0):
332    ### one 1D plot is created for the user-defined variable in choice.
333      (field, fieldlab) = self.definefield(choice)
334      if vertplot != 1:  absc = self.xcoord ; ordo = field ; ordolab = fieldlab ; absclab = self.xlabel
335      else:              ordo = self.xcoord ; absc = field ; absclab = fieldlab ; ordolab = self.xlabel
336      mpl.plot(absc,ordo,'-bo') ; mpl.ylabel(ordolab) ; mpl.xlabel(absclab) #; mpl.xticks(query.xcoord)
337      mpl.figtext(0.5, 0.01, "Mars Climate Database (c) LMD/OU/IAA/ESA/CNES", ha='center')
338
339    def plot1d(self,tabtodo,vertplot=0):
340    ### complete 1D figure with possible multiplots
341      if isinstance(tabtodo,np.str): tabtodo=[tabtodo] ## so that asking one element without [] is possible.
342      if isinstance(tabtodo,np.int): tabtodo=[tabtodo] ## so that asking one element without [] is possible.
343      fig = mpl.figure() ; subv,subh = myplot.definesubplot( len(tabtodo) , fig ) 
344      for i in range(len(tabtodo)): mpl.subplot(subv,subh,i+1).grid(True, linestyle=':', color='grey') ; self.makeplot1d(tabtodo[i],vertplot)
345
346    def htmlplot1d(self,tabtodo,vertplot=0,figname="temp.png"):
347    ### complete 1D figure with possible multiplots
348    ### added in 09/2012 for online MCD
349    ### see http://www.dalkescientific.com/writings/diary/archive/2005/04/23/matplotlib_without_gui.html
350      from matplotlib.figure import Figure
351      from matplotlib.backends.backend_agg import FigureCanvasAgg
352      if isinstance(tabtodo,np.str): tabtodo=[tabtodo] ## so that asking one element without [] is possible.
353      if isinstance(tabtodo,np.int): tabtodo=[tabtodo] ## so that asking one element without [] is possible.
354      fig = Figure(figsize=(8,8)) ; subv,subh = myplot.definesubplot( len(tabtodo) , fig )
355      for i in range(len(tabtodo)):
356        yeah = fig.add_subplot(subv,subh,i+1) #.grid(True, linestyle=':', color='grey')
357        choice = tabtodo[i]
358        (field, fieldlab) = self.definefield(choice)
359        if vertplot != 1:  absc = self.xcoord ; ordo = field ; ordolab = fieldlab ; absclab = self.xlabel
360        else:              ordo = self.xcoord ; absc = field ; absclab = fieldlab ; ordolab = self.xlabel
361        yeah.plot(absc,ordo,'-bo') #; mpl.xticks(query.xcoord)
362        ax = fig.gca() ; ax.set_ylabel(ordolab) ; ax.set_xlabel(absclab)
363      fig.text(0.5, 0.01, "Mars Climate Database (c) LMD/OU/IAA/ESA/CNES", ha='center')
364      canvas = FigureCanvasAgg(fig)
365      # The size * the dpi gives the final image size
366      #   a4"x4" image * 80 dpi ==> 320x320 pixel image
367      canvas.print_figure(figname, dpi=80)
368
369###################
370### 2D analysis ###
371###################
372
373    def latlon(self,ndx=37,ndy=19,fixedlt=False):
374    ### retrieve a latitude/longitude slice
375    ### default is: local time is not fixed. user-defined local time is at longitude 0.
376      self.xlabel = "East longitude (degrees)" ; self.ylabel = "North latitude (degrees)"
377      self.prepare(ndx=ndx,ndy=ndy)
378      self.ininterv(-180.,180.,ndx,start=self.lons,end=self.lone)
379      self.ininterv(-90.,  90.,ndy,start=self.lats,end=self.late,yaxis=True)
380      if not fixedlt: umst = self.loct
381      for i in range(ndx):
382       for j in range(ndy):
383         self.lon = self.xcoord[i] ; self.lat = self.ycoord[j]
384         if not fixedlt: self.loct = (umst + self.lon/15.) % 24
385         self.update() ; self.put2d(i,j)
386      if not fixedlt: self.loct = umst
387
388    def put2d(self,i,j):
389    ## fill in subscript i,j in output arrays
390    ## (arrays must have been correctly defined through prepare)
391      if self.prestab is None:  myplot.errormess("arrays must be prepared first through self.prepare")
392      self.prestab[i,j] = self.pres ; self.denstab[i,j] = self.dens ; self.temptab[i,j] = self.temp
393      self.zonwindtab[i,j] = self.zonwind ; self.merwindtab[i,j] = self.merwind
394      self.meanvartab[i,j,1:5] = self.meanvar[0:4]  ## note: var numbering according to MCD manual is kept
395      self.extvartab[i,j,1:100] = self.extvar[0:99] ## note: var numbering according to MCD manual is kept
396
397    def makemap2d(self,choice,incwind=False,fixedlt=False,proj="cyl"):
398    ### one 2D map is created for the user-defined variable in choice.
399      self.latlon(fixedlt=fixedlt) ## a map is implicitely a lat-lon plot. otherwise it is a plot (cf. makeplot2d)
400      if choice == "wind" or incwind:
401          (windx, fieldlabwx) = self.definefield("u")
402          (windy, fieldlabwy) = self.definefield("v")
403      if choice == "wind":
404          field = np.sqrt(windx*windx + windy*windy)
405          fieldlab = "Horizontal wind speed (m/s)"
406      else:   
407          (field, fieldlab) = self.definefield(choice)
408      if incwind:   myplot.maplatlon(self.xcoord,self.ycoord,field,title=fieldlab,proj=proj,vecx=windx,vecy=windy) #,stride=1)
409      else:         myplot.maplatlon(self.xcoord,self.ycoord,field,title=fieldlab,proj=proj)
410      mpl.figtext(0.5, 0.0, "Mars Climate Database (c) LMD/OU/IAA/ESA/CNES", ha='center')
411
412    def map2d(self,tabtodo,incwind=False,fixedlt=False,proj="cyl"):
413    ### complete 2D figure with possible multiplots
414      if isinstance(tabtodo,np.str): tabtodo=[tabtodo] ## so that asking one element without [] is possible.
415      if isinstance(tabtodo,np.int): tabtodo=[tabtodo] ## so that asking one element without [] is possible.
416      fig = mpl.figure()
417      subv,subh = myplot.definesubplot( len(tabtodo) , fig ) 
418      for i in range(len(tabtodo)): mpl.subplot(subv,subh,i+1) ; self.makemap2d(tabtodo[i],incwind=incwind,fixedlt=fixedlt,proj=proj)
419
420    def htmlmap2d(self,tabtodo,incwind=False,fixedlt=False,figname="temp.png",title=""):
421    ### complete 2D figure with possible multiplots
422    ### added in 09/2012 for online MCD
423    ### see http://www.dalkescientific.com/writings/diary/archive/2005/04/23/matplotlib_without_gui.html
424      from matplotlib.figure import Figure
425      from matplotlib.backends.backend_agg import FigureCanvasAgg
426      from matplotlib.cm import get_cmap
427      if isinstance(tabtodo,np.str): tabtodo=[tabtodo] ## so that asking one element without [] is possible.
428      if isinstance(tabtodo,np.int): tabtodo=[tabtodo] ## so that asking one element without [] is possible.
429      fig = Figure(figsize=(8,8)) ; subv,subh = myplot.definesubplot( len(tabtodo) , fig )
430
431      ### topocontours
432      fieldc = self.getextvar(self.convertlab("topo"))
433
434      for i in range(len(tabtodo)):
435        yeah = fig.add_subplot(subv,subh,i+1)
436        choice = tabtodo[i]
437        self.latlon(fixedlt=fixedlt) 
438        ## a map is implicitely a lat-lon plot. otherwise it is a plot (cf. makeplot2d)
439        (field, fieldlab) = self.definefield(choice)
440        if incwind: (windx, fieldlabwx) = self.definefield("u") ; (windy, fieldlabwy) = self.definefield("v")
441
442        proj="cyl" ; colorb="jet" ; ndiv=20 ; zeback="molabw" ; trans=1.0 #0.6
443        title="" ; vecx=None ; vecy=None ; stride=2
444        lon = self.xcoord
445        lat = self.ycoord
446
447        ### get lon and lat in 2D version. get lat/lon intervals
448        #numdim = len(np.array(lon).shape)
449        #if numdim == 2:     [lon2d,lat2d] = [lon,lat]
450        #elif numdim == 1:   [lon2d,lat2d] = np.meshgrid(lon,lat)
451        #else:               errormess("lon and lat arrays must be 1D or 2D")
452        #[wlon,wlat] = myplot.latinterv()
453        ### define projection and background. define x and y given the projection
454        #m = basemap.Basemap(projection='moll') marche pas
455        #m = myplot.define_proj(proj,wlon,wlat,back=zeback,blat=None,blon=None)
456        #x, y = m(lon2d, lat2d)
457        ### TEMP
458        x = lon ; y = lat
459        ## define field. bound field.
460        what_I_plot = np.transpose(field)
461        zevmin, zevmax = myplot.calculate_bounds(what_I_plot)  ## vmin=min(what_I_plot_frame), vmax=max(what_I_plot_frame))
462        what_I_plot = myplot.bounds(what_I_plot,zevmin,zevmax)
463        ## define contour field levels. define color palette
464        ticks = ndiv + 1
465        zelevels = np.linspace(zevmin,zevmax,ticks)
466        palette = get_cmap(name=colorb)
467        ## contours topo
468        zelevc = np.linspace(-8000.,20000.,20)
469        yeah.contour( x, y, np.transpose(fieldc), zelevc, colors='black',linewidths = 0.4)
470        # contour field
471        c = yeah.contourf( x, y, what_I_plot, zelevels, cmap = palette, alpha = trans )
472        Figure.colorbar(fig,c,orientation='vertical',format="%.1e")
473        ax = fig.gca() ; ax.set_title(fieldlab) ; ax.set_ylabel("Latitude") ; ax.set_xlabel("Longitude")
474        ax.set_xticks(np.arange(-180,181,45)) ; ax.set_xbound(lower=self.lons, upper=self.lone)
475        ax.set_yticks(np.arange(-90,91,30)) ; ax.set_ybound(lower=self.lats, upper=self.late)
476        if incwind:
477          [x2d,y2d] = np.meshgrid(x,y)
478          yeah.quiver(x2d,y2d,np.transpose(windx),np.transpose(windy))
479      fig.text(0.5, 0.95, title, ha='center')
480      fig.text(0.5, 0.01, "Mars Climate Database (c) LMD/OU/IAA/ESA/CNES", ha='center')
481      canvas = FigureCanvasAgg(fig)
482      # The size * the dpi gives the final image size
483      #   a4"x4" image * 80 dpi ==> 320x320 pixel image
484      canvas.print_figure(figname, dpi=80)
485
486
487    ### TODO: makeplot2d, plot2d, passer plot settings
488
Note: See TracBrowser for help on using the repository browser.