polishing

This commit is contained in:
Martin Diehl 2022-01-22 08:05:49 +01:00
parent a35a01d41b
commit 2bbc4c4e46
3 changed files with 35 additions and 35 deletions

View File

@ -70,7 +70,7 @@ class Grid:
]) ])
def __copy__(self) -> "Grid": def __copy__(self) -> 'Grid':
"""Create deep copy.""" """Create deep copy."""
return copy.deepcopy(self) return copy.deepcopy(self)
@ -161,7 +161,7 @@ class Grid:
@staticmethod @staticmethod
def load(fname: Union[str, Path]) -> "Grid": def load(fname: Union[str, Path]) -> 'Grid':
""" """
Load from VTK image data file. Load from VTK image data file.
@ -190,7 +190,7 @@ class Grid:
@typing. no_type_check @typing. no_type_check
@staticmethod @staticmethod
def load_ASCII(fname)-> "Grid": def load_ASCII(fname)-> 'Grid':
""" """
Load from geom file. Load from geom file.
@ -264,7 +264,7 @@ class Grid:
@staticmethod @staticmethod
def load_Neper(fname: Union[str, Path]) -> "Grid": def load_Neper(fname: Union[str, Path]) -> 'Grid':
""" """
Load from Neper VTK file. Load from Neper VTK file.
@ -279,7 +279,7 @@ class Grid:
Grid-based geometry from file. Grid-based geometry from file.
""" """
v = VTK.load(fname,'vtkImageData') v = VTK.load(fname,'ImageData')
cells = np.array(v.vtk_data.GetDimensions())-1 cells = np.array(v.vtk_data.GetDimensions())-1
bbox = np.array(v.vtk_data.GetBounds()).reshape(3,2).T bbox = np.array(v.vtk_data.GetBounds()).reshape(3,2).T
@ -292,7 +292,7 @@ class Grid:
def load_DREAM3D(fname: Union[str, Path], def load_DREAM3D(fname: Union[str, Path],
feature_IDs: str = None, cell_data: str = None, feature_IDs: str = None, cell_data: str = None,
phases: str = 'Phases', Euler_angles: str = 'EulerAngles', phases: str = 'Phases', Euler_angles: str = 'EulerAngles',
base_group: str = None) -> "Grid": base_group: str = None) -> 'Grid':
""" """
Load DREAM.3D (HDF5) file. Load DREAM.3D (HDF5) file.
@ -354,7 +354,7 @@ class Grid:
@staticmethod @staticmethod
def from_table(table: Table, def from_table(table: Table,
coordinates: str, coordinates: str,
labels: Union[str, Sequence[str]]) -> "Grid": labels: Union[str, Sequence[str]]) -> 'Grid':
""" """
Create grid from ASCII table. Create grid from ASCII table.
@ -453,7 +453,7 @@ class Grid:
size: FloatSequence, size: FloatSequence,
seeds: np.ndarray, seeds: np.ndarray,
material: IntSequence = None, material: IntSequence = None,
periodic: bool = True) -> "Grid": periodic: bool = True) -> 'Grid':
""" """
Create grid from Voronoi tessellation. Create grid from Voronoi tessellation.
@ -539,7 +539,7 @@ class Grid:
surface: str, surface: str,
threshold: float = 0.0, threshold: float = 0.0,
periods: int = 1, periods: int = 1,
materials: IntSequence = (0,1)) -> "Grid": materials: IntSequence = (0,1)) -> 'Grid':
""" """
Create grid from definition of triply periodic minimal surface. Create grid from definition of triply periodic minimal surface.
@ -685,7 +685,7 @@ class Grid:
fill: int = None, fill: int = None,
R: Rotation = Rotation(), R: Rotation = Rotation(),
inverse: bool = False, inverse: bool = False,
periodic: bool = True) -> "Grid": periodic: bool = True) -> 'Grid':
""" """
Insert a primitive geometric object at a given position. Insert a primitive geometric object at a given position.
@ -770,7 +770,7 @@ class Grid:
) )
def mirror(self, directions: Sequence[str], reflect: bool = False) -> "Grid": def mirror(self, directions: Sequence[str], reflect: bool = False) -> 'Grid':
""" """
Mirror grid along given directions. Mirror grid along given directions.
@ -822,7 +822,7 @@ class Grid:
) )
def flip(self, directions: Union[Literal['x', 'y', 'z'], Sequence[Literal['x', 'y', 'z']]]) -> "Grid": def flip(self, directions: Union[Literal['x', 'y', 'z'], Sequence[Literal['x', 'y', 'z']]]) -> 'Grid':
""" """
Flip grid along given directions. Flip grid along given directions.
@ -852,7 +852,7 @@ class Grid:
) )
def scale(self, cells: IntSequence, periodic: bool = True) -> "Grid": def scale(self, cells: IntSequence, periodic: bool = True) -> 'Grid':
""" """
Scale grid to new cells. Scale grid to new cells.
@ -899,7 +899,7 @@ class Grid:
def clean(self, def clean(self,
stencil: int = 3, stencil: int = 3,
selection: IntSequence = None, selection: IntSequence = None,
periodic: bool = True) -> "Grid": periodic: bool = True) -> 'Grid':
""" """
Smooth grid by selecting most frequent material index within given stencil at each location. Smooth grid by selecting most frequent material index within given stencil at each location.
@ -939,7 +939,7 @@ class Grid:
) )
def renumber(self) -> "Grid": def renumber(self) -> 'Grid':
""" """
Renumber sorted material indices as 0,...,N-1. Renumber sorted material indices as 0,...,N-1.
@ -958,7 +958,7 @@ class Grid:
) )
def rotate(self, R: Rotation, fill: int = None) -> "Grid": def rotate(self, R: Rotation, fill: int = None) -> 'Grid':
""" """
Rotate grid (pad if required). Rotate grid (pad if required).
@ -998,7 +998,7 @@ class Grid:
def canvas(self, def canvas(self,
cells: IntSequence = None, cells: IntSequence = None,
offset: IntSequence = None, offset: IntSequence = None,
fill: int = None) -> "Grid": fill: int = None) -> 'Grid':
""" """
Crop or enlarge/pad grid. Crop or enlarge/pad grid.
@ -1049,7 +1049,7 @@ class Grid:
) )
def substitute(self, from_material: IntSequence, to_material: IntSequence) -> "Grid": def substitute(self, from_material: IntSequence, to_material: IntSequence) -> 'Grid':
""" """
Substitute material indices. Substitute material indices.
@ -1077,7 +1077,7 @@ class Grid:
) )
def sort(self) -> "Grid": def sort(self) -> 'Grid':
""" """
Sort material indices such that min(material) is located at (0,0,0). Sort material indices such that min(material) is located at (0,0,0).
@ -1103,7 +1103,7 @@ class Grid:
vicinity: int = 1, vicinity: int = 1,
offset: int = None, offset: int = None,
trigger: IntSequence = [], trigger: IntSequence = [],
periodic: bool = True) -> "Grid": periodic: bool = True) -> 'Grid':
""" """
Offset material index of points in the vicinity of xxx. Offset material index of points in the vicinity of xxx.

View File

@ -2,7 +2,7 @@ import os
import warnings import warnings
import multiprocessing as mp import multiprocessing as mp
from pathlib import Path from pathlib import Path
from typing import Union, Optional, Literal, List from typing import Union, Literal, List
import numpy as np import numpy as np
import vtk import vtk
@ -10,7 +10,7 @@ from vtk.util.numpy_support import numpy_to_vtk as np_to_vtk
from vtk.util.numpy_support import numpy_to_vtkIdTypeArray as np_to_vtkIdTypeArray from vtk.util.numpy_support import numpy_to_vtkIdTypeArray as np_to_vtkIdTypeArray
from vtk.util.numpy_support import vtk_to_numpy as vtk_to_np from vtk.util.numpy_support import vtk_to_numpy as vtk_to_np
from ._typehints import FloatSequence from ._typehints import FloatSequence, IntSequence
from . import util from . import util
from . import Table from . import Table
@ -38,8 +38,7 @@ class VTK:
@staticmethod @staticmethod
#ITERABLES PROPER def from_image_data(cells: IntSequence, size: FloatSequence, origin: FloatSequence = np.zeros(3)) -> 'VTK':
def from_image_data(cells: np.ndarray, size: np.ndarray, origin: Optional[np.ndarray] = np.zeros(3)) -> "VTK":
""" """
Create VTK of type vtk.vtkImageData. Create VTK of type vtk.vtkImageData.
@ -63,13 +62,13 @@ class VTK:
vtk_data = vtk.vtkImageData() vtk_data = vtk.vtkImageData()
vtk_data.SetDimensions(*(np.array(cells)+1)) vtk_data.SetDimensions(*(np.array(cells)+1))
vtk_data.SetOrigin(*(np.array(origin))) vtk_data.SetOrigin(*(np.array(origin)))
vtk_data.SetSpacing(*(size/cells)) vtk_data.SetSpacing(*(np.array(size)/np.array(cells)))
return VTK(vtk_data) return VTK(vtk_data)
@staticmethod @staticmethod
def from_rectilinear_grid(grid: np.ndarray, size: FloatSequence, origin: FloatSequence = np.zeros(3)) -> "VTK": def from_rectilinear_grid(grid: np.ndarray, size: FloatSequence, origin: FloatSequence = np.zeros(3)) -> 'VTK':
""" """
Create VTK of type vtk.vtkRectilinearGrid. Create VTK of type vtk.vtkRectilinearGrid.
@ -101,7 +100,7 @@ class VTK:
@staticmethod @staticmethod
def from_unstructured_grid(nodes: np.ndarray, connectivity: np.ndarray, cell_type: str) -> "VTK": def from_unstructured_grid(nodes: np.ndarray, connectivity: np.ndarray, cell_type: str) -> 'VTK':
""" """
Create VTK of type vtk.vtkUnstructuredGrid. Create VTK of type vtk.vtkUnstructuredGrid.
@ -141,7 +140,7 @@ class VTK:
@staticmethod @staticmethod
def from_poly_data(points: np.ndarray) -> "VTK": def from_poly_data(points: np.ndarray) -> 'VTK':
""" """
Create VTK of type vtk.polyData. Create VTK of type vtk.polyData.
@ -176,15 +175,16 @@ class VTK:
@staticmethod @staticmethod
def load(fname: Union[str, Path], def load(fname: Union[str, Path],
dataset_type: Literal['vtkImageData', 'vtkRectilinearGrid', 'vtkUnstructuredGrid', 'vtkPolyData'] = None) -> "VTK": dataset_type: Literal['ImageData', 'UnstructuredGrid', 'PolyData'] = None) -> 'VTK':
""" """
Load from VTK file. Load from VTK file.
Parameters Parameters
---------- ----------
fname : str or pathlib.Path fname : str or pathlib.Path
Filename for reading. Valid extensions are .vti, .vtr, .vtu, .vtp, and .vtk. Filename for reading.
dataset_type : {'vtkImageData', ''vtkRectilinearGrid', 'vtkUnstructuredGrid', 'vtkPolyData'}, optional Valid extensions are .vti, .vtr, .vtu, .vtp, and .vtk.
dataset_type : {'ImageData', 'UnstructuredGrid', 'PolyData'}, optional
Name of the vtk.vtkDataSet subclass when opening a .vtk file. Name of the vtk.vtkDataSet subclass when opening a .vtk file.
Returns Returns
@ -423,7 +423,7 @@ class VTK:
return writer.GetOutputString() return writer.GetOutputString()
def show(self) -> None: def show(self):
""" """
Render. Render.

View File

@ -9,14 +9,14 @@ import re
import fractions import fractions
import collections.abc as abc import collections.abc as abc
from functools import reduce from functools import reduce
from typing import Union, Tuple, Iterable, Sequence, Callable, Dict, List, Any, Literal, Optional from typing import Union, Tuple, Iterable, Callable, Dict, List, Any, Literal, Optional
from pathlib import Path from pathlib import Path
import numpy as np import numpy as np
import h5py import h5py
from . import version from . import version
from ._typehints import FloatSequence, IntSequence from ._typehints import FloatSequence
# limit visibility # limit visibility
__all__=[ __all__=[