Changeset 23563


Ignore:
Timestamp:
12/20/18 08:43:50 (6 years ago)
Author:
bdef
Message:

CHG: updating overlay for plotmodel

Location:
issm/trunk-jpl/src/m
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/classes/plotoptions.py

    r17502 r23563  
    5252                                print "WARNING: option number %d is not a string and will be ignored." % (i+1)
    5353
    54                 #get figure number 
     54                #get figure number
    5555                self.figurenumber=rawoptions.getfieldvalue('figure',1)
    5656                rawoptions.removefield('figure',0)
    5757
    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'])
    6060                self.numberofplots=numberofplots
    6161
     
    7676                        #if alloptions flag is on, apply to all plots
    7777                        if (allflag and 'data' not in rawlist[i][0] and '#' not in rawlist[i][0]):
    78                                
     78
    7979                                for j in xrange(numberofplots):
    8080                                        self.list[j].addfield(rawlist[i][0],rawlist[i][1])
     
    106106                                                        raise ValueError('error: in option i-j both i and j must be integers')
    107107                                                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])
    109109
    110110                                        # Deal with #i
     
    115115                                                self.list[int(plotnum)-1].addfield(field,rawlist[i][1])
    116116                        else:
    117                                
     117
    118118                                #go through all subplots and assign key-value pairs
    119119                                j=0
  • issm/trunk-jpl/src/m/plot/applyoptions.py

    r21444 r23563  
    120120                for label in ax.get_xticklabels() + ax.get_yticklabels():
    121121                        label.set_fontsize(options.getfieldvalue('ticklabelfontsize'))
    122                 if int(md.mesh.dimension)==3: 
     122                if int(md.mesh.dimension)==3:
    123123                        for label in ax.get_zticklabels():
    124124                                label.set_fontsize(options.getfieldvalue('ticklabelfontsize'))
     
    142142        # }}}
    143143        # {{{ xlim, ylim, zlim
    144         if options.exist('xlim'):
     144        if options.exist('xlim'):
    145145                ax.set_xlim(options.getfieldvalue('xlim'))
    146146        if options.exist('ylim'):
     
    164164                options.addfielddefault('clim',lims)
    165165        else:
    166                 if len(data)>0: 
     166                if len(data)>0:
    167167                        lims=[data.min(),data.max()]
    168                 else: 
     168                else:
    169169                        lims=[0,1]
    170170        # }}}
     
    231231                cb.solids.set_rasterized(True)
    232232                cb.update_ticks()
    233                 cb.set_alpha(1)
    234233                cb.draw_all()
    235                 if options.exist('colorbarfontsize'):
    236                         colorbarfontsize=options.getfieldvalue('colorbarfontsize')
    237                         cb.ax.tick_params(labelsize=colorbarfontsize)
    238                         # cb.set_ticks([0,-10])
    239                         # cb.set_ticklabels([-10,0,10])
    240                 if options.exist('colorbarticks'):
    241                         colorbarticks=options.getfieldvalue('colorbarticks')
    242                         cb.set_ticks(colorbarticks)
     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)
    243242                plt.sca(ax) # return to original axes control
    244243        # }}}
    245         # {{{ expdisp 
     244        # {{{ expdisp
    246245        if options.exist('expdisp'):
    247246                expdisp(ax,options)
     
    291290        # {{{ inset TODO
    292291        # }}}
    293        
  • issm/trunk-jpl/src/m/plot/plot_manager.py

    r21475 r23563  
    9696        #apply all options
    9797        applyoptions(md,data2,options,fig,axgrid,gridindex)
    98        
     98
    9999        #ground overlay on kml plot_unit
    100100
  • issm/trunk-jpl/src/m/plot/plot_overlay.py

    r21303 r23563  
    55import matplotlib.pyplot as plt
    66import matplotlib as mpl
     7import os
    78try:
    8     from mpl_toolkits.basemap import Basemap
     9        from mpl_toolkits.basemap import Basemap
    910except ImportError:
    10     print 'Basemap toolkit not installed'
    11 
    12 import os
    13 
     11        print 'Basemap toolkit not installed'
    1412try:
    15         from osgeo import gdal
     13        from osgeo import gdal
    1614except ImportError:
    1715        print 'osgeo/gdal for python not installed, plot_overlay is disabled'
     
    2523
    2624        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
    2929                imageonly=1
    3030                data=np.float('nan')*np.ones((md.mesh.numberofvertices,))
    3131                datatype=1
    32         else:
    33                 imageonly=0
    34                 data,datatype=processdata(md,data,options)
    3532
    3633        if not is2d:
     
    5047        ymin=trans[3]+gtif.RasterYSize*trans[5]
    5148        ymax=trans[3]
    52        
    5349        # allow supplied image to have limits smaller than basemap or model limits
    5450        x0=max(min(xlim),xmin)
     
    5854        inputname='temp.tif'
    5955        os.system('gdal_translate -quiet -projwin ' + str(x0) + ' ' + str(y1) + ' ' + str(x1) + ' ' + str(y0) + ' ' + image+ ' ' + inputname)
    60        
     56
    6157        gtif=gdal.Open(inputname)
    6258        arr=gtif.ReadAsArray()
    6359        #os.system('rm -rf ./temp.tif')
    64        
     60
    6561        if gtif.RasterCount>=3:  # RGB array
    6662                r=gtif.GetRasterBand(1).ReadAsArray()
     
    8480                plt.hist(arr.flatten(),bins=256,range=(0.,1.))
    8581                plt.title('histogram of overlay image, use for setting overlaylims')
    86                 plt.show()
     82                plt.show()
    8783                plt.sca(ax) # return to original axes/figure
    88                
     84
    8985        # get parameters from cropped geotiff
    9086        trans=gtif.GetGeoTransform()
     
    9490        ymax=trans[3]
    9591        dx=trans[1]
    96         dy=trans[5]     
    97        
     92        dy=trans[5]
     93
    9894        xarr=np.arange(xmin,xmax,dx)
    9995        yarr=np.arange(ymin,ymax,-dy) # -dy since origin='upper' (not sure how robust this is)
     
    10298        norm=mpl.colors.Normalize(vmin=overlaylims[0],vmax=overlaylims[1])
    10399
     100        pc=ax.pcolormesh(xg, yg, np.flipud(arr), cmap=mpl.cm.Greys, norm=norm)
     101
    104102        if options.exist('basemap'):
    105103                # 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))
    126114
    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?
    131131        if options.getfieldvalue('rasterized',0):
    132132                pc.set_rasterized(True)
  • issm/trunk-jpl/src/m/plot/plot_streamlines.py

    r21303 r23563  
    1212def plot_streamlines(md,options,ax):
    1313    '''
    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.
    1515
    1616    Usage:
     
    2525        streamlineswidthscale: scaling multiplier for linewidth scaled by velocity
    2626        streamlinesarrowsize: size of arrows on lines (default 1)
    27        
     27
    2828    '''
    2929
     
    3636    arrowsize=options.getfieldvalue('streamlinesarrowsize',1)
    3737
    38     #process mesh and data 
     38    #process mesh and data
    3939    x,y,z,elements,is2d,isplanet=processmesh(md,vx,options)
    4040    u,datatype=processdata(md,vx,options)
  • issm/trunk-jpl/src/m/plot/plot_unit.py

    r22345 r23563  
    1111except ImportError:
    1212        print "could not import pylab, matplotlib has not been installed, no plotting capabilities enabled"
    13        
     13
    1414def plot_unit(x,y,z,elements,data,is2d,isplanet,datatype,options,fig,axgrid,gridindex):
    1515        """
    1616        PLOT_UNIT - unit plot, display data
    17        
     17
    1818        Usage:
    1919        plot_unit(x,y,z,elements,data,is2d,isplanet,datatype,options)
     
    3636        colorlevels=options.getfieldvalue('colorlevels',128)
    3737        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
    4044        try:
    4145                defaultmap=plt.cm.get_cmap('viridis',colorlevels)
     
    5155                cmap.set_under(under)
    5256        options.addfield('colormap',cmap)
    53         # }}}   
     57        # }}}
    5458        # {{{ if plotting only one of several layers reduce dataset, same for surface
    5559        if options.getfieldvalue('layer',0)>=1:
     
    8387        options.addfield('colornorm',norm)
    8488        # }}}
    85        
     89
    8690        # Plot depending on the datatype
    8791        # {{{ data are on elements
     92
    8893        if datatype==1:
    8994                if is2d:
     
    141146                        #raise ValueError('plot_unit error: 3D element plot not supported yet')
    142147                return
     148
    143149        # }}}
    144150        # {{{ data are on nodes
     151
    145152        elif datatype==2:
    146153                if is2d:
     
    152159                                #tri=ax.tricontourf(triangles,data,colorlevels,cmap=cmap,norm=norm,alpha=alpha)
    153160                        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)
    155164                        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)
    157168                        if edgecolor != 'None':
    158169                                ax.triplot(x,y,elements,color=edgecolor)
     
    162173                        loccmap.set_array([min(data),max(data)])
    163174                        loccmap.set_clim(vmin=min(data),vmax=max(data))
    164                        
     175
    165176                        #deal with prism sides
    166177                        recface=np.vstack((elements[:,0],elements[:,1],elements[:,4],elements[:,3])).T
     
    177188                                pl3.set_color(color)
    178189                                ax.add_collection3d(pl3)
    179                                
     190
    180191                        #deal with prism faces
    181192                        triface=np.vstack((elements[:,0:3],elements[:,3:6]))
     
    191202                                pl3.set_color(color)
    192203                                ax.add_collection3d(pl3)
    193                                
     204
    194205                        ax.set_xlim([min(x),max(x)])
    195206                        ax.set_ylim([min(y),max(y)])
     
    197208                        #raise ValueError('plot_unit error: 3D element plot not supported yet')
    198209                return
     210
    199211        # }}}
    200212        # {{{ plotting quiver
     
    223235        else:
    224236                raise ValueError('datatype=%d not supported' % datatype)
    225    
Note: See TracChangeset for help on using the changeset viewer.