VisIt-tutorial-Advanced-PythonUI

VisIt's python client interface integrates PySide LGPL Qt bindings for Python UI control. This capability allows you to quickly develop custom UIs for specific use cases or user communities.

Resources

Data (from Tutorial Data):

  • data/varying.visit

Example Files (from Tutorial Examples):

  • VisIt CLI Python Script: examples/advanced/python_ui/visit_pyside_custom_dt_example.py


Custom Python UI Tutorial

This tutorial will show you how to create a UI that displays several plots showing the difference of scalar field between two time steps of a data set.

Pyui example.png


This example demonstrates the following:

  • Use of PySide to display four coordinated viewports.
  • Use of time differencing via a Cross Mesh Field Evaluation (CMFE)
  • Customization of annotations

To run the example:

  • Launch VisIt's CLI with the followng command:
visit -cli -pysideviewer
  • Then run the following script:
Source("examples/advanced/python_ui/visit_pyside_custom_dt_example.py")

Description of the UI:

  • The top left plot shows the scalar field temp at the selected time step.
  • The top right plot shows the scalar field temp at the previous time step.
  • The bottom left plot shows difference of the temp field between two time steps.
  • The bottom right plot shows the absolute value of the difference of the temp field between the two time steps.
  • The difference is calculated using an expression that evaluates a position based CMFE.

Note: To hook up a time slider to this - wait for VisIt 2.6.0. This version includes many improvements including the ability to reuse our existing UI widgets (e.g. our existing time slider widget).

#
# file: visit_pyside_custom_dt_example.py
#
# Usage:
#  >visit -cli -pysideviewer
#  >>>Source("visit_pyside_custom_dt_example.py")
#

class TimeDiffWindow(QWidget):
    def __init__(self):
        super(TimeDiffWindow,self).__init__()
        # setup our time diff expression
        self.__setup_expressions()
        # short cut to create 4 viewer windows
        SetWindowLayout(4)
        # setup the main window layout
        self.__init_widgets()
        # open our example data base
        TimeSliderSetState(5)
        # Setup our example plots.
        self.__init_plots()
        # Change annotation setup
        self.__set_annotations()
    def __setup_expressions(self):
        # we use VisIt cross field mesh evaluation expression
        # to place the temp field from the previous time step
        # on to the current mesh, so we can execute a diff.
        DefineScalarExpression("temp_prev","pos_cmfe(<[-1]id:temp>, mesh, 0.000000)")
        DefineScalarExpression("temp_dt","temp - temp_prev")
        DefineScalarExpression("temp_dt_abs","abs(temp - temp_prev)")
    def __init_widgets(self):
        # Create Qt layout
        glout = QGridLayout(self)
        # Get the render window wigets from VisIt
        self.rwindows = []
        for i in range(4):
            self.rwindows.append(pyside_support.GetRenderWindow(i+1)) 
        # Add render windows to our main window
        glout.addWidget(self.rwindows[0],0,0)
        glout.addWidget(self.rwindows[1],0,1)
        glout.addWidget(self.rwindows[2],1,0)
        glout.addWidget(self.rwindows[3],1,1)
        self.resize(800,800)
    def __init_plots(self):
        # Create 4 plots
        self.__init_plot(1,"temp")
        self.__init_plot(2,"temp_prev")
        self.__init_plot(3,"temp_dt")
        self.__init_plot(4,"temp_dt_abs")
        SetActiveWindow(1)
    def __init_plot(self,window_id,var):
        # Create a Pseudocolor plot
        SetActiveWindow(window_id)
        AddPlot("Pseudocolor",var)
        patts = PseudocolorAttributes()
        patts.colorTableName = "hot_desaturated"
        SetPlotOptions(patts)
        # Lock view and time with other windows
        ToggleLockTime()
        ToggleLockViewMode()
        DrawPlots()
        # Create a title annotation
        title = CreateAnnotationObject("Text2D")
        title.position = (.1,.9)
        title.fontBold = 1
        title.text = var
    def __set_annotations(self):
        # Set global and legend annotation for each render window.
        for i in range(1,5):
            SetActiveWindow(i)
            aatts = AnnotationAttributes()
            aatts.userInfoFlag = 0
            aatts.databaseInfoFlag = 0
            aatts.axes3D.visible = 0
            SetAnnotationAttributes(aatts)
            legend = GetAnnotationObject("Plot%04d" % (i-1))
            legend.managePosition = 0
            legend.position = (0.4, 0.12)
            legend.xScale = 2
            legend.yScale = .75
            legend.numberFormat = "%0.2f"
            legend.fontFamily = legend.Arial 
            legend.fontBold = 1
            legend.fontHeight = 0.05
            legend.drawTitle = 0
            legend.drawMinMax = 0
            legend.orientation = legend.HorizontalBottom 
            legend.numTicks = 3
        SetActiveWindow(1)

if OpenDatabase("data/varying.visit") ==1 :
    # Create and show our custom window.
    main = TimeDiffWindow()
    main.show()
else:
    print "Error: Failed to open 'varying.visit'"