Ejemplo n.º 1
0
 def test_polyData(self, tmp_path):
     points = np.random.rand(3, 100)
     v = VTK.from_polyData(points)
     s = v.__repr__()
     v.write(os.path.join(tmp_path, 'polyData'))
     v = VTK.from_file(os.path.join(tmp_path, 'polyData.vtp'))
     assert (s == v.__repr__())
Ejemplo n.º 2
0
 def test_compress(self, tmp_path):
     points = np.random.rand(102, 3)
     v = VTK.from_poly_data(points)
     fname_c = tmp_path / 'compressed.vtp'
     fname_p = tmp_path / 'plain.vtp'
     v.save(fname_c, parallel=False, compress=False)
     v.save(fname_p, parallel=False, compress=True)
     assert (VTK.load(fname_c).__repr__() == VTK.load(fname_p).__repr__())
Ejemplo n.º 3
0
 def test_unstructuredGrid(self, tmp_path, cell_type, n):
     nodes = np.random.rand(n, 3)
     connectivity = np.random.choice(np.arange(n), n, False).reshape(-1, n)
     v = VTK.from_unstructuredGrid(nodes, connectivity, cell_type)
     s = v.__repr__()
     v.write(os.path.join(tmp_path, 'unstructuredGrid'))
     v = VTK.from_file(os.path.join(tmp_path, 'unstructuredGrid.vtu'))
     assert (s == v.__repr__())
Ejemplo n.º 4
0
 def test_rectilinearGrid(self, tmp_path):
     grid = np.random.randint(5, 10, 3) * 2
     size = np.random.random(3) + 1.0
     origin = np.random.random(3)
     v = VTK.from_rectilinearGrid(grid, size, origin)
     s = v.__repr__()
     v.write(os.path.join(tmp_path, 'rectilinearGrid'))
     v = VTK.from_file(os.path.join(tmp_path, 'rectilinearGrid.vtr'))
     assert (s == v.__repr__())
Ejemplo n.º 5
0
 def test_polyData(self, tmp_path):
     points = np.random.rand(100, 3)
     v = VTK.from_poly_data(points)
     string = v.__repr__()
     v.save(tmp_path / 'polyData', False)
     vtp = VTK.load(tmp_path / 'polyData.vtp')
     with open(tmp_path / 'polyData.vtk', 'w') as f:
         f.write(string)
     vtk = VTK.load(tmp_path / 'polyData.vtk', 'polyData')
     assert (string == vtp.__repr__() == vtk.__repr__())
Ejemplo n.º 6
0
 def test_compare_reference_polyData(self, update, ref_path, tmp_path):
     points = np.dstack((np.linspace(0., 1., 10), np.linspace(0., 2., 10),
                         np.linspace(-1., 1., 10))).squeeze()
     polyData = VTK.from_poly_data(points)
     polyData.add(points, 'coordinates')
     if update:
         polyData.save(ref_path / 'polyData')
     else:
         reference = VTK.load(ref_path / 'polyData.vtp')
         assert polyData.__repr__() == reference.__repr__() and \
                np.allclose(polyData.get('coordinates'),points)
Ejemplo n.º 7
0
 def test_unstructuredGrid(self, tmp_path, cell_type, n):
     nodes = np.random.rand(n, 3)
     connectivity = np.random.choice(np.arange(n), n, False).reshape(-1, n)
     v = VTK.from_unstructured_grid(nodes, connectivity, cell_type)
     string = v.__repr__()
     v.save(tmp_path / 'unstructuredGrid', False)
     vtu = VTK.load(tmp_path / 'unstructuredGrid.vtu')
     with open(tmp_path / 'unstructuredGrid.vtk', 'w') as f:
         f.write(string)
     vtk = VTK.load(tmp_path / 'unstructuredGrid.vtk', 'unstructuredgrid')
     assert (string == vtu.__repr__() == vtk.__repr__())
Ejemplo n.º 8
0
 def test_rectilinearGrid(self, tmp_path):
     cells = np.random.randint(5, 10, 3) * 2
     size = np.random.random(3) + 1.0
     origin = np.random.random(3)
     v = VTK.from_rectilinear_grid(cells, size, origin)
     string = v.__repr__()
     v.save(tmp_path / 'rectilinearGrid', False)
     vtr = VTK.load(tmp_path / 'rectilinearGrid.vtr')
     with open(tmp_path / 'rectilinearGrid.vtk', 'w') as f:
         f.write(string)
     vtk = VTK.load(tmp_path / 'rectilinearGrid.vtk', 'VTK_rectilinearGrid')
     assert (string == vtr.__repr__() == vtk.__repr__())
Ejemplo n.º 9
0
 def test_compare_reference_rectilinearGrid(self, update, reference_dir,
                                            tmp_path):
     grid = np.array([5, 6, 7], int)
     size = np.array([.6, 1., .5])
     rectilinearGrid = VTK.from_rectilinear_grid(grid, size)
     c = grid_filters.cell_coord0(grid, size).reshape(-1, 3, order='F')
     n = grid_filters.node_coord0(grid, size).reshape(-1, 3, order='F')
     rectilinearGrid.add(c, 'cell')
     rectilinearGrid.add(n, 'node')
     if update:
         rectilinearGrid.save(reference_dir / 'rectilinearGrid')
     else:
         reference = VTK.load(reference_dir / 'rectilinearGrid.vtr')
         assert rectilinearGrid.__repr__() == reference.__repr__() and \
                np.allclose(rectilinearGrid.get('cell'),c)
Ejemplo n.º 10
0
 def test_invalid_no_material(self, tmp_path):
     v = VTK.from_image_data(
         np.random.randint(5, 10, 3) * 2,
         np.random.random(3) + 1.0)
     v.save(tmp_path / 'no_materialpoint.vti', parallel=False)
     with pytest.raises(ValueError):
         Grid.load(tmp_path / 'no_materialpoint.vti')
Ejemplo n.º 11
0
 def test_get_grain_boundaries(self,update,ref_path,periodic,direction):
     grid = Grid.load(ref_path/'get_grain_boundaries_8g12x15x20.vtr')
     current = grid.get_grain_boundaries(periodic,direction)
     if update:
         current.save(ref_path/f'get_grain_boundaries_8g12x15x20_{direction}_{periodic}.vtu',parallel=False)
     reference = VTK.load(ref_path/f'get_grain_boundaries_8g12x15x20_{"".join(direction)}_{periodic}.vtu')
     assert current.__repr__() == reference.__repr__()
Ejemplo n.º 12
0
 def test_invalid_spacing(self,tmp_path,default):
     default.save(tmp_path/'spacing_ok.vtr')
     vtk = VTK.load(tmp_path/'spacing_ok.vtr')
     vtk.vtk_data.SetXCoordinates(np_to_vtk(np.sort(np.random.random(default.cells[0]))))
     vtk.save(tmp_path/'invalid_spacing.vtr',parallel=False)
     with pytest.raises(ValueError):
         Grid.load(tmp_path/'invalid_spacing.vtr')
Ejemplo n.º 13
0
 def test_compare_reference_rectilinearGrid(self, update, ref_path,
                                            tmp_path):
     cells = np.array([5, 6, 7], int)
     size = np.array([.6, 1., .5])
     rectilinearGrid = VTK.from_rectilinear_grid(cells, size)
     c = grid_filters.coordinates0_point(cells, size).reshape(-1,
                                                              3,
                                                              order='F')
     n = grid_filters.coordinates0_node(cells, size).reshape(-1,
                                                             3,
                                                             order='F')
     rectilinearGrid.add(np.ascontiguousarray(c), 'cell')
     rectilinearGrid.add(np.ascontiguousarray(n), 'node')
     if update:
         rectilinearGrid.save(ref_path / 'rectilinearGrid')
     else:
         reference = VTK.load(ref_path / 'rectilinearGrid.vtr')
         assert rectilinearGrid.__repr__() == reference.__repr__() and \
                np.allclose(rectilinearGrid.get('cell'),c)
Ejemplo n.º 14
0
 def test_parallel_out(self, tmp_path):
     points = np.random.rand(102, 3)
     v = VTK.from_poly_data(points)
     fname_s = tmp_path / 'single.vtp'
     fname_p = tmp_path / 'parallel.vtp'
     v.save(fname_s, False)
     v.save(fname_p, True)
     for i in range(10):
         if os.path.isfile(fname_p) and filecmp.cmp(fname_s, fname_p):
             assert (True)
             return
         time.sleep(.5)
     assert (False)
Ejemplo n.º 15
0
 def test_vtk(self, request, tmp_path, ref_path, update,
              patch_execution_stamp, patch_datetime_now, output, fname,
              inc):
     result = Result(ref_path / fname).view(increments=inc)
     os.chdir(tmp_path)
     result.export_VTK(output, parallel=False)
     fname = fname.split(
         '.')[0] + f'_inc{(inc if type(inc) == int else inc[0]):0>2}.vti'
     v = VTK.load(tmp_path / fname)
     v.set_comments('n/a')
     v.save(tmp_path / fname, parallel=False)
     with open(fname) as f:
         cur = hashlib.md5(f.read().encode()).hexdigest()
     if update:
         with open((ref_path / 'export_VTK' /
                    request.node.name).with_suffix('.md5'), 'w') as f:
             f.write(cur + '\n')
     with open((ref_path / 'export_VTK' /
                request.node.name).with_suffix('.md5')) as f:
         assert cur == f.read().strip('\n')
Ejemplo n.º 16
0
 def test_comments(self, tmp_path, default):
     default.add_comments(['this is a comment'])
     default.save(tmp_path / 'with_comments', parallel=False)
     new = VTK.load(tmp_path / 'with_comments.vtr')
     assert new.get_comments() == ['this is a comment']
Ejemplo n.º 17
0
 def test_invalid_vtr(self,tmp_path):
     v = VTK.from_rectilinear_grid(np.random.randint(5,10,3)*2,np.random.random(3) + 1.0)
     v.save(tmp_path/'no_materialpoint.vtr')
     with pytest.raises(ValueError):
         Geom.load(tmp_path/'no_materialpoint.vtr')
Ejemplo n.º 18
0
def default():
    """Simple VTK."""
    cells = np.array([5, 6, 7], int)
    size = np.array([.6, 1., .5])
    return VTK.from_image_data(cells, size)
Ejemplo n.º 19
0
 def test_filename_variations(self, tmp_path, fname):
     points = np.random.rand(102, 3)
     v = VTK.from_poly_data(points)
     v.save(tmp_path / fname)
Ejemplo n.º 20
0
 def test_invalid_dataset_type(self, name, dataset_type):
     with pytest.raises(TypeError):
         VTK.load(name, dataset_type)
Ejemplo n.º 21
0
 def test_invalid_dataset_type(self, tmp_path, fname, dataset_type):
     open(tmp_path / fname, 'a').close()
     with pytest.raises(TypeError):
         VTK.load(tmp_path / fname, dataset_type)
Ejemplo n.º 22
0
 def test_file_not_found(self):
     with pytest.raises(FileNotFoundError):
         VTK.load('/dev/null')
Ejemplo n.º 23
0
def default():
    """Simple VTK."""
    cells = np.array([5, 6, 7], int)
    size = np.array([.6, 1., .5])
    return VTK.from_rectilinear_grid(cells, size)