Changeset 21446


Ignore:
Timestamp:
12/21/16 09:46:50 (8 years ago)
Author:
bdef
Message:

CHG:optimizing the number of patch we plot for 3D with python (only plotting an enveloppe)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/plot/plot_unit.py

    r21444 r21446  
    11from cmaptools import truncate_colormap
    22from plot_quiver import plot_quiver
     3from scipy.interpolate import griddata
    34import numpy as  np
    45try:
     
    2223        #if we are plotting 3d replace the current axis
    2324        if not is2d:
     25                axgrid[gridindex].axis('off')
    2426                ax=inset_locator.inset_axes(axgrid[gridindex],width='100%',height='100%',loc=3,borderpad=0,axes_class=Axes3D)
     27                ax.set_axis_bgcolor((0.7,0.7,0.7))
    2528        else:
    2629                ax=axgrid[gridindex]
     
    9194                        tri=ax.tripcolor(triangles,data,colorlevels,cmap=cmap,norm=norm,alpha=alpha,edgecolors=edgecolor)
    9295                else:
     96
     97
    9398                        #first deal with colormap
    9499                        loccmap = plt.cm.ScalarMappable(cmap=cmap)
     
    103108                        recface=np.vstack((recface,np.vstack((elements[:,2],elements[:,0],elements[:,3],elements[:,5])).T))
    104109                        eltind=np.hstack((eltind,np.arange(0,np.shape(elements)[0])))
    105                         tmp = np.ascontiguousarray(recface).view(np.dtype((np.void, recface.dtype.itemsize * recface.shape[1])))
    106                         _, idx = np.unique(tmp, return_index=True)
    107                         recel= recface[idx]
    108                         recindex=eltind[idx]
     110                        tmp = np.ascontiguousarray(np.sort(recface)).view(np.dtype((np.void, recface.dtype.itemsize * recface.shape[1])))
     111                        _, idx, recur = np.unique(tmp, return_index=True, return_counts=True)
     112                        recel= recface[idx[np.where(recur==1)]]
     113                        recindex=eltind[idx[np.where(recur==1)]]
    109114                        for i,rectangle in enumerate(recel):
    110115                                rec=zip(x[rectangle],y[rectangle],z[rectangle])
     
    120125                        eltind=np.hstack((eltind,np.arange(0,np.shape(elements)[0])))
    121126                        tmp = np.ascontiguousarray(triface).view(np.dtype((np.void, triface.dtype.itemsize * triface.shape[1])))
    122                         _, idx = np.unique(tmp, return_index=True)
    123                         triel= triface[idx]
    124                         triindex=eltind[idx]
     127                        _, idx,recur = np.unique(tmp, return_index=True,return_counts=True)
     128                        #we keep only top and bottom elements
     129                        triel= triface[idx[np.where(recur==1)]]
     130                        triindex=eltind[idx[np.where(recur==1)]]
    125131                        for i,triangle in enumerate(triel):
    126132                                tri=zip(x[triangle],y[triangle],z[triangle])
     
    154160                        loccmap.set_array([min(data),max(data)])
    155161                        loccmap.set_clim(vmin=min(data),vmax=max(data))
    156 
     162                       
    157163                        #deal with prism sides
    158164                        recface=np.vstack((elements[:,0],elements[:,1],elements[:,4],elements[:,3])).T
    159165                        recface=np.vstack((recface,np.vstack((elements[:,1],elements[:,2],elements[:,5],elements[:,4])).T))
    160166                        recface=np.vstack((recface,np.vstack((elements[:,2],elements[:,0],elements[:,3],elements[:,5])).T))
    161                         tmp = np.ascontiguousarray(recface).view(np.dtype((np.void, recface.dtype.itemsize * recface.shape[1])))
    162                         _, idx = np.unique(tmp, return_index=True)
    163                         recel= recface[idx]                                     
     167                        tmp = np.ascontiguousarray(np.sort(recface)).view(np.dtype((np.void, recface.dtype.itemsize * recface.shape[1])))
     168                        _, idx, recur = np.unique(tmp, return_index=True, return_counts=True)
     169                        recel= recface[idx[np.where(recur==1)]]
    164170                        for rectangle in recel:
    165171                                rec=zip(x[rectangle],y[rectangle],z[rectangle])
     
    169175                                pl3.set_color(color)
    170176                                ax.add_collection3d(pl3)
    171 
     177                               
    172178                        #deal with prism faces
    173179                        triface=np.vstack((elements[:,0:3],elements[:,3:6]))
    174180                        tmp = np.ascontiguousarray(triface).view(np.dtype((np.void, triface.dtype.itemsize * triface.shape[1])))
    175                         _, idx = np.unique(tmp, return_index=True)
    176                         triel= triface[idx]
     181                        _, idx,recur = np.unique(tmp, return_index=True,return_counts=True)
     182                        #we keep only top and bottom elements
     183                        triel= triface[idx[np.where(recur==1)]]
    177184                        for triangle in triel:
    178185                                tri=zip(x[triangle],y[triangle],z[triangle])
     
    182189                                pl3.set_color(color)
    183190                                ax.add_collection3d(pl3)
    184        
     191                               
    185192                        ax.set_xlim([min(x),max(x)])
    186193                        ax.set_ylim([min(y),max(y)])
Note: See TracChangeset for help on using the changeset viewer.