VisIt Tutorial Python Simple Scripts

Download Tutorial Scripts

http://portal.nersc.gov/project/visit/visit_python_simple_scripts.tar.gz

Example: Run First Script

Source("script_1.py")

Tutorial Scripts Sources

Create a Pseudocolor Plot

#
# file: script_1.py
# example: Create a Pseudocolor Plot.
#
 
# Make sure the noise.silo database is open.

# Clean up any existing plots.
DeleteAllPlots()
# Create a pseudocolor plot
AddPlot("Pseudocolor", "hardyglobal")
# Render the plot
DrawPlots()

# Fetch the default Pseudocolor Plot Attributes
p = PseudocolorAttributes()
p.minFlag = 1
p.maxFlag = 1
p.min = 3.5
p.max = 7.5

# Set the attributes of our Pseudocolor plot.
SetPlotOptions(p)

Add an Isosurface Operator

#
# file: script_2.py
# example: Using an Isosurface Operator.
#

# Make sure the noise.silo database is open.

# Clean up any existing plots.
DeleteAllPlots()
# Create a pseudocolor plot
AddPlot("Pseudocolor", "hardyglobal")

# Add an isosurface operator
AddOperator("Isosurface")

# Fetch the default Isosurface Operator Attributes
iso_atts = IsosurfaceAttributes()
iso_atts.contourMethod = iso_atts.Value
iso_atts.variable = "hardyglobal"
iso_atts.contourValue = 2

# Set the attributes of our Isosurface Operator.
SetOperatorOptions(iso_atts)

# Render the plot
DrawPlots()

Animate the Isosurfaces

#
# file: script_3.py
# example: Animating an Isosurface Operator.
#

# Make sure the noise.silo database is open.

# Clean up any existing plots.
DeleteAllPlots()
# Create a pseudocolor plot
AddPlot("Pseudocolor", "hardyglobal")

# Add an isosurface operator
AddOperator("Isosurface")

# Fetch the default Isosurface Operator Attributes
iso_atts = IsosurfaceAttributes()
iso_atts.contourMethod = iso_atts.Value
iso_atts.variable = "hardyglobal"
iso_atts.contourValue = 1.9

# Render the plot
DrawPlots()

# Animate 30 steps, updating the Isosurface Operator Attributes.
for i in range(30):
   # Set new Isosurface Contour Value
   iso_atts.contourValue = (2 + 0.1*i)
   # Set the attributes of our Isosurface Operator.
   SetOperatorOptions(iso_atts)


Render Isosurface animation to png files

#
# file: script_4.py
# example: Saving an animation of Isosurfaces.
#

# Make sure the noise.silo database is open.

# Set options to render to png files.
swin_atts = SaveWindowAttributes()
swin_atts.outputToCurrentDirectory = 1
swin_atts.outputDirectory = "."
swin_atts.fileName = "isosurface.anim."
swin_atts.family = 1
swin_atts.format = swin_atts.PNG
swin_atts.width  = 512
swin_atts.height = 512
SetSaveWindowAttributes(swin_atts)

# Clean up any existing plots.
DeleteAllPlots()
# Create a pseudocolor plot
AddPlot("Pseudocolor", "hardyglobal")

# Add an isosurface operator
AddOperator("Isosurface")

# Fetch the default Isosurface Operator Attributes
iso_atts = IsosurfaceAttributes()
iso_atts.contourMethod = iso_atts.Value
iso_atts.variable = "hardyglobal"
iso_atts.contourValue = 1.9

# Render the plot
DrawPlots()

# Animate 30 steps, updating the Isosurface Operator Attributes
for i in range(30):
   # Set new Isosurface Contour Value
   iso_atts.contourValue = (2 + 0.1*i)
   # Set the attributes of our Isosurface Operator
   SetOperatorOptions(iso_atts)
   # Save the current frame to a png file
   SaveWindow()

Simple Data Analysis Example

#
# file: script_5.py
# example: Automating data analysis.
#
#

def CleanUp():
    # Remove any existing plots
    DeleteAllPlots()
    # Make sure noise.silo is the active source
    ga = GetGlobalAttributes()
    for src in ga.sources:
        if src.count("noise.silo"):
            ActivateDatabase(src)
        else:
            CloseDatabase(src)

def TakeMassPerSlice():
   # Create a Pseudocolor plot of a volume fraction variable
   AddPlot("Pseudocolor", "chromeVf")
   # Add a Slice Operator
   AddOperator("Slice")
   DrawPlots()
   # Open an output file for result curve
   f = open("mass_per_slice.ult", "w")
   # Set the name of the curve
   f.write("# mass_per_slice\n")
   for i in range(50):
     # Slide a Slice Operator along the x axis.
     intercept = -10 + 20*(i/49.)
     s = SliceAttributes()
     s.axisType = s.XAxis
     s.originType = s.Intercept
     s.originIntercept = intercept
     # Uncomment the next line to see the slice result in 3D
     # s.project2d = 0
     SetOperatorOptions(s)
     # Execute a query to obtain the mass of the current slice
     Query("Weighted Variable Sum")
     mval = GetQueryOutputValue()
     # Save mass vs current intercept
     f.write("%25.15e %25.15e\n" %(intercept, mval))
   f.close()

def ShowResult():
   DeleteAllPlots()
   # Open the curve file we just created
   OpenDatabase("mass_per_slice.ult")
   # Plot the curve
   AddPlot("Curve", "mass_per_slice")
   # Render the curve
   DrawPlots()

CleanUp()
TakeMassPerSlice()
ShowResult()