def plane_slice_plotting(window_number, axis_number, label, images, timestamp): """ Copy the Mesh, Pseudocolor, and Contour plots into a new VisIt window and slice through the proper axis. Input: ______ window_number: int The number of the window to open (2,3, or 4). axis_number: int The number of the axis to slice through (0 for X, 1 for Y, 2 for Z). label: str The title of the plane slice. images: boolean Whether or not to save images of the plot windows. timestamp: boolean Whether or not to keep the timestamp on plot window images. Returns: ________ none """ # Open a new window with all three plots. Vi.AddWindow() Vi.CopyPlotsToWindow(1, window_number) # Create the plane slice plot by activating the mesh, pseudocolor, and contour plots. Vi.SetActiveWindow(window_number) Vi.SetActivePlots((0, 1, 2)) # Remove the clip and slice operators from previous plot windows. Vi.RemoveAllOperators() # Add a slice through the proper axis. Vi.AddOperator("Slice", 1) s = Vi.SliceAttributes() s.axisType = axis_number Vi.SetOperatorOptions(s) # Include a label for each plane slice plot. banner = Vi.CreateAnnotationObject("Text2D") banner.position = (0.45, 0.92) banner.text = label banner.height = 0.05 # 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 images: if timestamp: attributes = Vi.GetAnnotationAttributes() attributes.userInfoFlag = 0 Vi.SetAnnotationAttributes(attributes) Vi.SaveWindow()
def Iterator(Files, OperatorSet=None, SliceProject=1): """Iterate through several operator options.""" Pa.PathCreator() # Creates necessary folders. Image = Mk.MakeImages(Files) Image.Plot() if OperatorSet is None: # If no operators are defined, the image of plots # without operators is saved. Image.Save() else: for item in OperatorSet: Vi.RemoveAllOperators(all) # Removes previous slice in loop. # Apply single dictionary operator. try: Operator = (item.keys())[0] myList = (item.values())[0] Image.Operator(Operator, myList, SliceProject) except Exception: pass # Apply single list operator. try: Operator = item[0] myList = item[1] Image.Operator(Operator, myList, SliceProject) except Exception: pass # Multiple Operators. try: for multiitem in item: # Apply dictionary operator. try: Operator = (multiitem.keys())[0] myList = (multiitem.values())[0] Image.Operator(Operator, myList, SliceProject) except Exception: pass # Apply list operator. try: Operator = multiitem[0] myList = multiitem[1] Image.Operator(Operator, myList, SliceProject) except Exception: pass except Exception: pass Image.Save() # Saves for every operator set defined.
def __get_isovol(self, lbound, ubound, i): """Gets the volume selection for isovolume and export just the outer surface of the volume as STL. Input: ------ lbound: float, lower boundary value for the isovolume ubound: float, upper boundary value for the isovolume i: int, surface number """ # generate isovolume v.AddOperator("Isovolume") att = v.IsovolumeAttributes() att.lbound = lbound att.ubound = ubound v.SetOperatorOptions(att) # set operator setting to only get surfaces meshes v.AddOperator("ExternalSurface") # draw plot v.DrawPlots() # export current volume to folder e = v.ExportDBAttributes() e.dirname = self.db + "/vols/" e.db_type = "STL" e.filename = str(i) e.variables = self.data export_res = v.ExportDatabase(e) # check if exporting was successful or not and adjust values if export_res == 0: # export not successful because there was no data # get new upper bound warn_message = "Warning: no data to export between " \ + "{} and {}.\n".format(lbound, ubound) \ + "Increasing upper bound to next selected level." warnings.warn(warn_message) if ubound == max(self.levels): # already at max so do not need to export more levels self.levels.remove(ubound) export_res = 1 else: # update to next level to try again index = self.levels.index(ubound) ubound_old = ubound ubound = self.levels[index + 1] self.levels.remove(ubound_old) # delete the operators v.RemoveAllOperators() return export_res, ubound
def _get_isovol(self, lbound, ubound, i): """Gets the volume selection for isovolume and export just the outer surface of the volume as STL. Input: ------ lbound: float, lower boundary value for the isovolume ubound: float, upper boundary value for the isovolume i: int, surface number """ # generate isovolume v.AddOperator("Isovolume") att = v.IsovolumeAttributes() att.lbound = lbound att.ubound = ubound v.SetOperatorOptions(att) # set operator setting to only get surfaces meshes v.AddOperator("ExternalSurface") # draw plot draw_res = v.DrawPlots() if draw_res == 0: sys.exit("Error with producing isovolume") # export current volume to folder e = v.ExportDBAttributes() e.dirname = self.db + "/vols/" e.db_type = "STL" e.filename = str(i) e.variables = self.data export_res = v.ExportDatabase(e) if export_res == 0: # export not successful because there was no data # get new upper bound warn_message = "Warning: no data to export between {} and {}.\n".format(lbound, ubound) \ + "Increasing upper bound to next selected level." print(warn_message) if ubound in self.levels: self._update_levels(ubound) else: # it is the arbitrary upper level set and is not needed self._update_levels(self.levels[-1]) # delete the operators v.RemoveAllOperators() return export_res, ubound
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 MultiSlice(File, myList): """ Take multiple sliced along an axis. Slices are evenly spaced. myList = (<axis>, <number of slices>). """ Pa.PathCreator() # Creates necessary folders. myList = list(myList) Image = Mk.MakeImages(File) Image.Plot() Bounds = Image.get_list()[2] xLower = Bounds["Pseudocolor"][0] xUpper = Bounds["Pseudocolor"][1] yLower = Bounds["Pseudocolor"][2] yUpper = Bounds["Pseudocolor"][3] zLower = Bounds["Pseudocolor"][4] zUpper = Bounds["Pseudocolor"][5] xRange = xUpper - xLower yRange = yUpper - yLower zRange = zUpper - zLower Number = int(myList[1]) xIncrement = xRange / float(Number) yIncrement = yRange / float(Number) zIncrement = zRange / float(Number) for i in range(len(myList[0])): Axis = myList[0][i] # For adding slices of and between maximum and minimum dimensions. Count = 0 SliceList = [] for i in range(Number): # Round up for lower bound. if Count == 0: Lower = Ma.ceil(eval(Axis.lower() + "Lower")) SliceSet = Ma.floor(eval(Axis.lower() + "Increment")) * Count SliceList.append(["Slice", (Axis.lower(), Lower + SliceSet)]) # Round down for upper bound. elif Count == Number - 1: Lower = eval(Axis.lower() + "Lower") SliceSet = Ma.floor(eval(Axis.lower() + "Increment")) * Count SliceList.append(["Slice", (Axis.lower(), Lower + SliceSet)]) else: Lower = eval(Axis.lower() + "Lower") SliceSet = eval(Axis.lower() + "Increment") * Count SliceList.append(["Slice", (Axis.lower(), Lower + SliceSet)]) Count += 1 for item in SliceList: Operator = item[0] List = item[1] Vi.RemoveAllOperators(all) # Removes previous slice in loop. Image.Operator(Operator, List) Image.Save()