Changeset 23563
- Timestamp:
- 12/20/18 08:43:50 (6 years ago)
- Location:
- issm/trunk-jpl/src/m
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/classes/plotoptions.py
r17502 r23563 52 52 print "WARNING: option number %d is not a string and will be ignored." % (i+1) 53 53 54 #get figure number 54 #get figure number 55 55 self.figurenumber=rawoptions.getfieldvalue('figure',1) 56 56 rawoptions.removefield('figure',0) 57 57 58 #get number of subplots 59 numberofplots= Counter(x for sublist in rawlist for x in sublist if isinstance(x,(str,unicode)))['data']58 #get number of subplots 59 numberofplots=len([1 for sublist in rawlist for x in sublist if str(x)=='data']) 60 60 self.numberofplots=numberofplots 61 61 … … 76 76 #if alloptions flag is on, apply to all plots 77 77 if (allflag and 'data' not in rawlist[i][0] and '#' not in rawlist[i][0]): 78 78 79 79 for j in xrange(numberofplots): 80 80 self.list[j].addfield(rawlist[i][0],rawlist[i][1]) … … 106 106 raise ValueError('error: in option i-j both i and j must be integers') 107 107 for j in xrange(int(nums[0])-1,int(nums[1])): 108 self.list[j].addfield(field,rawlist[i][1]) 108 self.list[j].addfield(field,rawlist[i][1]) 109 109 110 110 # Deal with #i … … 115 115 self.list[int(plotnum)-1].addfield(field,rawlist[i][1]) 116 116 else: 117 117 118 118 #go through all subplots and assign key-value pairs 119 119 j=0 -
issm/trunk-jpl/src/m/plot/applyoptions.py
r21444 r23563 120 120 for label in ax.get_xticklabels() + ax.get_yticklabels(): 121 121 label.set_fontsize(options.getfieldvalue('ticklabelfontsize')) 122 if int(md.mesh.dimension)==3: 122 if int(md.mesh.dimension)==3: 123 123 for label in ax.get_zticklabels(): 124 124 label.set_fontsize(options.getfieldvalue('ticklabelfontsize')) … … 142 142 # }}} 143 143 # {{{ xlim, ylim, zlim 144 if options.exist('xlim'):144 if options.exist('xlim'): 145 145 ax.set_xlim(options.getfieldvalue('xlim')) 146 146 if options.exist('ylim'): … … 164 164 options.addfielddefault('clim',lims) 165 165 else: 166 if len(data)>0: 166 if len(data)>0: 167 167 lims=[data.min(),data.max()] 168 else: 168 else: 169 169 lims=[0,1] 170 170 # }}} … … 231 231 cb.solids.set_rasterized(True) 232 232 cb.update_ticks() 233 cb.set_alpha(1)234 233 cb.draw_all() 235 236 237 238 239 240 241 242 234 if options.exist('colorbarfontsize'): 235 colorbarfontsize=options.getfieldvalue('colorbarfontsize') 236 cb.ax.tick_params(labelsize=colorbarfontsize) 237 # cb.set_ticks([0,-10]) 238 # cb.set_ticklabels([-10,0,10]) 239 if options.exist('colorbarticks'): 240 colorbarticks=options.getfieldvalue('colorbarticks') 241 cb.set_ticks(colorbarticks) 243 242 plt.sca(ax) # return to original axes control 244 243 # }}} 245 # {{{ expdisp 244 # {{{ expdisp 246 245 if options.exist('expdisp'): 247 246 expdisp(ax,options) … … 291 290 # {{{ inset TODO 292 291 # }}} 293 -
issm/trunk-jpl/src/m/plot/plot_manager.py
r21475 r23563 96 96 #apply all options 97 97 applyoptions(md,data2,options,fig,axgrid,gridindex) 98 98 99 99 #ground overlay on kml plot_unit 100 100 -
issm/trunk-jpl/src/m/plot/plot_overlay.py
r21303 r23563 5 5 import matplotlib.pyplot as plt 6 6 import matplotlib as mpl 7 import os 7 8 try: 8 9 from mpl_toolkits.basemap import Basemap 9 10 except ImportError: 10 print 'Basemap toolkit not installed' 11 12 import os 13 11 print 'Basemap toolkit not installed' 14 12 try: 15 13 from osgeo import gdal 16 14 except ImportError: 17 15 print 'osgeo/gdal for python not installed, plot_overlay is disabled' … … 25 23 26 24 x,y,z,elements,is2d,isplanet=processmesh(md,[],options) 27 28 if data=='none' or data==None: 25 try: 26 data,datatype=processdata(md,data,options) 27 imageonly=0 28 except (TypeError,ValueError):#that should catch None and 'none' but may also catch unwanted errors 29 29 imageonly=1 30 30 data=np.float('nan')*np.ones((md.mesh.numberofvertices,)) 31 31 datatype=1 32 else:33 imageonly=034 data,datatype=processdata(md,data,options)35 32 36 33 if not is2d: … … 50 47 ymin=trans[3]+gtif.RasterYSize*trans[5] 51 48 ymax=trans[3] 52 53 49 # allow supplied image to have limits smaller than basemap or model limits 54 50 x0=max(min(xlim),xmin) … … 58 54 inputname='temp.tif' 59 55 os.system('gdal_translate -quiet -projwin ' + str(x0) + ' ' + str(y1) + ' ' + str(x1) + ' ' + str(y0) + ' ' + image+ ' ' + inputname) 60 56 61 57 gtif=gdal.Open(inputname) 62 58 arr=gtif.ReadAsArray() 63 59 #os.system('rm -rf ./temp.tif') 64 60 65 61 if gtif.RasterCount>=3: # RGB array 66 62 r=gtif.GetRasterBand(1).ReadAsArray() … … 84 80 plt.hist(arr.flatten(),bins=256,range=(0.,1.)) 85 81 plt.title('histogram of overlay image, use for setting overlaylims') 86 82 plt.show() 87 83 plt.sca(ax) # return to original axes/figure 88 84 89 85 # get parameters from cropped geotiff 90 86 trans=gtif.GetGeoTransform() … … 94 90 ymax=trans[3] 95 91 dx=trans[1] 96 dy=trans[5] 97 92 dy=trans[5] 93 98 94 xarr=np.arange(xmin,xmax,dx) 99 95 yarr=np.arange(ymin,ymax,-dy) # -dy since origin='upper' (not sure how robust this is) … … 102 98 norm=mpl.colors.Normalize(vmin=overlaylims[0],vmax=overlaylims[1]) 103 99 100 pc=ax.pcolormesh(xg, yg, np.flipud(arr), cmap=mpl.cm.Greys, norm=norm) 101 104 102 if options.exist('basemap'): 105 103 # create coordinate grid in map projection units (for plotting) 106 lat,lon=xy2ll(xlim,ylim,-1,0,71) 107 #plt.sca(ax) 108 width=xmax-xmin 109 height=ymax-ymin 110 lat_0,lon_0=xy2ll(xmin+width/2.,ymin+height/2.,-1,0,71) 111 m=Basemap(projection='spstere', 112 llcrnrlon=lon[0],llcrnrlat=lat[0],urcrnrlon=lon[1],urcrnrlat=lat[1], 113 epsg=3031, 114 resolution='c') 115 #width=width,height=height,lon_0=lon_0,lat_0=lat_0, 116 #lat_0=-90,lon_0=0,lat_ts=-71, 117 #llcrnrx=x0,llcrnry=y0,urcrnrx=x1,urcrnry=y1) 118 #test 119 #m.ax=ax 120 meridians=np.arange(-180.,181.,1.) 121 parallels=np.arange(-80.,80.,1.) 122 m.drawparallels(parallels,labels=[0,0,1,1]) # labels=[left,right,top,bottom] 123 m.drawmeridians(meridians,labels=[1,1,0,0]) 124 m.drawcoastlines() 125 pc=m.pcolormesh(xg, yg, np.flipud(arr), cmap=mpl.cm.Greys, norm=norm, ax=ax) 104 if md.mesh.epsg==3413: 105 hemisphere=1 106 st_lat=70 107 lon_0=45 108 elif md.mesh.epsg==3031: 109 hemisphere=-1 110 st_lat=71 111 lon_0=0 112 else: 113 hemisphere=raw_input('epsg code {} is not supported chose your hemisphere (1 for North, -1 for south)'.format(mesh.epsg)) 126 114 127 else: 128 pc=ax.pcolormesh(xg, yg, np.flipud(arr), cmap=mpl.cm.Greys, norm=norm) 129 130 #rasterization? 115 lat,lon=xy2ll(xlim,ylim,hemisphere,lon_0,st_lat) 116 extent=[np.diff(xlim)[0],np.diff(ylim)[0]] 117 center=[lon[0]+np.diff(lon)[0]*0.5,lat[0]+np.diff(lat)[0]*0.5] 118 m=Basemap(llcrnrlon=lon[0],llcrnrlat=lat[0],urcrnrlon=lon[1],urcrnrlat=lat[1], 119 lon_0=center[0],lat_0=center[1],#width=extent[0],height=extent[1],# 120 epsg=md.mesh.epsg,anchor='NW', 121 resolution='i',ax=ax) 122 123 meridians=np.arange(np.floor(lon[0]),np.ceil(lon[1]),1.) 124 parallels=np.arange(np.floor(lat[0]),np.ceil(lat[1]),1.) 125 m.drawparallels(parallels,labels=[1,0,0,0],ax=ax) # labels=[left,right,top,bottom] 126 m.drawmeridians(meridians,labels=[0,0,1,0],ax=ax) 127 m.drawcoastlines(ax=ax) 128 m.drawmapboundary(ax=ax) 129 130 #rasterization? 131 131 if options.getfieldvalue('rasterized',0): 132 132 pc.set_rasterized(True) -
issm/trunk-jpl/src/m/plot/plot_streamlines.py
r21303 r23563 12 12 def plot_streamlines(md,options,ax): 13 13 ''' 14 plot streamlines on a figure, using by default vx and vy components in md.initialization. 14 plot streamlines on a figure, using by default vx and vy components in md.initialization. 15 15 16 16 Usage: … … 25 25 streamlineswidthscale: scaling multiplier for linewidth scaled by velocity 26 26 streamlinesarrowsize: size of arrows on lines (default 1) 27 27 28 28 ''' 29 29 … … 36 36 arrowsize=options.getfieldvalue('streamlinesarrowsize',1) 37 37 38 #process mesh and data 38 #process mesh and data 39 39 x,y,z,elements,is2d,isplanet=processmesh(md,vx,options) 40 40 u,datatype=processdata(md,vx,options) -
issm/trunk-jpl/src/m/plot/plot_unit.py
r22345 r23563 11 11 except ImportError: 12 12 print "could not import pylab, matplotlib has not been installed, no plotting capabilities enabled" 13 13 14 14 def plot_unit(x,y,z,elements,data,is2d,isplanet,datatype,options,fig,axgrid,gridindex): 15 15 """ 16 16 PLOT_UNIT - unit plot, display data 17 17 18 18 Usage: 19 19 plot_unit(x,y,z,elements,data,is2d,isplanet,datatype,options) … … 36 36 colorlevels=options.getfieldvalue('colorlevels',128) 37 37 alpha=options.getfieldvalue('alpha',1) 38 # }}} 39 # {{{ define wich colormap to use 38 if alpha<1: 39 antialiased=True 40 else: 41 antialiased=False 42 # }}} 43 # {{{ define wich colormap to use 40 44 try: 41 45 defaultmap=plt.cm.get_cmap('viridis',colorlevels) … … 51 55 cmap.set_under(under) 52 56 options.addfield('colormap',cmap) 53 # }}} 57 # }}} 54 58 # {{{ if plotting only one of several layers reduce dataset, same for surface 55 59 if options.getfieldvalue('layer',0)>=1: … … 83 87 options.addfield('colornorm',norm) 84 88 # }}} 85 89 86 90 # Plot depending on the datatype 87 91 # {{{ data are on elements 92 88 93 if datatype==1: 89 94 if is2d: … … 141 146 #raise ValueError('plot_unit error: 3D element plot not supported yet') 142 147 return 148 143 149 # }}} 144 150 # {{{ data are on nodes 151 145 152 elif datatype==2: 146 153 if is2d: … … 152 159 #tri=ax.tricontourf(triangles,data,colorlevels,cmap=cmap,norm=norm,alpha=alpha) 153 160 if options.exist('log'): 154 tri=ax.tricontourf(triangles,data,colorlevels,cmap=cmap,norm=norm,alpha=alpha) 161 if alpha<1:#help with antialiasing 162 tri=ax.tricontour(triangles,data,colorlevels,cmap=cmap,norm=norm,alpha=0.1,antialiased=antialiased) 163 tri=ax.tricontourf(triangles,data,colorlevels,cmap=cmap,norm=norm,alpha=alpha,antialiased=antialiased) 155 164 else: 156 tri=ax.tricontourf(triangles,data,colorlevels,cmap=cmap,norm=norm,alpha=alpha,extend='both') 165 if alpha<1:#help with antialiasing 166 tri=ax.tricontour(triangles,data,colorlevels,cmap=cmap,norm=norm,alpha=0.1,antialiased=antialiased) 167 tri=ax.tricontourf(triangles,data,colorlevels,cmap=cmap,norm=norm,alpha=alpha,extend='both',antialiased=antialiased) 157 168 if edgecolor != 'None': 158 169 ax.triplot(x,y,elements,color=edgecolor) … … 162 173 loccmap.set_array([min(data),max(data)]) 163 174 loccmap.set_clim(vmin=min(data),vmax=max(data)) 164 175 165 176 #deal with prism sides 166 177 recface=np.vstack((elements[:,0],elements[:,1],elements[:,4],elements[:,3])).T … … 177 188 pl3.set_color(color) 178 189 ax.add_collection3d(pl3) 179 190 180 191 #deal with prism faces 181 192 triface=np.vstack((elements[:,0:3],elements[:,3:6])) … … 191 202 pl3.set_color(color) 192 203 ax.add_collection3d(pl3) 193 204 194 205 ax.set_xlim([min(x),max(x)]) 195 206 ax.set_ylim([min(y),max(y)]) … … 197 208 #raise ValueError('plot_unit error: 3D element plot not supported yet') 198 209 return 210 199 211 # }}} 200 212 # {{{ plotting quiver … … 223 235 else: 224 236 raise ValueError('datatype=%d not supported' % datatype) 225
Note:
See TracChangeset
for help on using the changeset viewer.