<s> """<STR_LIT>""" <EOL> import numpy as np <EOL> from numpy import cos , sin , pi <EOL> from tvtk . api import tvtk <EOL> from mayavi . scripts import mayavi2 <EOL> def generate_annulus ( r = None , theta = None , z = None ) : <EOL> """<STR_LIT>""" <EOL> if r is None : r = np . linspace ( <NUM_LIT:1.0> , <NUM_LIT> , <NUM_LIT:11> ) <EOL> if theta is None : theta = np . linspace ( <NUM_LIT:0> , <NUM_LIT:2> * pi , <NUM_LIT:11> ) <EOL> if z is None : z = np . linspace ( <NUM_LIT:0.0> , <NUM_LIT:1.0> , <NUM_LIT:11> ) <EOL> x_plane = ( cos ( theta ) * r [ : , None ] ) . ravel ( ) <EOL> y_plane = ( sin ( theta ) * r [ : , None ] ) . ravel ( ) <EOL> points = np . empty ( [ len ( x_plane ) * len ( z ) , <NUM_LIT:3> ] ) <EOL> start = <NUM_LIT:0> <EOL> for z_plane in z : <EOL> end = start + len ( x_plane ) <EOL> plane_points = points [ start : end ] <EOL> plane_points [ : , <NUM_LIT:0> ] = x_plane <EOL> plane_points [ : , <NUM_LIT:1> ] = y_plane <EOL> plane_points [ : , <NUM_LIT:2> ] = z_plane <EOL> start = end <EOL> return points <EOL> dims = ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> theta = np . linspace ( <NUM_LIT:0> , <NUM_LIT:2> * np . pi , dims [ <NUM_LIT:0> ] ) <EOL> r = np . linspace ( <NUM_LIT:1> , <NUM_LIT:10> , dims [ <NUM_LIT:1> ] ) <EOL> z = np . linspace ( <NUM_LIT:0> , <NUM_LIT:5> , dims [ <NUM_LIT:2> ] ) <EOL> pts = generate_annulus ( r , theta , z ) <EOL> sgrid = tvtk . StructuredGrid ( dimensions = dims ) <EOL> sgrid . points = pts <EOL> s = np . sqrt ( pts [ : , <NUM_LIT:0> ] ** <NUM_LIT:2> + pts [ : , <NUM_LIT:1> ] ** <NUM_LIT:2> + pts [ : , <NUM_LIT:2> ] ** <NUM_LIT:2> ) <EOL> sgrid . point_data . scalars = np . ravel ( s . copy ( ) ) <EOL> sgrid . point_data . scalars . name = '<STR_LIT>' <EOL> @ mayavi2 . standalone <EOL> def view ( ) : <EOL> from mayavi . sources . vtk_data_source import VTKDataSource <EOL> from mayavi . modules . api import Outline , GridPlane <EOL> mayavi . new_scene ( ) <EOL> src = VTKDataSource ( data = sgrid ) <EOL> mayavi . add_source ( src ) <EOL> mayavi . add_module ( Outline ( ) ) <EOL> g = GridPlane ( ) <EOL> g . grid_plane . axis = '<STR_LIT:x>' <EOL> mayavi . add_module ( g ) <EOL> g = GridPlane ( ) <EOL> g . grid_plane . axis = '<STR_LIT:y>' <EOL> mayavi . add_module ( g ) <EOL> g = GridPlane ( ) <EOL> g . grid_plane . axis = '<STR_LIT:z>' <EOL> mayavi . add_module ( g ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> view ( ) </s>
