def generate_vols(self, filename): """Generates the isosurface volumes between the level values. Data files are exported as STLs and saved in the folder db. Files will be named based on their index corresponding to their level values (0.stl is lowest values). Input: ------ filename: string, path to vtk file with the mesh """ # create folder for database self.__make_db_dir() # launch VisIt try: v.LaunchNowin() except: pass # open file v.OpenDatabase(filename) # read data using meshio to get min and max and make sure levels are # within data bounds: arbmin, arbmax, mins, maxs = self.__check_data(filename) self.xmin = mins[0] self.ymin = mins[1] self.zmin = mins[2] self.xmax = maxs[0] self.ymax = maxs[1] self.zmax = maxs[2] self.levels.append(arbmax) # plot the pseudocolor data in order to get volumes v.AddPlot("Pseudocolor", self.data) v.DrawPlots() # iterate over all isovolume levels for i, l in enumerate(self.levels): res = 0 while res == 0: # lower bound if i == 0: lbound = arbmin else: lbound = self.levels[i - 1] # upper bound ubound = self.levels[i] # get volume # res = 0 if no level found (should update to next level) res, ubound = self.__get_isovol(lbound, ubound, i) # delete plots v.DeleteAllPlots() # close visit v.CloseComputeEngine()
def test_plot_direct(self): w = Window() ult.plot(db) obase = pjoin(output_dir, "test.ult.plot.direct.render") w.render(obase=obase, res=[200, 200]) self.assertTrue(os.path.isfile(obase + ".png")) WindowManager.cleanup_windows() visit.DeleteAllPlots() visit.CloseDatabase(db)
def LoadContourPlot(self): (windowid,filename,var) = self.GetDetails() if windowid is None: return wid = viswinmapper[windowid] visit.SetActiveWindow(wid) visit.DeleteAllPlots() visit.OpenDatabase(filename) visit.AddPlot("Contour",var) visit.DrawPlots()
def clear(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' vi.DeleteAllPlots() vi.CloseDatabase(plasma_file) vi.CloseDatabase(paraxial_file) vi.CloseDatabase(fullwave_file)
def doCleanup(self): print("LineoutAsynchTask.doCleanup()") assert(self._state == self.STATE_2_CLEANUP) # current state try: visit.SetActiveWindow(2) assert visit.GetNumPlots()!=0 visit.ClearWindow() visit.DeleteAllPlots() self._state = self.STATE_3_CHECK_CLEANUP # new state finally: visit.SetActiveWindow(1)
def test_python(self): visit.OpenDatabase(db) visit.AddPlot("Pseudocolor", "d") visit.DrawPlots() exprs.clear() exprs.define_python("test_vpe", file=vpe_file, args=["d"]) visit.Query("Max") r1 = visit.GetQueryOutputValue() visit.ChangeActivePlotsVar("test_vpe") visit.Query("Max") r2 = visit.GetQueryOutputValue() visit.ChangeActivePlotsVar("d") self.assertTrue(r1 * r1 - r2 < 1e-2) exprs.clear() visit.DeleteAllPlots() visit.CloseDatabase(db)
def _generate_vols(self): """Generates the isosurface volumes between the contour levels. Data files are exported as STLs and saved in the folder dbname. Files will be named based on their index corresponding to their level values (0.stl is lowest values). """ # create folder to store data if it does not already exist if not os.path.isdir(self.db): os.mkdir(self.db) if os.path.isdir(self.db + "/vols/"): # make sure folder is empty by removing it first shutil.rmtree(self.db + "/vols/") os.mkdir(self.db + "/vols/") # plot the pseudocolor data inorder to get volumes self._plot_pseudocolor() # get the minimum isovolume level lbound = 0.0 ubound = self.levels[0] self._get_isovol(lbound, ubound, 0) # iterate over all isovolume levels for l in self.levels[1:]: res = 0 while res == 0: # get index of current level i = self.levels.index(l) # assign bounds lbound = self.levels[i - 1] ubound = l # get volume # res = 0 if no level found (should update to next level) res = self._get_isovol(lbound, ubound, i) # get maximum isovolume level lbound = self.levels[-1] ubound = 1.e200 self._get_isovol(lbound, ubound, i + 1) # delete plots v.DeleteAllPlots()
def LoadExtremeValueAnalysisPlot(self): (windowid,filename,var) = self.GetDetails() if windowid is None: return wid = viswinmapper[windowid] visit.SetActiveWindow(wid) visit.DeleteAllPlots() visit.OpenDatabase(filename, 0) visit.AddPlot("Pseudocolor", var, 1, 1) #visit.AddOperator("Box", 1) #visit.SetActivePlots(0) #visit.SetActivePlots(0) #BoxAtts = visit.BoxAttributes() #BoxAtts.amount = BoxAtts.Some # Some, All #BoxAtts.minx = 90 #BoxAtts.maxx = 100 #BoxAtts.miny = -10 #BoxAtts.maxy = 10 #BoxAtts.minz = 0 #BoxAtts.maxz = 1 #visit.SetOperatorOptions(BoxAtts, 1) visit.AddOperator("ExtremeValueAnalysis") visit.DrawPlots()
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 unloadSources(self): v.DeleteAllPlots() if self.subsurface_src is not None: v.CloseDatabase(self.subsurface_src) if self.surface_src is not None: v.CloseDatabase(self.surface_src)
def run(conf): ''' Visualises clusters of a given run. :param conf: :return: ''' #pp = pprint.PrettyPrinter() #pp.pprint(conf) # Make sure the global configuration is in place utils.run_global_visit_configuration(conf) #pdb.set_trace() clusterConf = utils.getValueForKeyPath(conf, 'postprocessing.clusters') if not clusterConf: print "No configuration for cluster postprocessing. Nothing to do." return 0 visitConf = utils.getValueForKeyPath(clusterConf, 'visit') if not visitConf: print "No configuration for visuals. Nothing to do." return 0 views = utils.getValueForKeyPath(visitConf, 'views') # Set up background gradient, axis labels etc. utils.setAnnotations(visitConf, 'annotationAttributes') # Set view and annotation attributes utils.setAnnotations(conf, 'postprocessing.clusters.visit.annotations') if not utils.getValueForKeyPath(conf, 'resume'): print "Removing results from previous runs" subprocess.call( "rm -rf images movies *.vtk *.vtr *tracking*.png *source*.png", shell=True) else: print "Removing intermediary files from previous runs" subprocess.call("rm -f *.vtk *.vtr *.vtu", shell=True) # Figure out the ending for the cluster vtk files conversion_config = utils.getValueForKeyPath( conf, 'postprocessing.clusters.meanie3D-cfm2vtk') if "--write-as-xml" in conversion_config: cluster_vtk_extension = ".vtu" else: cluster_vtk_extension = ".vtk" # Glob the netcdf directory or find the single file uses_time = utils.getValueForKeyPath(conf, 'uses_time') print "Current work directory: " + os.path.abspath(os.getcwd()) if uses_time: print "Processing file " + conf['source_directory'] netcdf_file = conf['source_directory'] else: print "Processing files in directory " + conf['source_directory'] netcdf_files = sorted(glob.glob(conf['source_directory'] + "/*.nc")) # Keep track of number of images to allow # forced re-set in time to circumvent the # Visit memory leak image_count = 0 index_range = [] if uses_time: t1 = int(utils.getValueForKeyPath(conf, 'start_time_index')) t2 = int(utils.getValueForKeyPath(conf, 'end_time_index')) index_range = range(t1, t2 + 1) else: index_range = range(len(netcdf_files)) time_index = -1 for index in index_range: # construct the cluster filename and find it # in the cluster directory if not uses_time: netcdf_file = netcdf_files[index] else: time_index = index netcdf_path, filename = os.path.split(netcdf_file) basename = os.path.splitext(filename)[0] if uses_time: basename = basename + "-" + str(time_index) cluster_file = conf[ 'cluster_directory'] + os.path.sep + basename + "-clusters.nc" # cluster file gets it's basename from the input file rather than the cluster file cluster_vtk_file = os.path.splitext( filename)[0] + "-clusters" + cluster_vtk_extension # label and displacement files are based on the cluster file name label_vtk_file = basename + "-clusters-centers.vtk" displacement_vtk_file = basename + "-clusters-displacements.vtk" print "netcdf_file = " + netcdf_file print "cluster_file = " + cluster_file # check if the files both exist if not os.path.exists(cluster_file): print "Cluster file does not exist. Skipping." continue # predict the filenames for checking on resume number_postfix = str(image_count).rjust(4, '0') source_open = False skip_source = False if conf['resume'] == True: exists = utils.images_exist(visitConf['views'], "source", image_count) if exists == "all": print "Source visualization " + number_postfix + " exists. Skipping." skip_source = True elif exists == "partial": print "Deleting partial visualization " + number_postfix utils.delete_images(conf, "source", image_count) if skip_source == False: if utils.getValueForKeyPath(clusterConf, 'createSourceMovie'): # Add ancillary background data utils.plotMapdata(visitConf, 'map') # Add timestamp if utils.getValueForKeyPath(clusterConf, 'showDateTime'): utils.add_datetime(clusterConf, netcdf_file, time_index) # Add source data and threshold it print "Plotting source data ..." start_time = time.time() utils.addPseudocolorPlots(netcdf_file, visitConf, 'source.plots', time_index) source_open = True visit.DrawPlots() utils.saveImagesForViews(views, "source") visit.DeleteAllPlots() visit.ClearWindow() print " done. (%.2f seconds)" % (time.time() - start_time) if utils.getValueForKeyPath(clusterConf, 'visualiseClusters'): skip = False if conf['resume'] == True: exists = utils.images_exist(visitConf['views'], "tracking", image_count) if exists == "all": print "Cluster visualization " + number_postfix + " exists. Skipping." skip = True elif exists == "partial": print "Deleting partial cluster visualization " + number_postfix utils.delete_images(conf, "tracking", image_count) if skip == False: # Run the conversion print "-- Converting clusters to .vtr --" start_time = time.time() params = "-f %s %s" \ % (cluster_file,utils.getValueForKeyPath(conf,'postprocessing.clusters.meanie3D-cfm2vtk')) if utils.getValueForKeyPath( conf, 'postprocessing.clusters.showDisplacementVectors'): params += " --write-displacement-vectors" if utils.getValueForKeyPath(conf, 'data.vtkDimensions'): vtkDimString = ",".join( utils.getValueForKeyPath(conf, 'data.vtkDimensions')) params += " --vtk-dimensions=%s" % vtkDimString # pdb.set_trace(); print "meanie3D-cfm2vtk %s" % params meanie3D.app.external.execute_command('meanie3D-cfm2vtk', params) print " done. (%.2f seconds)" % (time.time() - start_time) # Move cluster output file to individual file if uses_time: cluster_vtk_file_dst = basename + "-clusters.vtk" os.rename(cluster_vtk_file, cluster_vtk_file_dst) cluster_vtk_file = cluster_vtk_file_dst print "-- Rendering cluster scene --" start_time = time.time() # Add ancillary background data utils.plotMapdata(visitConf, 'map') # Add timestamp if utils.getValueForKeyPath(clusterConf, 'showDateTime'): utils.add_datetime(clusterConf, netcdf_file, time_index) # Add background source data if utils.getValueForKeyPath(clusterConf, 'showSourceBackground'): utils.addPseudocolorPlots(netcdf_file, visitConf, 'sourceBackground.plots', time_index) source_open = True # Add the clusters add_clusters(cluster_vtk_file, conf) # Add modes as labels labelConf = utils.getValueForKeyPath(visitConf, 'label') if labelConf: utils.addLabelPlot(label_vtk_file, labelConf) # Add displacement vectors if utils.getValueForKeyPath(clusterConf, 'showDisplacementVectors'): vectorConf = utils.getValueForKeyPath( visitConf, 'displacementVectors') if vectorConf: utils.addVectorPlot(displacement_vtk_file, vectorConf) visit.DrawPlots() utils.saveImagesForViews(views, "tracking") print " done. (%.2f seconds)" % (time.time() - start_time) # clean up visit.DeleteAllPlots() visit.ClearWindow() if source_open: visit.CloseDatabase(netcdf_file) visit.CloseDatabase(label_vtk_file) utils.close_pattern(basename + "*.vtr") utils.close_pattern(basename + "*.vtk") utils.close_pattern(basename + "*.vtu") if utils.getValueForKeyPath(conf, 'cleanup_vtk'): subprocess.call("rm -f *.vt*", shell=True) # periodically kill computing engine to # work around the memory leak fix image_count = image_count + 1 # TODO: check if this is still necessary and re-implement if it is. #if image_count % 100 == 0: # visit.CloseComputeEngine() # close mapstuff # TODO: might need to keep track of open database files and # close them. # Use imagemagick to use image sequences to make movies movieFormats = utils.getValueForKeyPath(clusterConf, 'movieFormats') if utils.getValueForKeyPath(clusterConf, 'createSourceMovie'): utils.createMoviesForViews(views, "source", movieFormats) if utils.getValueForKeyPath(clusterConf, 'createClusterMovie'): utils.createMoviesForViews(views, "tracking", movieFormats) # clean up print "Cleaning up ..." subprocess.call("mkdir images", shell=True) subprocess.call("mv *tracking_*.png images", shell=True) subprocess.call("mv *source_*.png images", shell=True) subprocess.call("mkdir movies", shell=True) subprocess.call("mv *source*.gif *tracking*.gif *.m4v movies", shell=True) if utils.getValueForKeyPath(conf, 'cleanup_vtk'): subprocess.call("rm -f *.vt* visitlog.py", shell=True) return
def tearDown(self): # clean up visit.DeleteAllPlots() visit.CloseDatabase(self.data_path) visit.CloseComputeEngine()
def tearDown(self): visit.DeleteAllPlots() visit.CloseDatabase(db) visit.CloseComputeEngine()
def viewit(): tl = visit.CreateAnnotationObject("Text2D") tl.position = (.08, .93) tl.height = .026 tl.fontFamily = 0 tl.fontBold = 1 tl.fontShadow = 1 visit.DeleteAllPlots() k = 30000 kMax = 40001 while k < kMax: filename = "scalar" + str(k) + ".Point3D" print "opening database file: " + filename status = visit.OpenDatabase(filename, 0, "Point3D") if status != 1: print "Could not open " + filename return status = visit.AddPlot("Pseudocolor", "density") visit.DrawPlots() pca = visit.GetPlotOptions() pca.colorTableName = "density" pca.invertColorTable = 1 pca.minFlag = 1 pca.maxFlag = 1 pca.min = -.21 pca.max = .21 # visit.SetPlotOptions(pca) names = visit.GetAnnotationObjectNames() print names lastName = names[-1] print "lastName = " + lastName legend = visit.GetAnnotationObject(lastName) legend.numTicks = 3 legend.managePosition = 0 legend.position = (.1, .88) legend.orientation = 1 legend.drawMinMax = 0 legend.drawTitle = 0 legend.drawLabels = "Labels" legend.suppliedLabels = (" -.15", " 0.", " .15") legend.fontHeight = .024 legend.numberFormat = "%#-9.2g" legend.fontFamily = 2 legend.fontBold = 1 tl.text = "Density Fluctuation - Step " + str(k) tl.visible = 1 visit.SaveWindow() k = k + 1000 if k < kMax: tl.visible = 0 visit.DeleteAllPlots() visit.CloseDatabase(filename)
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 clear_plots(self): self.activate() visit.DeleteAllPlots()