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 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 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 make_moving_frame_of_reference_line_plot(point1, point2, velocity, variable_name, input_directory, input_file_name, output_directory, output_file_name, start_frame=-1, end_frame=-1, frame_skip_dt=1.0): ''' Function for making a line plot of some variable with a moving frame of reference :param point1 The starting point of the line (must be an array of size 3) :param point2 The ending point of the line (must be an array of size 3) :param velocity The velocity vector of the frame of reference (must be an array of size 3) :param variable_name Name of the variable (For ex \"rho\") :param input_directory The path to the directory where the files are :param input_file_name Name of the files (For ex \"bulk.*.silo\") :param output_directory Directory where to output the movie :param output_file_name Name of the outputted file (For ex \"RHOMOVIE\") :param start_frame Starting frame for the movie (if -1, equals 0, -1 by default) :param end_frame Ending frame for the movie (if -1, equals the last frame, -1 by default) :param frame_skip_dt The number of seconds one skip in frame equals (1.0 by default) (Note: This may change depending on the run and should always be checked) ''' if len(point1) != 3 or len(point2) != 3 or len(velocity) != 3: print "BAD INPUT IN make_moving_frame_of_reference_line_plot, POINT1, POINT2 AND VELOCITY MUST BE ARRAYS OF SIZE 3" # OPTIONS ################################################################# # Input the boundary box for starting coordinates (Starting values) startX = point1[0] # The left x-boundary of the box endX = point2[0] # The right x-boundary of the box startY = point1[1] # The bottom y-boundary of the box endY = point2[1] # The upper y-boundary of the box startZ = poin1[2] # The left z-boundary of the box endZ = point2[2] # The right z-boundary of the box # Input frame properties startFrame = start_frame # Note: if startFrame is set to -1 the start frame gets set to 0 endFrame = end_frame # Note: if endFrame is set to -1 the endFrame is automatically the number of frames in the database frameInSeconds = frame_skip_dt # Set how many seconds one frame skip is screenWidth = 3000 screenHeight = 3000 # Input speed in x and y direction speedX = velocity[0] # Meters per second speedY = velocity[1] # Meters per second speedZ = velocity[2] # Meters per second # Input variable name # Note: needs to have operators/Lineout/ for visit to recognize it as line plot. Additionally, visit does not accept any '/' in the variable name which is why they're removed. The curve definitions are in loadvisitsettings.py and in there the curve expressions are defined so that there's no '/' in the variable name variableName = "operators/Lineout/" + variable_name.replace("/", "") # Input directory and file names outputDir = output_directory # Set the output directory (Where .png s are saved) outputFileName = output_file_name # The file names for the png files. These for ex. will be saved visit0000.png, visit0001.png, .. databaseName = "localhost:" + input_directory + input_file_name + " database" # For navigating to the silo files # visitBinDirectory = "/usr/lvariableNameocal/visit/bin" #Nevermind this # Note: a slice of the plot in z-axis is taken automatically ################################################################# dx = speedX * frameInSeconds # Note: This is in meters per frame! dy = speedY * frameInSeconds # Note: This is in meters per frame! dz = speedZ * frameInSeconds # Note: This is in meters per frame! vis.OpenDatabase(databaseName, 0) #Load settings visSettings.load_visit_settings() vis.AddPlot("Curve", variableName, 1, 1) vis.LineoutAtts = vis.LineoutAttributes() vis.LineoutAtts.point1 = (startX, startY, 0) vis.LineoutAtts.point2 = (endX, endY, 0) vis.LineoutAtts.interactive = 0 vis.LineoutAtts.ignoreGlobal = 0 vis.LineoutAtts.samplingOn = 0 vis.LineoutAtts.numberOfSamplePoints = 50 vis.LineoutAtts.reflineLabels = 0 vis.SetOperatorOptions(vis.LineoutAtts, 1) vis.CurveAtts = vis.CurveAttributes() vis.CurveAtts.showLines = 1 vis.CurveAtts.lineStyle = vis.CurveAtts.SOLID # SOLID, DASH, DOT, DOTDASH vis.CurveAtts.lineWidth = 2 vis.CurveAtts.showPoints = 1 vis.CurveAtts.symbol = vis.CurveAtts.Point # Point, TriangleUp, TriangleDown, Square, Circle, Plus, X vis.CurveAtts.pointSize = 5 vis.CurveAtts.pointFillMode = vis.CurveAtts.Static # Static, Dynamic vis.CurveAtts.pointStride = 1 vis.CurveAtts.symbolDensity = 50 vis.CurveAtts.curveColorSource = vis.CurveAtts.Custom # Cycle, Custom vis.CurveAtts.curveColor = (0, 0, 0, 255) vis.CurveAtts.showLegend = 1 vis.CurveAtts.showLabels = 0 vis.CurveAtts.designator = "" vis.CurveAtts.doBallTimeCue = 0 vis.CurveAtts.ballTimeCueColor = (0, 0, 0, 255) vis.CurveAtts.timeCueBallSize = 0.01 vis.CurveAtts.doLineTimeCue = 0 vis.CurveAtts.lineTimeCueColor = (0, 0, 0, 255) vis.CurveAtts.lineTimeCueWidth = 0 vis.CurveAtts.doCropTimeCue = 0 vis.CurveAtts.timeForTimeCue = 0 vis.SetPlotOptions(vis.CurveAtts) vis.DrawPlots() # Iterate through frames for i in xrange(startFrame, endFrame + 1): vis.SetTimeSliderState(i) frame = i - startFrame vis.LineoutAtts = vis.LineoutAttributes() vis.LineoutAtts.point1 = (startX + frame * dx, startY + frame * dy, 0) vis.LineoutAtts.point2 = (endX + frame * dx, endY + frame * dy, 0) vis.LineoutAtts.interactive = 0 vis.LineoutAtts.ignoreGlobal = 0 vis.LineoutAtts.samplingOn = 0 vis.LineoutAtts.numberOfSamplePoints = 50 vis.LineoutAtts.reflineLabels = 0 vis.SetOperatorOptions(vis.LineoutAtts, 1) vis.SaveWindowAtts = vis.SaveWindowAttributes() vis.SaveWindowAtts.outputToCurrentDirectory = 0 vis.SaveWindowAtts.outputDirectory = outputDir vis.SaveWindowAtts.fileName = outputFileName 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 = screenWidth vis.SaveWindowAtts.height = screenHeight vis.SaveWindowAtts.screenCapture = 0 vis.SaveWindowAtts.saveTiled = 0 vis.SaveWindowAtts.quality = 80 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, outputFileName, framerate ])
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