本文整理汇总了Python中pyvista.read方法的典型用法代码示例。如果您正苦于以下问题:Python pyvista.read方法的具体用法?Python pyvista.read怎么用?Python pyvista.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyvista
的用法示例。
在下文中一共展示了pyvista.read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_save_rectilinear
# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import read [as 别名]
def test_save_rectilinear(extension, binary, tmpdir):
filename = str(tmpdir.mkdir("tmpdir").join('tmp.%s' % extension))
ogrid = examples.load_rectilinear()
ogrid.save(filename, binary)
grid = pyvista.RectilinearGrid(filename)
assert grid.n_cells == ogrid.n_cells
assert np.allclose(grid.x, ogrid.x)
assert np.allclose(grid.y, ogrid.y)
assert np.allclose(grid.z, ogrid.z)
assert grid.dimensions == ogrid.dimensions
grid = pyvista.read(filename)
assert isinstance(grid, pyvista.RectilinearGrid)
assert grid.n_cells == ogrid.n_cells
assert np.allclose(grid.x, ogrid.x)
assert np.allclose(grid.y, ogrid.y)
assert np.allclose(grid.z, ogrid.z)
assert grid.dimensions == ogrid.dimensions
示例2: test_multi_block_save_lines
# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import read [as 别名]
def test_multi_block_save_lines(tmpdir):
radius = 1
xr = np.random.random(10)
yr = np.random.random(10)
x = radius * np.sin(yr) * np.cos(xr)
y = radius * np.sin(yr) * np.sin(xr)
z = radius * np.cos(yr)
xyz = np.stack((x, y, z), axis=1)
poly = pyvista.lines_from_points(xyz, close=False)
blocks = pyvista.MultiBlock()
for _ in range(2):
blocks.append(poly)
path = tmpdir.mkdir("tmpdir")
line_filename = str(path.join('lines.vtk'))
block_filename = str(path.join('blocks.vtmb'))
poly.save(line_filename)
blocks.save(block_filename)
poly_load = pyvista.read(line_filename)
assert np.allclose(poly_load.points, poly.points)
blocks_load = pyvista.read(block_filename)
assert np.allclose(blocks_load[0].points, blocks[0].points)
示例3: get_mesh
# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import read [as 别名]
def get_mesh(self, indices=[]):
"""Return the pyvista mesh object (or submesh).
Parameters
----------
self : MeshVTK
a MeshVTK object
indices : list
list of the points to extract (optional)
Returns
-------
mesh : pyvista.core.pointset.UnstructuredGrid
a pyvista UnstructuredGrid object
"""
# Already available => Return
if self.mesh is not None:
return self.mesh
# Read mesh file
else:
if self.format != "vtk":
# Write vtk files with meshio
mesh = read(self.path + "/" + self.name + "." + self.format)
mesh.write(self.path + "/" + self.name + ".vtk")
# Read .vtk file with pyvista
mesh = pv.read(self.path + "/" + self.name + ".vtk")
# Extract submesh
if indices != []:
mesh = mesh.extract_points(indices)
if self.is_pyvista_mesh:
self.mesh = mesh
return mesh
示例4: test_vertice_cells_on_read
# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import read [as 别名]
def test_vertice_cells_on_read(tmpdir):
point_cloud = pyvista.PolyData(np.random.rand(100, 3))
filename = str(tmpdir.mkdir("tmpdir").join('foo.ply'))
point_cloud.save(filename)
recovered = pyvista.read(filename)
assert recovered.n_cells == 100
recovered = pyvista.PolyData(filename)
assert recovered.n_cells == 100
示例5: test_read
# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import read [as 别名]
def test_read(tmpdir):
fnames = (ex.antfile, ex.planefile, ex.hexbeamfile, ex.spherefile,
ex.uniformfile, ex.rectfile)
types = (pyvista.PolyData, pyvista.PolyData, pyvista.UnstructuredGrid,
pyvista.PolyData, pyvista.UniformGrid, pyvista.RectilinearGrid)
for i, filename in enumerate(fnames):
obj = fileio.read(filename)
assert isinstance(obj, types[i])
# Now test the standard_reader_routine
for i, filename in enumerate(fnames):
# Pass attrs to for the standard_reader_routine to be used
obj = fileio.read(filename, attrs={'DebugOn': None})
assert isinstance(obj, types[i])
# this is also tested for each mesh types init from file tests
filename = str(tmpdir.mkdir("tmpdir").join('tmp.%s' % 'npy'))
arr = np.random.rand(10, 10)
np.save(filename, arr)
with pytest.raises(IOError):
_ = pyvista.read(filename)
# read non existing file
with pytest.raises(IOError):
_ = pyvista.read('this_file_totally_does_not_exist.vtk')
# Now test reading lists of files as multi blocks
multi = pyvista.read(fnames)
assert isinstance(multi, pyvista.MultiBlock)
assert multi.n_blocks == len(fnames)
nested = [ex.planefile,
[ex.hexbeamfile, ex.uniformfile]]
multi = pyvista.read(nested)
assert isinstance(multi, pyvista.MultiBlock)
assert multi.n_blocks == 2
assert isinstance(multi[1], pyvista.MultiBlock)
assert multi[1].n_blocks == 2
示例6: test_save
# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import read [as 别名]
def test_save(extension, binary, tmpdir, hexbeam):
filename = str(tmpdir.mkdir("tmpdir").join('tmp.%s' % extension))
hexbeam.save(filename, binary)
grid = pyvista.UnstructuredGrid(filename)
assert grid.cells.shape == hexbeam.cells.shape
assert grid.points.shape == hexbeam.points.shape
grid = pyvista.read(filename)
assert grid.cells.shape == hexbeam.cells.shape
assert grid.points.shape == hexbeam.points.shape
assert isinstance(grid, pyvista.UnstructuredGrid)
示例7: test_save_structured
# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import read [as 别名]
def test_save_structured(extension, binary, tmpdir, struct_grid):
filename = str(tmpdir.mkdir("tmpdir").join('tmp.%s' % extension))
struct_grid.save(filename, binary)
grid = pyvista.StructuredGrid(filename)
assert grid.x.shape == struct_grid.y.shape
assert grid.n_cells
assert grid.points.shape == struct_grid.points.shape
grid = pyvista.read(filename)
assert grid.x.shape == struct_grid.y.shape
assert grid.n_cells
assert grid.points.shape == struct_grid.points.shape
assert isinstance(grid, pyvista.StructuredGrid)
示例8: test_read_rectilinear_grid_from_file
# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import read [as 别名]
def test_read_rectilinear_grid_from_file():
grid = pyvista.read(examples.rectfile)
assert grid.n_cells == 16146
assert grid.n_points == 18144
assert grid.bounds == [-350.0,1350.0, -400.0,1350.0, -850.0,0.0]
assert grid.n_arrays == 1
示例9: test_read_uniform_grid_from_file
# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import read [as 别名]
def test_read_uniform_grid_from_file():
grid = pyvista.read(examples.uniformfile)
assert grid.n_cells == 729
assert grid.n_points == 1000
assert grid.bounds == [0.0,9.0, 0.0,9.0, 0.0,9.0]
assert grid.n_arrays == 2
assert grid.dimensions == [10, 10, 10]
示例10: test_save_uniform
# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import read [as 别名]
def test_save_uniform(extension, binary, tmpdir):
filename = str(tmpdir.mkdir("tmpdir").join('tmp.%s' % extension))
ogrid = examples.load_uniform()
ogrid.save(filename, binary)
grid = pyvista.UniformGrid(filename)
assert grid.n_cells == ogrid.n_cells
assert grid.origin == ogrid.origin
assert grid.spacing == ogrid.spacing
assert grid.dimensions == ogrid.dimensions
grid = pyvista.read(filename)
assert isinstance(grid, pyvista.UniformGrid)
assert grid.n_cells == ogrid.n_cells
assert grid.origin == ogrid.origin
assert grid.spacing == ogrid.spacing
assert grid.dimensions == ogrid.dimensions
示例11: test_multi_block_io
# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import read [as 别名]
def test_multi_block_io(extension, binary, tmpdir, ant, sphere, uniform, airplane, globe):
filename = str(tmpdir.mkdir("tmpdir").join('tmp.%s' % extension))
multi = multi_from_datasets(ant, sphere, uniform, airplane, globe)
# Now check everything
assert multi.n_blocks == 5
# Save it out
multi.save(filename, binary)
foo = MultiBlock(filename)
assert foo.n_blocks == multi.n_blocks
foo = pyvista.read(filename)
assert foo.n_blocks == multi.n_blocks
示例12: load_channels
# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import read [as 别名]
def load_channels():
"""Load a uniform grid of fluvial channels in the subsurface."""
return pyvista.read(channelsfile)
示例13: _download_and_read
# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import read [as 别名]
def _download_and_read(filename, texture=False, file_format=None):
saved_file, _ = _download_file(filename)
if texture:
return pyvista.read_texture(saved_file)
return pyvista.read(saved_file, file_format=file_format)
###############################################################################
示例14: download_blood_vessels
# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import read [as 别名]
def download_blood_vessels():
"""Download data representing the bifurcation of blood vessels."""
local_path, _ = _download_file('pvtu_blood_vessels/blood_vessels.zip')
filename = os.path.join(local_path, 'T0000000500.pvtu')
mesh = pyvista.read(filename)
mesh.set_active_vectors('velocity')
return mesh
示例15: download_tetra_dc_mesh
# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import read [as 别名]
def download_tetra_dc_mesh():
"""Download two meshes defining an electrical inverse problem.
This contains a high resolution forward modeled mesh and a coarse
inverse modeled mesh.
"""
local_path, _ = _download_file('dc-inversion.zip')
filename = os.path.join(local_path, 'mesh-forward.vtu')
fwd = pyvista.read(filename)
fwd.set_active_scalars('Resistivity(log10)-fwd')
filename = os.path.join(local_path, 'mesh-inverse.vtu')
inv = pyvista.read(filename)
inv.set_active_scalars('Resistivity(log10)')
return pyvista.MultiBlock({'forward':fwd, 'inverse':inv})