def volume_render(field, outfile, maxopacity=<NUM_LIT:1.0>, cmap='<STR_LIT>',<EOL>size=<NUM_LIT>, elevation=<NUM_LIT>, azimuth=<NUM_LIT>, bkg=(<NUM_LIT:0.0>, <NUM_LIT:0.0>, <NUM_LIT:0.0>),<EOL>opacitycut=<NUM_LIT>, offscreen=False, rayfunction='<STR_LIT>'):
sh = field.shape<EOL>dataImporter = vtk.vtkImageImport()<EOL>dataImporter.SetDataScalarTypeToUnsignedChar()<EOL>data_string = field.tostring()<EOL>dataImporter.SetNumberOfScalarComponents(<NUM_LIT:1>)<EOL>dataImporter.CopyImportVoidPointer(data_string, len(data_string))<EOL>dataImporter.SetDataExtent(<NUM_LIT:0>, sh[<NUM_LIT:2>]-<NUM_LIT:1>, <NUM_LIT:0>, sh[<NUM_LIT:1>]-<NUM_LIT:1>, <NUM_LIT:0>, sh[<NUM_LIT:0>]-<NUM_LIT:1>)<EOL>dataImporter.SetWholeExtent(<NUM_LIT:0>, sh[<NUM_LIT:2>]-<NUM_LIT:1>, <NUM_LIT:0>, sh[<NUM_LIT:1>]-<NUM_LIT:1>, <NUM_LIT:0>, sh[<NUM_LIT:0>]-<NUM_LIT:1>)<EOL>alphaChannelFunc = vtk.vtkPiecewiseFunction()<EOL>alphaChannelFunc.AddPoint(<NUM_LIT:0>, <NUM_LIT:0.0>)<EOL>alphaChannelFunc.AddPoint(int(<NUM_LIT:255>*opacitycut), maxopacity)<EOL>volumeProperty = vtk.vtkVolumeProperty()<EOL>colorFunc = cmap2colorfunc(cmap)<EOL>volumeProperty.SetColor(colorFunc)<EOL>volumeProperty.SetScalarOpacity(alphaChannelFunc)<EOL>volumeMapper = vtk.vtkVolumeRayCastMapper()<EOL>if rayfunction == '<STR_LIT>':<EOL><INDENT>comp = vtk.vtkVolumeRayCastMIPFunction()<EOL>comp.SetMaximizeMethodToOpacity()<EOL><DEDENT>elif rayfunction == '<STR_LIT>':<EOL><INDENT>comp = vtk.vtkVolumeRayCastCompositeFunction()<EOL><DEDENT>elif rayfunction == '<STR_LIT>':<EOL><INDENT>comp = vtk.vtkVolumeRayCastIsosurfaceFunction()<EOL>comp.SetIsoValue(maxopacity/<NUM_LIT:2>)<EOL><DEDENT>else:<EOL><INDENT>comp = vtk.vtkVolumeRayCastIsosurfaceFunction()<EOL><DEDENT>volumeMapper.SetSampleDistance(<NUM_LIT:0.1>)<EOL>volumeMapper.SetVolumeRayCastFunction(comp)<EOL>if rayfunction == '<STR_LIT>':<EOL><INDENT>volumeMapper = vtk.vtkSmartVolumeMapper()<EOL><DEDENT>volumeMapper.SetInputConnection(dataImporter.GetOutputPort())<EOL>volume = vtk.vtkVolume()<EOL>volume.SetMapper(volumeMapper)<EOL>volume.SetProperty(volumeProperty)<EOL>light = vtk.vtkLight()<EOL>light.SetLightType(vtk.VTK_LIGHT_TYPE_HEADLIGHT)<EOL>light.SetIntensity(<NUM_LIT>)<EOL>light.SwitchOn()<EOL>renderer = vtk.vtkRenderer()<EOL>renderWin = vtk.vtkRenderWindow()<EOL>renderWin.AddRenderer(renderer)<EOL>renderWin.SetOffScreenRendering(<NUM_LIT:1>);<EOL>if not hasattr(size, '<STR_LIT>'):<EOL><INDENT>size = (size, size)<EOL><DEDENT>renderer.AddVolume(volume)<EOL>renderer.AddLight(light)<EOL>renderer.SetBackground(*bkg)<EOL>renderWin.SetSize(*size)<EOL>if offscreen:<EOL><INDENT>renderWin.SetOffScreenRendering(<NUM_LIT:1>)<EOL><DEDENT>def exitCheck(obj, event):<EOL><INDENT>if obj.GetEventPending() != <NUM_LIT:0>:<EOL><INDENT>obj.SetAbortRender(<NUM_LIT:1>)<EOL><DEDENT><DEDENT>renderWin.AddObserver("<STR_LIT>", exitCheck)<EOL>renderInteractor = vtk.vtkRenderWindowInteractor()<EOL>renderInteractor.Initialize()<EOL>renderWin.Render()<EOL>renderInteractor.Start()<EOL>writer = vtk.vtkPNGWriter()<EOL>w2i = vtk.vtkWindowToImageFilter()<EOL>w2i.SetInput(renderWin)<EOL>writer.SetInputConnection(w2i.GetOutputPort())<EOL>renderWin.Render()<EOL>ac = renderer.GetActiveCamera()<EOL>ac.Elevation(elevation)<EOL>ac.Azimuth(azimuth)<EOL>renderer.ResetCameraClippingRange()<EOL>renderWin.Render()<EOL>w2i.Modified()<EOL>writer.SetFileName(outfile)<EOL>writer.Write()<EOL>
Uses vtk to make render an image of a field, with control over the
camera angle and colormap.

Input Parameters
----------------
    field : np.ndarray
        3D array of the field to render.
    outfile : string
        The save name of the image.
    maxopacity : Float
        Default is 1.0
    cmap : matplotlib colormap string
        Passed to cmap2colorfunc. Default is bone.
    size : 2-element list-like of ints or Int
        The size of the final rendered image.
    elevation : Numeric
        The elevation of the camera angle, in degrees. Default is 45
    azimuth : Numeric
        The azimuth of the camera angle, in degrees. Default is 45
    bkg : Tuple of floats
        3-element tuple of floats on [0,1] of the background image color.
        Default is (0., 0., 0.).