Changeset 955 in lmdz_wrf for trunk/tools
- Timestamp:
- Jun 25, 2016, 7:15:26 PM (8 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/drawing.py
r954 r955 611 611 612 612 if mapvalue == 'None': mapvalue = None 613 if revals == 'None': revals = None 613 614 614 615 drw.plot_2D_shadow_contour(valshad, valcont, vnamesfig, odimxv, odimyv, odimxu, \ -
trunk/tools/drawing_tools.py
r953 r955 1624 1624 if flip == 'x': 1625 1625 newvals = newvals[...,::-1] 1626 if dv: 1627 newdxv = newdxv[...,::-1] 1628 if dt: 1629 newdxt = newdxt[::-1] 1630 if dl: 1626 # if wdvx: 1627 # if len(newdxv.shape) > 1: 1628 # newdxv = newdxv[...,::-1] 1629 # else: 1630 # newdxv = newdxv[::-1] 1631 # if wdtx: 1632 # newdxt = newdxt[::-1] 1633 if wdlx: 1631 1634 newdxl = newdxl[::-1] 1632 1635 elif flip == 'y': 1633 1636 newvals = newvals[...,::-1,:] 1634 if dv: 1635 newdyv = newdyv[...,::-1,:] 1636 if dt: 1637 newdyt = newdyt[::-1] 1638 if dl: 1637 # if wdvy: 1638 # Ny=len(newdyt) 1639 # if len(newdyv.shape) > 1: 1640 # newdyv = newdyv[...,::-1] 1641 # else: 1642 # newdyv = newdyv[::-1] 1643 # if wdty: 1644 # newdyt = newdyt[::-1] 1645 if wdly: 1639 1646 newdyl = newdyl[::-1] 1640 1647 elif flip == 'z': … … 4448 4455 quit() 4449 4456 4457 # Usually axis > x must be the lon, thus... 4458 dimxv0 = dimxv.copy() 4459 dimyv0 = dimyv.copy() 4460 dimxt0 = np.array(pretty_int(dimxv.min(),dimxv.max(),10)) 4461 dimyt0 = np.array(pretty_int(dimyv.min(),dimyv.max(),10)) 4462 dimxl0 = [] 4463 for i in range(len(dimxt0)): dimxl0.append('{:.1f}'.format(dimxt0[i])) 4464 dimyl0 = [] 4465 for i in range(len(dimyt0)): dimyl0.append('{:.1f}'.format(dimyt0[i])) 4466 dimxT0 = variables_values(dimn[0])[0] + ' (' + units_lunits(dimxu) + ')' 4467 dimyT0 = variables_values(dimn[1])[0] + ' (' + units_lunits(dimyu) + ')' 4468 4469 if reva is not None: 4470 varcv, dimxv, dimyv, dimxt, dimyt, dimxl, dimyl, dimxT, dimyT = \ 4471 transform(varcv, reva) 4472 varsv, dimxv, dimyv, dimxt, dimyt, dimxl, dimyl, dimxT, dimyT = \ 4473 transform(varsv, reva, dxv=dimxv0, dyv=dimyv0, dxt=dimxt0, dyt=dimyt0, \ 4474 dxl=dimxl0, dyl=dimyl0, dxtit=dimxT0, dytit=dimyT0) 4475 else: 4476 dimxv = dimxv0 4477 dimyv = dimyv0 4478 dimxt = dimxt0 4479 dimyt = dimyt0 4480 dimxl = dimxl0 4481 dimyl = dimyl0 4482 dimxT = dimxT0 4483 dimyT = dimyT0 4484 4485 if not mapv is None: 4486 if len(dimxv[:].shape) == 3: 4487 lon0 = dimxv[0,] 4488 lat0 = dimyv[0,] 4489 elif len(dimxv[:].shape) == 2: 4490 lon0 = dimxv[:] 4491 lat0 = dimyv[:] 4492 elif len(dimxv[:].shape) == 1: 4493 lon00 = dimxv[:] 4494 lat00 = dimyv[:] 4495 lon0 = np.zeros( (len(lat00),len(lon00)), dtype=np.float ) 4496 lat0 = np.zeros( (len(lat00),len(lon00)), dtype=np.float ) 4497 4498 for iy in range(len(lat00)): 4499 lon0[iy,:] = lon00 4500 for ix in range(len(lon00)): 4501 lat0[:,ix] = lat00 4502 4503 map_proj=mapv.split(',')[0] 4504 map_res=mapv.split(',')[1] 4505 4506 dx = lon0.shape[1] 4507 dy = lon0.shape[0] 4508 4509 nlon = lon0[0,0] 4510 xlon = lon0[dy-1,dx-1] 4511 nlat = lat0[0,0] 4512 xlat = lat0[dy-1,dx-1] 4513 4514 # Thats too much! :) 4515 # if lonlatLims is not None: 4516 # print ' ' + fname + ': cutting the domain to plot !!!!' 4517 # plt.xlim(lonlatLims[0], lonlatLims[2]) 4518 # plt.ylim(lonlatLims[1], lonlatLims[3]) 4519 # print ' limits: W-E', lonlatLims[0], lonlatLims[2] 4520 # print ' limits: N-S', lonlatLims[1], lonlatLims[3] 4521 4522 # if map_proj == 'cyl': 4523 # nlon = lonlatLims[0] 4524 # nlat = lonlatLims[1] 4525 # xlon = lonlatLims[2] 4526 # xlat = lonlatLims[3] 4527 # elif map_proj == 'lcc': 4528 # lon2 = (lonlatLims[0] + lonlatLims[2])/2. 4529 # lat2 = (lonlatLims[1] + lonlatLims[3])/2. 4530 # nlon = lonlatLims[0] 4531 # xlon = lonlatLims[2] 4532 # nlat = lonlatLims[1] 4533 # xlat = lonlatLims[3] 4534 4535 lon2 = lon0[dy/2,dx/2] 4536 lat2 = lat0[dy/2,dx/2] 4537 4538 print 'lon2:', lon2, 'lat2:', lat2, 'SW pt:', nlon, ',', nlat, 'NE pt:', \ 4539 xlon, ',', xlat 4540 4541 if map_proj == 'cyl': 4542 m = Basemap(projection=map_proj, llcrnrlon=nlon, llcrnrlat=nlat, \ 4543 urcrnrlon=xlon, urcrnrlat= xlat, resolution=map_res) 4544 elif map_proj == 'lcc': 4545 m = Basemap(projection=map_proj, lat_0=lat2, lon_0=lon2, llcrnrlon=nlon, \ 4546 llcrnrlat=nlat, urcrnrlon=xlon, urcrnrlat= xlat, resolution=map_res) 4547 4548 if len(dimxv.shape) == 1: 4549 lons, lats = np.meshgrid(dimxv, dimyv) 4550 else: 4551 if len(dimxv.shape) == 3: 4552 lons = dimxv[0,:,:] 4553 lats = dimyv[0,:,:] 4554 else: 4555 lons = dimxv[:] 4556 lats = dimyv[:] 4557 4558 x,y = m(lons,lats) 4559 4560 else: 4561 x,y = gen.lonlat2D(dimxv,dimyv) 4562 4563 plt.rc('text', usetex=True) 4564 4565 plt.pcolormesh(x, y, varsv, cmap=plt.get_cmap(colorbar), vmin=vs[0], vmax=vs[1]) 4566 cbar = plt.colorbar() 4567 4568 # contour 4569 ## 4570 print fname + '; Lluis: shapes x:', x.shape,'y:',y.shape,'varcv:',varcv.shape 4571 contkind = ckind.split(',')[0] 4572 if contkind == 'cmap': 4573 cplot = plt.contour(x, y, varcv, levels=vc) 4574 elif contkind == 'fixc': 4575 plt.rcParams['contour.negative_linestyle'] = 'solid' 4576 coln = ckind.split(',')[1] 4577 cplot = plt.contour(x, y, varcv, levels=vc, colors=coln) 4578 elif contkind == 'fixsigc': 4579 coln = ckind.split(',')[1] 4580 cplot = plt.contour(x, y, varcv, levels=vc, colors=coln) 4581 else: 4582 print errormsg 4583 print ' ' + fname + ': contour kind "' + contkind + '" not defined !!!!!' 4584 quit(-1) 4585 4586 if clabfmt is not None: 4587 plt.clabel(cplot, fmt=clabfmt) 4588 mincntS = format(vc[0], clabfmt[1:len(clabfmt)]) 4589 maxcntS = format(vc[len(vc)-1], clabfmt[1:len(clabfmt)]) 4590 else: 4591 mincntS = '{:g}'.format(vc[0]) 4592 maxcntS = '{:g}'.format(vc[len(vc)-1]) 4593 4594 if not mapv is None: 4595 m.drawcoastlines() 4596 4597 meridians = pretty_int(nlon,xlon,5) 4598 m.drawmeridians(meridians,labels=[True,False,False,True]) 4599 parallels = pretty_int(nlat,xlat,5) 4600 m.drawparallels(parallels,labels=[False,True,True,False]) 4601 4602 plt.xlabel('W-E') 4603 plt.ylabel('S-N') 4604 else: 4605 plt.xlabel(dimxT) 4606 plt.ylabel(dimyT) 4607 4608 plt.xticks(dimxt, dimxl) 4609 plt.yticks(dimyt, dimyl) 4610 4611 # set the limits of the plot to the limits of the data 4612 plt.axis([x.min(), x.max(), y.min(), y.max()]) 4613 4614 4615 # units labels 4616 cbar.set_label(vnames[0].replace('_','\_') + ' (' + units_lunits(uts[0]) + ')') 4617 plt.annotate(vnames[1].replace('_','\_') +' (' + units_lunits(uts[1]) + ') [' + \ 4618 mincntS + ', ' + maxcntS + ']', xy=(0.55,0.04), xycoords='figure fraction', \ 4619 color=coln) 4620 4621 figname = '2Dfields_shadow-contour' 4622 graphtit = vtit.replace('_','\_').replace('&','\&') 4623 4624 plt.title(graphtit) 4625 4626 output_kind(kfig, figname, True) 4627 4628 return 4629 4630 #Nvals=50 4631 #vals1 = np.zeros((Nvals,Nvals), dtype= np.float) 4632 #vals2 = np.zeros((Nvals,Nvals), dtype= np.float) 4633 #for j in range(Nvals): 4634 # for i in range(Nvals): 4635 # vals1[j,i]=np.sqrt((j-Nvals/2)**2. + (i-Nvals/2)**2.) 4636 # vals2[j,i]=np.sqrt((j-Nvals/2)**2. + (i-Nvals/2)**2.) - Nvals/2 4637 4638 #prettylev=pretty_int(-Nvals/2,Nvals/2,10) 4639 4640 #plot_2D_shadow_contour(vals1, vals2, ['var1', 'var2'], np.arange(50)*1., \ 4641 # np.arange(50)*1., ['x-axis','y-axis'], 'rainbow', 'fixc,b', "%.2f", [0, Nvals], \ 4642 # prettylev, ['$ms^{-1}$','$kJm^{-1}s^{-1}$'], 'test var1 & var2', 'pdf', False) 4643 4644 def plot_2D_shadow_contour_old(varsv,varcv,vnames,dimxv,dimyv,dimxu,dimyu,dimn, \ 4645 colorbar,ckind,clabfmt,vs,vc,uts,vtit,kfig,reva,mapv): 4646 """ Adding labels and other staff to the graph 4647 varsv= 2D values to plot with shading 4648 varcv= 2D values to plot with contours 4649 vnames= variable names for the figure 4650 dim[x/y]v = values at the axes of x and y 4651 dim[x/y]u = units at the axes of x and y 4652 dimn= dimension names to plot 4653 colorbar= name of the color bar to use 4654 ckind= contour kind 4655 'cmap': as it gets from colorbar 4656 'fixc,[colname]': fixed color [colname], all stright lines 4657 'fixsigc,[colname]': fixed color [colname], >0 stright, <0 dashed line 4658 clabfmt= format of the labels in the contour plot (None, no labels) 4659 vs= minmum and maximum values to plot in shadow 4660 vc= vector with the levels for the contour 4661 uts= units of the variable [u-shadow, u-contour] 4662 vtit= title of the variable 4663 kfig= kind of figure (jpg, pdf, png) 4664 reva= 4665 * 'transpose': reverse the axes (x-->y, y-->x) 4666 * 'flip'@[x/y]: flip the axis x or y 4667 mapv= map characteristics: [proj],[res] 4668 see full documentation: http://matplotlib.org/basemap/ 4669 [proj]: projection 4670 * 'cyl', cilindric 4671 * 'lcc', lamvbert conformal 4672 [res]: resolution: 4673 * 'c', crude 4674 * 'l', low 4675 * 'i', intermediate 4676 * 'h', high 4677 * 'f', full 4678 """ 4679 ## import matplotlib as mpl 4680 ## mpl.use('Agg') 4681 ## import matplotlib.pyplot as plt 4682 fname = 'plot_2D_shadow_contour' 4683 4684 if varsv == 'h': 4685 print fname + '_____________________________________________________________' 4686 print plot_2D_shadow_contour.__doc__ 4687 quit() 4688 4450 4689 if reva[0:4] == 'flip': 4451 4690 reva0 = 'flip' … … 4582 4821 # contour 4583 4822 ## 4823 print fname + '; Lluis: shapes x:', x.shape,'y:',y.shape,'varcv:',varcv.shape 4584 4824 contkind = ckind.split(',')[0] 4585 4825 if contkind == 'cmap': … … 4652 4892 4653 4893 return 4654 4655 #Nvals=504656 #vals1 = np.zeros((Nvals,Nvals), dtype= np.float)4657 #vals2 = np.zeros((Nvals,Nvals), dtype= np.float)4658 #for j in range(Nvals):4659 # for i in range(Nvals):4660 # vals1[j,i]=np.sqrt((j-Nvals/2)**2. + (i-Nvals/2)**2.)4661 # vals2[j,i]=np.sqrt((j-Nvals/2)**2. + (i-Nvals/2)**2.) - Nvals/24662 4663 #prettylev=pretty_int(-Nvals/2,Nvals/2,10)4664 4665 #plot_2D_shadow_contour(vals1, vals2, ['var1', 'var2'], np.arange(50)*1., \4666 # np.arange(50)*1., ['x-axis','y-axis'], 'rainbow', 'fixc,b', "%.2f", [0, Nvals], \4667 # prettylev, ['$ms^{-1}$','$kJm^{-1}s^{-1}$'], 'test var1 & var2', 'pdf', False)4668 4894 4669 4895 def plot_2D_shadow_contour_time(varsv,varcv,vnames,valv,timv,timpos,timlab,valu, \
Note: See TracChangeset
for help on using the changeset viewer.