Changeset 811


Ignore:
Timestamp:
Oct 20, 2012, 11:45:11 AM (12 years ago)
Author:
aslmd
Message:

UTIL PYTHON mcd interface. added option to print ASCII file. added sanity checks. topography contours are all solid lines. html section have cleaner bounds for axis. allowed for more separator namely , and /

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

Legend:

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

    r807 r811  
    200200    def update(self):
    201201    # retrieve fields from MCD (call_mcd). more info in fmcd.call_mcd.__doc__
     202        ## sanity first
     203        self.loct = abs(self.loct)%24
     204        if self.locts is not None and self.locte is not None:
     205            self.locts = abs(self.locts)%24
     206            self.locte = abs(self.locte)%24
     207            if self.locts == self.locte: self.locte = self.locts + 24
     208        if self.lat > 90.: self.lat = 90.
     209        if self.lat < -90.: self.lat = -90.
     210        if self.lats is not None and self.late is not None:
     211            if abs(self.lats) > 90.: self.lats = 90.
     212            if abs(self.late) > 90.: self.late = 90.
     213            if abs(self.lats) < -90.: self.lats = -90.
     214            if abs(self.late) < -90.: self.late = -90.
     215        ## now MCD request
    202216        (self.pres, self.dens, self.temp, self.zonwind, self.merwind, \
    203217         self.meanvar, self.extvar, self.seedout, self.ierr) \
     
    388402      for i in range(nd): self.xdate = self.xcoord[i] ; self.update() ; self.put1d(i)
    389403      self.xdate = save
     404
     405    def getascii(self,tabtodo,filename="output.txt"):
     406    ### print out values in an ascii file
     407      if isinstance(tabtodo,np.str): tabtodo=[tabtodo] ## so that asking one element without [] is possible.
     408      if isinstance(tabtodo,np.int): tabtodo=[tabtodo] ## so that asking one element without [] is possible.
     409      asciifile = open(filename, "w")
     410      for i in range(len(tabtodo)): 
     411          (field, fieldlab) = self.definefield(tabtodo[i])
     412          self.gettitle()
     413          asciifile.write("### " + self.title + "\n")
     414          asciifile.write("### " + self.ack + "\n")
     415          asciifile.write("### Column 1 is " + self.xlabel + "\n")
     416          asciifile.write("### Column 2 is " + fieldlab + "\n")
     417          for ix in range(len(self.xcoord)):
     418              asciifile.write("%15.5e%15.5e\n" % ( self.xcoord[ix], field[ix] ) )
     419      asciifile.close()
     420      return
    390421
    391422    def makeplot1d(self,choice):
     
    423454        ax = fig.gca() ; ax.set_ylabel(ordolab) ; ax.set_xlabel(absclab)
    424455        if self.zkey == 4: ax.set_yscale('log') ; ax.set_ylim(ax.get_ylim()[::-1])
     456
     457        if self.lats is not None:      ax.set_xticks(np.arange(-90,91,15)) ; ax.set_xbound(lower=self.lats, upper=self.late)
     458        elif self.lons is not None:    ax.set_xticks(np.arange(-360,361,30)) ; ax.set_xbound(lower=self.lons, upper=self.lone)
     459        elif self.locts is not None:   ax.set_xticks(np.arange(0,26,2)) ; ax.set_xbound(lower=self.locts, upper=self.locte)
     460
    425461      self.gettitle()
    426462      fig.text(0.5, 0.95, self.title, ha='center')
     
    529565      from matplotlib.backends.backend_agg import FigureCanvasAgg
    530566      from matplotlib.cm import get_cmap
     567      from matplotlib import rcParams
    531568
    532569      #from mpl_toolkits.basemap import Basemap
     
    554591        yeah = fig.add_subplot(subv,subh,i+1)
    555592        choice = tabtodo[i]
    556         self.latlon(fixedlt=fixedlt)
     593        self.latlon(fixedlt=fixedlt,ndx=64,ndy=48)
    557594        ## a map is implicitely a lat-lon plot. otherwise it is a plot (cf. makeplot2d)
    558595        (field, fieldlab) = self.definefield(choice)
     
    584621        palette = get_cmap(name=colorb)
    585622
     623        # You can set negative contours to be solid instead of dashed:
     624        rcParams['contour.negative_linestyle'] = 'solid'
    586625        ## contours topo
    587626        zelevc = np.linspace(-9.,20.,11)
    588627        yeah.contour( xc, yc, fieldc, zelevc, colors='black',linewidths = 0.4)
     628        yeah.contour( np.array(xc) + 360., yc, fieldc, zelevc, colors='black',linewidths = 0.4)
     629        yeah.contour( np.array(xc) - 360., yc, fieldc, zelevc, colors='black',linewidths = 0.4)
    589630        # contour field
    590631        c = yeah.contourf( x, y, what_I_plot, zelevels, cmap = palette, alpha = trans )
    591632        clb = Figure.colorbar(fig,c,orientation='vertical',format="%.2e",ticks=np.linspace(zevmin,zevmax,num=min([ticks/2+1,21])))
    592633        clb.set_label(fieldlab)
    593         ax = fig.gca() ; ax.set_ylabel("Latitude") ; ax.set_xlabel("Longitude")
    594         ax.set_xticks(np.arange(-180,181,45)) ; ax.set_xbound(lower=self.lons, upper=self.lone)
    595         ax.set_yticks(np.arange(-90,91,30)) ; ax.set_ybound(lower=self.lats, upper=self.late)
    596634        if incwind:
    597635          [x2d,y2d] = np.meshgrid(x,y)
    598636          yeah.quiver(x2d,y2d,np.transpose(windx),np.transpose(windy))
     637        ax = fig.gca() ; ax.set_ylabel("Latitude") ; ax.set_xlabel("Longitude")
     638        ax.set_xticks(np.arange(-360,361,45)) ; ax.set_xbound(lower=self.lons, upper=self.lone)
     639        ax.set_yticks(np.arange(-90,91,30)) ; ax.set_ybound(lower=self.lats, upper=self.late)
    599640      self.gettitle()
    600641      fig.text(0.5, 0.95, self.title, ha='center')
     
    640681        clb.set_label(fieldlab)
    641682        ax = fig.gca() ; ax.set_ylabel(self.ylabel) ; ax.set_xlabel(self.xlabel)
    642         if self.zkey == 4: ax.set_yscale('log') ; ax.set_ylim(ax.get_ylim()[::-1])
    643 
    644         #ax.set_xticks(np.arange(-180,181,45)) ; ax.set_xbound(lower=self.lons, upper=self.lone)
    645         #ax.set_yticks(np.arange(-90,91,30)) ; ax.set_ybound(lower=self.lats, upper=self.late)
     683
     684        if self.zkey == 4:
     685            ax.set_yscale('log') ; ax.set_ylim(ax.get_ylim()[::-1])
     686        else:
     687            #ax.set_yticks(np.arange(self.xzs,self.xze,10000.)) ;
     688            ax.set_ybound(lower=self.xzs, upper=self.xze)
     689
     690        if self.lons is not None: ax.set_xticks(np.arange(-360,361,45)) ; ax.set_xbound(lower=self.lons, upper=self.lone)
     691        elif self.lats is not None: ax.set_xticks(np.arange(-90,91,30)) ; ax.set_xbound(lower=self.lats, upper=self.late)
    646692
    647693      self.gettitle()
  • trunk/UTIL/PYTHON/mcd/proto/cgi-bin/mcdcgi.py

    r807 r811  
    4343if getlat == "all":  islatfree = 1 ; query.lats = -90. ; query.late = 90.
    4444elif ";" in getlat:  islatfree = 1 ; ind = getlat.find(";") ; query.lats = float(getlat[:ind]) ; query.late = float(getlat[ind+1:])
     45elif "," in getlat:  islatfree = 1 ; ind = getlat.find(",") ; query.lats = float(getlat[:ind]) ; query.late = float(getlat[ind+1:])
     46elif "/" in getlat:  islatfree = 1 ; ind = getlat.find("/") ; query.lats = float(getlat[:ind]) ; query.late = float(getlat[ind+1:])
    4547else:                islatfree = 0 ; query.lat = float(getlat)
    4648
     
    5052if getlon == "all":  islonfree = 1 ; query.lons = -180. ; query.lone = 180.
    5153elif ";" in getlon:  islonfree = 1 ; ind = getlon.find(";") ; query.lons = float(getlon[:ind]) ; query.lone = float(getlon[ind+1:])
     54elif "," in getlon:  islonfree = 1 ; ind = getlon.find(",") ; query.lons = float(getlon[:ind]) ; query.lone = float(getlon[ind+1:])
     55elif "/" in getlon:  islonfree = 1 ; ind = getlon.find("/") ; query.lons = float(getlon[:ind]) ; query.lone = float(getlon[ind+1:])
    5256else:                islonfree = 0 ; query.lon = float(getlon)
    5357
     
    5761if getloct == "all": isloctfree = 1 ; query.locts = 0. ; query.locte = 24.
    5862elif ";" in getloct: isloctfree = 1 ; ind = getloct.find(";") ; query.locts = float(getloct[:ind]) ; query.locte = float(getloct[ind+1:])
     63elif "," in getloct: isloctfree = 1 ; ind = getloct.find(",") ; query.locts = float(getloct[:ind]) ; query.locte = float(getloct[ind+1:])
     64elif "/" in getloct: isloctfree = 1 ; ind = getloct.find("/") ; query.locts = float(getloct[:ind]) ; query.locte = float(getloct[ind+1:])
    5965else:                isloctfree = 0 ; query.loct = float(getloct)
    6066
     
    7379    elif query.zkey == 1:  query.xzs = 3396000. ; query.xze = 3596000.
    7480elif ";" in getalt:  isaltfree = 1 ; ind = getalt.find(";") ; query.xzs = float(getalt[:ind]) ; query.xze = float(getalt[ind+1:])
     81elif "," in getalt:  isaltfree = 1 ; ind = getalt.find(",") ; query.xzs = float(getalt[:ind]) ; query.xze = float(getalt[ind+1:])
     82elif "/" in getalt:  isaltfree = 1 ; ind = getalt.find("/") ; query.xzs = float(getalt[:ind]) ; query.xze = float(getalt[ind+1:])
    7583else:                isaltfree = 0 ; query.xz = float(getalt)
    7684
     
    124132reference = query.getnameset()+str(var1)+str(var2)+str(var3)+str(var4)+str(iswind)+str(isfixedlt)
    125133figname = '../img/'+reference+'.png'
     134txtname = '../txt/'+reference
    126135testexist = daos.path.isfile(figname)
    127136
     
    133142
    134143    ### getting data
    135     if isloctfree == 1:         query.diurnal(nd=24)
     144    if isloctfree == 1:         query.diurnal(nd=24) 
    136145    elif islonfree == 1:        query.zonal()
    137146    elif islatfree == 1:        query.meridional()
     
    140149
    141150    ### generic building of figure
     151    query.getascii(vartoplot,filename=txtname)
    142152    query.htmlplot1d(vartoplot,figname=figname)
    143153    #mpl.savefig("img/temp.png",dpi=85,bbox_inches='tight',pad_inches=0.25)
     
    178188## Now the part which differs
    179189if sumfree == 0:        query.update() ; query.htmlprinttabextvar(vartoplot)  #query.printmeanvar()
    180 elif sumfree >= 1:      print "<img src='"+figname+"'><br />"
     190elif sumfree == 2:      print "<img src='"+figname+"'><br />"
     191elif sumfree == 1:     
     192    print "<a href='"+txtname+"'>Click here to download an ASCII file containing data</a><br />"
     193    print "<img src='"+figname+"'><br />"
    181194else:                   print "<h1>ERROR : sumfree is not or badly defined ...</h1></body></html>"
    182195
Note: See TracChangeset for help on using the changeset viewer.