Using a query to build an expression

Sometimes it is useful to use the output of queries to build an expression. This is possible through the use of a little Python scripting. The following script queries a particular IJK value for the plotted variable and then subtracts that value from the rest of the values in the dataset so all of the values are relative to the queried value.


Copy the script to a file called and then run:

 visit -cli -s
# Database and variable.
db = "/path/to/visit/data/noise.silo"    
var = "hardyglobal"

# Dimensions of the dataset (nodes)

# Do you like to count from 0 or 1 for i,j,k?
origin = 0

def Node_IJK_To_Node_Index(i,j,k):
    return (k-origin) * (NX*NY) + (j-origin)*NX + (i-origin)

# Make the first plot and query the ijk whose value you want.
AddPlot("Pseudocolor", var)
q = PickByNode(Node_IJK_To_Node_Index(10, 20, 30))

# Now, make an expression that subtracts off the variable value.
DefineScalarExpression("subtracted", var + " - " + str(q[var]))

# Now, plot the subtracted variable.