Slice and Filled Slice DatagridΒΆ

../../_images/slice_filled_jacks.png
import copy
import numpy as np
import matplotlib.pyplot as plt
import s3dlib.surface as s3d

#.. Sliced & Filled Sliced Datagrid

# 1. Define function to examine .....................................

Z=np.load('data/jacksboro_fault_dem.npz')['elevation']
datagrid = np.flip(Z,0)

sc,up,dn = 0.3, .5, -1
# 2. Setup and map surfaces .........................................

# upper lines...................
rez=6
line = s3d.ParametricLine(rez, cmap='gist_earth',lw=2)
line.map_xySlice_from_datagrid(datagrid, scale=sc, xset=2, yset=30)
line.map_cmap_from_datagrid(datagrid,cname='Elevation').shade(0.8)
line.transform(translate=[0,0,up])     # move up

# lower filled lines.........................
rez=5
lineF = s3d.ParametricLine(rez, cmap='gist_earth',lw=1)
lineF.map_xySlice_from_datagrid(datagrid, scale=sc, xset=2, yset=10)
lineF.map_cmap_from_datagrid(datagrid,cname='Elevation').shade(0.8)
lineF.set_color('k')

surface = lineF.get_filled_surface().triangulate(3)
surface.map_cmap_from_op( lambda xyz : xyz[2],'gist_earth')

lineF.transform(translate=[0,0,dn])    # move down
surface.transform(translate=[0,0,dn])  # move down

# 3. Construct figure, add surface, plot ............................

fig = plt.figure()
fig.text(0.975,0.975,str(surface), ha='right', va='top',
        fontsize='smaller', multialignment='right')
ax = plt.axes(projection='3d', aspect='equal')
ax.set(xlim=(-1,1), ylim=(-1,1), zlim=(-1,1) )
minc, maxc = line.bounds['vlim']
cbar=plt.colorbar(line.cBar_ScalarMappable, ax=ax,
        ticks=np.linspace(minc,maxc,5), shrink=0.6, pad=0  )
cbar.set_label('Elevation', rotation=270, labelpad = 15)
ax.set_axis_off()
ax.set_proj_type('ortho')
ax.view_init(elev=20, azim=60)

ax.add_collection3d(line)
ax.add_collection3d(s3d.PlanarSurface(color='k').domain(zcoor=up))

ax.add_collection3d(surface)
ax.add_collection3d(lineF)
ax.add_collection3d(s3d.PlanarSurface(color='k').domain(zcoor=dn))

fig.tight_layout(pad=0)
plt.show()