def test_read_uniform_grid_from_file(): grid = vtki.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_scalars == 2 assert grid.dimensions == [10, 10, 10]
def test_save(extension, binary, tmpdir): filename = str(tmpdir.mkdir("tmpdir").join('tmp.%s' % extension)) beam.save(filename, binary) grid = vtki.UnstructuredGrid(filename) assert grid.cells.shape == beam.cells.shape assert grid.points.shape == beam.points.shape grid = vtki.read(filename) assert grid.cells.shape == beam.cells.shape assert grid.points.shape == beam.points.shape assert isinstance(grid, vtki.UnstructuredGrid)
def load_frame_type(frame_num, dir_abs): """ Load the VTKI grid object for a frame number and specified directory (blood or drug). INPUTS: frame_num: the frame number to load, e.g. 100000 dir_abs: the absolute directory of data to load, e.g. 'd:/iacs/ac290/project2/data/RBC_0_Re10/DIRDATE_BloodFlow/VTK' """ # The filename of the .pvtu file for the requested frame filename = os.path.join(dir_abs, f'T{frame_num:010}.pvtu') # Read this file with VTKI ds = vtki.read(filename) return ds
def test_save_structured(extension, binary, tmpdir): filename = str(tmpdir.mkdir("tmpdir").join('tmp.%s' % extension)) sgrid.save(filename, binary) grid = vtki.StructuredGrid(filename) assert grid.x.shape == sgrid.y.shape assert grid.n_cells assert grid.points.shape == sgrid.points.shape grid = vtki.read(filename) assert grid.x.shape == sgrid.y.shape assert grid.n_cells assert grid.points.shape == sgrid.points.shape assert isinstance(grid, vtki.StructuredGrid)
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 = vtki.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 = vtki.read(filename) assert isinstance(grid, vtki.UniformGrid) assert grid.n_cells == ogrid.n_cells assert grid.origin == ogrid.origin assert grid.spacing == ogrid.spacing assert grid.dimensions == ogrid.dimensions
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 = vtki.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 = vtki.read(filename) assert isinstance(grid, vtki.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
def test_multi_block_io(extension, binary, tmpdir): filename = str(tmpdir.mkdir("tmpdir").join('tmp.%s' % extension)) multi = vtki.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_globe()) # Now check everything assert multi.n_blocks == 5 # Save it out multi.save(filename, binary) foo = vtki.MultiBlock(filename) assert foo.n_blocks == multi.n_blocks foo = vtki.read(filename) assert foo.n_blocks == multi.n_blocks
def test_read(tmpdir): fnames = (ex.antfile, ex.planefile, ex.hexbeamfile, ex.spherefile, ex.uniformfile, ex.rectfile) types = (vtki.PolyData, vtki.PolyData, vtki.UnstructuredGrid, vtki.PolyData, vtki.UniformGrid, vtki.RectilinearGrid) for i, filename in enumerate(fnames): obj = readers.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 = readers.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): data = vtki.read(filename)
def load_frame_pos(frame_num, dir_abs): """ Load position data for a frame number and specified directory (blood or drug). INPUTS: frame_num: the frame number to load, e.g. 100000 dir_abs: the absolute directory of data to load, e.g. 'd:/iacs/ac290/project2/data/RBC_0_Re10/DIRDATE_BloodFlow/VTK' """ # The filename of the .pvtu file for the requested frame filename = os.path.join(dir_abs, f'T{frame_num:010}.pvtu') # Read this file with VTKI ds = vtki.read(filename) # Extract the points point_pos = np.array(ds.points) # Extract the center of each cell cell_pos = ds.cell_centers().points # Compute the volume of each cell cell_vol = ds.compute_cell_sizes().cell_arrays['Volume'].astype(np.float32) # Return the points grid return point_pos, cell_pos, cell_vol
well_locs = pd.read_csv(gdc19.get_well_path('well_location_from_earth_model.csv')) well_locs = PVGeo.points_to_poly_data(well_locs[['x', 'y', 'z (land surface)']].values).clip_box( gdc19.get_roi_bounds(), invert=False) WELLS = gdc19.load_well_db() proposed = PVGeo.filters.AddCellConnToPoints().apply(WELLS.pop('well_new2'))#vtki.MultiBlock() well_5832 = PVGeo.filters.AddCellConnToPoints().apply(WELLS.pop('well_5832')) #well_5832.set_active_scalar('ECGR') well_Acord1 = PVGeo.filters.AddCellConnToPoints().apply(WELLS.pop('well_Acord1')) #well_Acord1 = WELLS.set_active_scalar('GR_SPLICE (GAPI)') ############################################################################### # load the gravity model gf = gdc19.get_gravity_path('forge_inverse_problem/RESULT_THRESHED.vtu') grav_model = vtki.read(gf) grav_model.active_scalar_name = 'Magnitude' ############################################################################### # Plotting Helpers # ++++++++++++++++ # # Functions for adding datasets to a scene in a consistent manner POINT_SIZE = 15 LINE_WIDTH = 15 vtki.rcParams['window_size'] = np.array([1024, 768]) * 2 legend_color = vtki.parse_color('lightgrey') ###############################################################################
Read a dataset from a known file type """ ################################################################################ # Loading a mesh is trivial. The following code block uses a built-in example # file, displays an airplane mesh, saves a screenshot, and returns the camera's # position: import vtki from vtki import examples import numpy as np import matplotlib.pyplot as plt # Get a sample file filename = examples.planefile mesh = vtki.read(filename) cpos = mesh.plot(color='orange') ################################################################################ # You can also take a screenshot without creating an interactive plot window using # the ``Plotter``: plotter = vtki.Plotter(off_screen=True) plotter.add_mesh(mesh, color='orange') plotter.show(auto_close=False) # plotter.screenshot('airplane.png') plotter.close() ################################################################################ # The ``img`` array can be used to plot the screenshot in ``matplotlib``:
def test_read_rectilinear_grid_from_file(): grid = vtki.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_scalars == 1
def load_channels(): """ Loads a uniform grid of fluvial channels in the subsurface """ return vtki.read(channelsfile)
def _download_and_read(filename, texture=False): saved_file, _ = _download_file(filename) if texture: return vtki.read_texture(saved_file) return vtki.read(saved_file)
def test_plot_rgb(): """"Test adding a texture to a plot""" image = vtki.read(examples.mapfile) plotter = vtki.Plotter(off_screen=OFF_SCREEN) plotter.add_mesh(image, rgb=True) plotter.plot()
def test_plot_multi_component_array(): """"Test adding a texture to a plot""" image = vtki.read(examples.mapfile) plotter = vtki.Plotter(off_screen=OFF_SCREEN) plotter.add_mesh(image) plotter.plot()
def download_blood_vessels(): """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') return vtki.read(filename)