Changeset 811
- Timestamp:
- Oct 20, 2012, 11:45:11 AM (12 years ago)
- Location:
- trunk/UTIL/PYTHON/mcd
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UTIL/PYTHON/mcd/mcd.py
r807 r811 200 200 def update(self): 201 201 # 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 202 216 (self.pres, self.dens, self.temp, self.zonwind, self.merwind, \ 203 217 self.meanvar, self.extvar, self.seedout, self.ierr) \ … … 388 402 for i in range(nd): self.xdate = self.xcoord[i] ; self.update() ; self.put1d(i) 389 403 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 390 421 391 422 def makeplot1d(self,choice): … … 423 454 ax = fig.gca() ; ax.set_ylabel(ordolab) ; ax.set_xlabel(absclab) 424 455 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 425 461 self.gettitle() 426 462 fig.text(0.5, 0.95, self.title, ha='center') … … 529 565 from matplotlib.backends.backend_agg import FigureCanvasAgg 530 566 from matplotlib.cm import get_cmap 567 from matplotlib import rcParams 531 568 532 569 #from mpl_toolkits.basemap import Basemap … … 554 591 yeah = fig.add_subplot(subv,subh,i+1) 555 592 choice = tabtodo[i] 556 self.latlon(fixedlt=fixedlt )593 self.latlon(fixedlt=fixedlt,ndx=64,ndy=48) 557 594 ## a map is implicitely a lat-lon plot. otherwise it is a plot (cf. makeplot2d) 558 595 (field, fieldlab) = self.definefield(choice) … … 584 621 palette = get_cmap(name=colorb) 585 622 623 # You can set negative contours to be solid instead of dashed: 624 rcParams['contour.negative_linestyle'] = 'solid' 586 625 ## contours topo 587 626 zelevc = np.linspace(-9.,20.,11) 588 627 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) 589 630 # contour field 590 631 c = yeah.contourf( x, y, what_I_plot, zelevels, cmap = palette, alpha = trans ) 591 632 clb = Figure.colorbar(fig,c,orientation='vertical',format="%.2e",ticks=np.linspace(zevmin,zevmax,num=min([ticks/2+1,21]))) 592 633 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)596 634 if incwind: 597 635 [x2d,y2d] = np.meshgrid(x,y) 598 636 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) 599 640 self.gettitle() 600 641 fig.text(0.5, 0.95, self.title, ha='center') … … 640 681 clb.set_label(fieldlab) 641 682 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) 646 692 647 693 self.gettitle() -
trunk/UTIL/PYTHON/mcd/proto/cgi-bin/mcdcgi.py
r807 r811 43 43 if getlat == "all": islatfree = 1 ; query.lats = -90. ; query.late = 90. 44 44 elif ";" in getlat: islatfree = 1 ; ind = getlat.find(";") ; query.lats = float(getlat[:ind]) ; query.late = float(getlat[ind+1:]) 45 elif "," in getlat: islatfree = 1 ; ind = getlat.find(",") ; query.lats = float(getlat[:ind]) ; query.late = float(getlat[ind+1:]) 46 elif "/" in getlat: islatfree = 1 ; ind = getlat.find("/") ; query.lats = float(getlat[:ind]) ; query.late = float(getlat[ind+1:]) 45 47 else: islatfree = 0 ; query.lat = float(getlat) 46 48 … … 50 52 if getlon == "all": islonfree = 1 ; query.lons = -180. ; query.lone = 180. 51 53 elif ";" in getlon: islonfree = 1 ; ind = getlon.find(";") ; query.lons = float(getlon[:ind]) ; query.lone = float(getlon[ind+1:]) 54 elif "," in getlon: islonfree = 1 ; ind = getlon.find(",") ; query.lons = float(getlon[:ind]) ; query.lone = float(getlon[ind+1:]) 55 elif "/" in getlon: islonfree = 1 ; ind = getlon.find("/") ; query.lons = float(getlon[:ind]) ; query.lone = float(getlon[ind+1:]) 52 56 else: islonfree = 0 ; query.lon = float(getlon) 53 57 … … 57 61 if getloct == "all": isloctfree = 1 ; query.locts = 0. ; query.locte = 24. 58 62 elif ";" in getloct: isloctfree = 1 ; ind = getloct.find(";") ; query.locts = float(getloct[:ind]) ; query.locte = float(getloct[ind+1:]) 63 elif "," in getloct: isloctfree = 1 ; ind = getloct.find(",") ; query.locts = float(getloct[:ind]) ; query.locte = float(getloct[ind+1:]) 64 elif "/" in getloct: isloctfree = 1 ; ind = getloct.find("/") ; query.locts = float(getloct[:ind]) ; query.locte = float(getloct[ind+1:]) 59 65 else: isloctfree = 0 ; query.loct = float(getloct) 60 66 … … 73 79 elif query.zkey == 1: query.xzs = 3396000. ; query.xze = 3596000. 74 80 elif ";" in getalt: isaltfree = 1 ; ind = getalt.find(";") ; query.xzs = float(getalt[:ind]) ; query.xze = float(getalt[ind+1:]) 81 elif "," in getalt: isaltfree = 1 ; ind = getalt.find(",") ; query.xzs = float(getalt[:ind]) ; query.xze = float(getalt[ind+1:]) 82 elif "/" in getalt: isaltfree = 1 ; ind = getalt.find("/") ; query.xzs = float(getalt[:ind]) ; query.xze = float(getalt[ind+1:]) 75 83 else: isaltfree = 0 ; query.xz = float(getalt) 76 84 … … 124 132 reference = query.getnameset()+str(var1)+str(var2)+str(var3)+str(var4)+str(iswind)+str(isfixedlt) 125 133 figname = '../img/'+reference+'.png' 134 txtname = '../txt/'+reference 126 135 testexist = daos.path.isfile(figname) 127 136 … … 133 142 134 143 ### getting data 135 if isloctfree == 1: query.diurnal(nd=24) 144 if isloctfree == 1: query.diurnal(nd=24) 136 145 elif islonfree == 1: query.zonal() 137 146 elif islatfree == 1: query.meridional() … … 140 149 141 150 ### generic building of figure 151 query.getascii(vartoplot,filename=txtname) 142 152 query.htmlplot1d(vartoplot,figname=figname) 143 153 #mpl.savefig("img/temp.png",dpi=85,bbox_inches='tight',pad_inches=0.25) … … 178 188 ## Now the part which differs 179 189 if sumfree == 0: query.update() ; query.htmlprinttabextvar(vartoplot) #query.printmeanvar() 180 elif sumfree >= 1: print "<img src='"+figname+"'><br />" 190 elif sumfree == 2: print "<img src='"+figname+"'><br />" 191 elif sumfree == 1: 192 print "<a href='"+txtname+"'>Click here to download an ASCII file containing data</a><br />" 193 print "<img src='"+figname+"'><br />" 181 194 else: print "<h1>ERROR : sumfree is not or badly defined ...</h1></body></html>" 182 195
Note: See TracChangeset
for help on using the changeset viewer.