forked from pyvista/pyvista
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support to meshio readers and writers (pyvista#472)
* add support to meshio readers * remove useless tolist * raise error if meshio not installed * fix minor issues * add avs ucd reader * include read_meshio in read * remove meshio import test * make read_meshio public * keep error thrown by meshio * add meshio dependency * use pypi link * fix offset * add save_meshio * fix bug due to wrong input type * use pyvista properties instead of vtk * Update pyvista/utilities/fileio.py Co-Authored-By: Bane Sullivan <banesullivan@gmail.com> * Update pyvista/utilities/fileio.py Co-Authored-By: Bane Sullivan <banesullivan@gmail.com> * Update pyvista/utilities/fileio.py Co-Authored-By: Bane Sullivan <banesullivan@gmail.com> * Update pyvista/utilities/fileio.py Co-Authored-By: Bane Sullivan <banesullivan@gmail.com> * Update pyvista/utilities/fileio.py Co-Authored-By: Bane Sullivan <banesullivan@gmail.com> * convert pixels to quads * add comments and remove duplicate os * add test for meshio reader and writer * handle white spaces in data name * improve meshio test * add uniform to meshio test * add meshio file format test * make sure filename is a string * add save_meshio
- Loading branch information
1 parent
4ff55a4
commit 272bf7c
Showing
6 changed files
with
184 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ imageio-ffmpeg | |
colorcet | ||
cmocean | ||
scooby>=0.2.2 | ||
meshio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
'imageio', | ||
'appdirs', | ||
'scooby>=0.2.2', | ||
'meshio', | ||
] | ||
|
||
# add vtk if not windows and 2.7 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import pytest | ||
|
||
import numpy | ||
|
||
import pyvista | ||
|
||
from pyvista import examples | ||
|
||
|
||
beam = pyvista.UnstructuredGrid(examples.hexbeamfile) | ||
airplane = examples.load_airplane().cast_to_unstructured_grid() | ||
uniform = examples.load_uniform().cast_to_unstructured_grid() | ||
@pytest.mark.parametrize("mesh_in", [beam, airplane, uniform]) | ||
def test_meshio(mesh_in, tmpdir): | ||
# Save and read reference mesh using meshio | ||
filename = tmpdir.mkdir("tmpdir").join("test_mesh.vtk") | ||
pyvista.save_meshio(filename, mesh_in) | ||
mesh = pyvista.read_meshio(filename) | ||
|
||
# Assert mesh is still the same | ||
assert numpy.allclose(mesh_in.points, mesh.points) | ||
if (mesh_in.celltypes == 11).all(): | ||
cells = mesh_in.cells.reshape((mesh_in.n_cells, 9))[:,[0,1,2,4,3,5,6,8,7]].ravel() | ||
assert numpy.allclose(cells, mesh.cells) | ||
else: | ||
assert numpy.allclose(mesh_in.cells, mesh.cells) | ||
for k, v in mesh_in.point_arrays.items(): | ||
assert numpy.allclose(v, mesh.point_arrays[k.replace(" ", "_")]) | ||
for k, v in mesh_in.cell_arrays.items(): | ||
assert numpy.allclose(v, mesh.cell_arrays[k.replace(" ", "_")]) | ||
|
||
|
||
def test_file_format(): | ||
with pytest.raises(AssertionError): | ||
_ = pyvista.read_meshio(examples.hexbeamfile, file_format = "bar") | ||
|
||
with pytest.raises(KeyError): | ||
pyvista.save_meshio("foo.bar", beam, file_format = "bar") |