Exemple #1
0
    def createMesh(self, color='w', opacity=0.15, silo=False):
        _colors = dict(
            w=(255, 255, 255, 255),
            k=(0, 0, 0, 255),
            gray=(175, 175, 175),
        )

        if silo:
            v.AddPlot('Mesh', "mesh")
        else:
            v.AddPlot('Mesh', "Mesh")
        ma = v.MeshAttributes()
        ma.legendFlag = 0
        ma.meshColor = _colors[color]
        ma.meshColorSource = ma.MeshCustom
        if (opacity < 1.):
            ma.opaqueMode = ma.On
            ma.opacity = opacity

        v.SetPlotOptions(ma)

        pname = v.GetPlotList().GetPlots(v.GetNumPlots() - 1).plotName
        if silo:
            plot = Plot(pname, 'mesh', ma)
        else:
            plot = Plot(pname, 'Mesh', ma)
        self.nonplots.append(plot)
        return plot
Exemple #2
0
    def createContour(self, varname, value, color=None, linewidth=None):
        """Generic creation of a single contour without a legend"""
        
        v.AddPlot('Contour', varname)
        ca = v.ContourAttributes()

        ca.contourMethod = ca.Value
        ca.contourValue = (value,)
        ca.colorType = ca.ColorBySingleColor

        if color is None:
            color = vrc.rcParams['contour.color']
        if type(color) is str:
            color = vc.common_colors[color]
        ca.singleColor = color

        if linewidth is None:
            linewidth = vrc.rcParams['contour.linewidth']
        ca.lineWidth = linewidth

        # turn off legend for 2D surf
        ca.legendFlag = 0

        v.SetPlotOptions(ca)
        pname = v.GetPlotList().GetPlots(v.GetNumPlots()-1).plotName
        plot = Plot(pname, 'Contour', ca)
        self.plots.append(plot)
        return plot
 def isCleanupDone(self):
     print("LineoutAsynchTask.doCleanup()")
     assert(self._state == self.STATE_3_CHECK_CLEANUP) # current state
     try:
         visit.SetActiveWindow(2)
         if visit.GetNumPlots()==0:
             self._state = self.STATE_DONE # new state
     finally:
         visit.SetActiveWindow(1)
 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 doLineout(self):
     print("LineoutAsynchTask.doLineout()")
     assert(self._state == self.STATE_INITIAL) # current state
     try:
         if (2 in visit.GetGlobalAttributes().GetWindows()):
             visit.SetActiveWindow(2)
             assert visit.GetNumPlots()==0 
         print("passed assertion that Window2 doesn't exist yet or has no plots")
         print(visit.SetActiveWindow(1))
         visit.Lineout(self._startPoint, self._endPoint)
         self._state = self.STATE_1_CHECK_DATA # new state
     finally:
         visit.SetActiveWindow(1)
    def isDataReady(self):
        print("LineoutAsynchTask.isDataReady()")
        assert(self._state == self.STATE_1_CHECK_DATA) # current state

        visit.SetActiveWindow(2)
        if visit.GetNumPlots()==1:
            print("Lineout data ready\n")
            self._lineOutData = visit.GetPlotInformation()['Curve']
            print("The data from the lineout from (0,0,0) to (1,1,1) is:\n")
            print("\n")
            print(str(self._lineOutData))
            print("\n")
            if isinstance(self._lineOutData, tuple):
                self._state = self.STATE_2_CLEANUP # new state
            else:
                raise Exception("LineoutAsynchTask.isDataReady(): failed to return lineout plot data");
        else:
            pass # don't change state ... still waiting for plot
Exemple #7
0
    def write_plots(f):
        f.write('# Create plots\n')
        pL = visit.GetPlotList()
        activePlots = []
        for i in range(visit.GetNumPlots()):
            plot = pL.GetPlots(i)
            if plot.activeFlag:
                activePlots = activePlots + [i]
            plotName = visit.PlotPlugins()[plot.plotType]
            visit.SetActivePlots(i)
            f.write('# Create plot %d\n' % (i + 1))
            f.write('OpenDatabase("%s")\n' % plot.databaseName)
            f.write('AddPlot("%s", "%s", 0, 0)\n' % (plotName, plot.plotVar))
            atts = eval("visit." + plotName + "Attributes(1)")
            defaultatts = eval("visit." + plotName + "Attributes()")
            if write_state_object_diffs(f, atts, defaultatts, "atts"):
                f.write('SetPlotOptions(atts)\n')
            else:
                f.write('#SetPlotOptions(atts)\n')

            opIndex = 0
            for op in plot.operatorNames:
                f.write('AddOperator("%s", 0)\n' % op)
                opAtts = visit.GetOperatorOptions(opIndex)
                defaultAtts = eval("visit." + object_type(opAtts) + "()")
                if write_state_object_diffs(f, opAtts, defaultAtts, "opAtts"):
                    f.write('SetOperatorOptions(opAtts)\n')
                else:
                    f.write('#SetOperatorOptions(opAtts)\n')
                opIndex += 1

            # Set the SIL restriction
            write_sil(f)

            f.write('\n')
        if len(activePlots) > 1:
            f.write('SetActivePlots(%s)\n\n' % str(activePlots))
            visit.SetActivePlots(activePlots)
        elif len(activePlots) == 1:
            f.write('SetActivePlots(%d)\n\n' % activePlots[0])
            visit.SetActivePlots(activePlots[0])
Exemple #8
0
    def createPseudocolor(self, varname, display_name=None, cmap=None, 
                          limits=None, linewidth=None, legend=True, alpha=False):
        """Generic creation of pseudocolor"""
        if display_name is None:
            display_name = vrc.renameScalar(varname)

        if "temperature" in display_name:
            display_name = display_name.replace("[K]", "[C]")
            print "defining alias: %s = %s"%(display_name, varname)
            v.DefineScalarExpression(display_name, "%s - 273.15"%varname)
        elif display_name != varname:
            print "defining alias: %s = %s"%(display_name, varname)
            v.DefineScalarExpression(display_name, varname)

        v.AddPlot('Pseudocolor', display_name)
        pa = v.PseudocolorAttributes()

        # limits
        if limits is None:
            limits = vrc.getLimits(varname)

        if limits is not None:
            min = limits[0]
            max = limits[1]
            if min is not None:
                pa.minFlag = 1
                pa.min = min
            if max is not None:
                pa.maxFlag = 1
                pa.max = max

        # opacity
        if alpha:
            pa.opacity = 0
            pa.opacityType = pa.ColorTable

        # colormap
        if cmap is not None:
            reverse = cmap.endswith("_r")
            if reverse:
                cmap = cmap.strip("_r")
                pa.invertColorTable = 1
            pa.colorTableName = cmap

        # linewidth for 2D
        if linewidth is None:
            linewidth = vrc.rcParams['pseudocolor.linewidth']
        pa.lineWidth = linewidth

        # turn off legend for 2D surf
        if not legend:
            pa.legendFlag = 0

        v.SetPlotOptions(pa)
        pname = v.GetPlotList().GetPlots(v.GetNumPlots()-1).plotName
        if legend:
            plot = Plot(pname, 'Pseudocolor', pa, display_name)
        else:
            plot = Plot(pname, 'Pseudocolor', pa)
        self.plots.append(plot)
        return plot
Exemple #9
0
def create_visit_point_movie(variableName,
                             minValue,
                             maxValue,
                             inputDirectory,
                             inputFileNames,
                             coordinates,
                             outputDirectory,
                             outputFileName,
                             colorTable="hot_desaturated"):
    '''
   Function for making a movie
   
   Arguments:
   :param variableName                  Name of the variable
   :param minValue                      Minimum value of the variable
   :param maxValue                      Maximum value of the variable
   :param inputDirectory                Path to input vlsv/silo files
   :param inputFileNames                Name of the files for example [\"bulk.00000.silo\", \"bulk.00001.silo\"]
   :param coordinates                   Coordinates corresponding to the files so for example [ [[0,0,0], [0,1,0]], [[2,1,2], [2,1,4]] ]
   :param outputDirectory               Path to output directory
   :param outputFileName                Name of the output file
   :param colorTable="hot_desaturated"  Color table for the plots
   '''
    coordinates = [coordinates]

    for i in range(len(inputFileNames)):
        # OPTIONS
        #################################################################

        # Input variable
        _variableName = variableName
        minVariableValue = minValue
        maxVariableValue = maxValue
        colorTableName = colorTable

        # Input directory and file names
        #_outputDir = "/home/hannukse/MOVINGFRAME_MOVIES/AAJ_BZ_REMAKE/" # Set the output directory (Where .png s are saved)
        _outputDir = outputDirectory
        #_outputFileName = "BZ_FORESHOCK_2_" # The file names for the png files. These for ex. will be saved visit0000.png, visit0001.png, ..
        _outputFileName = outputFileName  # The file names for the png files.
        #databaseName = "localhost:/home/hannukse/meteo/stornext/field/vlasiator/2D/AAJ/silo_files/bulk.*.silo database" # For navigating to the silo files
        inputFileName = inputFileNames[i]
        databaseName = "localhost:" + inputDirectory + inputFileName  # For navigating to the silo files
        # Note: a slice of the plot in z-axis is taken automatically
        #################################################################
        # LaunchNowin(vdir=visitBinDirectory)
        #dx = speedX * frameInSeconds # Note: This is in meters per frame!
        #dy = speedY * frameInSeconds # Note: This is in meters per frame!
        #LaunchNowin(vdir="/usr/local/visit/bin")
        #Set up window and annotations
        #vis.LaunchNowin(vdir="/usr/local/visit/bin")

        inputFileName2 = "point.vtk"
        databaseName2 = "localhost:" + os.getcwd() + "/" + inputFileName2

        vis.OpenDatabase(databaseName, 0)
        #vis.ActiveDatabase("localhost:" + inputDirectory + inputFileName)
        #Load settings
        visSettings.load_visit_settings()
        vis.AddPlot("Pseudocolor", _variableName, 1, 1)  #CONTINUE
        vis.SetActivePlots(1)
        vis.PseudocolorAtts = vis.PseudocolorAttributes()
        vis.PseudocolorAtts.legendFlag = 1
        vis.PseudocolorAtts.lightingFlag = 1
        vis.PseudocolorAtts.minFlag = 1
        vis.PseudocolorAtts.maxFlag = 1
        vis.PseudocolorAtts.centering = vis.PseudocolorAtts.Natural  # Natural, Nodal, Zonal
        vis.PseudocolorAtts.scaling = vis.PseudocolorAtts.Linear  # Linear, Log, Skew
        vis.PseudocolorAtts.limitsMode = vis.PseudocolorAtts.CurrentPlot  # OriginalData, CurrentPlot
        vis.PseudocolorAtts.min = minVariableValue
        vis.PseudocolorAtts.max = maxVariableValue
        vis.PseudocolorAtts.pointSize = 0.05
        vis.PseudocolorAtts.pointType = vis.PseudocolorAtts.Point  # Box, Axis, Icosahedron, Point, Sphere
        vis.PseudocolorAtts.skewFactor = 1
        vis.PseudocolorAtts.opacity = 1
        vis.PseudocolorAtts.colorTableName = colorTableName
        vis.PseudocolorAtts.invertColorTable = 0
        vis.PseudocolorAtts.smoothingLevel = 0
        vis.PseudocolorAtts.pointSizeVarEnabled = 0
        vis.PseudocolorAtts.pointSizeVar = "default"
        vis.PseudocolorAtts.pointSizePixels = 2
        vis.PseudocolorAtts.lineStyle = vis.PseudocolorAtts.SOLID  # SOLID, DASH, DOT, DOTDASH
        vis.PseudocolorAtts.lineWidth = 0
        vis.PseudocolorAtts.opacityType = vis.PseudocolorAtts.Explicit  # Explicit, ColorTable
        vis.SetPlotOptions(vis.PseudocolorAtts)

        vis.SetActivePlots(1)
        vis.AddOperator("Slice", 1)
        vis.SetActivePlots(1)
        vis.SliceAtts = vis.SliceAttributes()
        vis.SliceAtts.originType = vis.SliceAtts.Intercept  # Point, Intercept, Percent, Zone, Node
        vis.SliceAtts.originPoint = (0, 0, 0)
        vis.SliceAtts.originIntercept = 0
        vis.SliceAtts.originPercent = 0
        vis.SliceAtts.originZone = 0
        vis.SliceAtts.originNode = 0
        vis.SliceAtts.normal = (0, 0, 1)
        vis.SliceAtts.axisType = vis.SliceAtts.ZAxis  # XAxis, YAxis, ZAxis, Arbitrary, ThetaPhi
        vis.SliceAtts.upAxis = (0, 1, 0)
        vis.SliceAtts.project2d = 1
        vis.SliceAtts.interactive = 1
        vis.SliceAtts.flip = 0
        vis.SliceAtts.originZoneDomain = 0
        vis.SliceAtts.originNodeDomain = 0
        vis.SliceAtts.meshName = "SpatialGrid"
        vis.SliceAtts.theta = 0
        vis.SliceAtts.phi = 90
        vis.SetOperatorOptions(vis.SliceAtts, 1)
        vis.DrawPlots()
        vis.SetActivePlots(0)

        for coordinate in coordinates[i]:
            print(str(coordinate))
            create_point_vtk(fileName=inputFileName2, coordinates=coordinate)
            vis.OpenDatabase(databaseName2, 0)
            vis.AddPlot("Mesh", "mesh", 1, 1)
            vis.SetActivePlots(vis.GetNumPlots())
            vis.MeshAtts = vis.MeshAttributes()
            vis.MeshAtts.legendFlag = 1
            vis.MeshAtts.lineStyle = vis.MeshAtts.SOLID  # SOLID, DASH, DOT, DOTDASH
            vis.MeshAtts.lineWidth = 0
            vis.MeshAtts.meshColor = (0, 0, 0, 255)
            vis.MeshAtts.outlineOnlyFlag = 0
            vis.MeshAtts.errorTolerance = 0.01
            vis.MeshAtts.meshColorSource = vis.MeshAtts.Foreground  # Foreground, MeshCustom
            vis.MeshAtts.opaqueColorSource = vis.MeshAtts.Background  # Background, OpaqueCustom
            vis.MeshAtts.opaqueMode = vis.MeshAtts.Auto  # Auto, On, Off
            vis.MeshAtts.pointSize = 0.05
            vis.MeshAtts.opaqueColor = (255, 255, 255, 255)
            vis.MeshAtts.smoothingLevel = vis.MeshAtts.None  # None, Fast, High
            vis.MeshAtts.pointSizeVarEnabled = 0
            vis.MeshAtts.pointSizeVar = "default"
            vis.MeshAtts.pointType = vis.MeshAtts.Point  # Box, Axis, Icosahedron, Point, Sphere
            vis.MeshAtts.showInternal = 0
            vis.MeshAtts.pointSizePixels = 10
            vis.MeshAtts.opacity = 1
            vis.SetPlotOptions(vis.MeshAtts)
            vis.DrawPlots()
            # Iterate through frames
            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 = 3000
            vis.SaveWindowAtts.height = 3000
            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.DeleteActivePlots()
        vis.CloseDatabase(databaseName)
    vis.CloseDatabase(databaseName2)
    # Make the movie:
    #subprocess.call("./moviecompilescript.sh " + _outputDir + " " + _outputFileName)
    pyVisitPath = "pyVisit/"
    #subprocess.call(pythonLibDirectoryPath + pyVisitPath + "moviecompilescript.sh")
    #subprocess.call(pythonLibDirectoryPath + pyVisitPath + "moviecompilescript.sh " + _outputDir + " " + _outputFileName)
    framerate = "10"
    subprocess.call([
        pythonLibDirectoryPath + pyVisitPath + "moviecompilescript.sh",
        _outputDir, _outputFileName, framerate
    ])
    # Delete the point vtk file:
    os.remove(os.getcwd() + "/" + inputFileName2)