def view(state,param): param = {i:np.array(v) for i,v in param.iteritems()} #covert lat lon to xyz f = open('basemap.pkl','r') bm = pickle.load(f) f.close() fluidity_transforms = [] x,y = bm(*basis.FLUIDITY_ANCHOR[:2]) length = basis.FLUIDITY_LENGTH width = basis.FLUIDITY_WIDTH thickness = basis.FLUIDITY_THICKNESS t = trans.point_stretch([basis.FLUIDITY_LENGTH, basis.FLUIDITY_THICKNESS, 1.0]) t += trans.point_rotation_x(np.pi/2.0) t += trans.point_translation([0.0,-width/2.0,0.0]) t += trans.point_rotation_z(np.pi/2.0 - basis.FLUIDITY_STRIKE*np.pi/180) t += trans.point_translation([x,y,0.0]) fluidity_transforms += [t] t = trans.point_stretch([basis.FLUIDITY_WIDTH, basis.FLUIDITY_THICKNESS, 1.0]) t += trans.point_rotation_x(np.pi/2.0) t += trans.point_rotation_z(-np.pi/2.0) t += trans.point_translation([basis.FLUIDITY_LENGTH/2.0, 0.0, 0.0]) t += trans.point_rotation_z(np.pi/2.0 - basis.FLUIDITY_STRIKE*np.pi/180) t += trans.point_translation([x,y,0.0]) fluidity_transforms += [t] fault_transforms = basis.FAULT_TRANSFORMS xs1 = XSection(basis.fluidity, f_args=(state['fluidity'][-1],), base_square_y=(-1,0), transforms = fluidity_transforms, clim = param['fluidity_clim']) xs2 = XSection(basis.fluidity, f_args=(state['fluidity'][-1],), base_square_y=(-1,0), transforms = fault_transforms) class InteractiveSlip(HasTraits): #time_index = Range(0,len(state['slip']),0.5) #print(state) time = Range(round(min(state['time']),2),round(max(state['time']),2)) scene = Instance(MlabSceneModel,()) view = View(Item('scene',editor=SceneEditor(scene_class=MayaviScene), height=250,width=300,show_label=False), Group('time'),resizable=True) def __init__(self): #myplot.topo.draw_topography(bm,opacity=0.2) time_index = np.argmin(abs(state['time'][...] - self.time)) slip = np.array(state[str(param['slip_type'])][time_index]) self.xs = () self.vxs = () for i,t in enumerate(fault_transforms): self.xs += XSection(slip_mag, f_args=(slip,i), base_square_y=(-1,0), transforms = [t],clim=param['slip_clim']), self.vxs += VectorXSection(slip_vec, f_args=(slip,basis.FAULT_STRIKE[i],basis.FAULT_DIP[i],i), base_square_y=(-1,0), transforms = [t]), HasTraits.__init__(self) @on_trait_change('time,scene.activated') def update_plot(self): time_index = np.argmin(abs(state['time'][...] - self.time)) slip = np.array(state[str(param['slip_type'])][time_index]) for i,t in enumerate(fault_transforms): self.xs[i].set_f_args((slip,i)) self.vxs[i].set_f_args((slip,basis.FAULT_STRIKE[i],basis.FAULT_DIP[i],i)) if self.xs[i]._plots is None: self.xs[i].draw() else: self.xs[i].redraw() if self.vxs[i]._plots is None: self.vxs[i].draw() else: self.vxs[i].redraw() #myplot.topo.draw_topography(bm,opacity=0.2) mayavi.mlab.figure(1) xs1.draw() xs2.draw(color=(0.2,0.2,0.2),opacity=0.5) myplot.topo.draw_topography(bm,opacity=0.2) #mayavi.mlab.figure(2) xs2 = InteractiveSlip() xs2.configure_traits()
t += trans.point_rotation_z(np.pi/2.0 - FLUIDITY_STRIKE*np.pi/180) t += trans.point_translation([x,y,0.0]) fluidity_transforms += [t] xs1 = XSection(fluidity, f_args=(np.random.random(FLUIDITY_N),), base_square_y=(-1,0), transforms = fluidity_transforms, clim = (0,1)) xs2 = XSection(fluidity, f_args=(np.random.random(FLUIDITY_N),), base_square_y=(-1,0), transforms = FAULT_TRANSFORMS) xs1.draw() xs2.draw(color=(0.2,0.2,0.2),opacity=0.5) mayavi.mlab.points3d(sta_pos_x,sta_pos_y,0*sta_pos[:,1],scale_factor=10000) xs1.view() coeff = np.random.random(FAULT_N) xs1 = XSection(slip, f_args=(coeff,), base_square_y=(-1,0), transforms = FAULT_TRANSFORMS, clim=(0,1)) xs1.draw() xs1.view() coeff = np.random.random(FLUIDITY_N)