Changeset 806 for trunk/UTIL/PYTHON/mcd/mcd.py
- Timestamp:
- Oct 15, 2012, 2:01:19 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UTIL/PYTHON/mcd/mcd.py
r805 r806 291 291 return field,fieldlab 292 292 293 def ininterv(self,dstart,dend,nd,start=None,end=None,yaxis=False ):293 def ininterv(self,dstart,dend,nd,start=None,end=None,yaxis=False,vertcoord=False): 294 294 ### user-defined start and end are used to create xcoord (or ycoord) vector 295 if start is not None and end is not None: first, second = self.correctbounds(start,end )296 else: first, second = self.correctbounds(dstart,dend )297 if self.zkey != 4 :tabtab = np.linspace(first,second,nd)298 else: tabtab = np.logspace(first,second,nd)295 if start is not None and end is not None: first, second = self.correctbounds(start,end,vertcoord) 296 else: first, second = self.correctbounds(dstart,dend,vertcoord) 297 if self.zkey != 4 or not vertcoord: tabtab = np.linspace(first,second,nd) 298 else: tabtab = np.logspace(first,second,nd) 299 299 if not yaxis: self.xcoord = tabtab 300 300 else: self.ycoord = tabtab 301 301 302 def correctbounds(self,start,end ):303 if self.zkey != 4 :302 def correctbounds(self,start,end,vertcoord): 303 if self.zkey != 4 or not vertcoord: 304 304 # regular altitudes 305 305 if start > end: first = end ; second = start … … 325 325 elif self.zkey == 5: self.vunits = "m AMMRad" 326 326 327 def vertaxis(self,number,yaxis=False): 328 if self.zkey == 2: self.ininterv(-5000.,100000.,number,start=self.xzs,end=self.xze,yaxis=yaxis,vertcoord=True) 329 elif self.zkey == 3: self.ininterv(0.,120000.,number,start=self.xzs,end=self.xze,yaxis=yaxis,vertcoord=True) 330 elif self.zkey == 5: self.ininterv(-5000.,100000.,number,start=self.xzs,end=self.xze,yaxis=yaxis,vertcoord=True) 331 elif self.zkey == 4: self.ininterv(1000.,0.001,number,start=self.xzs,end=self.xze,yaxis=yaxis,vertcoord=True) 332 elif self.zkey == 1: self.ininterv(3396000,3596000,number,start=self.xzs,end=self.xze,yaxis=yaxis,vertcoord=True) 333 327 334 ################### 328 335 ### 1D analysis ### … … 369 376 if tabperso is not None: nd = len(tabperso) 370 377 correct = False 371 self.prepare(ndx=nd) ; self. ininterv(0.,120000.,nd,start=self.xzs,end=self.xze)378 self.prepare(ndx=nd) ; self.vertaxis(nd) 372 379 if tabperso is not None: self.xcoord = tabperso 373 380 for i in range(nd): self.xz = self.xcoord[i] ; self.update() ; self.put1d(i) … … 446 453 if not fixedlt: self.loct = umst 447 454 self.lon = save1 ; self.lat = save2 ; self.loct = save3 455 456 def lonalt(self,ndx=37,ndy=20,fixedlt=False): 457 ### retrieve a longitude/altitude slice 458 save1 = self.lon ; save2 = self.xz ; save3 = self.loct 459 self.vertlabel() ; self.ylabel = self.xlabel 460 self.xlabel = "East longitude (degrees)" 461 self.prepare(ndx=ndx,ndy=ndy) 462 self.ininterv(-180.,180.,ndx,start=self.lons,end=self.lone) 463 self.vertaxis(ndy,yaxis=True) 464 if not fixedlt: umst = self.loct 465 for i in range(ndx): 466 for j in range(ndy): 467 self.lon = self.xcoord[i] ; self.xz = self.ycoord[j] 468 if not fixedlt: 469 if self.lons is not None and self.lone is not None: self.loct = (umst + (self.lons+self.lone)/30.) % 24 470 else: self.loct = (umst + self.lon/15.) % 24 471 self.update() ; self.put2d(i,j) 472 if not fixedlt: self.loct = umst 473 self.lon = save1 ; self.xz = save2 ; self.loct = save3 474 475 def latalt(self,ndx=19,ndy=20,fixedlt=False): 476 ### retrieve a latitude/altitude slice 477 save1 = self.lat ; save2 = self.xz ; save3 = self.loct 478 self.vertlabel() ; self.ylabel = self.xlabel 479 self.xlabel = "North latitude (degrees)" 480 self.prepare(ndx=ndx,ndy=ndy) 481 self.ininterv(-90.,90.,ndx,start=self.lats,end=self.late) 482 self.vertaxis(ndy,yaxis=True) 483 if not fixedlt: umst = self.loct 484 for i in range(ndx): 485 for j in range(ndy): 486 self.lat = self.xcoord[i] ; self.xz = self.ycoord[j] 487 if not fixedlt: self.loct = (umst + self.lon/15.) % 24 488 self.update() ; self.put2d(i,j) 489 if not fixedlt: self.loct = umst 490 self.lat = save1 ; self.xz = save2 ; self.loct = save3 448 491 449 492 def put2d(self,i,j): … … 547 590 canvas.print_figure(figname, dpi=80) 548 591 592 def htmlplot2d(self,tabtodo,fixedlt=False,figname="temp.png",title=""): 593 ### complete 2D figure with possible multiplots 594 ### added in 10/2012 for online MCD 595 ### see http://www.dalkescientific.com/writings/diary/archive/2005/04/23/matplotlib_without_gui.html 596 from matplotlib.figure import Figure 597 from matplotlib.backends.backend_agg import FigureCanvasAgg 598 from matplotlib.cm import get_cmap 599 if isinstance(tabtodo,np.str): tabtodo=[tabtodo] ## so that asking one element without [] is possible. 600 if isinstance(tabtodo,np.int): tabtodo=[tabtodo] ## so that asking one element without [] is possible. 601 fig = Figure(figsize=(8,8)) ; subv,subh = myplot.definesubplot( len(tabtodo) , fig ) 602 603 for i in range(len(tabtodo)): 604 yeah = fig.add_subplot(subv,subh,i+1) 605 choice = tabtodo[i] 606 607 if self.lons is not None: self.lonalt(fixedlt=fixedlt) 608 elif self.lats is not None: self.latalt(fixedlt=fixedlt) 609 610 (field, fieldlab) = self.definefield(choice) 611 612 colorb="jet" ; ndiv=20 ; title="" 613 614 ## define field. bound field. 615 what_I_plot = np.transpose(field) 616 zevmin, zevmax = myplot.calculate_bounds(what_I_plot) ## vmin=min(what_I_plot_frame), vmax=max(what_I_plot_frame)) 617 what_I_plot = myplot.bounds(what_I_plot,zevmin,zevmax) 618 ## define contour field levels. define color palette 619 ticks = ndiv + 1 620 zelevels = np.linspace(zevmin,zevmax,ticks) 621 palette = get_cmap(name=colorb) 622 # contour field 623 c = yeah.contourf( self.xcoord, self.ycoord, what_I_plot, zelevels, cmap = palette ) 624 clb = Figure.colorbar(fig,c,orientation='vertical',format="%.1e") 625 clb.set_label(fieldlab) 626 ax = fig.gca() ; ax.set_ylabel(self.ylabel) ; ax.set_xlabel(self.xlabel) 627 if self.zkey == 4: ax.set_yscale('log') ; ax.set_ylim(ax.get_ylim()[::-1]) 628 629 #ax.set_xticks(np.arange(-180,181,45)) ; ax.set_xbound(lower=self.lons, upper=self.lone) 630 #ax.set_yticks(np.arange(-90,91,30)) ; ax.set_ybound(lower=self.lats, upper=self.late) 631 632 self.gettitle() 633 fig.text(0.5, 0.95, self.title, ha='center') 634 fig.text(0.5, 0.01, self.ack, ha='center') 635 canvas = FigureCanvasAgg(fig) 636 # The size * the dpi gives the final image size 637 # a4"x4" image * 80 dpi ==> 320x320 pixel image 638 canvas.print_figure(figname, dpi=80) 639 549 640 550 641 ### TODO: makeplot2d, plot2d, passer plot settings
Note: See TracChangeset
for help on using the changeset viewer.