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_bad_keyword_arguments():
"""Make sure bad keyword arguments raise an error"""
mesh = examples.load_uniform()
with pytest.raises(TypeError):
pyvista.plot(mesh, foo=5, off_screen=OFF_SCREEN)
with pytest.raises(TypeError):
pyvista.plot(mesh, scalar=mesh.active_scalars_name, off_screen=OFF_SCREEN)
with pytest.raises(TypeError):
plotter = pyvista.Plotter(off_screen=OFF_SCREEN)
plotter.add_mesh(mesh, scalar=mesh.active_scalars_name)
plotter.show()
with pytest.raises(TypeError):
plotter = pyvista.Plotter(off_screen=OFF_SCREEN)
plotter.add_mesh(mesh, foo="bad")
plotter.show()
def test_user_annotations_scalar_bar():
p = pyvista.Plotter(off_screen=OFF_SCREEN)
p.add_mesh(examples.load_uniform(), annotations={100.:'yum'})
p.show()
p = pyvista.Plotter(off_screen=OFF_SCREEN)
p.add_volume(examples.load_uniform(), annotations={100.:'yum'})
p.show()
def test_scalars_by_name():
plotter = pyvista.Plotter(off_screen=OFF_SCREEN)
data = examples.load_uniform()
plotter.add_mesh(data, scalars='Spatial Cell Data')
plotter.show()
def test_multi_block_volume():
multi = pyvista.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(None)
assert multi.volume
def test_merge_general():
mesh = examples.load_uniform()
thresh = mesh.threshold_percent([0.2, 0.5]) # unstructured grid
con = mesh.contour() # poly data
merged = thresh + con
assert isinstance(merged, pyvista.UnstructuredGrid)
merged = con + thresh
assert isinstance(merged, pyvista.UnstructuredGrid)
# Pure PolyData inputs should yield poly data output
merged = mesh.extract_surface() + con
assert isinstance(merged, pyvista.PolyData)
def test_cast_uniform_to_structured():
grid = examples.load_uniform()
structured = grid.cast_to_structured_grid()
assert structured.n_points == grid.n_points
assert structured.n_arrays == grid.n_arrays
assert structured.bounds == grid.bounds
def test_combine_filter():
multi = pyvista.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
# Now apply the geometry filter to combine a plethora of data blocks
geom = multi.combine()
assert isinstance(geom, pyvista.UnstructuredGrid)
"""
Rotate Points
~~~~~~~~~~~~~
This example will demonstrate how to rotate points in a `vtkPolyData` object around some origin on the XY plane.
THis example demos :class:`PVGeo.filters.RotatePoints`
"""
from pyvista import examples
from PVGeo.filters import RotatePoints
###############################################################################
# Get :class:`pyvista.PolyData` sample input to rotate
mesh = examples.load_uniform().cell_centers()
mesh.plot()
###############################################################################
# Use the filter:
rotated = RotatePoints(angle=33.3).apply(mesh)
rotated.plot()
output. The user can specify how they want to rename the array, can choose a
multiplier, and can choose from two types of common normalizations:
Feature Scaling and Standard Score.
This example demos :class:`PVGeo.filters.NormalizeArray`
"""
import numpy as np
import pyvista
from pyvista import examples
import PVGeo
from PVGeo.filters import NormalizeArray
###############################################################################
# Create some input data. this can be any `vtkDataObject`
mesh = examples.load_uniform()
title = 'Spatial Point Data'
mesh.plot(scalars=title)
###############################################################################
# Apply the filter
f = NormalizeArray(normalization='feature_scale', new_name='foo')
output = f.apply(mesh, title)
print(output)
###############################################################################
output.plot(scalars='foo')
plotter.camera_position = [
(-1.5, 1.5, 3.0),
(0.05, 0.6, 1.2),
(0.2, 0.9, -0.25)]
plotter.show()
###############################################################################
# Label Scalar Values
# +++++++++++++++++++
#
# This example will label pooints with their scalar values
mesh = examples.load_uniform().slice()
###############################################################################
p = pv.Plotter()
# Add the mesh:
p.add_mesh(mesh, scalars="Spatial Point Data", show_edges=True)
# Add the points with scalar labels:
p.add_point_scalar_labels(mesh, "Spatial Point Data", point_size=20, font_size=36)
# Use a nice camera position:
p.camera_position = [(7, 4, 5), (4.4, 7.0, 7.2), (0.8, 0.5, 0.25)]
p.show()