Changeset 800


Ignore:
Timestamp:
Oct 1, 2012, 7:38:09 PM (12 years ago)
Author:
aslmd
Message:

UTIL PYTHON : mcd interface. handling of all vertical coordinates. added title.

Location:
trunk/UTIL/PYTHON/mcd
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/UTIL/PYTHON/mcd/mcd.py

    r797 r800  
    2727    # default settings
    2828        ## 0. general stuff
    29         self.name      = "MCD v4.3 output"
     29        self.name      = "MCD v4.3"
     30        self.ack       = "Mars Climate Database (c) LMD/OU/IAA/ESA/CNES"
    3031        #self.dset      = '/home/aymeric/Science/MCD_v4.3/data/'
    3132        self.dset      = '/home/marshttp/MCD_v4.3/data/'
     
    7273        self.prestab = None ; self.denstab = None ; self.temptab = None
    7374        self.zonwindtab = None ; self.merwindtab = None ; self.meanvartab = None ; self.extvartab = None
     75        ## plot stuff
     76        self.xlabel = None ; self.ylabel = None
     77        self.vertplot = False
    7478
    7579    def viking1(self): self.name = "Viking 1 site. MCD v4.3 output" ; self.lat = 22.48 ; self.lon = -49.97 ; self.xdate = 97.
    7680    def viking2(self): self.name = "Viking 2 site. MCD v4.3 output" ; self.lat = 47.97 ; self.lon = -225.74 ; self.xdate = 117.6
     81
     82    def getdustlabel(self):
     83        if self.dust == 1: self.dustlabel = "MY24 minimum solar scenario"
     84        elif self.dust == 2: self.dustlabel = "MY24 average solar scenario"
     85        elif self.dust == 3: self.dustlabel = "MY24 maximum solar scenario"
     86        elif self.dust == 4: self.dustlabel = "dust storm minimum solar scenario"
     87        elif self.dust == 5: self.dustlabel = "dust storm average solar scenario"
     88        elif self.dust == 6: self.dustlabel = "dust storm maximum solar scenario"
     89        elif self.dust == 7: self.dustlabel = "warm scenario (dusty, maximum solar)"
     90        elif self.dust == 8: self.dustlabel = "cold scenario (low dust, minimum solar)"
     91
     92    def gettitle(self):
     93        self.getdustlabel()
     94        self.title = self.name + " with " + self.dustlabel + "."
    7795
    7896    def getextvarlab(self,num):
     
    185203        self.extvar[90] = self.pres ; self.extvar[91] = self.dens
    186204        self.extvar[92] = self.temp ; self.extvar[93] = self.zonwind ; self.extvar[94] = self.merwind
     205        ## treat missing values
     206        if self.temp == -999: self.extvar[:] = np.NaN ; self.meanvar[:] = np.NaN
    187207
    188208    def printset(self):
     
    268288      if start is not None and end is not None:  first, second = self.correctbounds(start,end)
    269289      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
     290      if self.zkey != 4: tabtab = np.linspace(first,second,nd)
     291      else:              tabtab = np.logspace(first,second,nd)
     292      if not yaxis:      self.xcoord = tabtab
     293      else:              self.ycoord = tabtab
    273294
    274295    def correctbounds(self,start,end):
     
    279300      else:
    280301        # pressure: reversed avis
    281         if start < end: first = end ; second = start
    282         else:           first = start ; second = end
     302        if start < end: first = np.log10(end) ; second = np.log10(start)
     303        else:           first = np.log10(start) ; second = np.log10(end)
    283304      return first, second
     305
     306    def vertlabel(self):
     307      if self.zkey == 1:   self.xlabel = "radius from centre of planet (m)"
     308      elif self.zkey == 2: self.xlabel = "height above areoid (m) (MOLA zero datum)"
     309      elif self.zkey == 3: self.xlabel = "height above surface (m)"
     310      elif self.zkey == 4: self.xlabel = "pressure level (Pa)"
     311      elif self.zkey == 5: self.xlabel = "altitude above mean Mars Radius(=3396000m) (m)"
    284312
    285313###################
     
    316344    def profile(self,nd=20,tabperso=None):
    317345    ### retrieve an altitude slice (profile)
    318       self.xlabel = "Altitude (m)"
     346      self.vertlabel()
     347      self.vertplot = True
    319348      if tabperso is not None: nd = len(tabperso)
    320349      correct = False
     
    329358      for i in range(nd): self.xdate = self.xcoord[i] ; self.update() ; self.put1d(i)
    330359
    331     def makeplot1d(self,choice,vertplot=0):
     360    def makeplot1d(self,choice):
    332361    ### one 1D plot is created for the user-defined variable in choice.
    333362      (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
     363      if not self.vertplot:  absc = self.xcoord ; ordo = field ; ordolab = fieldlab ; absclab = self.xlabel
     364      else:                  ordo = self.xcoord ; absc = field ; absclab = fieldlab ; ordolab = self.xlabel
    336365      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):
     366      if self.zkey == 4: mpl.semilogy() ; ax = mpl.gca() ; ax.set_ylim(ax.get_ylim()[::-1])
     367      mpl.figtext(0.5, 0.01, self.ack, ha='center')
     368
     369    def plot1d(self,tabtodo):
    340370    ### complete 1D figure with possible multiplots
    341371      if isinstance(tabtodo,np.str): tabtodo=[tabtodo] ## so that asking one element without [] is possible.
    342372      if isinstance(tabtodo,np.int): tabtodo=[tabtodo] ## so that asking one element without [] is possible.
    343373      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"):
     374      for i in range(len(tabtodo)): mpl.subplot(subv,subh,i+1).grid(True, linestyle=':', color='grey') ; self.makeplot1d(tabtodo[i])
     375
     376    def htmlplot1d(self,tabtodo,figname="temp.png",title=""):
    347377    ### complete 1D figure with possible multiplots
    348378    ### added in 09/2012 for online MCD
     
    357387        choice = tabtodo[i]
    358388        (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
     389        if not self.vertplot:  absc = self.xcoord ; ordo = field ; ordolab = fieldlab ; absclab = self.xlabel
     390        else:                  ordo = self.xcoord ; absc = field ; absclab = fieldlab ; ordolab = self.xlabel
    361391        yeah.plot(absc,ordo,'-bo') #; mpl.xticks(query.xcoord)
    362392        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')
     393        if self.zkey == 4: ax.set_yscale('log') ; ax.set_ylim(ax.get_ylim()[::-1])
     394      self.gettitle()
     395      fig.text(0.5, 0.95, self.title, ha='center')
     396      fig.text(0.5, 0.01, self.ack, ha='center')
    364397      canvas = FigureCanvasAgg(fig)
    365398      # The size * the dpi gives the final image size
     
    408441      if incwind:   myplot.maplatlon(self.xcoord,self.ycoord,field,title=fieldlab,proj=proj,vecx=windx,vecy=windy) #,stride=1)
    409442      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')
     443      mpl.figtext(0.5, 0.0, self.ack, ha='center')
    411444
    412445    def map2d(self,tabtodo,incwind=False,fixedlt=False,proj="cyl"):
     
    477510          [x2d,y2d] = np.meshgrid(x,y)
    478511          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')
     512      self.gettitle()
     513      fig.text(0.5, 0.95, self.title, ha='center')
     514      fig.text(0.5, 0.01, self.ack, ha='center')
    481515      canvas = FigureCanvasAgg(fig)
    482516      # The size * the dpi gives the final image size
  • trunk/UTIL/PYTHON/mcd/proto/cgi-bin/mcdcgi.py

    r797 r800  
    109109reference = query.getnameset()+str(var1)+str(var2)+str(var3)+str(var4)+str(iswind)+str(isfixedlt)
    110110figname = '../img/'+reference+'.png'
    111 
    112111testexist = daos.path.isfile(figname)
    113112
     
    126125
    127126    ### generic building of figure
    128     query.htmlplot1d(vartoplot,vertplot=isaltfree,figname=figname)
     127    query.htmlplot1d(vartoplot,figname=figname)
    129128    #mpl.savefig("img/temp.png",dpi=85,bbox_inches='tight',pad_inches=0.25)
    130129    #Image.open("../img/temp.png").save(figname,'JPEG')
     
    138137
    139138    ### figure   
    140     zetitle = "MCD v4.3 - Dust scenario "+str(query.dust)+" - Date is "+str(query.xdate)
    141     query.htmlmap2d(vartoplot,incwind=iswindlog,fixedlt=input_fixedlt,figname=figname,title=zetitle)
     139    query.htmlmap2d(vartoplot,incwind=iswindlog,fixedlt=input_fixedlt,figname=figname)
    142140    #mpl.savefig("img/temp.png",dpi=110,bbox_inches='tight',pad_inches=0.4)
    143141    #Image.open("img/temp.png").save(figname,'JPEG') ##lighter images   
Note: See TracChangeset for help on using the changeset viewer.