<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> import numpy <EOL> from threading import Thread <EOL> from time import sleep <EOL> from mayavi . scripts import mayavi2 <EOL> from traits . api import HasTraits , Button , Instance <EOL> from traitsui . api import View , Item <EOL> from mayavi . sources . array_source import ArraySource <EOL> from mayavi . modules . outline import Outline <EOL> from mayavi . modules . image_plane_widget import ImagePlaneWidget <EOL> from pyface . api import GUI <EOL> def make_data ( dims = ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ) : <EOL> """<STR_LIT>""" <EOL> np = dims [ <NUM_LIT:0> ] * dims [ <NUM_LIT:1> ] * dims [ <NUM_LIT:2> ] <EOL> x , y , z = numpy . ogrid [ - <NUM_LIT:5> : <NUM_LIT:5> : dims [ <NUM_LIT:0> ] * <NUM_LIT> , - <NUM_LIT:5> : <NUM_LIT:5> : dims [ <NUM_LIT:1> ] * <NUM_LIT> , - <NUM_LIT:5> : <NUM_LIT:5> : dims [ <NUM_LIT:2> ] * <NUM_LIT> ] <EOL> x = x . astype ( '<STR_LIT:f>' ) <EOL> y = y . astype ( '<STR_LIT:f>' ) <EOL> z = z . astype ( '<STR_LIT:f>' ) <EOL> scalars = ( numpy . sin ( x * y * z ) / ( x * y * z ) ) <EOL> s = numpy . transpose ( scalars ) . copy ( ) <EOL> s . shape = s . shape [ : : - <NUM_LIT:1> ] <EOL> return s <EOL> class ThreadedAction ( Thread ) : <EOL> def __init__ ( self , data , ** kwargs ) : <EOL> Thread . __init__ ( self , ** kwargs ) <EOL> self . data = data <EOL> def run ( self ) : <EOL> print ( "<STR_LIT>" % self . getName ( ) , end = '<STR_LIT:U+0020>' ) <EOL> sleep ( <NUM_LIT:3> ) <EOL> sd = self . data . scalar_data <EOL> sd += numpy . sin ( numpy . random . rand ( * sd . shape ) * <NUM_LIT> * numpy . pi ) <EOL> GUI . invoke_later ( self . data . update ) <EOL> print ( '<STR_LIT>' ) <EOL> class Controller ( HasTraits ) : <EOL> run_calculation = Button ( '<STR_LIT>' ) <EOL> data = Instance ( ArraySource ) <EOL> view = View ( Item ( name = '<STR_LIT>' ) ) <EOL> def _run_calculation_changed ( self , value ) : <EOL> action = ThreadedAction ( self . data ) <EOL> action . start ( ) <EOL> @ mayavi2 . standalone <EOL> def view_numpy ( ) : <EOL> """<STR_LIT>""" <EOL> mayavi . new_scene ( ) <EOL> data = make_data ( ) <EOL> src = ArraySource ( transpose_input_array = False ) <EOL> src . scalar_data = data <EOL> mayavi . add_source ( src ) <EOL> o = Outline ( ) <EOL> mayavi . add_module ( o ) <EOL> ipw = ImagePlaneWidget ( ) <EOL> mayavi . add_module ( ipw ) <EOL> ipw . module_manager . scalar_lut_manager . show_scalar_bar = True <EOL> ipw_y = ImagePlaneWidget ( ) <EOL> mayavi . add_module ( ipw_y ) <EOL> ipw_y . ipw . plane_orientation = '<STR_LIT>' <EOL> computation = Controller ( data = src ) <EOL> computation . edit_traits ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> view_numpy ( ) </s>
