예제 #1
0
def test_rectilinear_grid(field_data, compression_fixture, format_fixture,
                          ordering_fixture):
    coords, r, e_r, field, order = field_data
    dim = r.ndim
    f = io.StringIO()

    compress = compression_fixture.param
    format = format_fixture.param
    rect = RectilinearGrid(f, coords, compression=compress, byte_order=order)
    rect.addPointData(
        DataArray(r, range(dim), 'point', ordering_fixture.param),
        vtk_format=format).addCellData(
            DataArray(e_r, range(dim), 'cell', ordering_fixture.param),
            vtk_format=format).addFieldData(DataArray(field, [0], 'field',
                                                      ordering_fixture.param),
                                            vtk_format=format)

    rect.write()

    reader = vtkXMLRectilinearGridReader()

    # Testing the xml pretty print output as well
    pretty_sstream = io.StringIO(str(rect.writer))

    for ss in [f, pretty_sstream]:
        vtk_r, vtk_e_r, vtk_f = get_vtk_data(reader, ss)

        vtk_r = vtk_r.reshape(r.shape, order='F')
        vtk_e_r = vtk_e_r.reshape(e_r.shape, order='F') \
                         .transpose(ordering_fixture.transp(dim))

        assert all(vtk_r == r)
        assert all(vtk_e_r == e_r)
        assert all(vtk_f == field)
예제 #2
0
파일: Output.py 프로젝트: snytav/Alma
def fields(world, species):
    import numpy as np
    from uvw import RectilinearGrid, DataArray

    # Creating coordinates
    x = np.linspace(-0.5, 0.5, 10)
    y = np.linspace(-0.5, 0.5, 20)
    z = np.linspace(-0.9, 0.9, 30)

    # Creating the file (with possible data compression)
    grid = RectilinearGrid('grid.vtr', (x, y, z), compression=True)

    # A centered ball
    x, y, z = np.meshgrid(x, y, z, indexing='ij')
    r = np.sqrt(x**2 + y**2 + z**2)
    ball = r < 0.3

    # Some multi-component multi-dimensional data
    data = np.zeros([10, 20, 30, 3, 3])
    data[ball, ...] = np.array([[0, 1, 0], [1, 0, 0], [0, 1, 1]])

    # Some cell data
    cell_data = np.zeros([9, 19, 29])
    cell_data[0::2, 0::2, 0::2] = 1

    # Adding the point data (see help(DataArray) for more info)
    grid.addPointData(DataArray(data, range(3), 'ball'))
    # Adding the cell data
    grid.addCellData(DataArray(cell_data, range(3), 'checkers'))
    grid.write()
예제 #3
0
def test_paraview_data(tmp_path):
    """
    NB: This is just testing writing. Since PVD is a ParaView related extension,
    it cannot be tested with vanilla VTK
    """
    x = np.linspace(0, 1, 10)
    y = x.copy()

    grid = RectilinearGrid(tmp_path / 'grid.vtr', [x, y])
    grid.write()

    group = ParaViewData(tmp_path / 'grid.pvd')
    group.addFile(grid)
    group.write()
예제 #4
0
def write_uvw():
    f = RectilinearGrid('uvw.vtr', (x, y, z))
    f.addPointData(DataArray(r, range(r.ndim), ''), vtk_format='append')
    f.write()
예제 #5
0
"Rectilinear grid example with reordering of components"

import numpy as np
from uvw import RectilinearGrid, DataArray

# Creating coordinates
x = np.linspace(-0.5, 0.5, 10)
y = np.linspace(-0.5, 0.5, 20)
z = np.linspace(-0.9, 0.9, 30)

# Creating the file
grid = RectilinearGrid('grid.vtr', (x, y, z), compression=True)

# A centered ball
z, x, y = np.meshgrid(z, y, x, indexing='ij')
r = np.sqrt(x**2 + y**2 + z**2)
ball = r < 0.3

# Some multi-component multi-dimensional data (components order z y x)
data = np.zeros([30, 20, 10, 3, 3])
data[ball, ...] = np.array([[0, 1, 0], [1, 0, 0], [0, 1, 1]])

# Adding the point data (see help(DataArray) for more info)
grid.addPointData(DataArray(data, [2, 1, 0], 'data'))
grid.write()