def view_data(data): """Example showing how to view a 3D numpy array in mayavi2. """ def set_labelE(ind): return '{0:.0f} eV'.format(source.energies[ind]) def move_view(obj, evt): labelE.text = set_labelE(ipwX.ipw.slice_index) pos = labelE.position labelE.position = ipwX.ipw.slice_index * src.spacing[0] + 1,\ pos[1], pos[2] labelE.vector_text.update() def set_lut(ipw): lutM = ipw.module_manager.scalar_lut_manager # lutM.show_scalar_bar = True # lutM.number_of_labels = 9 lutM.lut.scale = 'log10' lutM.lut.range = [dataMax * vmin, dataMax] lutM.lut_mode = 'hot' @animate() def anim(data, ipwX): scene.scene.off_screen_rendering = True scene.scene.anti_aliasing_frames = 0 for i in range(0, data.shape[0], 1): ipwX.ipw.slice_index = i move_view(None, None) if saveName is not None: scene.scene.save('{0}{1:04d}.png'.format(saveName, i)) yield # 'mayavi' is always defined on the interpreter. scene = mayavi.new_scene() # analysis:ignore scene.scene.background = (0, 0, 0) print(source.prefix_save_name()) src = ArraySource(transpose_input_array=True) sh = data.shape # print(sh) if 'xrt' in source.prefix_save_name() or\ 'srw' in source.prefix_save_name(): src.scalar_data = data[:, :sh[1] // 2 + 1, :sh[2] // 2 + 1].copy() else: src.scalar_data = data[:, ::-1, ::-1].copy() # src.spacing = np.array([-0.05, 1, 1]) # src.spacing = np.array([-0.25, 1, 1]) src.spacing = np.array([-0.25, 0.25, 0.25]) mayavi.add_source(src) # analysis:ignore # Visualize the data. # o = Outline() # mayavi.add_module(o) ipwY = ImagePlaneWidget() mayavi.add_module(ipwY) # analysis:ignore ipwY.ipw.plane_orientation = 'y_axes' # our x-axis ipwY.ipw.slice_index = int(data.shape[1] - 1) # if 'xrt' in source.prefix_save_name(): # ipwY.ipw.slice_index /= int(2) ipwY.ipw.left_button_action = 0 set_lut(ipwY) if isZplane: ipwZ = ImagePlaneWidget() mayavi.add_module(ipwZ) # analysis:ignore ipwZ.ipw.plane_orientation = 'z_axes' # our z-axis ipwZ.ipw.slice_index = int(data.shape[2] - 1) # if 'xrt' in source.prefix_save_name(): # ipwZ.ipw.slice_index /= int(2) ipwZ.ipw.left_button_action = 0 if 'xrt' in source.prefix_save_name() or\ 'srw' in source.prefix_save_name(): pass else: data = np.concatenate((data[:, :0:-1, :], data), axis=1) data = np.concatenate((data[:, :, :0:-1], data), axis=2) sh = data.shape print(sh) src = ArraySource(transpose_input_array=True) src.scalar_data = data.copy() # src.spacing = np.array([-0.05, 1, 1]) # src.spacing = np.array([-0.25, 1, 1]) src.spacing = np.array([-0.25, 0.25, 0.25]) mayavi.add_source(src) # analysis:ignore ipwX = ImagePlaneWidget() mayavi.add_module(ipwX) # analysis:ignore ipwX.ipw.plane_orientation = 'x_axes' # energy set_lut(ipwX) ipwX.ipw.add_observer('WindowLevelEvent', move_view) ipwX.ipw.add_observer('StartInteractionEvent', move_view) ipwX.ipw.add_observer('EndInteractionEvent', move_view) labelE = Text3D() mayavi.add_module(labelE) # analysis:ignore labelE.position = (1, data.shape[1] * 0.73 * src.spacing[1], data.shape[2] * 0.85 * src.spacing[2]) labelE.orientation = 90, 0, 90 labelE.text = 'Energy' labelE.scale = 3, 3, 1 labelE.actor.property.color = 0, 1, 1 labelE.orient_to_camera = False labelE.text = set_labelE(0) view(45, 70, 200) wantToAnimate = True if wantToAnimate: anim(data, ipwX) else: ipwX.ipw.slice_index = data.shape[0] - 1 move_view(None, None)
def view_data(data): """Example showing how to view a 3D numpy array in mayavi2. """ def set_labelE(ind): return '{0:.0f} eV'.format(source.energies[ind]) def move_view(obj, evt): labelE.text = set_labelE(ipwX.ipw.slice_index) pos = labelE.position labelE.position = ipwX.ipw.slice_index * src.spacing[0] + 1,\ pos[1], pos[2] labelE.vector_text.update() def set_lut(ipw): lutM = ipw.module_manager.scalar_lut_manager # lutM.show_scalar_bar = True # lutM.number_of_labels = 9 lutM.lut.scale = 'log10' lutM.lut.range = [dataMax*vmin, dataMax] lutM.lut_mode = 'hot' @animate() def anim(data, ipwX): scene.scene.off_screen_rendering = True scene.scene.anti_aliasing_frames = 0 for i in range(0, data.shape[0], 1): ipwX.ipw.slice_index = i move_view(None, None) if saveName is not None: scene.scene.save('{0}{1:04d}.png'.format(saveName, i)) yield # 'mayavi' is always defined on the interpreter. scene = mayavi.new_scene() # analysis:ignore scene.scene.background = (0, 0, 0) print(source.prefix_save_name()) src = ArraySource(transpose_input_array=True) sh = data.shape # print(sh) if 'xrt' in source.prefix_save_name() or\ 'srw' in source.prefix_save_name(): src.scalar_data = data[:, :sh[1]//2+1, :sh[2]//2+1].copy() else: src.scalar_data = data[:, ::-1, ::-1].copy() # src.spacing = np.array([-0.05, 1, 1]) # src.spacing = np.array([-0.25, 1, 1]) src.spacing = np.array([-0.25, 0.25, 0.25]) mayavi.add_source(src) # analysis:ignore # Visualize the data. # o = Outline() # mayavi.add_module(o) ipwY = ImagePlaneWidget() mayavi.add_module(ipwY) # analysis:ignore ipwY.ipw.plane_orientation = 'y_axes' # our x-axis ipwY.ipw.slice_index = int(data.shape[1] - 1) # if 'xrt' in source.prefix_save_name(): # ipwY.ipw.slice_index /= int(2) ipwY.ipw.left_button_action = 0 set_lut(ipwY) if isZplane: ipwZ = ImagePlaneWidget() mayavi.add_module(ipwZ) # analysis:ignore ipwZ.ipw.plane_orientation = 'z_axes' # our z-axis ipwZ.ipw.slice_index = int(data.shape[2] - 1) # if 'xrt' in source.prefix_save_name(): # ipwZ.ipw.slice_index /= int(2) ipwZ.ipw.left_button_action = 0 if 'xrt' in source.prefix_save_name() or\ 'srw' in source.prefix_save_name(): pass else: data = np.concatenate((data[:, :0:-1, :], data), axis=1) data = np.concatenate((data[:, :, :0:-1], data), axis=2) sh = data.shape print(sh) src = ArraySource(transpose_input_array=True) src.scalar_data = data.copy() # src.spacing = np.array([-0.05, 1, 1]) # src.spacing = np.array([-0.25, 1, 1]) src.spacing = np.array([-0.25, 0.25, 0.25]) mayavi.add_source(src) # analysis:ignore ipwX = ImagePlaneWidget() mayavi.add_module(ipwX) # analysis:ignore ipwX.ipw.plane_orientation = 'x_axes' # energy set_lut(ipwX) ipwX.ipw.add_observer('WindowLevelEvent', move_view) ipwX.ipw.add_observer('StartInteractionEvent', move_view) ipwX.ipw.add_observer('EndInteractionEvent', move_view) labelE = Text3D() mayavi.add_module(labelE) # analysis:ignore labelE.position = (1, data.shape[1]*0.73*src.spacing[1], data.shape[2]*0.85*src.spacing[2]) labelE.orientation = 90, 0, 90 labelE.text = 'Energy' labelE.scale = 3, 3, 1 labelE.actor.property.color = 0, 1, 1 labelE.orient_to_camera = False labelE.text = set_labelE(0) view(45, 70, 200) wantToAnimate = True if wantToAnimate: anim(data, ipwX) else: ipwX.ipw.slice_index = data.shape[0]-1 move_view(None, None)