Exemplo n.º 1
0
def _absarg2png(filenames):
    """Create images of |psi|^2 and arg(psi).
    The 'filenames' arguments is a dictionary with
    key:value = array_name:file_name.
    """

    data_representation = pv.Show()
    # Reset the camera here to get the whole object.
    view = pv.GetRenderView()
    view.ResetCamera()

    # create calculator filter that computes the Cooper pair density
    array_name = list(filenames.keys())[1]
    # make background green
    view.Background = [0.0, 1.0, 0.0]
    # data_representation.ScalarOpacityFunction = pv.CreatePiecewiseFunction()
    data_representation.ColorArrayName = array_name
    data_representation.LookupTable = pv.GetLookupTableForArray(
        array_name,
        1,
        RGBPoints=[0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0],
        LockScalarRange=1,
    )
    pv.WriteImage(list(filenames.values())[1])
    # pv.Render()

    array_name = list(filenames.keys())[0]
    # make background gray
    view.Background = [0.5, 0.5, 0.5]
    # data_representation.ScalarOpacityFunction = pv.CreatePiecewiseFunction()
    data_representation.ColorArrayName = array_name
    data_representation.LookupTable = pv.GetLookupTableForArray(
        array_name,
        1,
        RGBPoints=_create_circular_hsv_colormap(),
        LockScalarRange=1)
    # Don't interpolate scalars as otherwise, the circular HSV color map
    # gets messed up at the pi/-pi seam.
    data_representation.InterpolateScalarsBeforeMapping = 0
    pv.WriteImage(list(filenames.values())[0])
    return
Exemplo n.º 2
0
    def WriteImages(self, datadescription, rescale_lookuptable=False):
        """This method will update all views, if present and write output
            images, as needed."""
        timestep = datadescription.GetTimeStep()

        cinema_dirs = []
        for view in self.__ViewsList:
            if (view.cpFrequency and timestep % view.cpFrequency == 0) or \
               datadescription.GetForceOutput() == True:
                fname = view.cpFileName
                fname = fname.replace("%t", str(timestep))
                if view.cpFitToScreen != 0:
                    if view.IsA("vtkSMRenderViewProxy") == True:
                        view.ResetCamera()
                    elif view.IsA("vtkSMContextViewProxy") == True:
                        view.ResetDisplay()
                    else:
                        print ' do not know what to do with a ', view.GetClassName()
                view.ViewTime = datadescription.GetTime()
                if rescale_lookuptable:
                    self.RescaleDataRange(view, datadescription.GetTime())
                cinemaOptions = view.cpCinemaOptions
                if cinemaOptions and 'camera' in cinemaOptions:
                    dirname = None
                    if 'composite' in cinemaOptions:
                        dirname = self.UpdateCinemaComposite(view, datadescription)
                    else:
                        dirname = self.UpdateCinema(view, datadescription)
                    if dirname:
                        cinema_dirs.append(dirname)
                else:
                    simple.WriteImage(fname, view, Magnification=view.cpMagnification)


        if len(cinema_dirs) > 1:
            workspace = open('cinema/info.json', 'w')
            workspace.write('{\n')
            workspace.write('    "metadata": {\n')
            workspace.write('        "type": "workbench"\n')
            workspace.write('    },\n')
            workspace.write('    "runs": [\n')
            for i in range(0,len(cinema_dirs)):
                workspace.write('        {\n')
                workspace.write('        "title": "%s",\n' % cinema_dirs[i])
                workspace.write('        "description": "%s",\n' % cinema_dirs[i])
                workspace.write('        "path": "%s"\n' % cinema_dirs[i])
                if i+1 < len(cinema_dirs):
                    workspace.write('        },\n')
                else:
                    workspace.write('        }\n')
            workspace.write('    ]\n')
            workspace.write('}\n')
            workspace.close()
Exemplo n.º 3
0
    def insert(self, document):
        # FIXME: for now we'll write a temporary image and read that in.
        # we need to provide nicer API for this.
        simple.WriteImage("temporary.png", view=self.view)
        with open("temporary.png", "rb") as file:
            document.data = file.read()

        #alternatively if you are just writing out files and don't need them in memory
        ##fn = self.cinema_store.get_filename(document)
        ##simple.WriteImage(fn)

        super(ImageExplorer, self).insert(document)
Exemplo n.º 4
0
    def saveView(self, reader):
        """Save figure
        """

        # Get animation scene
        animationScene = pv.GetAnimationScene()
        animationScene.PlayMode = "Snap To TimeSteps"

        # Save animation images
        print("[PNGViewer] ###  Generating PNG images...")
        for t in reader.TimestepValues.GetData()[:]:
            animationScene.AnimationTime = t
            pv.WriteImage(self.file_name + ".%f.png" % t)
        print("[PNGViewer] ### All PNG images generated.")
    def UpdatePipeline(self, time=0):
        """
        Change camera position and dump images to the disk
        """
        self.file_name_generator.update_active_arguments(time=time)
        self.view_proxy.CameraFocalPoint = self.focal_point
        self.view_proxy.CameraViewUp = self.phi_rotation_axis
        theta_offset = 90 % self.angular_steps[1]
        if theta_offset == 0:
            theta_offset += self.angular_steps[1]
        for theta in range(-90 + theta_offset, 90 - theta_offset + 1,
                           self.angular_steps[1]):
            theta_rad = float(theta) / 180 * math.pi
            for phi in range(0, 360, self.angular_steps[0]):
                phi_rad = float(phi) / 180 * math.pi

                pos = [
                    float(self.focal_point[0]) -
                    math.cos(phi_rad) * self.distance * math.cos(theta_rad),
                    float(self.focal_point[1]) +
                    math.sin(phi_rad) * self.distance * math.cos(theta_rad),
                    float(self.focal_point[2]) +
                    math.sin(theta_rad) * self.distance
                ]
                up = [
                    +math.cos(phi_rad) * math.sin(theta_rad),
                    -math.sin(phi_rad) * math.sin(theta_rad),
                    +math.cos(theta_rad)
                ]

                # Handle rotation around Z => 0 | Y => 2 | X => 1
                for i in range(self.offset):
                    pos.insert(0, pos.pop())
                    up.insert(0, up.pop())

                # Apply new camera position
                self.view_proxy.CameraPosition = pos
                self.view_proxy.CameraViewUp = up
                simple.Render()

                # Update file name pattern
                self.file_name_generator.update_active_arguments(phi=phi,
                                                                 theta=(90 +
                                                                        theta))
                simple.WriteImage(self.file_name_generator.get_fullpath())

        # Generate metadata
        self.file_name_generator.WriteMetaData()
    def UpdatePipeline(self, time=0):
        """
        Probe dataset and dump images to the disk
        """
        self.file_name_generator.update_active_arguments(time=time)
        self.slice.SMProxy.InvokeEvent('UserEvent', 'HideWidget')
        self.view_proxy.CameraParallelProjection = 1
        self.view_proxy.CameraViewUp = self.viewup
        self.view_proxy.CameraFocalPoint = [0, 0, 0]
        self.view_proxy.CameraPosition = self.slice.SliceType.Normal
        self.slice.SliceType.Origin = [
            (self.dataBounds[0] + self.dataBounds[1]) / 2,
            (self.dataBounds[2] + self.dataBounds[3]) / 2,
            (self.dataBounds[4] + self.dataBounds[5]) / 2
        ]
        simple.Render()
        simple.ResetCamera()
        self.view_proxy.CameraParallelScale = self.view_proxy.CameraParallelScale / self.parallelScaleRatio

        for step in range(int(self.number_of_steps)):
            self.slice.SliceType.Origin = [
                self.origin[0] + float(step) * self.origin_inc[0],
                self.origin[1] + float(step) * self.origin_inc[1],
                self.origin[2] + float(step) * self.origin_inc[2]
            ]

            # Loop over each color withour changing geometry
            for name in self.colorByArray:
                # Choose color by
                self.sliceRepresentation.ColorArrayName = (
                    self.colorByArray[name]["type"], name)
                self.sliceRepresentation.LookupTable = self.colorByArray[name][
                    "lut"]
                self.file_name_generator.update_active_arguments(
                    sliceColor=name)

                # Update file name pattern
                self.file_name_generator.update_active_arguments(
                    slicePosition=step)
                simple.Render()
                simple.WriteImage(self.file_name_generator.get_fullpath())

        # Generate metadata
        self.file_name_generator.update_label_arguments(sliceColor="Color by:")
        self.file_name_generator.WriteMetaData()
        self.view_proxy.CameraParallelProjection = 0
    def WriteImages(self, datadescription, rescale_lookuptable=False):
        """This method will update all views, if present and write output
            images, as needed."""
        timestep = datadescription.GetTimeStep()

        for view in self.__ViewsList:
            if timestep % view.cpFrequency == 0 or \
                                            datadescription.GetForceOutput() == True:
                fname = view.cpFileName
                fname = fname.replace("%t", str(timestep))
                if view.cpFitToScreen != 0:
                    if view.IsA("vtkSMRenderViewProxy") == True:
                        view.ResetCamera()
                    elif view.IsA("vtkSMContextViewProxy") == True:
                        view.ResetDisplay()
                    else:
                        print ' do not know what to do with a ', view.GetClassName()
                view.ViewTime = datadescription.GetTime()
                if rescale_lookuptable:
                    self.RescaleDataRange(view, datadescription.GetTime())
                simple.WriteImage(fname, view, Magnification=view.cpMagnification)
Exemplo n.º 8
0
 def writeImages(self):
     for cam in self.camera:
         update_camera(self.view, cam)
         simple.WriteImage(
             self.dataHandler.getDataAbsoluteFilePath('image'))
Exemplo n.º 9
0
for key in dipole_K1000_ds.field_lines:
    if dipole_K1000_ds.field_lines[key] is None:
        continue
    forward2 = pv.Show(dipole_K1000_ds.field_lines[key].fieldLineObj_f, rvs2)
    backward2 = pv.Show(dipole_K1000_ds.field_lines[key].fieldLineObj_b, rvs2)
    forward2.DiffuseColor = [0.6666666666666666, 0.0, 0.0]
    backward2.DiffuseColor = [0., 0., 0.66]

    dipole_K1000_spheres[key] = pv.Sphere()
    dipole_K1000_spheres[key].Center = b_loc_dipole_K1000[key][0]
    dipole_K1000_spheres[key].Radius = 0.1
    dipole_K1000_spheres[key].ThetaResolution = 8
    dipole_K1000_spheres[key].PhiResolution = 8
    disp = pv.Show(dipole_K1000_spheres[key], rvs2)
    disp.DiffuseColor = [.75, .75, .75]

    dipole_K1000_spheres2[key] = pv.Sphere()
    dipole_K1000_spheres2[key].Center = b_loc_dipole_K1000[key][1]
    dipole_K1000_spheres2[key].Radius = 0.1
    dipole_K1000_spheres2[key].ThetaResolution = 8
    dipole_K1000_spheres2[key].PhiResolution = 8
    disp = pv.Show(dipole_K1000_spheres2[key], rvs2)
    disp.DiffuseColor = [.75, .75, .75]

pv.RenderAllViews()

pv.WriteImage("drift_shell_t96.png", view=rvs)
pv.WriteImage("drift_shell_dipole.png", view=rvs2)
pv.WriteImage("drift_shell_t96_m.png", view=rvs3)
Exemplo n.º 10
0
# This is how you can run this script:
# mpiexec -n NUM_PROCS pvbatch Test_Parallel.py

import paraview.simple as pv
import paraview.servermanager as pvserver

num_partitions = pvserver.ActiveConnection.GetNumberOfDataPartitions()
print("Rendering {} data partitions".format(num_partitions))

sphere = pv.Sphere()
pids = pv.ProcessIdScalars()

rep = pv.Show()
lut = pv.GetLookupTableForArray(
    "ProcessId",
    1,
    RGBPoints=[0.0, 0.23, 0.3, 0.754, num_partitions, 0.706, 0.016, 0.15],
    ColorSpace='Diverging')
rep.LookupTable = lut
rep.ColorArrayName = 'ProcessId'

pv.Render()
pv.WriteImage('Parallel.png')
print(
    "Rendering done. You should find an image file named `Parallel.png` that shows a sphere. The sphere should be divided into wedges that are color-coded by processor."
)
Exemplo n.º 11
0
points = []
orderedKeys = sorted(phi_location.keys())

points2 = []
orderedKeys2 = sorted(phi_location2.keys())

for key in orderedKeys:
    points.append(phi_location[key])

for key in orderedKeys2:
    points2.append(phi_location2[key])


pointsFlat = np.array(points).flatten()
pointsFlat2 = np.array(points2).flatten()

polyLineSource1.Points = pointsFlat
polyLineSource2.Points = pointsFlat2

tube1 = pv.Tube(Input=polyLineSource1)
tube1.Radius = 0.005
tube1Display = pv.Show(tube1, rvs4)
tube1Display.DiffuseColor = [1.0, 1.0, 0.0]

tube2 = pv.Tube(Input=polyLineSource2)
tube2.Radius = 0.005
tube2Display = pv.Show(tube2, rvs4)
tube2Display.DiffuseColor = [0.0, 0.0, 1.0]

pv.WriteImage("out/png/polar_cap_grid_t96_dp20.png", view=rvs4)
Exemplo n.º 12
0
def WriteImages(currentTimeStep, currentTime, views):
    for view in views:
        filename = view.tpFileName.replace("%t", str(currentTimeStep))
        view.ViewTime = currentTime
        pvsimple.WriteImage(filename, view, Magnification=view.tpMagnification)
Exemplo n.º 13
0
#from gen_data import *

import paraview.simple as ps

# reads in a vtk file
test = ps.OpenDataFile("/home/james/projects/GPUE/py/test.vtk")
c = ps.Contour(Input=test)
c.Isosurfaces = [0.5]
c.UpdatePipeline()

ps.Show(test)
ps.Show(c)
ps.Render()
ps.WriteImage("/home/james/projects/GPUE/py/check.png")

print("done with test script")
Exemplo n.º 14
0
    test_points_f.append(pv.Sphere())
    test_points_f[-1].Radius = 0.20
    test_points_f[-1].Center = fline.fieldLinePoints_f[(n * 10)]
    test_disp_f.append(pv.Show(test_points_f[-1], rv))
    test_disp_f[-1].DiffuseColor = [0.9, 0.1, 0.1]

    test_contour_list.append(ih.mag(fline.fieldLineData_f[(n*10)]))

# min point
test_points_m = pv.Sphere()
test_points_m.Radius = 0.25
test_points_m.Center = fline.fieldLinePoints_b[0]
test_disp_m = pv.Show(test_points_m, rv)
test_disp_m.DiffuseColor = [0, 0, 0]


Bmag_contour.Isosurfaces = test_contour_list
contour_disp = pv.Show(Bmag_contour, rv)
contour_disp.DiffuseColor = [0.0, 0.0, 0.0]

rv.Background = [1.0, 1.0, 1.0]

pv.Render(rv)

pv.WriteImage("test.png", view=rv)



# Keep displays up until user hits enter.
# raw_input("Press Enter to Continue...")
Exemplo n.º 15
0
for key in t96_K0_ds.field_lines:
    if t96_K0_ds.field_lines[key] is None:
        continue
    forward = pv.Show(t96_K0_ds.field_lines[key].fieldLineObj_f, rvs4)
    backward = pv.Show(t96_K0_ds.field_lines[key].fieldLineObj_b, rvs4)

    forward.DiffuseColor = [1, 0.0, 0.0]
    forward.LineWidth = 2.0
    backward.DiffuseColor = [1, 0.0, 0.0]
    backward.LineWidth = 2.0

eqc = ih.mag(t96_K0_ds.field_lines[0.0].fieldLinePoints_f[0])

print "Equatorial Crossing of Drift Shell: ", eqc
print "L* (500): ", L_500
print "L* (100): ", L_100
print "L* (50): ", L_50
print "L* (25): ", L_25
print "L* (10): ", L_10
print
print "Error: "
print "-------"
print "div=10: ", (eqc - L_10) / eqc * 100, "%"
print "div=25: ", (eqc - L_25) / eqc * 100, "%"
print "div=50: ", (eqc - L_50) / eqc * 100, "%"
print "div=100: ", (eqc - L_100) / eqc * 100, "%"
print "div=500: ", (eqc - L_500) / eqc * 100, "%"

pv.RenderAllViews()
pv.WriteImage("out/png/lstar_test.png", view=rvs4)
Exemplo n.º 16
0
List = sorted(List)
#print List
K=0
for file in List:
    K=K+1 # count all state files
N=0
for file in List:
    Fpath,Ffile = os.path.split(file)    
    N=N+1
    print N," of ",K,"  (",Ffile,")"

    # old
    #TE23 = GetActiveSource()
    #TE23.FileName = file # das State file muss ausgewählt sein
    # new
    for object in PSources:
        # check all objects in pipiline and find out which are State files
        if hasattr(PSources[object], 'FileName'):
          if (PSources[object].FileName.find("State")>0.0 and 
              PSources[object].FileName.find(".h5") > 0.0):
              PSources[object].FileName=file
    
    SetActiveView(view)
    Render()
    simple.WriteImage("new"+"%0.4d" % N+".bmp")
    #N=N-1

print "Creating Video ..."
os.system('avconv -r 10 -y -i new%4d.bmp -b:v 4000k output.mp4')
print "Done."