示例#1
0
文件: visit_ats.py 项目: wk1984/ats
    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
示例#2
0
    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!")
示例#3
0
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
示例#4
0
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
def visit_plot_qcrit_wx_3d(xdmf_path,
                           qcrit_vals=(6.0, 1.0),
                           wx_lims=(-5.0, 5.0),
                           config_view=None,
                           out_dir=os.getcwd(),
                           prefix='qcrit_wx_3d_',
                           figsize=(1024, 1024),
                           state=None,
                           states=None,
                           states_range=[0, None, 1]):
    """Plot the 3D isosurface of the Q-criterion at 2 values.

    The first isosurface is colored by the streamwise vorticity.
    The second isosurface is colored with a single color (grey).

    Parameters
    ----------
    xdmf_path : str
        Path of the XDMF file with information about the Q-criterion and
        the streamwise vorticity.
    qcrit_vals : tuple, optional
        Values of the Q-criterion to display as a tuple of 2 floats;
        default is (6.0, 1.0).
    wx_lims : tuple, optional
        Limits of the color range for the streamwise vorticity
        as a tuple of 2 floats; default is (-5.0, 5.0).
    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 in which figures will be saved;
        default is the present working directory.
    prefix : str, optional
        Output filename prefix; default is "qcrit_wx_3d_".
    figsize : tuple
        Figure width and height (in pixels); default is (1024, 1024).
    state : int, optional
        Single state index to render;
        default is None (i.e., render multiple states).
    states : list, optional
        List of states to render; default is None (i.e., render all states).
    states_range : list, optional
        Start, end, and step indices for states to render;
        default is [0, None, 1] (i.e., render all states).

    """
    visit_initialize()

    # Open database from XDMF file.
    visit.OpenDatabase(xdmf_path, 0)

    # Add a pseudocolor of the streamwise vorticity.
    visit.AddPlot('Pseudocolor', 'wx_cc', 1, 0)
    PseudocolorAtts = visit.PseudocolorAttributes()
    PseudocolorAtts.minFlag, PseudocolorAtts.maxFlag = 1, 1
    PseudocolorAtts.min, PseudocolorAtts.max = wx_lims
    PseudocolorAtts.colorTableName = 'viridis'
    PseudocolorAtts.invertColorTable = 0
    visit.SetPlotOptions(PseudocolorAtts)

    # Add isosurface of the Q-criterion (colored by streamwise vorticity).
    visit.AddOperator('Isosurface', 0)
    IsosurfaceAtts = visit.IsosurfaceAttributes()
    IsosurfaceAtts.contourMethod = IsosurfaceAtts.Value
    IsosurfaceAtts.contourValue = (qcrit_vals[0])
    IsosurfaceAtts.variable = 'qcrit'
    visit.SetOperatorOptions(IsosurfaceAtts, 0)

    # Add single-value contour of the Q-criterion.
    visit.AddPlot('Contour', 'qcrit', 1, 0)
    ContourAtts = visit.ContourAttributes()
    ContourAtts.colorType = ContourAtts.ColorBySingleColor
    ContourAtts.legendFlag = 0
    ContourAtts.singleColor = (128, 128, 128, 153)  # grey
    ContourAtts.contourNLevels = 1
    ContourAtts.minFlag, ContourAtts.maxFlag = 1, 1
    ContourAtts.min, ContourAtts.max = qcrit_vals[1], qcrit_vals[1]
    visit.SetPlotOptions(ContourAtts)

    # Remove some annotations; keep triad.
    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)

    # Define state indices to render.
    states = visit_get_states(state=state,
                              states=states,
                              states_range=states_range)

    # Render states and save figures to files.
    visit_render_save_states(states,
                             config_view=config_view,
                             out_dir=out_dir,
                             prefix=prefix,
                             figsize=figsize)

    visit_finalize()