Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_compute_cell_sizes():
for i, dataset in enumerate(DATASETS):
result = dataset.compute_cell_sizes()
assert result is not None
assert isinstance(result, type(dataset))
assert 'Area' in result.array_names
assert 'Volume' in result.array_names
# Test the volume property
grid = pyvista.UniformGrid((10,10,10))
volume = float(np.prod(np.array(grid.dimensions) - 1))
assert np.allclose(grid.volume, volume)
# Now test composite data structures
output = COMPOSITE.compute_cell_sizes()
assert output.n_blocks == COMPOSITE.n_blocks
def test_uniform_setters():
grid = pyvista.UniformGrid()
grid.dimensions = [10, 10, 10]
assert grid.GetDimensions() == (10, 10, 10)
assert grid.dimensions == [10, 10, 10]
grid.spacing = [5, 2, 1]
assert grid.GetSpacing() == (5, 2, 1)
assert grid.spacing == [5, 2, 1]
grid.origin = [6, 27.7, 19.8]
assert grid.GetOrigin() == (6, 27.7, 19.8)
assert grid.origin == [6, 27.7, 19.8]
def load_uniform():
""" Loads a sample uniform grid """
return pyvista.UniformGrid(uniformfile)
This filter allows the user to select two input data arrays on which to perform
math operations. The input arrays are used in their order of selection for the
operations.
This example demos: :class:`PVGeo.filters.ArrayMath`
"""
import numpy as np
import pyvista
import PVGeo
from PVGeo.filters import ArrayMath
###############################################################################
# Create some input data. This can be any `vtkDataObject`
inp = pyvista.UniformGrid((10,10,4))
# Populate the tables
n = 400
arr0 = np.random.random(n)
arr1 = np.random.random(n)
inp['Array 0'] = arr0
inp['Array 1'] = arr1
###############################################################################
# Use the filter:
f = ArrayMath(operation='add', new_name='foo')
# Now get the result
output = f.apply(inp, 'Array 0', 'Array 1')
print(output)
###############################################################################
# Note that the output now has three arrays
def _from_image_data(self, image):
if not isinstance(image, pyvista.UniformGrid):
image = pyvista.UniformGrid(image)
self.SetInputDataObject(image)
return self.Update()
if multi_colors:
color = next(cycler)
else:
color = cmap
a = self.add_volume(block, resolution=block_resolution, opacity=opacity,
n_colors=n_colors, cmap=color, flip_scalars=flip_scalars,
reset_camera=reset_camera, name=next_name,
ambient=ambient, categories=categories, loc=loc,
backface_culling=backface_culling, rng=rng,
mapper=mapper, **kwargs)
actors.append(a)
return actors
if not isinstance(volume, pyvista.UniformGrid):
raise TypeError('Type ({}) not supported for volume rendering at this time. Use `pyvista.UniformGrid`.')
if scalars is None:
# Make sure scalar components are not vectors/tuples
scalars = volume.active_scalar
# Don't allow plotting of string arrays by default
if scalars is not None and np.issubdtype(scalars.dtype, np.number):
if stitle is None:
stitle = volume.active_scalar_info[1]
else:
raise RuntimeError('No scalars to use for volume rendering.')
elif isinstance(scalars, str):
pass
##############
grid.plot(show_edges=True)
###############################################################################
# Don't like cell data? You could also add the NumPy array to the point data of
# a :class:`pyvista.UniformGrid`. Take note of the subtle difference when
# setting the grid dimensions upon initialization.
# Create the 3D NumPy array of spatially referenced data
# This is spatially referenced such that the grid is 20 by 5 by 10
# (nx by ny by nz)
values = np.linspace(0, 10, 1000).reshape((20, 5, 10))
values.shape
# Create the spatial reference
grid = pv.UniformGrid()
# Set the grid dimensions: shape because we want to inject our values on the
# POINT data
grid.dimensions = values.shape
# Edit the spatial reference
grid.origin = (100, 33, 55.6) # The bottom left corner of the data set
grid.spacing = (1, 5, 2) # These are the cell sizes along each axis
# Add the data values to the cell data
grid.point_arrays["values"] = values.flatten(order="F") # Flatten the array!
# Now plot the grid!
grid.plot(show_edges=True)
def create_pyvista_grid(self) -> pv.grid.UniformGrid:
"""Generate UniformGrid object for 3D plotting of the seismic.
Args:
seismic (Seismic): Seismic object.
Returns:
(pv.grid.UniformGrid)
"""
grid = pv.UniformGrid()
grid.spacing = (1, 1, 1) # TODO: cell sizes? vertical exaggeration etc
grid.dimensions = np.array(self.data.shape) + 1
grid.cell_arrays["values"] = self.data.flatten(order="F")
# TODO: correct orientation of cube
return grid
###############################################################################
# Take a 3D NumPy array of data values that holds some spatial data where each
# axis corresponds to the XYZ cartesian axes. This example will create a
# :class:`pyvista.UniformGrid` object that will hold the spatial reference for
# a 3D grid which a 3D NumPy array of values can be plotted against.
###############################################################################
# Create the 3D NumPy array of spatially referenced data.
# This is spatially referenced such that the grid is 20 by 5 by 10
# (nx by ny by nz)
values = np.linspace(0, 10, 1000).reshape((20, 5, 10))
values.shape
# Create the spatial reference
grid = pv.UniformGrid()
# Set the grid dimensions: shape + 1 because we want to inject our values on
# the CELL data
grid.dimensions = np.array(values.shape) + 1
# Edit the spatial reference
grid.origin = (100, 33, 55.6) # The bottom left corner of the data set
grid.spacing = (1, 5, 2) # These are the cell sizes along each axis
# Add the data values to the cell data
grid.cell_arrays["values"] = values.flatten(order="F") # Flatten the array!
# Now plot the grid!
grid.plot(show_edges=True)