def save_window(): visit.ResetView() v = visit.GetView3D() v.RotateAxis(0,-90) visit.SetView3D(v) swatts= visit.SaveWindowAttributes() swatts.outputToCurrentDirectory = 1 swatts.outputDirectory = "." swatts.fileName = "chunk_render" swatts.family = 0 swatts.format = swatts.PNG swatts.width = 1024 swatts.height = 1024 swatts.screenCapture = 0 swatts.saveTiled = 0 swatts.quality = 100 swatts.progressive = 0 swatts.binary = 0 swatts.stereo = 0 swatts.compression = swatts.PackBits swatts.forceMerge = 0 swatts.resConstraint = swatts.NoConstraint swatts.advancedMultiWindowSave = 0 visit.SetSaveWindowAttributes(swatts) visit.SaveWindow()
def make_slide(time): plasma_file = vtk_path + plasma_file_head + str(time) +'.vtk' paraxial_file = vtk_path + paraxial_file_head + str(time) + '.vtk' fullwave_file = vtk_path + fullwave_file_head + str(time) + '.vtk' print('opening plamsa file:' + plasma_file) sts = vi.OpenDatabase(plasma_file,0,'VTK') if (sts != 1): print('open file failed! error code:' + str(sts)) return sts = vi.AddPlot('Pseudocolor','cutoff') vi.DrawPlots() po = vi.GetPlotOptions() vi.LoadAttribute(plasma_attr_file,po) vi.SetPlotOptions(po) print('opening paraxial file:' + paraxial_file) sts = vi.OpenDatabase(paraxial_file,0,'VTK') if (sts != 1): print('open file failed! error code:' + str(sts)) return sts = vi.AddPlot('Pseudocolor','Er_para') vi.DrawPlots() po = vi.GetPlotOptions() vi.LoadAttribute(wave_attr_file,po) vi.SetPlotOptions(po) print('opening fullwave file:' + fullwave_file) sts = vi.OpenDatabase(fullwave_file,0,'VTK') if (sts != 1): print('open file failed! error code:' + str(sts)) return sts = vi.AddPlot('Pseudocolor','Er_fullw') vi.DrawPlots() po = vi.GetPlotOptions() vi.LoadAttribute(wave_attr_file,po) vi.SetPlotOptions(po) view_attr = vi.GetView3D() vi.LoadAttribute(view_attr_file,view_attr) vi.SetView3D(view_attr) anno_attr = vi.GetAnnotationAttributes() vi.LoadAttribute(annotation_attr_file,anno_attr) vi.SetAnnotationAttributes(anno_attr) anno_names = vi.GetAnnotationObjectNames() for name in anno_names: legend = vi.GetAnnotationObject(name) legend.numberFormat = "%# -9.2g" legend.drawMinMax = 0 legend.controlTicks = 1 legend.numTicks = 3 vi.SaveWindow()
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 draw(self): print "drawing window %d of dimension %d"%(self.i,self.dim) v.SetActiveWindow(self.i) v.SetAnnotationAttributes(self.annot) if self.dim == 2: # add the slice assert self._slice is not None for i,plot in enumerate(self.plots): sliced = False for op in plot.operators: if "slice" == op.oname: sliced = True if not sliced: print "slicing plot %d..."%i v.SetActivePlots(i) v.AddOperator("Slice") sa = self._slice.toAttributes() v.SetOperatorOptions(sa) plot.operators.append(Operator("slice", "Slice", sa)) if self.exaggeration is not None: print "exaggerating..." self._exaggerateVertical() # set the plot options for i, plot in enumerate(self.plots): print "setting plot options for plot %i..."%i v.SetActivePlots(i) v.SetPlotOptions(plot.patts) # set the view print "setting the view..." if self.dim == 2: v.SetView2D(self.view) else: v.SetView3D(self.view) print "drawing..." v.DrawPlots()
def scatterPlot(self, coords=["var00", "var01", "var02", "var03"], colorTable="hot", pixelSize=5, stay=False): visit.AddWindow() if len(visit.ListPlots()) > 0: visit.SetActivePlots(0) visit.HideActivePlots() plot = visit.AddPlot("Scatter", coords[0]) p = visit.ScatterAttributes() # Variables if coords[1]: p.var2 = coords[1] if coords[2]: p.var3 = coords[2] if coords[3]: p.var4 = coords[3] #Role Variable Roles take intergers as inputs, not strings p.var1Role = 0 p.var2Role = 1 p.var3Role = 2 p.var4Role = 3 p.scaleCube = 0 #p.colorType = "ColorByColorTable" p.pointSizePixels = pixelSize p.colorTableName = colorTable #p.colorScaling = "Log" v = visit.GetView3D() v.viewNormal = (-0.571619, 0.405393, 0.713378) v.viewUp = (0.308049, 0.911853, -0.271346) visit.SetPlotOptions(p) visit.SetView3D(v) visit.DrawPlots() count = 0 time.sleep(5) return visit.SaveWindow()
aatts.timeInfoFlag = 1 if args.legend: aatts.legendInfoFlag = 1 if args.dbase: aatts.databaseInfoFlag = 1 v.SetAnnotationAttributes(aatts) # Set initial view cc = v.GetView3D() cc.viewNormal = tuple(args.normal) # View x-plane cc.viewUp = (0, 0, 1) # Z-axis points up cc.imageZoom = args.zoom cc.imagePan = tuple(args.pan) cc.perspective = 0 v.SetView3D(cc) # Set box selection if args.bbox: v.AddOperator('Box') batts = v.BoxAttributes() batts.amount = batts.All # Some, All batts.minx = args.bbox[0] batts.maxx = args.bbox[1] batts.miny = args.bbox[2] batts.maxy = args.bbox[3] batts.minz = args.bbox[4] batts.maxz = args.bbox[5] batts.inverse = 0 v.SetOperatorOptions(batts) v.DrawPlots()
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
import sys # visit sys.path.append("/home/neo/visit/2.11.0/linux-x86_64/lib/site-packages") import visit as vs vs.Launch() vs.OpenDatabase("visit-data/noise.silo") vs.AddPlot("Pseudocolor", "hardyglobal") vs.AddPlot("Mesh", "Mesh") vs.DrawPlots() v = vs.GetView3D() print "The view is: ", v v.viewNormal = (-0.571619, 0.405393, 0.713378) v.viewUp = (0.308049, 0.911853, -0.271346) vs.SetView3D(v) d = input('Press anything to quit')
def make_distribution_movie(cellids, rotated, inputDirectory, outputDirectory, outputFileName, zoom=1.0, viewNormal=[0.488281, 0.382966, -0.784167], minThreshold=1e-18, maxThreshold=1e37): '''Makes a distribution movie of some given distribution data Example usage: make_distribution_movie(cellids=[18302, 19432, 19042], rotated=True, inputDirectory=\"/home/hannukse/meteo/stornext/field/vlasiator/2D/AAJ/silo_files/\", outputDirectory=\"/home/hannukse/MOVIES/\", outputFileName=\"testmovie\", zoom=0.8, viewNormal=[0.488281, 0.382966, -0.784167], minThreshold=1e-17, maxThreshold=1.2e37) Note: viewNormal determines the angle of view (straight from visit) ''' if len(viewNormal) != 3: print "ERROR, INVALID VIEWNORMAL LENGTH, SHOULD BE 3" return for cell in sorted(cellids): # OPTIONS ########################################################### cellid = str(cell) #databaseName = "localhost:/home/hannukse/meteo/lustre/tmp/hannuksela/AAM/velgrid.rotated." + cellid + ".*.silo database" if rotated == True: rotateFix = "rotated." else: rotateFix = "" inputFileName = "velgrid." + rotateFix + cellid + ".*.silo" databaseName = "localhost:" + inputDirectory + inputFileName + " database" outputDir = outputDirectory fileName = outputFileName + "_" + cellid + "_" WIDTH = 3000 HEIGHT = 3000 # Threshold values: # TODO: USE VLSV READER TO AUTOMATE THIS minimumThreshold = minThreshold maximumThreshold = maxThreshold ########################################################### vis.OpenDatabase(databaseName, 0) #Load settings visSettings.load_visit_settings() #Make a plot vis.AddPlot("Pseudocolor", "avgs", 1, 1) vis.SetActivePlots(0) vis.AddOperator("Threshold", 1) vis.ThresholdAtts = vis.ThresholdAttributes() vis.ThresholdAtts.outputMeshType = 0 vis.ThresholdAtts.listedVarNames = ("default") vis.ThresholdAtts.zonePortions = (1) vis.ThresholdAtts.lowerBounds = (minimumThreshold) vis.ThresholdAtts.upperBounds = (maximumThreshold) vis.ThresholdAtts.defaultVarName = "avgs" vis.ThresholdAtts.defaultVarIsScalar = 1 vis.SetOperatorOptions(vis.ThresholdAtts, 1) vis.DrawPlots() # Begin spontaneous state vis.View3DAtts = vis.View3DAttributes() vis.View3DAtts.viewNormal = (viewNormal[0], viewNormal[1], viewNormal[2]) vis.View3DAtts.focus = (-634.56, 91.3781, -13.7891) vis.View3DAtts.viewUp = (-0.102795, 0.917551, 0.3841) vis.View3DAtts.viewAngle = 30 vis.View3DAtts.parallelScale = 1.45614e+06 vis.View3DAtts.nearPlane = -2.91228e+06 vis.View3DAtts.farPlane = 2.91228e+06 vis.View3DAtts.imagePan = (0, 0) vis.View3DAtts.imageZoom = zoom vis.View3DAtts.perspective = 1 vis.View3DAtts.eyeAngle = 2 vis.View3DAtts.centerOfRotationSet = 0 vis.View3DAtts.centerOfRotation = (-634.56, 91.3781, -13.7891) vis.View3DAtts.axis3DScaleFlag = 0 vis.View3DAtts.axis3DScales = (1, 1, 1) vis.View3DAtts.shear = (0, 0, 1) vis.SetView3D(vis.View3DAtts) # End spontaneous state vis.ViewCurveAtts = vis.ViewCurveAttributes() vis.ViewCurveAtts.domainCoords = (0, 1) vis.ViewCurveAtts.rangeCoords = (0, 1) vis.ViewCurveAtts.viewportCoords = (0.2, 0.95, 0.15, 0.95) vis.ViewCurveAtts.domainScale = vis.ViewCurveAtts.LINEAR # LINEAR, LOG vis.ViewCurveAtts.rangeScale = vis.ViewCurveAtts.LINEAR # LINEAR, LOG vis.SetViewCurve(vis.ViewCurveAtts) vis.View2DAtts = vis.View2DAttributes() vis.View2DAtts.windowCoords = (0, 1, 0, 1) vis.View2DAtts.viewportCoords = (0.2, 0.95, 0.15, 0.95) vis.View2DAtts.fullFrameActivationMode = vis.View2DAtts.Auto # On, Off, Auto vis.View2DAtts.fullFrameAutoThreshold = 100 vis.View2DAtts.xScale = vis.View2DAtts.LINEAR # LINEAR, LOG vis.View2DAtts.yScale = vis.View2DAtts.LINEAR # LINEAR, LOG vis.View2DAtts.windowValid = 0 vis.SetView2D(vis.View2DAtts) vis.View3DAtts = vis.View3DAttributes() vis.View3DAtts.viewNormal = (viewNormal[0], viewNormal[1], viewNormal[2]) vis.View3DAtts.focus = (-634.56, 91.3781, -13.7891) vis.View3DAtts.viewUp = (-0.102795, 0.917551, 0.3841) vis.View3DAtts.viewAngle = 30 vis.View3DAtts.parallelScale = 1.45614e+06 vis.View3DAtts.nearPlane = -2.91228e+06 vis.View3DAtts.farPlane = 2.91228e+06 vis.View3DAtts.imagePan = (0, 0) vis.View3DAtts.imageZoom = zoom vis.View3DAtts.perspective = 1 vis.View3DAtts.eyeAngle = 2 vis.View3DAtts.centerOfRotationSet = 0 vis.View3DAtts.centerOfRotation = (-634.56, 91.3781, -13.7891) vis.View3DAtts.axis3DScaleFlag = 0 vis.View3DAtts.axis3DScales = (1, 1, 1) vis.View3DAtts.shear = (0, 0, 1) vis.SetView3D(vis.View3DAtts) vis.ViewAxisArrayAtts = vis.ViewAxisArrayAttributes() vis.ViewAxisArrayAtts.domainCoords = (0, 1) vis.ViewAxisArrayAtts.rangeCoords = (0, 1) vis.ViewAxisArrayAtts.viewportCoords = (0.15, 0.9, 0.1, 0.85) vis.SetViewAxisArray(vis.ViewAxisArrayAtts) for i in range(0, vis.GetDatabaseNStates()): vis.SetTimeSliderState(i) vis.SaveWindowAtts = vis.SaveWindowAttributes() vis.SaveWindowAtts.outputToCurrentDirectory = 0 vis.SaveWindowAtts.outputDirectory = outputDir vis.SaveWindowAtts.fileName = fileName vis.SaveWindowAtts.family = 1 vis.SaveWindowAtts.format = vis.SaveWindowAtts.PNG # BMP, CURVE, JPEG, OBJ, PNG, POSTSCRIPT, POVRAY, PPM, RGB, STL, TIFF, ULTRA, VTK, PLY vis.SaveWindowAtts.width = WIDTH vis.SaveWindowAtts.height = HEIGHT vis.SaveWindowAtts.screenCapture = 0 vis.SaveWindowAtts.saveTiled = 0 vis.SaveWindowAtts.quality = 100 vis.SaveWindowAtts.progressive = 0 vis.SaveWindowAtts.binary = 0 vis.SaveWindowAtts.stereo = 0 vis.SaveWindowAtts.compression = vis.SaveWindowAtts.PackBits # None, PackBits, Jpeg, Deflate vis.SaveWindowAtts.forceMerge = 0 vis.SaveWindowAtts.resConstraint = vis.SaveWindowAtts.ScreenProportions # NoConstraint, EqualWidthHeight, ScreenProportions vis.SaveWindowAtts.advancedMultiWindowSave = 0 vis.SetSaveWindowAttributes(vis.SaveWindowAtts) vis.SaveWindow() vis.DeleteActivePlots() vis.CloseDatabase(databaseName) # Make the movie: framerate = 5 subprocess.call([ pythonLibDirectoryPath + pyVisitPath + "moviecompilescript.sh", outputDir, fileName, framerate ])
Vi.LaunchNowin() for file in Files: Vi.OpenDatabase(file["file_name"]) Vi.AddPlot(file["plot_type"], file["data_tag"]) # Hide the contour plot in the first plot window. Vi.SetActivePlots(2) Vi.HideActivePlots() # Create the plot of the cube by activating the mesh and pseudocolor plots. Vi.SetActivePlots((0, 1)) # Set the view normal to the first octant. v = Vi.GetView3D() v.viewNormal = (1, 1, 1) Vi.SetView3D(v) # Apply a clip through the first octant. Vi.AddOperator("Clip") c = Vi.ClipAttributes() c.plane1Origin = (40, 40, 40) c.plane1Normal = (1, 1, 1) Vi.SetOperatorOptions(c) # Include the CNERG logo in the bottom left corner of the plot. image = Vi.CreateAnnotationObject("Image") image.image = os.path.dirname(os.path.abspath(__file__)) + "/cnerg.jpg" image.position = (0.02, 0.02) image.width = 10 image.height = 10
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='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
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
def Orbit(Files, OrbitOptions, OperatorSet=False): """ Take multiple views around vertically, horizontally, or both. Views are evenly spaced. OrbitOptions = (<axis>, <number of views>). The higher the number of views the smoother the rotation. This assumes the following positive axis orientation: y - Up x - Right z - Out from screen """ Pa.PathCreator() # Creates necessary folders. OrbitOptions = tuple(OrbitOptions) Line = str(OrbitOptions[0]) Number = int(OrbitOptions[1]) Increment = 360.0 / float(Number) # Degrees Image = Mk.MakeImages(Files) Image.Plot() # Multiple Operators. try: for multiitem in OperatorSet: # Apply dictionary operator. try: Operator = (multiitem.keys())[0] List = (multiitem.values())[0] Image.Operator(Operator, List, SliceProject=0) except Exception: pass # Apply list operator. try: Operator = multiitem[0] List = multiitem[1] Image.Operator(Operator, List, SliceProject=0) except Exception: pass except Exception: pass # Define which orbits to do. orbitSettings = {} orbitSettings["vertical"] = {"Line": 0} orbitSettings["horizontal"] = {"Line": 1} # Choose which orbits to do. if OrbitOptions[0].lower() == "both": OrbitOptions = ["vertical", "horizontal"] for orbit in OrbitOptions: Vi.ResetView() try: Line = orbitSettings[orbit]["Line"] v = Vi.GetView3D() v.viewNormal = (0, 0, 1) v.viewUp = (0, 1, 0) Degrees = 0 while 360.0 > Degrees: # Turning shading False yields black images. Image.Save(Shading=True) v.RotateAxis(Line, Increment) Vi.SetView3D(v) Degrees += Increment except Exception: pass
def visit_render_save_states(states, config_view=None, out_dir=os.getcwd(), prefix=None, figsize=(1024, 1024)): """Render and save states into PNG files. Parameters ---------- states : list-alike List of states to render and save. 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; created is non-existent; default is the present working directory ("."). prefix : str, optional Filename prefix; default is "None" (no prefix). figsize : tuple Figure width and height (in pixels); default is (1024, 1024). """ visit.Source(VISIT_MAKEMOVIE) visit.ToggleCameraViewMode() # Create output directory if necessary. if not os.path.isdir(out_dir): os.makedirs(out_dir) # Define common attributes to save the window. SaveWindowAtts = visit.SaveWindowAttributes() SaveWindowAtts.outputToCurrentDirectory = 0 SaveWindowAtts.outputDirectory = out_dir SaveWindowAtts.family = 0 SaveWindowAtts.format = SaveWindowAtts.PNG SaveWindowAtts.width, SaveWindowAtts.height = figsize SaveWindowAtts.quality = 100 SaveWindowAtts.resConstraint = SaveWindowAtts.NoConstraint # Define common rendering attributes. RenderingAtts = visit.RenderingAttributes() # Parse YAML file with the 3D view configuration. if config_view is not None: View3DAtts = visit_get_view(config_view, 3) # Loop over the states to render and save the plots. for i, state in enumerate(states): print('[state {}] Rendering and saving figure ...'.format(state)) visit.SetTimeSliderState(state) if i == 0: visit.DrawPlots() visit.SetView3D(View3DAtts) # Get time-step index (stored as time value in XDMF file). visit.Query('Time') timestep = int(visit.GetQueryOutputValue()) # Set rendering attributes. visit.SetRenderingAttributes(RenderingAtts) # Set state-specific attributes to save the window. SaveWindowAtts.fileName = '{}{:0>7}'.format(prefix, timestep) visit.SetSaveWindowAttributes(SaveWindowAtts) visit.SaveWindow()
f.write(response.read()) print("Successfully downloaded example silo") visit.LaunchNowin() saveatts = visit.SaveWindowAttributes() saveatts.fileName = 'result-visit.png' saveatts.family = 0 saveatts.width = 1024 saveatts.height = 768 saveatts.resConstraint = saveatts.NoConstraint saveatts.outputToCurrentDirectory = 1 visit.SetSaveWindowAttributes(saveatts) visit.OpenDatabase('example.silo') visit.AddPlot('Contour', 'density') c = visit.ContourAttributes() c.colorType = c.ColorByColorTable c.colorTableName = "hot" visit.SetPlotOptions(c) visit.DrawPlots() v = visit.GetView3D() v.viewNormal = (-0.554924, 0.703901, 0.443377) v.viewUp = (0.272066, -0.3501, 0.896331) visit.SetView3D(v) visit.SaveWindow() visit.DeleteAllPlots() visit.CloseDatabase('example.silo') print("Successfully rendered output raster") print("All done!")
def visit_config(geometry_file, data_file, args): """ Convert geometry file to stl, convert data file to vtk, load each file into VisIt, and create and load a session file containing four plot windows. 1) A cube with a slice through an octant. 2) XY plane slice through the centroid. 3) XZ plane slice through the centroid. 4) YZ plane slice through the centroid. Each window has a mesh plot with the "STL_mesh" variable, a Pseudocolor plot with the "TALLY_TAG" variable, and the second, third, and fourth windows have Contour plots with the "ERROR_TAG" variable. If the user has indicated to, launch VisIt and load the session file. Input: ______ geometry_file: h5m file User supplied geometry file. data_file: h5m or vtk file User supplied data file. args: Namespace User supplied geometry file location, data file location, and indication if the user wants images of the plot windows with a timestamp and the session file saved and opened in VisIt. Returns: ________ None """ # Create a list of dictionaries indicating the data, plot, and variable in VisIt. Files = [{ "file_name": data_file, "plot_type": "Pseudocolor", "data_tag": "TALLY_TAG" }, { "file_name": data_file, "plot_type": "Contour", "data_tag": "ERROR_TAG" }, { "file_name": geometry_file, "plot_type": "Mesh", "data_tag": "STL_mesh" }] # Launch VisIt and add appropriate plots. Vi.LaunchNowin() for file in Files: Vi.OpenDatabase(file["file_name"]) Vi.AddPlot(file["plot_type"], file["data_tag"]) # Hide the contour plot in the first plot window. Vi.SetActivePlots(1) Vi.HideActivePlots() # Create the plot of the cube by activating the mesh and pseudocolor plots. Vi.SetActivePlots((0, 2)) # Set the view normal to the first octant. v = Vi.GetView3D() v.viewNormal = (1, 1, 1) Vi.SetView3D(v) # Apply a clip through the first octant. Vi.AddOperator("Clip") c = Vi.ClipAttributes() c.plane1Origin = (40, 40, 40) c.plane1Normal = (1, 1, 1) Vi.SetOperatorOptions(c) # Include the CNERG logo in the bottom left corner of the plot. image = Vi.CreateAnnotationObject("Image") image.image = os.path.dirname(os.path.abspath(__file__)) + "/cnerg.jpg" image.position = (0.02, 0.02) image.width = 10 image.height = 10 Vi.DrawPlots() if args.images: if args.timestamp: attributes = Vi.GetAnnotationAttributes() attributes.userInfoFlag = 0 Vi.SetAnnotationAttributes(attributes) Vi.SaveWindow() # Create the second plot of the XY plane slice. plane_slice_plotting(2, 2, "XY Plane", args.images, args.timestamp) # Create the third plot of the XZ plane slice. plane_slice_plotting(3, 1, "XZ Plane", args.images, args.timestamp) # Create the fourth plot of the YZ plane slice. plane_slice_plotting(4, 0, "ZY Plane", args.images, args.timestamp) # Display the four windows in a 2x2 grid. Vi.SetWindowLayout(4) # Save the session file with the default VisIt output to the current directory. visit_output = "VisitDefaultOutput.session" Vi.SaveSession(visit_output) Vi.Close() # Retrieve the path to the VisIt session file. session_file_path = os.path.join(os.getcwd(), visit_output) # If the user has indicated to, open the session file with the VisIt GUI. if args.openvisit: os.system("visit -sessionfile {} &".format(session_file_path)) # If the user has indicated to, remove the session file after VisIt has opened. if not args.sessionfile: os.system("sleep 10; rm {}".format(session_file_path))