def plotEnergyLinear(localPowerAllDB): data = visit.OpenDatabase(localPowerAllDB, 0, 'Vs') visit.AddPlot('Curve', 'Energy') AnnotationAtts = visit.AnnotationAttributes() AnnotationAtts.axes2D.yAxis.grid = 0 AnnotationAtts.axes2D.xAxis.grid = 0 AnnotationAtts.axes2D.xAxis.title.userTitle = 1 AnnotationAtts.axes2D.xAxis.title.userUnits = 1 AnnotationAtts.axes2D.xAxis.title.title = "z" AnnotationAtts.axes2D.xAxis.title.units = "m" AnnotationAtts.axes2D.yAxis.title.userTitle = 1 AnnotationAtts.axes2D.yAxis.title.userUnits = 1 AnnotationAtts.axes2D.yAxis.title.title = "Energy" AnnotationAtts.axes2D.yAxis.title.units = "J" AnnotationAtts.userInfoFlag = 0 AnnotationAtts.databaseInfoFlag = 0 AnnotationAtts.legendInfoFlag = 0 visit.SetAnnotationAttributes(AnnotationAtts) visit.DrawPlots() CurveAtts = visit.CurveAttributes() CurveAtts.showLines = 1 CurveAtts.lineStyle = CurveAtts.SOLID # SOLID, DASH, DOT, DOTDASH CurveAtts.lineWidth = 2 CurveAtts.curveColorSource = CurveAtts.Custom # Cycle, Custom CurveAtts.curveColor = (255, 0, 0, 255) CurveAtts.showLabels = 0 CurveAtts.showLegend = 0 visit.SetPlotOptions(CurveAtts)
def plotPowNorm(localPowerAllDB): data=visit.OpenDatabase(localPowerAllDB,0,'Vs') visit.AddPlot('Pseudocolor','power_SI_Norm') visit.DrawPlots() View2DAtts = visit.View2DAttributes() # View2DAtts.windowCoords = (0, 30, 0, 15.0796) # View2DAtts.viewportCoords = (0.2, 0.95, 0.15, 0.95) # View2DAtts.fullFrameAutoThreshold = 100 View2DAtts.xScale = View2DAtts.LINEAR # LINEAR, LOG View2DAtts.yScale = View2DAtts.LINEAR # LINEAR, LOG View2DAtts.windowValid = 1 View2DAtts.fullFrameActivationMode = View2DAtts.On # On, Off, Auto #View2DAtts.fullFrameAutoThreshold = 100 visit.SetView2D(View2DAtts) visit.ResetView() AnnotationAtts = visit.AnnotationAttributes() AnnotationAtts.userInfoFlag = 0 AnnotationAtts.databaseInfoFlag = 0 AnnotationAtts.axes2D.xAxis.title.userTitle = 1 AnnotationAtts.axes2D.xAxis.title.userUnits = 1 AnnotationAtts.axes2D.xAxis.title.title = "ct-z" AnnotationAtts.axes2D.xAxis.title.units = "m" AnnotationAtts.axes2D.yAxis.title.userTitle = 1 AnnotationAtts.axes2D.yAxis.title.userUnits = 1 AnnotationAtts.axes2D.yAxis.title.title = "z" AnnotationAtts.axes2D.yAxis.title.units = "m" # AnnotationAtts.legendInfoFlag = 0 visit.SetAnnotationAttributes(AnnotationAtts)
def binPhase(eDB): visit.OpenDatabase(eDB, 0) visit.AddPlot("Pseudocolor", "operators/DataBinning/2D/electrons", 1, 1) DataBinningAtts = visit.DataBinningAttributes() DataBinningAtts.numDimensions = DataBinningAtts.Two # One, Two, Three DataBinningAtts.dim1BinBasedOn = DataBinningAtts.Variable # X, Y, Z, Variable DataBinningAtts.dim1Var = "electrons_zSI" DataBinningAtts.dim1SpecifyRange = 1 DataBinningAtts.dim1MinRange = 0 DataBinningAtts.dim1MaxRange = 1.0E-7 DataBinningAtts.dim1NumBins = 100 DataBinningAtts.dim2BinBasedOn = DataBinningAtts.Variable # X, Y, Z, Variable DataBinningAtts.dim2Var = "electrons_gamma" DataBinningAtts.dim2SpecifyRange = 1 DataBinningAtts.dim2MinRange = 0.991 DataBinningAtts.dim2MaxRange = 1.005 DataBinningAtts.dim2NumBins = 100 DataBinningAtts.outOfBoundsBehavior = DataBinningAtts.Clamp # Clamp, Discard DataBinningAtts.reductionOperator = DataBinningAtts.Sum # Average, Minimum, Maximum, StandardDeviation, Variance, Sum, Count, RMS, PDF DataBinningAtts.varForReduction = "electrons_chargeSI" DataBinningAtts.emptyVal = 0 DataBinningAtts.outputType = DataBinningAtts.OutputOnBins # OutputOnBins, OutputOnInputMesh DataBinningAtts.removeEmptyValFromCurve = 1 visit.SetOperatorOptions(DataBinningAtts, 1) visit.SetTimeSliderState(0) visit.SetTimeSliderState(1) PseudocolorAtts = visit.PseudocolorAttributes() PseudocolorAtts.centering = PseudocolorAtts.Nodal # Natural, Nodal, Zonal PseudocolorAtts.opacityType = PseudocolorAtts.Ramp # ColorTable, FullyOpaque, Constant, Ramp, VariableRange PseudocolorAtts.colorTableName = "hot_desaturated" visit.SetPlotOptions(PseudocolorAtts) View2DAtts = visit.View2DAttributes() View2DAtts.fullFrameActivationMode = View2DAtts.On # View2DAtts.fullFrameAutoThreshold = 100 visit.SetView2D(View2DAtts) visit.ResetView() AnnotationAtts = visit.AnnotationAttributes() AnnotationAtts.axes2D.yAxis.grid = 0 AnnotationAtts.axes2D.xAxis.grid = 0 AnnotationAtts.axes2D.xAxis.title.userTitle = 1 AnnotationAtts.axes2D.xAxis.title.userUnits = 1 AnnotationAtts.axes2D.xAxis.title.title = "ct-z" AnnotationAtts.axes2D.xAxis.title.units = "m" AnnotationAtts.axes2D.yAxis.title.userTitle = 1 AnnotationAtts.axes2D.yAxis.title.userUnits = 1 AnnotationAtts.axes2D.yAxis.title.title = "gamma" AnnotationAtts.axes2D.yAxis.title.units = "" AnnotationAtts.userInfoFlag = 0 AnnotationAtts.databaseInfoFlag = 0 # AnnotationAtts.legendInfoFlag = 0 visit.SetAnnotationAttributes(AnnotationAtts) visit.DrawPlots()
def write_window(f, prefix): # Window setup f.write('width, height = %d, %d\n' % visit.GetWindowInformation().windowSize) f.write( 'win = GetGlobalAttributes().windows[GetGlobalAttributes().activeWindow]\n' ) f.write('ResizeWindow(win, width, height)\n') f.write('SetActiveWindow(win) # Synchronize\n') f.write('size = GetWindowInformation().windowSize\n') f.write('if width < size[0] or height < size[1]:\n') f.write( ' ResizeWindow(win, width + (size[0] - width), height + (size[1] - height))\n' ) f.write('DeleteAllPlots()\n') f.write('for name in GetAnnotationObjectNames():\n') f.write(' DeleteAnnotationObject(name)\n') f.write('\n') # Write the plots. write_plots(f) f.write('DrawPlots()\n\n') # Set the view f.write('# Set the view\n') if visit.GetWindowInformation().viewDimension == 1: view = visit.GetViewCurve() elif visit.GetWindowInformation().viewDimension == 2: view = visit.GetView2D() else: view = visit.GetView3D() write_state_object(f, view, "view") if visit.GetWindowInformation().viewDimension == 1: f.write('SetViewCurve(view)\n') elif visit.GetWindowInformation().viewDimension == 2: f.write('SetView2D(view)\n') else: f.write('SetView3D(view)\n') f.write('\n') # Get the annotation attributes f.write('# Set the annotation attributes\n') annot = visit.GetAnnotationAttributes() if write_state_object_diffs(f, annot, visit.AnnotationAttributes(), "annot"): f.write('SetAnnotationAttributes(annot)\n\n') else: f.write('#SetAnnotationAttributes(annot)\n\n') set_annotation_objects(f, prefix)
def test_visit(): import visit VISIT_ARGS = os.environ.get('VISIT_ARGS', ["-nosplash"]) if isinstance(VISIT_ARGS, str): VISIT_ARGS = VISIT_ARGS.split() for arg in VISIT_ARGS: visit.AddArgument(arg) visit.Launch() print "visit is installed in", os.path.dirname(visit.__file__) print "visit version", visit.Version() visit.ResetView() v3D = visit.GetView3D() v3D.SetViewUp(0, 0, 1) v3D.SetViewNormal(-0.5, -0.8, 0.4) v3D.SetImageZoom(1.0) visit.SetView3D(v3D) aa = visit.AnnotationAttributes() aa.SetAxesType(2) # outside edges aa.SetDatabaseInfoFlag(False) aa.SetUserInfoFlag(False) visit.SetAnnotationAttributes(aa) t = visit.CreateAnnotationObject("Text2D") t.SetText("Hello VisIt!") t.SetPosition(0.4, 0.9) # (0,0) is lower left corner t.SetFontFamily(0) # 0: Arial, 1: Courier, 2: Times t.SetWidth(0.25) # 25% t.SetTextColor((0, 0, 0)) t.SetUseForegroundForTextColor(False) t.SetVisible(True) visit.OpenDatabase("tmp_.vtk") visit.AddPlot("Mesh", "scalars") ma = visit.MeshAttributes() visit.SetPlotOptions(ma) visit.AddPlot("Pseudocolor", "scalars") pa = visit.PseudocolorAttributes() visit.SetPlotOptions(pa) visit.RedrawWindow() visit.DrawPlots() wait()
def TimeSeriesS1(): visit.AddPlot('Curve', 's1') visit.AddPlot('Curve', 's2') visit.DrawPlots() visit.AddWindow() visit.AddPlot('Curve', 'pAverage') visit.DrawPlots() visit.SetActiveWindow(1) AnnotationAtts = visit.AnnotationAttributes() AnnotationAtts.axes2D.yAxis.grid = 1 AnnotationAtts.axes2D.xAxis.grid = 1 AnnotationAtts.axes2D.xAxis.title.userTitle = 1 AnnotationAtts.axes2D.xAxis.title.userUnits = 1 AnnotationAtts.axes2D.xAxis.title.title = "Position along the machine s" AnnotationAtts.axes2D.xAxis.title.units = "m" visit.SetAnnotationAttributes(AnnotationAtts) visit.DrawPlots()
def plotEnergy(localPowerAllDB): # Get upper and lower limits for energy plots h5in = tables.open_file(localPowerAllDB, 'r') minZ = h5in.root.zSeries._v_attrs.vsLowerBounds maxZ = h5in.root.zSeries._v_attrs.vsUpperBounds h5in.close() data = visit.OpenDatabase(localPowerAllDB, 0, 'Vs') visit.AddPlot('Curve', 'Energy', 1, 1) # For log scale equivalent plot ViewCurveAtts = visit.ViewCurveAttributes() ViewCurveAtts.domainScale = ViewCurveAtts.LINEAR # LINEAR, LOG ViewCurveAtts.rangeScale = ViewCurveAtts.LOG # LINEAR, LOG visit.SetViewCurve(ViewCurveAtts) visit.DrawPlots() ViewCurveAtts.domainCoords = (minZ, maxZ) ViewCurveAtts.rangeCoords = (-12, 2) ViewCurveAtts.viewportCoords = (0.2, 0.95, 0.15, 0.95) visit.SetViewCurve(ViewCurveAtts) visit.DrawPlots() AnnotationAtts = visit.AnnotationAttributes() AnnotationAtts.axes2D.yAxis.grid = 1 AnnotationAtts.axes2D.xAxis.grid = 1 AnnotationAtts.axes2D.xAxis.title.userTitle = 1 AnnotationAtts.axes2D.xAxis.title.userUnits = 1 AnnotationAtts.axes2D.xAxis.title.title = "z" AnnotationAtts.axes2D.xAxis.title.units = "m" AnnotationAtts.axes2D.yAxis.title.userTitle = 1 AnnotationAtts.axes2D.yAxis.title.userUnits = 1 AnnotationAtts.axes2D.yAxis.title.title = "Energy" AnnotationAtts.axes2D.yAxis.title.units = "J" AnnotationAtts.userInfoFlag = 0 AnnotationAtts.databaseInfoFlag = 0 AnnotationAtts.legendInfoFlag = 0 visit.SetAnnotationAttributes(AnnotationAtts) visit.DrawPlots() CurveAtts = visit.CurveAttributes() CurveAtts.showLines = 1 CurveAtts.lineStyle = CurveAtts.SOLID # SOLID, DASH, DOT, DOTDASH CurveAtts.lineWidth = 2 CurveAtts.curveColorSource = CurveAtts.Custom # Cycle, Custom CurveAtts.curveColor = (51, 153, 102, 255) CurveAtts.showLegend = 0 CurveAtts.showLabels = 0 visit.SetPlotOptions(CurveAtts)
def current(): visit.OpenDatabase(iDB, 0) visit.AddPlot("Curve", "beamCurrent", 1, 1) visit.DrawPlots() # Begin spontaneous state ViewCurveAtts = visit.ViewCurveAttributes() ViewCurveAtts.domainCoords = (-0.0240932, 29.972) ViewCurveAtts.rangeCoords = (0, 22000) ViewCurveAtts.viewportCoords = (0.2, 0.95, 0.15, 0.95) ViewCurveAtts.domainScale = ViewCurveAtts.LINEAR # LINEAR, LOG ViewCurveAtts.rangeScale = ViewCurveAtts.LINEAR # LINEAR, LOG visit.SetViewCurve(ViewCurveAtts) # End spontaneous state ViewCurveAtts = visit.ViewCurveAttributes() ViewCurveAtts.domainCoords = (-0.0240932, 29.972) ViewCurveAtts.rangeCoords = (0, 22000) ViewCurveAtts.viewportCoords = (0.2, 0.95, 0.15, 0.95) ViewCurveAtts.domainScale = ViewCurveAtts.LINEAR # LINEAR, LOG ViewCurveAtts.rangeScale = ViewCurveAtts.LINEAR # LINEAR, LOG visit.SetViewCurve(ViewCurveAtts) AnnotationAtts = visit.AnnotationAttributes() AnnotationAtts.axes2D.yAxis.grid = 0 AnnotationAtts.axes2D.xAxis.grid = 0 AnnotationAtts.axes2D.xAxis.title.userTitle = 1 AnnotationAtts.axes2D.xAxis.title.userUnits = 1 AnnotationAtts.axes2D.xAxis.title.title = "z2bar" AnnotationAtts.axes2D.xAxis.title.units = "cooperation lengths" AnnotationAtts.axes2D.yAxis.title.userTitle = 1 AnnotationAtts.axes2D.yAxis.title.userUnits = 1 AnnotationAtts.axes2D.yAxis.title.title = "Current" AnnotationAtts.axes2D.yAxis.title.units = "A" AnnotationAtts.userInfoFlag = 0 AnnotationAtts.databaseInfoFlag = 0 AnnotationAtts.legendInfoFlag = 0 visit.SetAnnotationAttributes(AnnotationAtts) CurveAtts = visit.CurveAttributes() CurveAtts.showLines = 1 CurveAtts.lineStyle = CurveAtts.SOLID # SOLID, DASH, DOT, DOTDASH CurveAtts.lineWidth = 2 CurveAtts.curveColorSource = CurveAtts.Custom # Cycle, Custom CurveAtts.curveColor = (51, 153, 102, 255) CurveAtts.showLegend = 0 CurveAtts.showLabels = 0 visit.SetPlotOptions(CurveAtts)
def bunching(): #visit.OpenDatabase("localhost:/home/tml/tmp/test/build/examples/simple/1D/OptCommV165pp65-70/fig2/f2main_bunching1st_0_* database", 0) visit.OpenDatabase(iDB, 0) visit.AddPlot("Curve", "bunchingFundamental", 1, 1) visit.SetTimeSliderState(0) # Begin spontaneous state ViewCurveAtts = visit.ViewCurveAttributes() ViewCurveAtts.domainCoords = (0, 29.8745) ViewCurveAtts.rangeCoords = (0, 0.75) ViewCurveAtts.viewportCoords = (0.2, 0.95, 0.15, 0.95) ViewCurveAtts.domainScale = ViewCurveAtts.LINEAR # LINEAR, LOG ViewCurveAtts.rangeScale = ViewCurveAtts.LINEAR # LINEAR, LOG visit.SetViewCurve(ViewCurveAtts) AnnotationAtts = visit.AnnotationAttributes() AnnotationAtts.axes2D.yAxis.grid = 0 AnnotationAtts.axes2D.xAxis.grid = 0 AnnotationAtts.axes2D.xAxis.title.userTitle = 1 AnnotationAtts.axes2D.xAxis.title.userUnits = 1 AnnotationAtts.axes2D.xAxis.title.title = "z2bar" AnnotationAtts.axes2D.xAxis.title.units = "cooperation lengths" AnnotationAtts.axes2D.yAxis.title.userTitle = 1 AnnotationAtts.axes2D.yAxis.title.userUnits = 1 AnnotationAtts.axes2D.yAxis.title.title = "bunching" AnnotationAtts.axes2D.yAxis.title.units = "" AnnotationAtts.userInfoFlag = 0 AnnotationAtts.databaseInfoFlag = 0 AnnotationAtts.legendInfoFlag = 0 visit.SetAnnotationAttributes(AnnotationAtts) CurveAtts = visit.CurveAttributes() CurveAtts.showLines = 1 CurveAtts.lineStyle = CurveAtts.SOLID # SOLID, DASH, DOT, DOTDASH CurveAtts.lineWidth = 2 CurveAtts.curveColorSource = CurveAtts.Custom # Cycle, Custom CurveAtts.curveColor = (51, 153, 102, 255) CurveAtts.showLegend = 0 CurveAtts.showLabels = 0 visit.SetPlotOptions(CurveAtts) visit.DrawPlots()
def _updateDisplay(self,bSameDomain): print("") print("_updateDisplay() - start ..... variable="+str(self._variable)+", plot="+str(self._currentPlot)+", op="+str(self._currentOperator)+", opEnabled="+str(self._operatorEnabled)) # # remove old plot if not applicable # if (bSameDomain == False or (self._currentPlot != None and (self._variable == None or (self._currentPlot[1] != self._variable)))): print(" _updateDisplay() - removing plots and operators") visit.DeleteAllPlots() self._currentPlot = None visit.RemoveAllOperators() self._currentOperator = None # # remove old operator if not needed # if (self._currentOperator != None and self._operatorEnabled == False): print(" _updateDisplay() - removing operators, operatorEnabled is False") visit.RemoveAllOperators() self._currentOperator = None # # remove old operator if wrong type # if (self._currentOperator == "Slice" and self._operatorProject2d == False): print(" _updateDisplay() - removing operators, 'Slice' incompatible with project2d==False") visit.RemoveAllOperators() self._currentOperator = None if (self._currentOperator == "Clip" and self._operatorProject2d == True): print(" _updateDisplay() - removing operators, 'Clip' incompatible with project2d==True") visit.RemoveAllOperators() self._currentOperator = None # # add new plot if needed # if (self._variable != None and self._currentPlot == None): print(" _updateDisplay() - adding 'Pseudocolor' plot for variable '"+str(self._variable)+"'") print(" _updateDisplay() -- variable without str = ") print(self._variable) visit.AddPlot("Pseudocolor", str(self._variable)) visit.SetPlotOptions(self._pseudocolorAttributes) self._currentPlot = ("Pseudocolor",str(self._variable)) # Turn off display database name in plot window to reduce clutter attributes = visit.AnnotationAttributes() attributes.databaseInfoFlag=0 visit.SetAnnotationAttributes(attributes) # # if operator needed, set operator attributes (add new operator if needed) # if (self._operatorEnabled == True and self._currentPlot != None): # # if no operator, then add one # if (self._currentOperator == None): if (self._operatorProject2d): print(" _updateDisplay() - adding operator 'Slice'") visit.AddOperator("Slice") self._currentOperator = "Slice" else: print(" _updateDisplay() - adding operator 'Clip'") visit.AddOperator("Clip") self._currentOperator = "Clip" # # set operator attributes # if (self._currentOperator == "Slice"): print(" _updateDisplay() - setting operator options for 'Slice'") visit.SetOperatorOptions(self._getSliceAttributes()) else: print(" _updateDisplay() - setting operator options for 'Clip'") visit.SetOperatorOptions(self._getClipAttributes()) # # Redraw # print(" _updateDisplay() - redrawing") visit.DrawPlots() print("_updateDisplay() - end") print("")
def getAnnotationAttributes(): annot = v.AnnotationAttributes() annot.userInfoFlag = 0 annot.databaseInfoFlag = 0 # 3D annot.axes3D.triadFlag = 0 annot.axes3D.bboxFlag = 0 # clobber the names if rcParams['axes.3D.x.title'] is not None: annot.axes3D.xAxis.title.userTitle = 1 annot.axes3D.xAxis.title.title = rcParams['axes.3D.x.title'] else: annot.axes3D.xAxis.title.visible = 0 if rcParams['axes.3D.y.title'] is not None: annot.axes3D.yAxis.title.userTitle = 1 annot.axes3D.yAxis.title.title = rcParams['axes.3D.y.title'] else: annot.axes3D.yAxis.title.visible = 0 if rcParams['axes.3D.z.title'] is not None: annot.axes3D.zAxis.title.userTitle = 1 annot.axes3D.zAxis.title.title = rcParams['axes.3D.z.title'] else: annot.axes3D.zAxis.title.visible = 0 # move the axes to outside edges annot.axes3D.tickLocation = annot.axes3D.OutsideEdges if not rcParams['axes.3D.tickson']: annot.axes3D.visible = 0 # 2D if rcParams['axes.2D.x.title'] is not None: annot.axes2D.xAxis.title.userTitle = 1 annot.axes2D.xAxis.title.title = rcParams['axes.2D.x.title'] else: annot.axes2D.xAxis.title.visible = 0 if rcParams['axes.2D.y.title'] is not None: annot.axes2D.yAxis.title.userTitle = 1 annot.axes2D.yAxis.title.title = rcParams['axes.2D.y.title'] else: annot.axes2D.xAxis.title.visible = 0 if not rcParams['axes.2D.tickson']: annot.axes2D.visible = 0 # Fonts fnum = getDefaultFont() annot.axes2D.xAxis.title.font.font = fnum annot.axes2D.xAxis.title.font.scale = rcParams['axes.2D.title.fontscale'] annot.axes2D.xAxis.label.font.font = fnum annot.axes2D.xAxis.label.font.scale = rcParams['axes.2D.label.fontscale'] annot.axes2D.yAxis.title.font.font = fnum annot.axes2D.yAxis.title.font.scale = rcParams['axes.2D.title.fontscale'] annot.axes2D.yAxis.label.font.font = fnum annot.axes2D.yAxis.label.font.scale = rcParams['axes.2D.label.fontscale'] annot.axes3D.xAxis.title.font.font = fnum annot.axes3D.xAxis.title.font.scale = rcParams['axes.3D.title.fontscale'] annot.axes3D.xAxis.label.font.font = fnum annot.axes3D.xAxis.label.font.scale = rcParams['axes.3D.label.fontscale'] annot.axes3D.yAxis.title.font.font = fnum annot.axes3D.yAxis.title.font.scale = rcParams['axes.3D.title.fontscale'] annot.axes3D.yAxis.label.font.font = fnum annot.axes3D.yAxis.label.font.scale = rcParams['axes.3D.label.fontscale'] annot.axes3D.zAxis.title.font.font = fnum annot.axes3D.zAxis.title.font.scale = rcParams['axes.3D.title.fontscale'] annot.axes3D.zAxis.label.font.font = fnum annot.axes3D.zAxis.label.font.scale = rcParams['axes.3D.label.fontscale'] return annot
def visit_plot_qcrit_wx_3d_direct(xdmf_path, wx_range=(-5.0, 5.0), q_value=0.1, config_view=None, out_dir=os.getcwd(), out_prefix='qcrit_wx_', figsize=(1024, 1024), state=None, states=None, states_range=[0, None, 1]): visit_initialize() visit.OpenDatabase(str(xdmf_path), 0) # Add a pseudocolor of the cell-centered streamwise vorticity. visit.AddPlot('Pseudocolor', 'wx_cc', 1, 1) PseudocolorAtts = visit.PseudocolorAttributes() PseudocolorAtts.minFlag = 1 PseudocolorAtts.min = wx_range[0] PseudocolorAtts.maxFlag = 1 PseudocolorAtts.max = wx_range[1] PseudocolorAtts.colorTableName = 'viridis' PseudocolorAtts.invertColorTable = 0 PseudocolorAtts.opacityType = PseudocolorAtts.Constant PseudocolorAtts.opacity = 0.8 PseudocolorAtts.legendFlag = 0 visit.SetPlotOptions(PseudocolorAtts) # Add an isosurface of the Q-criterion. visit.AddOperator('Isosurface', 1) IsosurfaceAtts = visit.IsosurfaceAttributes() IsosurfaceAtts.variable = 'qcrit' IsosurfaceAtts.contourMethod = IsosurfaceAtts.Value IsosurfaceAtts.contourValue = (q_value) IsosurfaceAtts.scaling = IsosurfaceAtts.Linear visit.SetOperatorOptions(IsosurfaceAtts, 1) # Remove info about user, time, database, and legend. AnnotationAtts = visit.AnnotationAttributes() AnnotationAtts.userInfoFlag = 0 AnnotationAtts.databaseInfoFlag = 0 AnnotationAtts.timeInfoFlag = 0 AnnotationAtts.legendInfoFlag = 0 AnnotationAtts.axes3D.visible = 0 AnnotationAtts.axes3D.triadFlag = 1 AnnotationAtts.axes3D.bboxFlag = 0 visit.SetAnnotationAttributes(AnnotationAtts) # Parse the 3D view configuration file. if config_view is not None: View3DAtts = visit_get_view(config_view, '3D') visit.SetView3D(View3DAtts) visit.SetActiveWindow(1) states = visit_get_states(state=state, states=states, states_range=states_range) visit_render_save_states(states, out_dir=out_dir, out_prefix=out_prefix, figsize=figsize) visit_finalize() return
def visit_plot_qcrit_wx_3d(xdmf_dir, wx_range=(-5.0, 5.0), q_value=0.1, config_view=None, out_dir=os.getcwd(), out_prefix='wake3d_', figsize=(1024, 1024), visit_dir=None, visit_arch='linux-x86_64', state=None, states=None, states_range=[0, None, 1]): # Import VisIt package. if visit_dir is None: visit_dir = os.environ.get('VISIT_DIR') if visit_dir is None: raise ValueError('Provide VisIt installation path or ' 'set env variable VISIT_DIR') sys.path.append(os.path.join(visit_dir, visit_arch, 'lib', 'site-packages')) import visit visit.LaunchNowin() # Check version of VisIt. visit_check_version(visit.Version()) # Define some variables to get the q_crit and wx_cc. p_xdmf_path = os.path.join(str(xdmf_dir), 'p.xmf') visit.OpenDatabase(p_xdmf_path, 0) visit.DefineScalarExpression("operators/ConnectedComponents/p Grid", "cell_constant(<p Grid>, 0.)") visit.DefineCurveExpression("operators/DataBinning/1D/p Grid", "cell_constant(<p Grid>, 0)") visit.DefineScalarExpression("operators/DataBinning/2D/p Grid", "cell_constant(<p Grid>, 0)") visit.DefineScalarExpression("operators/DataBinning/3D/p Grid", "cell_constant(<p Grid>, 0)") visit.DefineScalarExpression("operators/Flux/p Grid", "cell_constant(<p Grid>, 0.)") visit.DefineCurveExpression("operators/Lineout/p", "cell_constant(<p>, 0.)") visit.DefineCurveExpression( "operators/Lineout/time_derivative/p Grid_time", "cell_constant(time_derivative/p Grid_time, 0.)") visit.DefineCurveExpression( "operators/Lineout/time_derivative/p Grid_lasttime", "cell_constant(time_derivative/p Grid_lasttime, 0.)") visit.DefineCurveExpression("operators/Lineout/time_derivative/p", "cell_constant(time_derivative/p, 0.)") visit.DefineScalarExpression("operators/ModelFit/model", "point_constant(<p Grid>, 0)") visit.DefineScalarExpression("operators/ModelFit/distance", "point_constant(<p Grid>, 0)") visit.DefineScalarExpression("operators/StatisticalTrends/Sum/p", "cell_constant(<p>, 0.)") visit.DefineScalarExpression("operators/StatisticalTrends/Mean/p", "cell_constant(<p>, 0.)") visit.DefineScalarExpression("operators/StatisticalTrends/Variance/p", "cell_constant(<p>, 0.)") visit.DefineScalarExpression("operators/StatisticalTrends/Std. Dev./p", "cell_constant(<p>, 0.)") visit.DefineScalarExpression("operators/StatisticalTrends/Slope/p", "cell_constant(<p>, 0.)") visit.DefineScalarExpression("operators/StatisticalTrends/Residuals/p", "cell_constant(<p>, 0.)") visit.DefineScalarExpression( "operators/StatisticalTrends/Sum/time_derivative/p Grid_time", "cell_constant(<time_derivative/p Grid_time>, 0.)") visit.DefineScalarExpression( "operators/StatisticalTrends/Sum/time_derivative/p Grid_lasttime", "cell_constant(<time_derivative/p Grid_lasttime>, 0.)") visit.DefineScalarExpression( "operators/StatisticalTrends/Sum/time_derivative/p", "cell_constant(<time_derivative/p>, 0.)") visit.DefineScalarExpression( "operators/StatisticalTrends/Mean/time_derivative/p Grid_time", "cell_constant(<time_derivative/p Grid_time>, 0.)") visit.DefineScalarExpression( "operators/StatisticalTrends/Mean/time_derivative/p Grid_lasttime", "cell_constant(<time_derivative/p Grid_lasttime>, 0.)") visit.DefineScalarExpression( "operators/StatisticalTrends/Mean/time_derivative/p", "cell_constant(<time_derivative/p>, 0.)") visit.DefineScalarExpression( "operators/StatisticalTrends/Variance/time_derivative/p Grid_time", "cell_constant(<time_derivative/p Grid_time>, 0.)") visit.DefineScalarExpression( "operators/StatisticalTrends/Variance/time_derivative/p Grid_lasttime", "cell_constant(<time_derivative/p Grid_lasttime>, 0.)") visit.DefineScalarExpression( "operators/StatisticalTrends/Variance/time_derivative/p", "cell_constant(<time_derivative/p>, 0.)") visit.DefineScalarExpression( "operators/StatisticalTrends/Std. Dev./time_derivative/p Grid_time", "cell_constant(<time_derivative/p Grid_time>, 0.)") visit.DefineScalarExpression( "operators/StatisticalTrends/Std. Dev./time_derivative/p Grid_lasttime", "cell_constant(<time_derivative/p Grid_lasttime>, 0.)") visit.DefineScalarExpression( "operators/StatisticalTrends/Std. Dev./time_derivative/p", "cell_constant(<time_derivative/p>, 0.)") visit.DefineScalarExpression( "operators/StatisticalTrends/Slope/time_derivative/p Grid_time", "cell_constant(<time_derivative/p Grid_time>, 0.)") visit.DefineScalarExpression( "operators/StatisticalTrends/Slope/time_derivative/p Grid_lasttime", "cell_constant(<time_derivative/p Grid_lasttime>, 0.)") visit.DefineScalarExpression( "operators/StatisticalTrends/Slope/time_derivative/p", "cell_constant(<time_derivative/p>, 0.)") visit.DefineScalarExpression( "operators/StatisticalTrends/Residuals/time_derivative/p Grid_time", "cell_constant(<time_derivative/p Grid_time>, 0.)") visit.DefineScalarExpression( "operators/StatisticalTrends/Residuals/time_derivative/p Grid_lasttime", "cell_constant(<time_derivative/p Grid_lasttime>, 0.)") visit.DefineScalarExpression( "operators/StatisticalTrends/Residuals/time_derivative/p", "cell_constant(<time_derivative/p>, 0.)") visit.DefineVectorExpression("operators/SurfaceNormal/p Grid", "cell_constant(<p Grid>, 0.)") # Define cell-centered velocity vector field. ux_xdmf_path = os.path.join(str(xdmf_dir), 'u.xmf') uy_xdmf_path = os.path.join(str(xdmf_dir), 'v.xmf') uz_xdmf_path = os.path.join(str(xdmf_dir), 'w.xmf') vel_exp = ('{' + 'pos_cmfe(<{}[0]id:u>, <p Grid>, 1.0),'.format(ux_xdmf_path) + 'pos_cmfe(<{}[0]id:v>, <p Grid>, 0.0),'.format(uy_xdmf_path) + 'pos_cmfe(<{}[0]id:w>, <p Grid>, 0.0)'.format(uz_xdmf_path) + '}') visit.DefineVectorExpression('velocity', vel_exp) # Define Q-criterion. qcrit_exp = ('q_criterion(' + 'gradient(velocity[0]),' + 'gradient(velocity[1]),' + 'gradient(velocity[2])' + ')') visit.DefineScalarExpression('q_crit', qcrit_exp) # Define cell-centered streamwise vorticity. wx_xdmf_path = os.path.join(str(xdmf_dir), 'wx.xmf') wx_exp = 'pos_cmfe(<{}[0]id:wx>, <p Grid>, 0.0)'.format(wx_xdmf_path) visit.DefineScalarExpression('wx_cc', wx_exp) # Add a pseudocolor of the cell-centered streamwise vorticity. visit.AddPlot('Pseudocolor', 'wx_cc', 1, 1) PseudocolorAtts = visit.PseudocolorAttributes() PseudocolorAtts.minFlag = 1 PseudocolorAtts.min = wx_range[0] PseudocolorAtts.maxFlag = 1 PseudocolorAtts.max = wx_range[1] PseudocolorAtts.colorTableName = 'viridis' PseudocolorAtts.invertColorTable = 1 PseudocolorAtts.opacityType = PseudocolorAtts.Constant PseudocolorAtts.opacity = 0.8 PseudocolorAtts.legendFlag = 0 visit.SetPlotOptions(PseudocolorAtts) # Add an isosurface of the Q-criterion. visit.AddOperator('Isosurface', 1) IsosurfaceAtts = visit.IsosurfaceAttributes() IsosurfaceAtts.variable = 'q_crit' IsosurfaceAtts.contourMethod = IsosurfaceAtts.Value IsosurfaceAtts.contourValue = (q_value) IsosurfaceAtts.scaling = IsosurfaceAtts.Linear visit.SetOperatorOptions(IsosurfaceAtts, 1) # Remove info about user, time, database, and legend. AnnotationAtts = visit.AnnotationAttributes() AnnotationAtts.userInfoFlag = 0 AnnotationAtts.databaseInfoFlag = 0 AnnotationAtts.timeInfoFlag = 0 AnnotationAtts.legendInfoFlag = 0 AnnotationAtts.axes3D.visible = 0 AnnotationAtts.axes3D.triadFlag = 1 AnnotationAtts.axes3D.bboxFlag = 0 visit.SetAnnotationAttributes(AnnotationAtts) # Parse the 3D view configuration file. if config_view is not None: with open(str(config_view), 'r') as infile: config_view = yaml.load(infile, Loader=yaml.FullLoader) config_view = config_view['View3DAtts'] # Set attributes of the view. View3DAtts = visit.View3DAttributes() for key, value in config_view.items(): if type(value) is list: value = tuple(value) setattr(View3DAtts, key, value) visit.SetView3D(View3DAtts) visit.SetActiveWindow(1) visit.Source(os.path.join(visit_dir, visit_arch, 'bin', 'makemovie.py')) visit.ToggleCameraViewMode() # Create output directory if necessary. if not os.path.isdir(str(out_dir)): os.makedirs(str(out_dir)) # Loop over the states to render and save the plots. if state is not None: states = [state] elif states is None: if states_range[1] is None: states_range[1] = visit.TimeSliderGetNStates() else: states_range[1] += 1 states = range(*states_range) for i, state in enumerate(states): print('[state {}] Rendering and saving figure ...'.format(state)) visit.SetTimeSliderState(state) if i == 0: visit.DrawPlots() RenderingAtts = visit.RenderingAttributes() visit.SetRenderingAttributes(RenderingAtts) SaveWindowAtts = visit.SaveWindowAttributes() SaveWindowAtts.outputToCurrentDirectory = 0 SaveWindowAtts.outputDirectory = str(out_dir) SaveWindowAtts.fileName = '{}{:0>4}'.format(out_prefix, state) SaveWindowAtts.family = 0 SaveWindowAtts.format = SaveWindowAtts.PNG SaveWindowAtts.width = figsize[0] SaveWindowAtts.height = figsize[1] SaveWindowAtts.quality = 100 SaveWindowAtts.resConstraint = SaveWindowAtts.NoConstraint visit.SetSaveWindowAttributes(SaveWindowAtts) visit.SaveWindow() os.remove('visitlog.py') visit.CloseComputeEngine() visit.Close() return
def visit_plot_contour_3d(xdmf_path, name, value_range=(-5.0, 5.0), p3d_paths=None, config_view=None, out_dir=os.getcwd(), out_prefix='wake3d_', figsize=(1024, 1024), visit_dir=None, visit_arch='linux-x86_64', state=None, states=None, states_range=[0, None, 1]): # Import VisIt package. if visit_dir is None: visit_dir = os.environ.get('VISIT_DIR') if visit_dir is None: raise ValueError('Provide VisIt installation path or ' 'set env variable VISIT_DIR') sys.path.append(os.path.join(visit_dir, visit_arch, 'lib', 'site-packages')) import visit visit.LaunchNowin() # Check version of VisIt. visit_check_version(visit.Version()) # Create database correlation with optional Point3D files. num_bodies = 0 databases = [str(xdmf_path)] if p3d_paths is not None: num_bodies = len(p3d_paths) databases = [str(path) for path in p3d_paths] databases.append(str(xdmf_path)) visit.CreateDatabaseCorrelation('common', databases[num_bodies:], 0) # Open the file with the coordinates of the immersed boundary. if num_bodies > 0: for i in range(num_bodies): visit.OpenDatabase(databases[i], 0, 'Point3D_1.0') # Add plot the mesh points. visit.AddPlot('Mesh', 'points', 1, 1) # Set attributes of the mesh plot. MeshAtts = visit.MeshAttributes() MeshAtts.legendFlag = 0 MeshAtts.meshColor = (255, 204, 0, 1.0 * 255) MeshAtts.meshColorSource = MeshAtts.MeshCustom MeshAtts.pointSize = 0.05 MeshAtts.pointType = MeshAtts.Point MeshAtts.pointSizePixels = 2 MeshAtts.opacity = 1 visit.SetPlotOptions(MeshAtts) # Open the XMF file for the z-component of the vorticity. visit.OpenDatabase(databases[-1], 0) # Add the plot of the contour of the z-component of the vorticity. visit.AddPlot('Contour', name, 1, 1) # Set attributes of the contour. ContourAtts = visit.ContourAttributes() ContourAtts.contourNLevels = 2 ContourAtts.SetMultiColor(0, (0, 51, 102, 0.6 * 255)) ContourAtts.SetMultiColor(1, (255, 0, 0, 0.6 * 255)) ContourAtts.legendFlag = 1 ContourAtts.minFlag = 1 ContourAtts.maxFlag = 1 ContourAtts.min = value_range[0] ContourAtts.max = value_range[1] visit.SetPlotOptions(ContourAtts) # Parse the 3D view configuration file. if config_view is not None: with open(str(config_view), 'r') as infile: config_view = yaml.load(infile, Loader=yaml.FullLoader) config_view = config_view['View3DAtts'] # Set attributes of the view. View3DAtts = visit.View3DAttributes() for key, value in config_view.items(): if type(value) is list: value = tuple(value) setattr(View3DAtts, key, value) visit.SetView3D(View3DAtts) # Remove time and user info. AnnotationAtts = visit.AnnotationAttributes() AnnotationAtts.userInfoFlag = 0 AnnotationAtts.timeInfoFlag = 0 AnnotationAtts.axes3D.visible = 0 AnnotationAtts.axes3D.triadFlag = 1 AnnotationAtts.axes3D.bboxFlag = 0 visit.SetAnnotationAttributes(AnnotationAtts) visit.SetActiveWindow(1) visit.Source(os.path.join(visit_dir, visit_arch, 'bin', 'makemovie.py')) visit.ToggleCameraViewMode() # Create output directory if necessary. if not os.path.isdir(str(out_dir)): os.makedirs(str(out_dir)) # Loop over the states to render and save the plots. if state is not None: states = [state] elif states is None: if states_range[1] is None: states_range[1] = visit.TimeSliderGetNStates() else: states_range[1] += 1 states = range(*states_range) for i, state in enumerate(states): print('[state {}] Rendering and saving figure ...'.format(state)) visit.SetTimeSliderState(state) if i == 0: visit.DrawPlots() RenderingAtts = visit.RenderingAttributes() visit.SetRenderingAttributes(RenderingAtts) SaveWindowAtts = visit.SaveWindowAttributes() SaveWindowAtts.outputToCurrentDirectory = 0 SaveWindowAtts.outputDirectory = str(out_dir) SaveWindowAtts.fileName = '{}{:0>4}'.format(out_prefix, state) SaveWindowAtts.family = 0 SaveWindowAtts.format = SaveWindowAtts.PNG SaveWindowAtts.width = figsize[0] SaveWindowAtts.height = figsize[1] SaveWindowAtts.quality = 100 SaveWindowAtts.resConstraint = SaveWindowAtts.NoConstraint visit.SetSaveWindowAttributes(SaveWindowAtts) visit.SaveWindow() os.remove('visitlog.py') visit.Close() return
def visit_plot_qcrit_wx_3d(xdmf_path, qcrit_vals=(6.0, 1.0), wx_lims=(-5.0, 5.0), config_view=None, out_dir=os.getcwd(), prefix='qcrit_wx_3d_', figsize=(1024, 1024), state=None, states=None, states_range=[0, None, 1]): """Plot the 3D isosurface of the Q-criterion at 2 values. The first isosurface is colored by the streamwise vorticity. The second isosurface is colored with a single color (grey). Parameters ---------- xdmf_path : str Path of the XDMF file with information about the Q-criterion and the streamwise vorticity. qcrit_vals : tuple, optional Values of the Q-criterion to display as a tuple of 2 floats; default is (6.0, 1.0). wx_lims : tuple, optional Limits of the color range for the streamwise vorticity as a tuple of 2 floats; default is (-5.0, 5.0). config_view : str, optional Path of the YAML file with the configuration of the view; default is None (use default VisIt view). out_dir : str, optional Output directory in which figures will be saved; default is the present working directory. prefix : str, optional Output filename prefix; default is "qcrit_wx_3d_". figsize : tuple Figure width and height (in pixels); default is (1024, 1024). state : int, optional Single state index to render; default is None (i.e., render multiple states). states : list, optional List of states to render; default is None (i.e., render all states). states_range : list, optional Start, end, and step indices for states to render; default is [0, None, 1] (i.e., render all states). """ visit_initialize() # Open database from XDMF file. visit.OpenDatabase(xdmf_path, 0) # Add a pseudocolor of the streamwise vorticity. visit.AddPlot('Pseudocolor', 'wx_cc', 1, 0) PseudocolorAtts = visit.PseudocolorAttributes() PseudocolorAtts.minFlag, PseudocolorAtts.maxFlag = 1, 1 PseudocolorAtts.min, PseudocolorAtts.max = wx_lims PseudocolorAtts.colorTableName = 'viridis' PseudocolorAtts.invertColorTable = 0 visit.SetPlotOptions(PseudocolorAtts) # Add isosurface of the Q-criterion (colored by streamwise vorticity). visit.AddOperator('Isosurface', 0) IsosurfaceAtts = visit.IsosurfaceAttributes() IsosurfaceAtts.contourMethod = IsosurfaceAtts.Value IsosurfaceAtts.contourValue = (qcrit_vals[0]) IsosurfaceAtts.variable = 'qcrit' visit.SetOperatorOptions(IsosurfaceAtts, 0) # Add single-value contour of the Q-criterion. visit.AddPlot('Contour', 'qcrit', 1, 0) ContourAtts = visit.ContourAttributes() ContourAtts.colorType = ContourAtts.ColorBySingleColor ContourAtts.legendFlag = 0 ContourAtts.singleColor = (128, 128, 128, 153) # grey ContourAtts.contourNLevels = 1 ContourAtts.minFlag, ContourAtts.maxFlag = 1, 1 ContourAtts.min, ContourAtts.max = qcrit_vals[1], qcrit_vals[1] visit.SetPlotOptions(ContourAtts) # Remove some annotations; keep triad. AnnotationAtts = visit.AnnotationAttributes() AnnotationAtts.userInfoFlag = 0 AnnotationAtts.databaseInfoFlag = 0 AnnotationAtts.timeInfoFlag = 0 AnnotationAtts.legendInfoFlag = 0 AnnotationAtts.axes3D.visible = 0 AnnotationAtts.axes3D.triadFlag = 1 AnnotationAtts.axes3D.bboxFlag = 0 visit.SetAnnotationAttributes(AnnotationAtts) # Define state indices to render. states = visit_get_states(state=state, states=states, states_range=states_range) # Render states and save figures to files. visit_render_save_states(states, config_view=config_view, out_dir=out_dir, prefix=prefix, figsize=figsize) visit_finalize()
def SetAnnotationAttributes(domain, legendInfo): # turn on legend (i.e. color bar) # turn off user and database info # turn on x- and y-axes with ticks but turn off all annotations aa = visit.AnnotationAttributes() # options I like to set if legendInfo.visible: aa.legendInfoFlag = 1 else: aa.legendInfoFlag = 0 aa.userInfoFlag = 0 aa.databaseInfoFlag = 0 # aa.axes2D.visible = 1 aa.axes2D.visible = 0 aa.axes2D.autoSetTicks = 0 aa.axes2D.autoSetScaling = 0 aa.axes2D.lineWidth = 0 aa.axes2D.tickLocation = aa.axes2D.Inside # Inside, Outside, Both aa.axes2D.tickAxes = aa.axes2D.All # Off, Bottom, Left, BottomLeft, All aa.axes2D.xAxis.title.visible = 0 aa.axes2D.xAxis.label.visible = 0 aa.axes2D.xAxis.tickMarks.visible = 1 aa.axes2D.xAxis.tickMarks.majorMinimum = domain.xlo aa.axes2D.xAxis.tickMarks.majorMaximum = domain.xhi aa.axes2D.xAxis.tickMarks.minorSpacing = (domain.xhi - domain.xlo) / 16. aa.axes2D.xAxis.tickMarks.majorSpacing = (domain.xhi - domain.xlo) / 4. aa.axes2D.xAxis.grid = 1 aa.axes2D.yAxis.title.visible = 0 aa.axes2D.yAxis.label.visible = 0 aa.axes2D.yAxis.tickMarks.visible = 1 aa.axes2D.yAxis.tickMarks.majorMinimum = domain.ylo aa.axes2D.yAxis.tickMarks.majorMaximum = domain.yhi aa.axes2D.yAxis.tickMarks.minorSpacing = (domain.yhi - domain.ylo) / 16. aa.axes2D.yAxis.tickMarks.majorSpacing = (domain.yhi - domain.ylo) / 4. aa.axes2D.yAxis.grid = 1 # other options with default values aa.backgroundColor = (255, 255, 255, 255) aa.foregroundColor = (0, 0, 0, 255) aa.gradientBackgroundStyle = aa.Radial # TopToBottom, BottomToTop, LeftToRight, RightToLeft, Radial aa.gradientColor1 = (0, 0, 255, 255) aa.gradientColor2 = (0, 0, 0, 255) aa.backgroundMode = aa.Solid # Solid, Gradient, Image, ImageSphere aa.axes2D.xAxis.title.font.font = aa.axes2D.xAxis.title.font.Courier # Arial, Courier, Times aa.axes2D.xAxis.title.font.scale = 1 aa.axes2D.xAxis.title.font.useForegroundColor = 1 aa.axes2D.xAxis.title.font.color = (0, 0, 0, 255) aa.axes2D.xAxis.title.font.bold = 1 aa.axes2D.xAxis.title.font.italic = 1 aa.axes2D.xAxis.title.userTitle = 0 aa.axes2D.xAxis.title.userUnits = 0 aa.axes2D.xAxis.title.title = "X-Axis" aa.axes2D.xAxis.title.units = "" aa.axes2D.xAxis.label.font.font = aa.axes2D.xAxis.label.font.Courier # Arial, Courier, Times aa.axes2D.xAxis.label.font.scale = 1 aa.axes2D.xAxis.label.font.useForegroundColor = 1 aa.axes2D.xAxis.label.font.color = (0, 0, 0, 255) aa.axes2D.xAxis.label.font.bold = 1 aa.axes2D.xAxis.label.font.italic = 1 aa.axes2D.xAxis.label.scaling = 0 aa.axes2D.yAxis.title.font.font = aa.axes2D.yAxis.title.font.Courier # Arial, Courier, Times aa.axes2D.yAxis.title.font.scale = 1 aa.axes2D.yAxis.title.font.useForegroundColor = 1 aa.axes2D.yAxis.title.font.color = (0, 0, 0, 255) aa.axes2D.yAxis.title.font.bold = 1 aa.axes2D.yAxis.title.font.italic = 1 aa.axes2D.yAxis.title.userTitle = 0 aa.axes2D.yAxis.title.userUnits = 0 aa.axes2D.yAxis.title.title = "Y-Axis" aa.axes2D.yAxis.title.units = "" aa.axes2D.yAxis.label.font.font = aa.axes2D.yAxis.label.font.Courier # Arial, Courier, Times aa.axes2D.yAxis.label.font.scale = 1 aa.axes2D.yAxis.label.font.useForegroundColor = 1 aa.axes2D.yAxis.label.font.color = (0, 0, 0, 255) aa.axes2D.yAxis.label.font.bold = 1 aa.axes2D.yAxis.label.font.italic = 1 aa.axes2D.yAxis.label.scaling = 0 visit.SetAnnotationAttributes(aa)
pa.minFlag = 1 pa.min = minSk pa.maxFlag = 1 pa.max = maxSk visit.SetPlotOptions(pa) # x- and y-ranges of plot and position of plot va = visit.View2DAttributes() va.windowCoords = (kxlo, kxhi, kylo, kyhi) va.viewportCoords = (0.06, 0.94, 0.11, 0.99) visit.SetView2D(va) # legend(colorbox) and user/database info on/off | axes aa = visit.AnnotationAttributes() aa.legendInfoFlag = 1 aa.userInfoFlag = 0 aa.databaseInfoFlag = 0 aa.axes2D.visible = 1 aa.axes2D.autoSetTicks = 0 aa.axes2D.autoSetScaling = 0 aa.axes2D.lineWidth = 0 aa.axes2D.tickLocation = aa.axes2D.Inside # Inside, Outside, Both aa.axes2D.tickAxes = aa.axes2D.All # Off, Bottom, Left, BottomLeft, All aa.axes2D.xAxis.title.visible = 0 aa.axes2D.xAxis.label.visible = 0 aa.axes2D.xAxis.tickMarks.visible = 1 aa.axes2D.xAxis.tickMarks.majorMinimum = kxlo aa.axes2D.xAxis.tickMarks.majorMaximum = kxhi aa.axes2D.xAxis.tickMarks.minorSpacing = (kxhi - kxlo) / 16.
def visit_plot_pseudocolor_2d(xdmf_path, name, value_range=(-5.0, 5.0), curve2d_paths=None, config_view=None, out_dir=os.getcwd(), out_prefix=None, figsize=(1024, 1024), state=None, states=None, states_range=[0, None, 1]): visit_initialize() # Create database correlation with optional Curve2D files. num_bodies = 0 databases = [str(xdmf_path)] if curve2d_paths is not None: num_bodies = len(curve2d_paths) databases = [str(path) for path in curve2d_paths] databases.append(str(xdmf_path)) visit.CreateDatabaseCorrelation('common', databases[num_bodies:], 0) # Open the file with the coordinates of the immersed boundary. if num_bodies > 0: for i in range(num_bodies): visit.OpenDatabase(databases[i], 0) # Add plot the mesh points. visit.AddPlot('Curve', 'curve', 1, 1) # Set attributes of the curve. CurveAtts = visit.CurveAttributes() CurveAtts.lineWidth = 1 CurveAtts.curveColorSource = CurveAtts.Custom CurveAtts.curveColor = (0, 0, 0, 255) CurveAtts.showLegend = 0 CurveAtts.showLabels = 0 visit.SetPlotOptions(CurveAtts) # Open the XMF file for the spanwise-averaged z-component of the vorticity. visit.OpenDatabase(databases[-1], 0) # Add a pseudocolor plot of the scalar field. visit.AddPlot('Pseudocolor', name, 1, 1) # Set attributes of the pseudocolor. PseudocolorAtts = visit.PseudocolorAttributes() PseudocolorAtts.minFlag = 1 PseudocolorAtts.min = value_range[0] PseudocolorAtts.maxFlag = 1 PseudocolorAtts.max = value_range[1] PseudocolorAtts.colorTableName = 'viridis' visit.SetPlotOptions(PseudocolorAtts) # Parse the 2D view configuration file. if config_view is not None: View2DAtts = visit_get_view(config_view, '2D') visit.SetView2D(View2DAtts) # Remove time and user info. AnnotationAtts = visit.AnnotationAttributes() AnnotationAtts.userInfoFlag = 0 AnnotationAtts.timeInfoFlag = 1 visit.SetAnnotationAttributes(AnnotationAtts) visit.SetActiveWindow(1) states = visit_get_states(state=state, states=states, states_range=states_range) if out_prefix is None: out_prefix = name + '_' visit_render_save_states(states, out_dir=out_dir, out_prefix=out_prefix, figsize=figsize) visit_finalize() return
def visit_plot_pseudocolor_2d(xdmf_path, name, value_range=(-5.0, 5.0), curve2d_paths=None, config_view=None, out_dir=os.getcwd(), out_prefix='wake2d_', figsize=(1024, 1024), visit_dir=None, visit_arch='linux-x86_64', state=None, states=None, states_range=[0, None, 1]): # Import VisIt package. if visit_dir is None: visit_dir = os.environ.get('VISIT_DIR') if visit_dir is None: raise ValueError('Provide VisIt installation path or ' 'set env variable VISIT_DIR') sys.path.append(os.path.join(visit_dir, visit_arch, 'lib', 'site-packages')) import visit visit.LaunchNowin() # Check version of VisIt. visit_check_version(visit.Version()) # Create database correlation with optional Curve2D files. num_bodies = 0 databases = [str(xdmf_path)] if curve2d_paths is not None: num_bodies = len(curve2d_paths) databases = [str(path) for path in curve2d_paths] databases.append(str(xdmf_path)) visit.CreateDatabaseCorrelation('common', databases[num_bodies:], 0) # Open the file with the coordinates of the immersed boundary. if num_bodies > 0: for i in range(num_bodies): visit.OpenDatabase(databases[i], 0) # Add plot the mesh points. visit.AddPlot('Curve', 'curve', 1, 1) # Set attributes of the curve. CurveAtts = visit.CurveAttributes() CurveAtts.lineWidth = 1 CurveAtts.curveColorSource = CurveAtts.Custom CurveAtts.curveColor = (0, 0, 0, 255) CurveAtts.showLegend = 0 CurveAtts.showLabels = 0 visit.SetPlotOptions(CurveAtts) # Open the XMF file for the spanwise-averaged z-component of the vorticity. visit.OpenDatabase(databases[-1], 0) # Add a pseudocolor plot of the scalar field. visit.AddPlot('Pseudocolor', name, 1, 1) # Set attributes of the pseudocolor. PseudocolorAtts = visit.PseudocolorAttributes() PseudocolorAtts.minFlag = 1 PseudocolorAtts.min = value_range[0] PseudocolorAtts.maxFlag = 1 PseudocolorAtts.max = value_range[1] PseudocolorAtts.colorTableName = 'viridis' visit.SetPlotOptions(PseudocolorAtts) # Parse the 2D view configuration file. if config_view is not None: with open(str(config_view), 'r') as infile: config_view = yaml.load(infile, Loader=yaml.FullLoader) config_view = config_view['View2DAtts'] # Set attributes of the view. View2DAtts = visit.View2DAttributes() for key, value in config_view.items(): if type(value) is list: value = tuple(value) setattr(View2DAtts, key, value) visit.SetView2D(View2DAtts) # Remove time and user info. AnnotationAtts = visit.AnnotationAttributes() AnnotationAtts.userInfoFlag = 0 AnnotationAtts.timeInfoFlag = 1 visit.SetAnnotationAttributes(AnnotationAtts) visit.SetActiveWindow(1) visit.Source(os.path.join(visit_dir, visit_arch, 'bin', 'makemovie.py')) visit.ToggleCameraViewMode() # Create output directory if necessary. if not os.path.isdir(str(out_dir)): os.makedirs(str(out_dir)) # Loop over the states to render and save the plots. if state is not None: states = [state] elif states is None: if states_range[1] is None: states_range[1] = visit.TimeSliderGetNStates() else: states_range[1] += 1 states = range(*states_range) for i, state in enumerate(states): print('[state {}] Rendering and saving figure ...'.format(state)) visit.SetTimeSliderState(state) if i == 0: visit.DrawPlots() RenderingAtts = visit.RenderingAttributes() visit.SetRenderingAttributes(RenderingAtts) SaveWindowAtts = visit.SaveWindowAttributes() SaveWindowAtts.outputToCurrentDirectory = 0 SaveWindowAtts.outputDirectory = str(out_dir) SaveWindowAtts.fileName = '{}{:0>4}'.format(out_prefix, state) SaveWindowAtts.family = 0 SaveWindowAtts.format = SaveWindowAtts.PNG SaveWindowAtts.width = figsize[0] SaveWindowAtts.height = figsize[1] SaveWindowAtts.quality = 100 SaveWindowAtts.resConstraint = SaveWindowAtts.NoConstraint visit.SetSaveWindowAttributes(SaveWindowAtts) visit.SaveWindow() os.remove('visitlog.py') visit.Close() return
def visit_plot_contour_3d(xdmf_path, name, value_range=(-5.0, 5.0), p3d_paths=None, config_view=None, out_dir=os.getcwd(), out_prefix=None, figsize=(1024, 1024), state=None, states=None, states_range=[0, None, 1]): visit_initialize() # Create database correlation with optional Point3D files. num_bodies = 0 databases = [str(xdmf_path)] if p3d_paths is not None: num_bodies = len(p3d_paths) databases = [str(path) for path in p3d_paths] databases.append(str(xdmf_path)) visit.CreateDatabaseCorrelation('common', databases[num_bodies:], 0) # Open the file with the coordinates of the immersed boundary. if num_bodies > 0: for i in range(num_bodies): visit.OpenDatabase(databases[i], 0, 'Point3D_1.0') # Add plot the mesh points. visit.AddPlot('Mesh', 'points', 1, 1) # Set attributes of the mesh plot. MeshAtts = visit.MeshAttributes() MeshAtts.legendFlag = 0 MeshAtts.meshColor = (255, 204, 0, 1.0 * 255) MeshAtts.meshColorSource = MeshAtts.MeshCustom MeshAtts.pointSize = 0.05 MeshAtts.pointType = MeshAtts.Point MeshAtts.pointSizePixels = 2 MeshAtts.opacity = 1 visit.SetPlotOptions(MeshAtts) # Open the XMF file for the z-component of the vorticity. visit.OpenDatabase(databases[-1], 0) # Add the plot of the contour of the z-component of the vorticity. visit.AddPlot('Contour', name, 1, 1) # Set attributes of the contour. ContourAtts = visit.ContourAttributes() ContourAtts.contourNLevels = 2 ContourAtts.SetMultiColor(0, (0, 51, 102, 0.6 * 255)) ContourAtts.SetMultiColor(1, (255, 0, 0, 0.6 * 255)) ContourAtts.legendFlag = 1 ContourAtts.minFlag = 1 ContourAtts.maxFlag = 1 ContourAtts.min = value_range[0] ContourAtts.max = value_range[1] visit.SetPlotOptions(ContourAtts) # Parse the 3D view configuration file. if config_view is not None: View3DAtts = visit_get_view(config_view, '3D') visit.SetView3D(View3DAtts) # Remove time and user info. AnnotationAtts = visit.AnnotationAttributes() AnnotationAtts.userInfoFlag = 0 AnnotationAtts.timeInfoFlag = 0 AnnotationAtts.axes3D.visible = 0 AnnotationAtts.axes3D.triadFlag = 1 AnnotationAtts.axes3D.bboxFlag = 0 visit.SetAnnotationAttributes(AnnotationAtts) visit.SetActiveWindow(1) states = visit_get_states(state=state, states=states, states_range=states_range) if out_prefix is None: out_prefix = name + '_' visit_render_save_states(states, out_dir=out_dir, out_prefix=out_prefix, figsize=figsize) visit_finalize() return
vatts.resampleTarget = args.nsamples vatts.lightingFlag = 0 if args.cmin is not None: vatts.useColorVarMin = 1 vatts.colorVarMin = args.cmin if args.cmax is not None: vatts.useColorVarMax = 1 vatts.colorVarMax = args.cmax vatts.opacityAttenuation = args.attenuation v.SetPlotOptions(vatts) # Set annotations aatts = v.AnnotationAttributes() aatts.axes3D.visible = 0 if args.triad: aatts.axes3D.triadFlag = 1 else: aatts.axes3D.triadFlag = 0 aatts.axes3D.bboxFlag = 0 aatts.userInfoFlag = 0 aatts.timeInfoFlag = 0 aatts.legendInfoFlag = 0 aatts.databaseInfoFlag = 0 if args.time: aatts.timeInfoFlag = 1 if args.legend: aatts.legendInfoFlag = 1 if args.dbase:
def visit_plot_qcrit_wx_3d(xdmf_dir, wx_range=(-5.0, 5.0), q_value=0.1, config_view=None, out_dir=os.getcwd(), out_prefix='qcrit_wx_', figsize=(1024, 1024), state=None, states=None, states_range=[0, None, 1]): visit_initialize() # Define some variables to get the q_crit and wx_cc. p_xdmf_path = os.path.join(str(xdmf_dir), 'p.xmf') visit.OpenDatabase(p_xdmf_path, 0) # Define cell-centered velocity vector field. ux_xdmf_path = os.path.join(str(xdmf_dir), 'u.xmf') uy_xdmf_path = os.path.join(str(xdmf_dir), 'v.xmf') uz_xdmf_path = os.path.join(str(xdmf_dir), 'w.xmf') vel_expr = ('{' + 'pos_cmfe(<{}[0]id:u>, <p Grid>, 1.0),'.format(ux_xdmf_path) + 'pos_cmfe(<{}[0]id:v>, <p Grid>, 0.0),'.format(uy_xdmf_path) + 'pos_cmfe(<{}[0]id:w>, <p Grid>, 0.0)'.format(uz_xdmf_path) + '}') visit.DefineVectorExpression('velocity', vel_expr) # Define Q-criterion. qcrit_expr = ('q_criterion(' + 'gradient(velocity[0]),' + 'gradient(velocity[1]),' + 'gradient(velocity[2])' + ')') visit.DefineScalarExpression('q_crit', qcrit_expr) # Define cell-centered streamwise vorticity. wx_xdmf_path = os.path.join(str(xdmf_dir), 'wx.xmf') wx_exp = 'pos_cmfe(<{}[0]id:wx>, <p Grid>, 0.0)'.format(wx_xdmf_path) visit.DefineScalarExpression('wx_cc', wx_exp) # Add a pseudocolor of the cell-centered streamwise vorticity. visit.AddPlot('Pseudocolor', 'wx_cc', 1, 1) PseudocolorAtts = visit.PseudocolorAttributes() PseudocolorAtts.minFlag = 1 PseudocolorAtts.min = wx_range[0] PseudocolorAtts.maxFlag = 1 PseudocolorAtts.max = wx_range[1] PseudocolorAtts.colorTableName = 'viridis' PseudocolorAtts.invertColorTable = 0 PseudocolorAtts.opacityType = PseudocolorAtts.Constant PseudocolorAtts.opacity = 0.8 PseudocolorAtts.legendFlag = 0 visit.SetPlotOptions(PseudocolorAtts) # Add an isosurface of the Q-criterion. visit.AddOperator('Isosurface', 1) IsosurfaceAtts = visit.IsosurfaceAttributes() IsosurfaceAtts.variable = 'q_crit' IsosurfaceAtts.contourMethod = IsosurfaceAtts.Value IsosurfaceAtts.contourValue = (q_value) IsosurfaceAtts.scaling = IsosurfaceAtts.Linear visit.SetOperatorOptions(IsosurfaceAtts, 1) # Remove info about user, time, database, and legend. AnnotationAtts = visit.AnnotationAttributes() AnnotationAtts.userInfoFlag = 0 AnnotationAtts.databaseInfoFlag = 0 AnnotationAtts.timeInfoFlag = 0 AnnotationAtts.legendInfoFlag = 0 AnnotationAtts.axes3D.visible = 0 AnnotationAtts.axes3D.triadFlag = 1 AnnotationAtts.axes3D.bboxFlag = 0 visit.SetAnnotationAttributes(AnnotationAtts) # Parse the 3D view configuration file. if config_view is not None: View3DAtts = visit_get_view(config_view, '3D') visit.SetView3D(View3DAtts) visit.SetActiveWindow(1) states = visit_get_states(state=state, states=states, states_range=states_range) visit_render_save_states(states, out_dir=out_dir, out_prefix=out_prefix, figsize=figsize) visit_finalize() return