Esempio n. 1
0
def test_mutli_block_clean():
    # now test a clean of the null values
    multi = pyvista.MultiBlock()
    multi[1, 'rect'] = ex.load_rectilinear()
    multi[2, 'empty'] = pyvista.PolyData()
    multi[3, 'mempty'] = pyvista.MultiBlock()
    multi[5, 'uni'] = ex.load_uniform()
    # perfromt he clean to remove all Null elements
    multi.clean()
    assert multi.n_blocks == 2
    assert multi.GetNumberOfBlocks() == 2
    assert isinstance(multi[0], pyvista.RectilinearGrid)
    assert isinstance(multi[1], pyvista.UniformGrid)
    assert multi.get_block_name(0) == 'rect'
    assert multi.get_block_name(1) == 'uni'
    # Test a nested data struct
    foo = pyvista.MultiBlock()
    foo[3] = ex.load_ant()
    assert foo.n_blocks == 4
    multi = pyvista.MultiBlock()
    multi[1, 'rect'] = ex.load_rectilinear()
    multi[5, 'multi'] = foo
    # perfromt he clean to remove all Null elements
    assert multi.n_blocks == 6
    multi.clean()
    assert multi.n_blocks == 2
    assert multi.GetNumberOfBlocks() == 2
    assert isinstance(multi[0], pyvista.RectilinearGrid)
    assert isinstance(multi[1], pyvista.MultiBlock)
    assert multi.get_block_name(0) == 'rect'
    assert multi.get_block_name(1) == 'multi'
    assert foo.n_blocks == 1
Esempio n. 2
0
def test_multi_block_init_list():
    data = [ex.load_rectilinear(), ex.load_airplane()]
    multi = pyvista.MultiBlock(data)
    assert isinstance(multi, pyvista.MultiBlock)
    assert multi.n_blocks == 2
    assert isinstance(multi.GetBlock(0), pyvista.RectilinearGrid)
    assert isinstance(multi.GetBlock(1), pyvista.PolyData)
Esempio n. 3
0
def test_multi_block_keys():
    data = dict()
    data['grid'] = ex.load_rectilinear()
    data['poly'] = ex.load_airplane()
    multi = pyvista.MultiBlock(data)
    assert len(multi.keys()) == 2
    assert 'grid' in multi.keys()
    assert 'poly' in multi.keys()
Esempio n. 4
0
def datasets():
    return [
        examples.load_uniform(),  # UniformGrid
        examples.load_rectilinear(),  # RectilinearGrid
        examples.load_hexbeam(),  # UnstructuredGrid
        examples.load_airplane(),  # PolyData
        examples.load_structured(),  # StructuredGrid
    ]
Esempio n. 5
0
def test_multi_block_plot():
    multi = pyvista.MultiBlock()
    multi.append(examples.load_rectilinear())
    uni = examples.load_uniform()
    arr = np.random.rand(uni.n_cells)
    uni._add_cell_array(arr, 'Random Data')
    multi.append(uni)
    # And now add a data set without the desired array and a NULL component
    multi[3] = examples.load_airplane()
    multi.plot(scalars='Random Data', off_screen=OFF_SCREEN, multi_colors=True)
Esempio n. 6
0
def test_multi_block_init_dict():
    data = dict()
    data['grid'] = ex.load_rectilinear()
    data['poly'] = ex.load_airplane()
    multi = pyvista.MultiBlock(data)
    assert isinstance(multi, pyvista.MultiBlock)
    assert multi.n_blocks == 2
    # Note that disctionaries do not maintain order
    assert isinstance(multi[0], (pyvista.RectilinearGrid, pyvista.PolyData))
    assert multi.get_block_name(0) in ['grid', 'poly']
    assert isinstance(multi[1], (pyvista.RectilinearGrid, pyvista.PolyData))
    assert multi.get_block_name(1) in ['grid', 'poly']
Esempio n. 7
0
def test_mutli_block_clean():
    # now test a clean of the null values
    multi = pyvista.MultiBlock()
    multi[1, 'rect'] = ex.load_rectilinear()
    multi[5, 'uni'] = ex.load_uniform()
    # perfromt he clean to remove all Null elements
    multi.clean()
    assert multi.n_blocks == 2
    assert multi.GetNumberOfBlocks() == 2
    assert isinstance(multi[0], pyvista.RectilinearGrid)
    assert isinstance(multi[1], pyvista.UniformGrid)
    assert multi.get_block_name(0) == 'rect'
    assert multi.get_block_name(1) == 'uni'
Esempio n. 8
0
def test_multi_block_plot():
    multi = pyvista.MultiBlock()
    multi.append(examples.load_rectilinear())
    uni = examples.load_uniform()
    arr = np.random.rand(uni.n_cells)
    uni.cell_arrays.append(arr, 'Random Data')
    multi.append(uni)
    # And now add a data set without the desired array and a NULL component
    multi[3] = examples.load_airplane()
    with pytest.raises(ValueError):
        # The scalars are not available in all datasets so raises ValueError
        multi.plot(scalars='Random Data', multi_colors=True)
    multi.plot(multi_colors=True, before_close_callback=verify_cache_image)
Esempio n. 9
0
def test_export_multi(tmpdir):
    filename = str(tmpdir.mkdir("tmpdir").join('scene-multi'))
    multi = pyvista.MultiBlock()
    # Add examples
    multi.append(ex.load_ant())
    multi.append(ex.load_sphere())
    multi.append(ex.load_uniform())
    multi.append(ex.load_airplane())
    multi.append(ex.load_rectilinear())
    # Create the scene
    plotter = pyvista.Plotter(off_screen=OFF_SCREEN)
    plotter.add_mesh(multi)
    plotter.export_vtkjs(filename, compress_arrays=True)
    cpos_out = plotter.show()  # Export must be called before showing!
    plotter.close()
    # Now make sure the file is there
    assert os.path.isfile(f'{filename}.vtkjs')
Esempio n. 10
0
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
Esempio n. 11
0
def test_multi_block_set_get_ers():
    """This puts all of the example data objects into a a MultiBlock container"""
    multi = MultiBlock()
    # Set the number of blocks
    multi.n_blocks = 6
    assert multi.GetNumberOfBlocks() == 6  # Check that VTK side registered it
    assert multi.n_blocks == 6  # Check pyvista side registered it
    # Add data to the MultiBlock
    data = ex.load_rectilinear()
    multi[1, 'rect'] = data
    # Make sure number of blocks is constant
    assert multi.n_blocks == 6
    # Check content
    assert isinstance(multi[1], RectilinearGrid)
    for i in [0, 2, 3, 4, 5]:
        assert multi[i] is None
    # Check the bounds
    assert multi.bounds == list(data.bounds)
    multi[5] = ex.load_uniform()
    multi.set_block_name(5, 'uni')
    multi.set_block_name(5, None)  # Make sure it doesn't get overwritten
    assert isinstance(multi.get(5), UniformGrid)
    # Test get by name
    assert isinstance(multi['uni'], UniformGrid)
    assert isinstance(multi['rect'], RectilinearGrid)
    # Test the del operator
    del multi[0]
    assert multi.n_blocks == 5
    # Make sure the rect grid was moved up
    assert isinstance(multi[0], RectilinearGrid)
    assert multi.get_block_name(0) == 'rect'
    assert multi.get_block_name(2) == None
    # test del by name
    del multi['uni']
    assert multi.n_blocks == 4
    # test the pop operator
    pop = multi.pop(0)
    assert isinstance(pop, RectilinearGrid)
    assert multi.n_blocks == 3
    assert multi.get_block_name(10) is None
    with pytest.raises(KeyError):
        _ = multi.get_index_by_name('foo')
    # allow Sequence but not Iterable in setitem
    with pytest.raises(TypeError):
        multi[{1, 'foo'}] = data
Esempio n. 12
0
def test_multi_block_append():
    """This puts all of the example data objects into a a MultiBlock container"""
    multi = pyvista.MultiBlock()
    # Add examples
    multi.append(ex.load_ant())
    multi.append(ex.load_sphere())
    multi.append(ex.load_uniform())
    multi.append(ex.load_airplane())
    multi.append(ex.load_rectilinear())
    # Now check everything
    assert multi.n_blocks == 5
    assert multi.bounds is not None
    assert isinstance(multi[0], pyvista.PolyData)
    assert isinstance(multi[1], pyvista.PolyData)
    assert isinstance(multi[2], pyvista.UniformGrid)
    assert isinstance(multi[3], pyvista.PolyData)
    assert isinstance(multi[4], pyvista.RectilinearGrid)
    # Now overwrite a block
    multi[4] = pyvista.Sphere()
    assert isinstance(multi[4], pyvista.PolyData)
    multi[4] = vtk.vtkUnstructuredGrid()
    assert isinstance(multi[4], pyvista.UnstructuredGrid)
Esempio n. 13
0
"""
Extract Array to Table
~~~~~~~~~~~~~~~~~~~~~~
This example will demonstrate how to extract an array from any input data set
to make a `vtkTable` of that single data array

This example demos :class:`PVGeo.filters.ExtractArray`
"""
from PVGeo.filters import ExtractArray
from pyvista import examples
################################################################################
# Create input data
grd = examples.load_rectilinear()

################################################################################
# Construct the filter
filt = ExtractArray()
# Define the array to extract
# Apply the filter on the input
table = filt.apply(grd, 'Random Data')
print(table)
Esempio n. 14
0
def rectilinear():
    return examples.load_rectilinear()
Esempio n. 15
0
import os
import sys
import platform

import numpy as np
import pytest

import pyvista
from pyvista import examples

DATASETS = [
    examples.load_uniform(),  # UniformGrid
    examples.load_rectilinear(),  # RectilinearGrid
    examples.load_hexbeam(),  # UnstructuredGrid
    examples.load_airplane(),  # PolyData
    examples.load_structured(),  # StructuredGrid
]
normals = ['x', 'y', '-z', (1, 1, 1), (3.3, 5.4, 0.8)]

COMPOSITE = pyvista.MultiBlock(DATASETS, deep=True)

skip_py2_nobind = pytest.mark.skipif(
    int(sys.version[0]) < 3, reason="Python 2 doesn't support binding methods")

skip_windows = pytest.mark.skipif(os.name == 'nt',
                                  reason="Flaky Windows tests")
skip_mac = pytest.mark.skipif(platform.system() == 'Darwin',
                              reason="Flaky Mac tests")


@pytest.fixture(scope='module')
Esempio n. 16
0
"""
Append Cell Centers
~~~~~~~~~~~~~~~~~~~

This example will demonstrate how to append a dataset's cell centers as a length 3 tuple array.

This example demonstrates :class:`PVGeo.filters.AppendCellCenters`
"""

from pyvista import examples
from PVGeo.filters import AppendCellCenters

################################################################################
# Use an example mesh from pyvista
mesh = examples.load_rectilinear()
print(mesh)

################################################################################
#  Run the PVGeo algorithm
centers = AppendCellCenters().apply(mesh)
print(centers)

################################################################################
centers.plot()
Esempio n. 17
0
def test_create_rectilinear_grid_from_file():
    grid = examples.load_rectilinear()
    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