示例#1
0
 def writeVTK(self, filename):
     import pyvtk
     origin = N.array([self.x_axis[0], self.y_axis[0], self.z_axis[0]])
     spacing = N.array([self.x_axis[1], self.y_axis[1], self.z_axis[1]]) \
               - origin
     values = pyvtk.Scalars(N.ravel(N.transpose(self.data)),
                            'electron density')
     data = pyvtk.VtkData(
         pyvtk.StructuredPoints(self.data.shape, origin, spacing),
         'Density map', pyvtk.PointData(values))
     data.tofile(filename, format='binary')
示例#2
0
    def _make_vtk_mesh_3d(self):
        """
        Create a simple 3D mesh using vtk.StructuredPoints method,
        and using the dimensions, origin, resolutions from
        OpenPMDTimeSeries meta-info object (returned as the second
        argument of ts.get_field method).
        Note:
            this function operates only once, and all following calls
        """

        dimensions = self.fld.shape
        if self.fixed_zmin is None:
            origin = (self.info.xmin, self.info.ymin, self.info.zmin)
        else:
            origin = (self.info.xmin, self.info.ymin, fixed_zmin)
        resolutions = (self.info.dx, self.info.dy, self.info.dz)
        self.grid = vtk.StructuredPoints(dimensions, origin, resolutions)
示例#3
0
    def _make_vtk_mesh_3d(self):
        """
        Create a simple 3D mesh using vtk.StructuredPoints method,
        and using the dimensions, origin, resolutions from
        OpenPMDTimeSeries meta-info object (returned as the second
        argument of ts.get_field method).
        """
        # Exit if the grid already exists and CommonMesh is True
        if self.grid is not None and self.CommonMesh:
            return

        # Get origin and resolution of the 3D visualization domain
        origin = self._get_origin_3d()
        resolutions = (self.info.dx, self.info.dy, self.info.dz)

        # register the grid VTK container
        self.grid = vtk.StructuredPoints(self.dimensions, origin,
                                         resolutions)
    def solnToVTK(self):
        done = False
        lcv = 0

        coords = self.loadVec('coords.dat', 3)
        dims = list(coords.shape[:-1])
        try:
            dx = coords[1, 1, 1] - coords[0, 0, 0]
        except IndexError:
            try:
                dx = coords[0, 1, 1] - coords[0, 0, 0]
            except IndexError:
                try:
                    dx = coords[1, 0, 1] - coords[0, 0, 0]
                except IndexError:
                    dx = coords[1, 1, 0] - coords[0, 0, 0]

        dx = np.where(dx == 0., 0.1, dx)
        if dims[2] == 1:
            dims[2] = 2
        dims = tuple(dims)
        print dims
        dx = tuple(dx)
        vtkgrid = pyvtk.StructuredPoints(dims, coords[0, 0, 0], dx)

        while not done:
            try:
                if not os.path.exists(self._file_prefix + 'prs%03d.dat' % lcv):
                    raise IOError('Nonexistent file')
            except IOError:
                done = True
                print 'Read %d timesteps' % lcv
            else:
                prs_data = self.loadVecToVTK('prs%03d.dat' % lcv, 1)
                vel_data = self.loadVecToVTK('u%03d.dat' % lcv, 3)
                wall_data = self.loadVecToVTK('walls%03d.dat' % lcv, 1)

                pointdata = pyvtk.PointData(prs_data, vel_data, wall_data)
                data = pyvtk.VtkData(
                    vtkgrid,
                    self._prefix.strip('_') + ' step %d' % lcv, pointdata)
                data.tofile(self._file_prefix + 'soln_%03d.vtk' % lcv)
                lcv += 1
        return
示例#5
0
文件: generate.py 项目: Rauell/neuron
# generate the data.
from numpy import *
import scipy
x = (arange(50.0) - 25) / 2.0
y = (arange(50.0) - 25) / 2.0
r = sqrt(x**2 + y**2)
z = x * 5.0 * sin(x)  # Bessel function of order 0
# now dump the data to a VTK file.
import pyvtk
# Flatten the 2D array data as per VTK's requirements.
z1 = reshape(transpose(z), (-1, ))
point_data = pyvtk.PointData(pyvtk.Scalars(z1))
grid = pyvtk.StructuredPoints((50, 50, 1), (-12.5, -12.5, 0), (0.5, 0.5, 1))
data = pyvtk.VtkData(grid, point_data)
data.tofile('/tmp/test.vtk')
示例#6
0
 def _get_vtk_mesh_3d(self, origin, resolutions):
     self.grid = vtk.StructuredPoints(self.dimensions, origin, resolutions)
# -*- coding: utf-8 -*-
"""
Created on Thu Jun  8 12:03:31 2017

@author: Jonas Lindemann
"""
import numpy as np
import matplotlib.pyplot as plt
import pyvtk as vtk
import os

f = open("colorado_elev.vit", "rb")  # reopen the file
f.seek(268, os.SEEK_SET)  # seek

x = np.fromfile(f, dtype=np.ubyte)  # read the data into numpy

elevation = np.reshape(x, (400, 400))
plt.imshow(elevation)

plt.show()

pointdata = vtk.PointData(vtk.Scalars(x))
data = vtk.VtkData(vtk.StructuredPoints([400, 400]), pointdata)
data.tofile('elevation', 'ascii')
# -*- coding: utf-8 -*-
"""
Created on Thu Jun  8 12:03:31 2017

@author: Jonas Lindemann
"""

import numpy as np
import matplotlib.pyplot as plt
import perlin2d as pn
import pyvtk as vtk

if __name__ == "__main__":

    noise = pn.generate_perlin_noise_2d((256, 256), (8, 8))

    pointdata = vtk.PointData(vtk.Scalars(noise.reshape((256 * 256, ))))
    data = vtk.VtkData(vtk.StructuredPoints([256, 256]), pointdata)
    data.tofile('perlin', 'ascii')
示例#9
0
# -*- coding: utf-8 -*-
"""
Created on Thu Jun  8 12:03:31 2017

@author: Jonas Lindemann
"""

import numpy as np
import matplotlib.pyplot as plt
import perlin3d as pn
import pyvtk as vtk

if __name__ == "__main__":

    noise = pn.generate_perlin_noise_3d((128, 128, 128), (8, 8, 8))

    pointdata = vtk.PointData(vtk.Scalars(noise.reshape((128 * 128 * 128, ))))
    data = vtk.VtkData(vtk.StructuredPoints([128, 128, 128]), pointdata)
    data.tofile('perlin3d', 'ascii')