Changeset 652 in lmdz_wrf for trunk/tools
- Timestamp:
- Sep 23, 2015, 11:28:59 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/drawing_tools.py
r647 r652 203 203 * -1: all along the dimension 204 204 * [beg]:[end] slice from [beg] to [end] 205 * -9: last value of the dimension 206 205 207 """ 206 208 fname = 'slice_variable' … … 223 225 varvalsdim = [] 224 226 dimnslice = [] 225 227 monodim = [] 226 228 for idd in range(Ndimvar): 227 229 found = False … … 241 243 dimnslice.append(vardims[idd]) 242 244 elif int(dimcutv) == -9: 243 varvalsdim.append(int(varobj.shape[idd])-1) 245 varvalsdim.append(varobj.shape[idd]-1) 246 monodim.append(vardims[idd]) 244 247 else: 245 248 varvalsdim.append(int(dimcutv)) 249 monodim.append(vardims[idd]) 246 250 found = True 247 251 break 248 if not found and not searchInlist(dimnslice,vardims[idd]): 252 if not found and not searchInlist(dimnslice,vardims[idd]) and \ 253 not searchInlist(monodim,vardims[idd]): 249 254 varvalsdim.append(slice(0,varobj.shape[idd])) 250 255 dimnslice.append(vardims[idd]) 251 256 varvalues = varobj[tuple(varvalsdim)] 257 258 varvalues = np.squeeze(varobj[tuple(varvalsdim)]) 252 259 253 260 return varvalues, dimnslice … … 3507 3514 if len(varsv.shape) != 2: 3508 3515 print errormsg 3509 print ' ' + fname + ': wrong variable shape:',var v.shape,'is has to be 2D!!'3516 print ' ' + fname + ': wrong variable shape:',varsv.shape,'is has to be 2D!!' 3510 3517 quit(-1) 3511 3518 … … 3547 3554 ydims = '0' 3548 3555 3549 lon0 = dimxv3550 lat0 = dimyv3551 #lon0, lat0 = dxdy_lonlat(dimxv,dimyv, xdims, ydims)3556 # lon0 = dimxv 3557 # lat0 = dimyv 3558 lon0, lat0 = dxdy_lonlat(dimxv,dimyv, xdims, ydims) 3552 3559 3553 3560 if not mapv is None: … … 4711 4718 [val]: value (-1 for all the range) 4712 4719 """ 4713 4714 4720 fname = 'dxdy_lonlatDIMS' 4721 4722 print 'Lluis dd:',dd 4715 4723 4716 4724 slicex = [] … … 4719 4727 for idd in range(len(dd)): 4720 4728 dname = dd[idd].split('|')[0] 4721 dvalue = int(dd[idd].split('|')[1])4729 dvalue = dd[idd].split('|')[1] 4722 4730 if dn == dname: 4723 if dvalue == -1: 4724 slicex.append(slice(0,dxv.shape[ipos])) 4731 if dvalue.find('@') != -1: 4732 slicex.append(slice(int(dvalue.split('@')[0]), \ 4733 int(dvalue.split('@')[1]))) 4725 4734 else: 4726 slicex.append(dvalue) 4727 break 4735 if int(dvalue) == -1: 4736 slicex.append(slice(0,dxv.shape[ipos])) 4737 elif int(dvalue) == -9: 4738 slicex.append(dxv.shape[ipos]-1) 4739 else: 4740 slicex.append(int(dvalue)) 4741 break 4728 4742 ipos = ipos + 1 4729 4743 … … 4733 4747 for idd in range(len(dd)): 4734 4748 dname = dd[idd].split('|')[0] 4735 dvalue = int(dd[idd].split('|')[1])4749 dvalue = dd[idd].split('|')[1] 4736 4750 if dn == dname: 4737 if dvalue == -1: 4738 slicey.append(slice(0,dyv.shape[ipos])) 4751 if dvalue.find('@') != -1: 4752 slicey.append(slice(int(dvalue.split('@')[0]), \ 4753 int(dvalue.split('@')[1]))) 4739 4754 else: 4740 slicey.append(dvalue) 4741 break 4755 if int(dvalue) == -1: 4756 slicey.append(slice(0,dyv.shape[ipos])) 4757 elif int(dvalue) == -9: 4758 slicey.append(dyv.shape[ipos]-1) 4759 else: 4760 slicey.append(int(dvalue)) 4761 break 4742 4762 ipos = ipos + 1 4743 4744 4763 4745 4764 lonv = dxv[tuple(slicex)] … … 5493 5512 return 5494 5513 5514 def plot_ptZvals(vname,vunits,points,ptype,ptsize,graphlims,minmax,figtitle,cbar, \ 5515 mapv,kfig): 5516 """ Function to plot a given list of points and values 5517 vname= name of the variable in the graph 5518 vunits= units of the variable 5519 points= [lon,lat,val] matrix of values 5520 ptype= type of the point 5521 ptsize= size of the point 5522 graphlims= minLON,minLAT,maxLON,maxLAT limits of the graph, None for the full size 5523 minmax= minimum and maximum type 5524 'auto': values taken from the extrems of the data 5525 [min],[max]: given minimum and maximum values 5526 figtitle= title of the figure 5527 cbar= color bar 5528 mapv= map characteristics: [proj],[res] 5529 see full documentation: http://matplotlib.org/basemap/ 5530 [proj]: projection 5531 * 'cyl', cilindric 5532 * 'lcc', lambert-conformal 5533 [res]: resolution: 5534 * 'c', crude 5535 * 'l', low 5536 * 'i', intermediate 5537 * 'h', high 5538 * 'f', full 5539 kfig= kind of figure 5540 """ 5541 fname = 'plot_ptZvals' 5542 5543 figname = 'pointsZval' 5544 5545 minlon = points[:,0].min() 5546 maxlon = points[:,0].max() 5547 5548 minlat = points[:,1].min() 5549 maxlat = points[:,1].max() 5550 5551 minval = points[:,2].min() 5552 maxval = points[:,2].max() 5553 5554 # print 'min/max val;',minval,maxval 5555 5556 lonrange = (points[:,0] - minlon)/(maxlon - minlon) 5557 latrange = (points[:,1] - minlat)/(maxlat - minlat) 5558 colorrange = (points[:,2] - minval)/(maxval - minval) 5559 5560 plt.rc('text', usetex=True) 5561 5562 if mapv is not None: 5563 vlon = points[:,0] 5564 vlat = points[:,1] 5565 dx = len(vlon) 5566 dy = len(vlat) 5567 5568 # vlon = np.where(vlon[:] < 0., 360. + vlon[:], vlon[:]) 5569 # xvala = np.array(xval) 5570 # xvala = np.where(xvala < 0., 360. + xvala, xvala) 5571 # xval = list(xvala) 5572 5573 map_proj=mapv.split(',')[0] 5574 map_res=mapv.split(',')[1] 5575 5576 if graphlims is not None: 5577 nlon = graphlims[0] 5578 xlon = graphlims[2] 5579 nlat = graphlims[1] 5580 xlat = graphlims[3] 5581 else: 5582 nlon = np.min(vlon) 5583 xlon = np.max(vlon) 5584 nlat = np.min(vlat) 5585 xlat = np.max(vlat) 5586 5587 lon2 = vlon[dy/2] 5588 lat2 = vlat[dy/2] 5589 5590 print 'lon2:', lon2, 'lat2:', lat2, 'SW pt:', nlon, ',', nlat, 'NE pt:', \ 5591 xlon, ',', xlat 5592 5593 if map_proj == 'cyl': 5594 m = Basemap(projection=map_proj, llcrnrlon=nlon, llcrnrlat=nlat, \ 5595 urcrnrlon=xlon, urcrnrlat= xlat, resolution=map_res) 5596 elif map_proj == 'lcc': 5597 m = Basemap(projection=map_proj, lat_0=lat2, lon_0=lon2, llcrnrlon=nlon, \ 5598 llcrnrlat=nlat, urcrnrlon=xlon, urcrnrlat= xlat, resolution=map_res) 5599 else: 5600 print errormsg 5601 print ' ' + fname + ": map projecion '" + map_proj + "' not ready!!" 5602 print ' available: cyl, lcc' 5603 quit(-1) 5604 5605 # lons, lats = np.meshgrid(vlon, vlat) 5606 # lons = np.where(lons < 0., lons + 360., lons) 5607 5608 x,y = m(vlon,vlat) 5609 5610 m.drawcoastlines() 5611 5612 meridians = pretty_int(nlon,xlon,5) 5613 m.drawmeridians(meridians,labels=[True,False,False,True]) 5614 5615 parallels = pretty_int(nlat,xlat,5) 5616 m.drawparallels(parallels,labels=[False,True,True,False]) 5617 # else: 5618 # x = vlon 5619 # y = vlat 5620 # plt.xlim(0,dx-1) 5621 # plt.ylim(0,dy-1) 5622 5623 if minmax == 'auto': 5624 plt.scatter(points[:,0], points[:,1], c=points[:,2], s=ptsize, cmap=cbar, \ 5625 marker=ptype) 5626 else: 5627 minv = np.float(minmax.split(',')[0]) 5628 maxv = np.float(minmax.split(',')[1]) 5629 5630 plt.scatter(points[:,0], points[:,1], c=points[:,2], s=ptsize, cmap=cbar, \ 5631 marker=ptype, vmin=minv, vmax=maxv) 5632 5633 cbar = plt.colorbar() 5634 cbar.set_label(vname.replace('_','\_') +' ('+ units_lunits(vunits) + ')') 5635 5636 plt.title(figtitle) 5637 if graphlims is not None: 5638 plt.xlim(graphlims[0], graphlims[2]) 5639 plt.ylim(graphlims[1], graphlims[3]) 5640 5641 output_kind(kfig, figname, True) 5642 5643 return 5644 5645 #pts = np.zeros((10,3), dtype=np.float) 5646 #pts[:,0] = np.arange(10,20)*1. 5647 #pts[:,1] = np.arange(30,40)*1. 5648 #pts[:,2] = np.arange(-5,5)*1. 5649 5650 #plot_ptZvals('vals','kgm-2',pts,'.',300, 'values of values', 'seismic', 'cyl,l', 'pdf') 5651 5495 5652 def plot_ZQradii(Zmeans, graphtit, kfig, figname): 5496 5653 """ Function to plot following radial averages only at exact grid poins
Note: See TracChangeset
for help on using the changeset viewer.