Skip to content

Commit

Permalink
apply blackdoc to python source
Browse files Browse the repository at this point in the history
  • Loading branch information
akaszynski committed Mar 11, 2023
1 parent a313b23 commit 5ff97bb
Show file tree
Hide file tree
Showing 46 changed files with 451 additions and 408 deletions.
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Expand Up @@ -4,6 +4,13 @@ repos:
hooks:
- id: black

- repo: https://github.com/keewis/blackdoc
rev: v0.3.8
hooks:
- id: blackdoc
files: '\.py$'
exclude: pyvista/plotting/charts.py

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
Expand Down
21 changes: 13 additions & 8 deletions pyvista/core/celltype.py
Expand Up @@ -23,14 +23,19 @@ class CellType(IntEnum):
>>> import pyvista
>>> cells = np.array([8, 0, 1, 2, 3, 4, 5, 6, 7])
>>> cell_type = np.array([CellType.HEXAHEDRON], np.int8)
>>> points = np.array([[0, 0, 0],
... [1, 0, 0],
... [1, 1, 0],
... [0, 1, 0],
... [0, 0, 1],
... [1, 0, 1],
... [1, 1, 1],
... [0, 1, 1]], dtype=np.float32)
>>> points = np.array(
... [
... [0, 0, 0],
... [1, 0, 0],
... [1, 1, 0],
... [0, 1, 0],
... [0, 0, 1],
... [1, 0, 1],
... [1, 1, 1],
... [0, 1, 1],
... ],
... dtype=np.float32,
... )
>>> grid = pyvista.UnstructuredGrid(cells, cell_type, points)
>>> grid # doctest:+SKIP
UnstructuredGrid (0x7f5b0a55e1a0)
Expand Down
7 changes: 4 additions & 3 deletions pyvista/core/composite.py
Expand Up @@ -60,8 +60,7 @@ class MultiBlock(
Instantiate from a list of objects.
>>> data = [pv.Sphere(center=(2, 0, 0)), pv.Cube(center=(0, 2, 0)),
... pv.Cone()]
>>> data = [pv.Sphere(center=(2, 0, 0)), pv.Cube(center=(0, 2, 0)), pv.Cone()]
>>> blocks = pv.MultiBlock(data)
>>> blocks.plot()
Expand All @@ -75,9 +74,11 @@ class MultiBlock(
>>> for name in blocks.keys():
... block = blocks[name]
...
>>> for block in blocks:
... surf = block.extract_surface() # Do something with each dataset
...
"""

Expand Down Expand Up @@ -543,7 +544,7 @@ def replace(self, index: int, dataset: Optional[_TypeMultiBlockLeaf]) -> None:
>>> blocks.replace(1, pv.Sphere(center=(10, 10, 10)))
>>> blocks.keys()
['cube', 'sphere']
>>> np.allclose(blocks[1].center, [10., 10., 10.])
>>> np.allclose(blocks[1].center, [10.0, 10.0, 10.0])
True
"""
Expand Down
3 changes: 1 addition & 2 deletions pyvista/core/dataobject.py
Expand Up @@ -366,8 +366,7 @@ def add_field_data(self, array: np.ndarray, name: str, deep=True):
Add field data to a UniformGrid dataset.
>>> mesh = pyvista.UniformGrid(dimensions=(2, 2, 1))
>>> mesh.add_field_data(['I could', 'write', 'notes', 'here'],
... 'my-field-data')
>>> mesh.add_field_data(['I could', 'write', 'notes', 'here'], 'my-field-data')
>>> mesh['my-field-data']
pyvista_ndarray(['I could', 'write', 'notes', 'here'], dtype='<U7')
Expand Down
13 changes: 6 additions & 7 deletions pyvista/core/dataset.py
Expand Up @@ -373,7 +373,7 @@ def points(self) -> pyvista_ndarray:
You can also update the points in-place:
>>> cube.points[...] = 2*points
>>> cube.points[...] = 2 * points
>>> cube.points
pyvista_ndarray([[-1., -1., 1.],
[-1., -1., 3.],
Expand Down Expand Up @@ -2286,8 +2286,7 @@ def find_closest_cell(
>>> unit_square = pyvista.Rectangle()
>>> index, closest_point = unit_square.find_closest_cell(
... [0.25, 0.25, 0.5],
... return_closest_point=True
... [0.25, 0.25, 0.5], return_closest_point=True
... )
>>> closest_point
array([0.25, 0.25, 0. ])
Expand All @@ -2297,8 +2296,7 @@ def find_closest_cell(
desired, see :func:`DataSet.find_closest_point`.
>>> index, closest_point = unit_square.find_closest_cell(
... [1.0, 1.0, 0.5],
... return_closest_point=True
... [1.0, 1.0, 0.5], return_closest_point=True
... )
>>> closest_point
array([1., 1., 0.])
Expand Down Expand Up @@ -2368,7 +2366,7 @@ def find_containing_cell(
containing the point ``[0.3, 0.3, 0.0]`` is found.
>>> import pyvista
>>> mesh = pyvista.UniformGrid(dimensions=[5, 5, 1], spacing=[1/4, 1/4, 0])
>>> mesh = pyvista.UniformGrid(dimensions=[5, 5, 1], spacing=[1 / 4, 1 / 4, 0])
>>> mesh
UniformGrid...
>>> mesh.find_containing_cell([0.3, 0.3, 0.0])
Expand Down Expand Up @@ -2575,9 +2573,10 @@ def cell(self) -> Iterator['pyvista.Cell']:
Loop over the cells
>>> import pyvista as pv
>>> mesh = pv.UniformGrid(dimensions=(3, 3, 1)) # 9 points, 4 cells
>>> mesh = pv.UniformGrid(dimensions=(3, 3, 1)) # 9 points, 4 cells
>>> for cell in mesh.cell: # doctest: +SKIP
... cell
...
"""
for i in range(self.n_cells):
Expand Down
9 changes: 4 additions & 5 deletions pyvista/core/datasetattributes.py
Expand Up @@ -913,7 +913,7 @@ def items(self) -> List[Tuple[str, pyvista_ndarray]]:
>>> import pyvista
>>> mesh = pyvista.Cube()
>>> mesh.clear_data()
>>> mesh.cell_data['data0'] = [0]*mesh.n_cells
>>> mesh.cell_data['data0'] = [0] * mesh.n_cells
>>> mesh.cell_data['data1'] = range(mesh.n_cells)
>>> mesh.cell_data.items()
[('data0', pyvista_ndarray([0, 0, 0, 0, 0, 0])), ('data1', pyvista_ndarray([0, 1, 2, 3, 4, 5]))]
Expand All @@ -934,7 +934,7 @@ def keys(self) -> List[str]:
>>> import pyvista
>>> mesh = pyvista.Sphere()
>>> mesh.clear_data()
>>> mesh.point_data['data0'] = [0]*mesh.n_points
>>> mesh.point_data['data0'] = [0] * mesh.n_points
>>> mesh.point_data['data1'] = range(mesh.n_points)
>>> mesh.point_data.keys()
['data0', 'data1']
Expand Down Expand Up @@ -966,7 +966,7 @@ def values(self) -> List[pyvista_ndarray]:
>>> import pyvista
>>> mesh = pyvista.Cube()
>>> mesh.clear_data()
>>> mesh.cell_data['data0'] = [0]*mesh.n_cells
>>> mesh.cell_data['data0'] = [0] * mesh.n_cells
>>> mesh.cell_data['data1'] = range(mesh.n_cells)
>>> mesh.cell_data.values()
[pyvista_ndarray([0, 0, 0, 0, 0, 0]), pyvista_ndarray([0, 1, 2, 3, 4, 5])]
Expand Down Expand Up @@ -1096,8 +1096,7 @@ def active_vectors_name(self) -> Optional[str]:
>>> import pyvista
>>> import numpy as np
>>> mesh = pyvista.Sphere()
>>> mesh.point_data.set_vectors(np.random.random((mesh.n_points, 3)),
... 'my-vectors')
>>> mesh.point_data.set_vectors(np.random.random((mesh.n_points, 3)), 'my-vectors')
>>> mesh.point_data.active_vectors_name
'my-vectors'
Expand Down
7 changes: 3 additions & 4 deletions pyvista/core/filters/composite.py
Expand Up @@ -52,10 +52,9 @@ def combine(self, merge_points=False, tolerance=0.0):
Combine blocks within a multiblock without merging points.
>>> import pyvista
>>> block = pyvista.MultiBlock([
... pyvista.Cube(clean=False),
... pyvista.Cube(center=(1, 0, 0), clean=False)
... ])
>>> block = pyvista.MultiBlock(
... [pyvista.Cube(clean=False), pyvista.Cube(center=(1, 0, 0), clean=False)]
... )
>>> merged = block.combine()
>>> merged.n_points
48
Expand Down
72 changes: 37 additions & 35 deletions pyvista/core/filters/data_set.py
Expand Up @@ -393,7 +393,9 @@ def clip_scalar(
>>> import pyvista as pv
>>> from pyvista import examples
>>> dataset = examples.load_hexbeam()
>>> _below, _above = dataset.clip_scalar(scalars="sample_point_scalars", value=100, both=True)
>>> _below, _above = dataset.clip_scalar(
... scalars="sample_point_scalars", value=100, both=True
... )
Remove the part of the mesh with "sample_point_scalars" below 100.
Expand Down Expand Up @@ -900,8 +902,7 @@ def slice_along_line(self, line, generate_triangles=False, contour=False, progre
>>> pl = pyvista.Plotter()
>>> _ = pl.add_mesh(hills, smooth_shading=True, style='wireframe')
>>> _ = pl.add_mesh(line_slice, line_width=10, render_lines_as_tubes=True,
... color='k')
>>> _ = pl.add_mesh(line_slice, line_width=10, render_lines_as_tubes=True, color='k')
>>> _ = pl.add_mesh(arc, line_width=10, color='grey')
>>> pl.show()
Expand Down Expand Up @@ -1051,16 +1052,14 @@ def threshold(
>>> import pyvista
>>> noise = pyvista.perlin_noise(0.1, (1, 1, 1), (0, 0, 0))
>>> grid = pyvista.sample_function(noise, [0, 1.0, -0, 1.0, 0, 1.0],
... dim=(20, 20, 20))
>>> grid = pyvista.sample_function(noise, [0, 1.0, -0, 1.0, 0, 1.0], dim=(20, 20, 20))
>>> grid.plot(cmap='gist_earth_r', show_scalar_bar=True, show_edges=False)
Next, apply the threshold.
>>> import pyvista
>>> noise = pyvista.perlin_noise(0.1, (1, 1, 1), (0, 0, 0))
>>> grid = pyvista.sample_function(noise, [0, 1.0, -0, 1.0, 0, 1.0],
... dim=(20, 20, 20))
>>> grid = pyvista.sample_function(noise, [0, 1.0, -0, 1.0, 0, 1.0], dim=(20, 20, 20))
>>> threshed = grid.threshold(value=0.02)
>>> threshed.plot(cmap='gist_earth_r', show_scalar_bar=False, show_edges=True)
Expand Down Expand Up @@ -1183,8 +1182,7 @@ def threshold_percent(
>>> import pyvista
>>> noise = pyvista.perlin_noise(0.1, (2, 2, 2), (0, 0, 0))
>>> grid = pyvista.sample_function(noise, [0, 1.0, -0, 1.0, 0, 1.0],
... dim=(30, 30, 30))
>>> grid = pyvista.sample_function(noise, [0, 1.0, -0, 1.0, 0, 1.0], dim=(30, 30, 30))
>>> threshed = grid.threshold_percent(0.5)
>>> threshed.plot(cmap='gist_earth_r', show_scalar_bar=False, show_edges=True)
Expand Down Expand Up @@ -1601,29 +1599,34 @@ def contour(
>>> a = 0.4
>>> b = 0.1
>>> def f(x, y, z):
... xx = x*x
... yy = y*y
... zz = z*z
... xyz = x*y*z
... xx = x * x
... yy = y * y
... zz = z * z
... xyz = x * y * z
... xx_yy = xx + yy
... a_xx = a*xx
... b_yy = b*yy
... a_xx = a * xx
... b_yy = b * yy
... return (
... (xx_yy + 1) * (a_xx + b_yy)
... + zz * (b * xx + a * yy) - 2 * (a - b) * xyz
... + zz * (b * xx + a * yy)
... - 2 * (a - b) * xyz
... - a * b * xx_yy
... )**2 - 4 * (xx + yy) * (a_xx + b_yy - xyz * (a - b))**2
... ) ** 2 - 4 * (xx + yy) * (a_xx + b_yy - xyz * (a - b)) ** 2
...
>>> n = 100
>>> x_min, y_min, z_min = -1.35, -1.7, -0.65
>>> grid = pv.UniformGrid(
... dimensions=(n, n, n),
... spacing=(abs(x_min)/n*2, abs(y_min)/n*2, abs(z_min)/n*2),
... spacing=(abs(x_min) / n * 2, abs(y_min) / n * 2, abs(z_min) / n * 2),
... origin=(x_min, y_min, z_min),
... )
>>> x, y, z = grid.points.T
>>> values = f(x, y, z)
>>> out = grid.contour(
... 1, scalars=values, rng=[0, 0], method='flying_edges',
... 1,
... scalars=values,
... rng=[0, 0],
... method='flying_edges',
... )
>>> out.plot(color='tan', smooth_shading=True)
Expand Down Expand Up @@ -1943,8 +1946,9 @@ def cell_centers(self, vertex=True, progress_bar=False):
>>> centers = mesh.cell_centers()
>>> pl = pyvista.Plotter()
>>> actor = pl.add_mesh(mesh, show_edges=True)
>>> actor = pl.add_points(centers, render_points_as_spheres=True,
... color='red', point_size=20)
>>> actor = pl.add_points(
... centers, render_points_as_spheres=True, color='red', point_size=20
... )
>>> pl.show()
See :ref:`cell_centers_example` for more examples using this filter.
Expand Down Expand Up @@ -2043,8 +2047,7 @@ def glyph(
>>> arrows = mesh.glyph(scale="Normals", orient="Normals", tolerance=0.05)
>>> pl = pyvista.Plotter()
>>> actor = pl.add_mesh(arrows, color="black")
>>> actor = pl.add_mesh(mesh, scalars="Elevation", cmap="terrain",
... show_scalar_bar=False)
>>> actor = pl.add_mesh(mesh, scalars="Elevation", cmap="terrain", show_scalar_bar=False)
>>> pl.show()
See :ref:`glyph_example` and :ref:`glyph_table_example` for more
Expand Down Expand Up @@ -2813,8 +2816,7 @@ def select_enclosed_points(
>>> sphere = pyvista.Sphere()
>>> plane = pyvista.Plane()
>>> selected = plane.select_enclosed_points(sphere)
>>> pts = plane.extract_points(selected['SelectedPoints'].view(bool),
... adjacent_cells=False)
>>> pts = plane.extract_points(selected['SelectedPoints'].view(bool), adjacent_cells=False)
>>> pl = pyvista.Plotter()
>>> _ = pl.add_mesh(sphere, style='wireframe')
>>> _ = pl.add_points(pts, color='r')
Expand Down Expand Up @@ -3538,9 +3540,9 @@ def streamlines_evenly_spaced_2D(
>>> import pyvista
>>> from pyvista import examples
>>> mesh = examples.download_cylinder_crossflow()
>>> streams = mesh[0].streamlines_evenly_spaced_2D(start_position=(4, 0.1, 0.),
... separating_distance=3,
... separating_distance_ratio=0.2)
>>> streams = mesh[0].streamlines_evenly_spaced_2D(
... start_position=(4, 0.1, 0.0), separating_distance=3, separating_distance_ratio=0.2
... )
>>> plotter = pyvista.Plotter()
>>> _ = plotter.add_mesh(streams.tube(radius=0.02), scalars="vorticity_mag")
>>> plotter.view_xy()
Expand Down Expand Up @@ -3840,7 +3842,9 @@ def sample_over_multiple_lines(self, points, tolerance=None, progress_bar=False)
>>> plane = pyvista.Plane()
>>> plane.clear_data()
>>> plane = plane.interpolate(pdata, sharpness=3.5)
>>> sample = plane.sample_over_multiple_lines([[-0.5, -0.5, 0], [0.5, -0.5, 0], [0.5, 0.5, 0]])
>>> sample = plane.sample_over_multiple_lines(
... [[-0.5, -0.5, 0], [0.5, -0.5, 0], [0.5, 0.5, 0]]
... )
>>> pl = pyvista.Plotter()
>>> _ = pl.add_mesh(pdata, render_points_as_spheres=True, point_size=50)
>>> _ = pl.add_mesh(sample, scalars='values', line_width=10)
Expand Down Expand Up @@ -3978,8 +3982,7 @@ def sample_over_circular_arc_normal(
>>> normal = [0, 0, 1]
>>> polar = [0, 9, 0]
>>> center = [uniform.bounds[1], uniform.bounds[2], uniform.bounds[5]]
>>> arc = uniform.sample_over_circular_arc_normal(center, normal=normal,
... polar=polar)
>>> arc = uniform.sample_over_circular_arc_normal(center, normal=normal, polar=polar)
>>> pl = pyvista.Plotter()
>>> _ = pl.add_mesh(uniform, style='wireframe')
>>> _ = pl.add_mesh(arc, line_width=10)
Expand Down Expand Up @@ -5084,10 +5087,9 @@ def transform(
``vtk.vtkMatrix4x4`` and ``vtk.vtkTransform`` are also
accepted.
>>> transform_matrix = np.array([[1, 0, 0, 50],
... [0, 1, 0, 100],
... [0, 0, 1, 200],
... [0, 0, 0, 1]])
>>> transform_matrix = np.array(
... [[1, 0, 0, 50], [0, 1, 0, 100], [0, 0, 1, 200], [0, 0, 0, 1]]
... )
>>> transformed = mesh.transform(transform_matrix)
>>> transformed.plot(show_edges=True)
Expand Down

0 comments on commit 5ff97bb

Please sign in to comment.