Merge branch 'fix-mypy-no-implicit-optional' into 'development'
PEP 484 compatibility (no-implicit-optional in mypy) See merge request damask/DAMASK!664
This commit is contained in:
commit
92ae86b636
|
@ -2,7 +2,7 @@ import os
|
|||
import json
|
||||
import functools
|
||||
import colorsys
|
||||
from typing import Union, TextIO
|
||||
from typing import Optional, Union, TextIO
|
||||
from itertools import chain
|
||||
|
||||
import numpy as np
|
||||
|
@ -275,8 +275,8 @@ class Colormap(mpl.colors.ListedColormap):
|
|||
|
||||
def shade(self,
|
||||
field: np.ndarray,
|
||||
bounds: FloatSequence = None,
|
||||
gap: float = None) -> Image:
|
||||
bounds: Optional[FloatSequence] = None,
|
||||
gap: Optional[float] = None) -> Image:
|
||||
"""
|
||||
Generate PIL image of 2D field using colormap.
|
||||
|
||||
|
@ -315,7 +315,7 @@ class Colormap(mpl.colors.ListedColormap):
|
|||
|
||||
|
||||
def reversed(self,
|
||||
name: str = None) -> 'Colormap':
|
||||
name: Optional[str] = None) -> 'Colormap':
|
||||
"""
|
||||
Reverse.
|
||||
|
||||
|
@ -364,7 +364,7 @@ class Colormap(mpl.colors.ListedColormap):
|
|||
|
||||
|
||||
def save_paraview(self,
|
||||
fname: FileHandle = None):
|
||||
fname: Optional[FileHandle] = None):
|
||||
"""
|
||||
Save as JSON file for use in Paraview.
|
||||
|
||||
|
@ -388,7 +388,7 @@ class Colormap(mpl.colors.ListedColormap):
|
|||
|
||||
|
||||
def save_ASCII(self,
|
||||
fname: FileHandle = None):
|
||||
fname: Optional[FileHandle] = None):
|
||||
"""
|
||||
Save as ASCII file.
|
||||
|
||||
|
@ -403,7 +403,7 @@ class Colormap(mpl.colors.ListedColormap):
|
|||
t.save(self._get_file_handle(fname,'.txt'))
|
||||
|
||||
|
||||
def save_GOM(self, fname: FileHandle = None):
|
||||
def save_GOM(self, fname: Optional[FileHandle] = None):
|
||||
"""
|
||||
Save as ASCII file for use in GOM Aramis.
|
||||
|
||||
|
@ -424,7 +424,7 @@ class Colormap(mpl.colors.ListedColormap):
|
|||
|
||||
|
||||
def save_gmsh(self,
|
||||
fname: FileHandle = None):
|
||||
fname: Optional[FileHandle] = None):
|
||||
"""
|
||||
Save as ASCII file for use in gmsh.
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ import copy
|
|||
from io import StringIO
|
||||
from collections.abc import Iterable
|
||||
import abc
|
||||
from typing import Union, Dict, Any, Type, TypeVar
|
||||
from typing import Optional, Union, Dict, Any, Type, TypeVar
|
||||
|
||||
import numpy as np
|
||||
import yaml
|
||||
|
@ -21,7 +21,7 @@ class NiceDumper(yaml.SafeDumper):
|
|||
"""Make YAML readable for humans."""
|
||||
|
||||
def write_line_break(self,
|
||||
data: str = None):
|
||||
data: Optional[str] = None):
|
||||
super().write_line_break(data)
|
||||
|
||||
if len(self.indents) == 1:
|
||||
|
@ -53,7 +53,7 @@ class Config(dict):
|
|||
"""YAML-based configuration."""
|
||||
|
||||
def __init__(self,
|
||||
yml: Union[str, Dict[str, Any]] = None,
|
||||
yml: Union[None, str, Dict[str, Any]] = None,
|
||||
**kwargs):
|
||||
"""Initialize from YAML, dict, or key=value pairs."""
|
||||
if isinstance(yml,str):
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import numpy as np
|
||||
import h5py
|
||||
from typing import Union, Sequence, Dict, Any, Collection
|
||||
from typing import Optional, Union, Sequence, Dict, Any, Collection
|
||||
|
||||
from ._typehints import FileHandle
|
||||
from . import Config
|
||||
|
@ -22,7 +22,7 @@ class ConfigMaterial(Config):
|
|||
"""
|
||||
|
||||
def __init__(self,
|
||||
d: Dict[str, Any] = None,
|
||||
d: Optional[Dict[str, Any]] = None,
|
||||
**kwargs):
|
||||
"""
|
||||
New material configuration.
|
||||
|
@ -83,13 +83,13 @@ class ConfigMaterial(Config):
|
|||
|
||||
@staticmethod
|
||||
def load_DREAM3D(fname: str,
|
||||
grain_data: str = None,
|
||||
cell_data: str = None,
|
||||
grain_data: Optional[str] = None,
|
||||
cell_data: Optional[str] = None,
|
||||
cell_ensemble_data: str = 'CellEnsembleData',
|
||||
phases: str = 'Phases',
|
||||
Euler_angles: str = 'EulerAngles',
|
||||
phase_names: str = 'PhaseName',
|
||||
base_group: str = None) -> 'ConfigMaterial':
|
||||
base_group: Optional[str] = None) -> 'ConfigMaterial':
|
||||
"""
|
||||
Load DREAM.3D (HDF5) file.
|
||||
|
||||
|
@ -354,8 +354,8 @@ class ConfigMaterial(Config):
|
|||
|
||||
def material_rename_phase(self,
|
||||
mapping: Dict[str, str],
|
||||
ID: Sequence[int] = None,
|
||||
constituent: Sequence[int] = None) -> 'ConfigMaterial':
|
||||
ID: Optional[Sequence[int]] = None,
|
||||
constituent: Optional[Sequence[int]] = None) -> 'ConfigMaterial':
|
||||
"""
|
||||
Change phase name in material.
|
||||
|
||||
|
@ -388,7 +388,7 @@ class ConfigMaterial(Config):
|
|||
|
||||
def material_rename_homogenization(self,
|
||||
mapping: Dict[str, str],
|
||||
ID: Sequence[int] = None) -> 'ConfigMaterial':
|
||||
ID: Optional[Sequence[int]] = None) -> 'ConfigMaterial':
|
||||
"""
|
||||
Change homogenization name in material.
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from typing import Union, Dict, List, Tuple
|
||||
from typing import Optional, Union, Dict, List, Tuple
|
||||
|
||||
import numpy as np
|
||||
|
||||
|
@ -324,10 +324,10 @@ class Crystal():
|
|||
"""
|
||||
|
||||
def __init__(self, *,
|
||||
family: CrystalFamily = None,
|
||||
lattice: CrystalLattice = None,
|
||||
a: float = None, b: float = None, c: float = None,
|
||||
alpha: float = None, beta: float = None, gamma: float = None,
|
||||
family: Optional[CrystalFamily] = None,
|
||||
lattice: Optional[CrystalLattice] = None,
|
||||
a: Optional[float] = None, b: Optional[float] = None, c: Optional[float] = None,
|
||||
alpha: Optional[float] = None, beta: Optional[float] = None, gamma: Optional[float] = None,
|
||||
degrees: bool = False):
|
||||
"""
|
||||
New representation of a crystal.
|
||||
|
@ -690,8 +690,8 @@ class Crystal():
|
|||
self.lattice[-1],None),dtype=float)
|
||||
|
||||
def to_lattice(self, *,
|
||||
direction: FloatSequence = None,
|
||||
plane: FloatSequence = None) -> np.ndarray:
|
||||
direction: Optional[FloatSequence] = None,
|
||||
plane: Optional[FloatSequence] = None) -> np.ndarray:
|
||||
"""
|
||||
Calculate lattice vector corresponding to crystal frame direction or plane normal.
|
||||
|
||||
|
@ -717,8 +717,8 @@ class Crystal():
|
|||
|
||||
|
||||
def to_frame(self, *,
|
||||
uvw: FloatSequence = None,
|
||||
hkl: FloatSequence = None) -> np.ndarray:
|
||||
uvw: Optional[FloatSequence] = None,
|
||||
hkl: Optional[FloatSequence] = None) -> np.ndarray:
|
||||
"""
|
||||
Calculate crystal frame vector corresponding to lattice direction [uvw] or plane normal (hkl).
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import warnings
|
|||
import multiprocessing as mp
|
||||
from functools import partial
|
||||
import typing
|
||||
from typing import Union, Optional, TextIO, List, Sequence, Dict
|
||||
from typing import Optional, Union, TextIO, List, Sequence, Dict
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
|
@ -34,8 +34,8 @@ class Grid:
|
|||
material: np.ndarray,
|
||||
size: FloatSequence,
|
||||
origin: FloatSequence = np.zeros(3),
|
||||
initial_conditions: Dict[str,np.ndarray] = None,
|
||||
comments: Union[str, Sequence[str]] = None):
|
||||
initial_conditions: Optional[Dict[str,np.ndarray]] = None,
|
||||
comments: Union[None, str, Sequence[str]] = None):
|
||||
"""
|
||||
New geometry definition for grid solvers.
|
||||
|
||||
|
@ -348,9 +348,11 @@ class Grid:
|
|||
|
||||
@staticmethod
|
||||
def load_DREAM3D(fname: Union[str, Path],
|
||||
feature_IDs: str = None, cell_data: str = None,
|
||||
phases: str = 'Phases', Euler_angles: str = 'EulerAngles',
|
||||
base_group: str = None) -> 'Grid':
|
||||
feature_IDs: Optional[str] = None,
|
||||
cell_data: Optional[str] = None,
|
||||
phases: str = 'Phases',
|
||||
Euler_angles: str = 'EulerAngles',
|
||||
base_group: Optional[str] = None) -> 'Grid':
|
||||
"""
|
||||
Load DREAM.3D (HDF5) file.
|
||||
|
||||
|
@ -463,7 +465,7 @@ class Grid:
|
|||
size: FloatSequence,
|
||||
seeds: np.ndarray,
|
||||
weights: FloatSequence,
|
||||
material: IntSequence = None,
|
||||
material: Optional[IntSequence] = None,
|
||||
periodic: bool = True):
|
||||
"""
|
||||
Create grid from Laguerre tessellation.
|
||||
|
@ -520,7 +522,7 @@ class Grid:
|
|||
def from_Voronoi_tessellation(cells: IntSequence,
|
||||
size: FloatSequence,
|
||||
seeds: np.ndarray,
|
||||
material: IntSequence = None,
|
||||
material: Optional[IntSequence] = None,
|
||||
periodic: bool = True) -> 'Grid':
|
||||
"""
|
||||
Create grid from Voronoi tessellation.
|
||||
|
@ -763,9 +765,9 @@ class Grid:
|
|||
|
||||
|
||||
def canvas(self,
|
||||
cells: IntSequence = None,
|
||||
offset: IntSequence = None,
|
||||
fill: int = None) -> 'Grid':
|
||||
cells: Optional[IntSequence] = None,
|
||||
offset: Optional[IntSequence] = None,
|
||||
fill: Optional[int] = None) -> 'Grid':
|
||||
"""
|
||||
Crop or enlarge/pad grid.
|
||||
|
||||
|
@ -901,7 +903,7 @@ class Grid:
|
|||
|
||||
def rotate(self,
|
||||
R: Rotation,
|
||||
fill: int = None) -> 'Grid':
|
||||
fill: Optional[int] = None) -> 'Grid':
|
||||
"""
|
||||
Rotate grid (and pad if required).
|
||||
|
||||
|
@ -1093,10 +1095,10 @@ class Grid:
|
|||
|
||||
def clean(self,
|
||||
distance: float = np.sqrt(3),
|
||||
selection: IntCollection = None,
|
||||
selection: Optional[IntCollection] = None,
|
||||
invert_selection: bool = False,
|
||||
periodic: bool = True,
|
||||
rng_seed: NumpyRngSeed = None) -> 'Grid':
|
||||
rng_seed: Optional[NumpyRngSeed] = None) -> 'Grid':
|
||||
"""
|
||||
Smooth grid by selecting most frequent material ID within given stencil at each location.
|
||||
|
||||
|
@ -1163,7 +1165,7 @@ class Grid:
|
|||
dimension: Union[FloatSequence, IntSequence],
|
||||
center: Union[FloatSequence, IntSequence],
|
||||
exponent: Union[FloatSequence, float],
|
||||
fill: int = None,
|
||||
fill: Optional[int] = None,
|
||||
R: Rotation = Rotation(),
|
||||
inverse: bool = False,
|
||||
periodic: bool = True) -> 'Grid':
|
||||
|
@ -1254,8 +1256,8 @@ class Grid:
|
|||
|
||||
def vicinity_offset(self,
|
||||
distance: float = np.sqrt(3),
|
||||
offset: int = None,
|
||||
selection: IntCollection = None,
|
||||
offset: Optional[int] = None,
|
||||
selection: Optional[IntCollection] = None,
|
||||
invert_selection: bool = False,
|
||||
periodic: bool = True) -> 'Grid':
|
||||
"""
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import inspect
|
||||
import copy
|
||||
from typing import Union, Callable, Dict, Any, Tuple, TypeVar
|
||||
from typing import Optional, Union, Callable, Dict, Any, Tuple, TypeVar
|
||||
|
||||
import numpy as np
|
||||
|
||||
|
@ -98,10 +98,10 @@ class Orientation(Rotation,Crystal):
|
|||
def __init__(self,
|
||||
rotation: Union[FloatSequence, Rotation] = np.array([1.,0.,0.,0.]),
|
||||
*,
|
||||
family: CrystalFamily = None,
|
||||
lattice: CrystalLattice = None,
|
||||
a: float = None, b: float = None, c: float = None,
|
||||
alpha: float = None, beta: float = None, gamma: float = None,
|
||||
family: Optional[CrystalFamily] = None,
|
||||
lattice: Optional[CrystalLattice] = None,
|
||||
a: Optional[float] = None, b: Optional[float] = None, c: Optional[float] = None,
|
||||
alpha: Optional[float] = None, beta: Optional[float] = None, gamma: Optional[float] = None,
|
||||
degrees: bool = False):
|
||||
"""
|
||||
New orientation.
|
||||
|
@ -131,7 +131,7 @@ class Orientation(Rotation,Crystal):
|
|||
|
||||
|
||||
def __copy__(self: MyType,
|
||||
rotation: Union[FloatSequence, Rotation] = None) -> MyType:
|
||||
rotation: Union[None, FloatSequence, Rotation] = None) -> MyType:
|
||||
"""
|
||||
Return deepcopy(self).
|
||||
|
||||
|
@ -617,7 +617,7 @@ class Orientation(Rotation,Crystal):
|
|||
|
||||
|
||||
def average(self,
|
||||
weights: FloatSequence = None,
|
||||
weights: Optional[FloatSequence] = None,
|
||||
return_cloud: bool = False):
|
||||
"""
|
||||
Return orientation average over last dimension.
|
||||
|
@ -819,8 +819,8 @@ class Orientation(Rotation,Crystal):
|
|||
# functions that require lattice, not just family
|
||||
|
||||
def to_pole(self, *,
|
||||
uvw: FloatSequence = None,
|
||||
hkl: FloatSequence = None,
|
||||
uvw: Optional[FloatSequence] = None,
|
||||
hkl: Optional[FloatSequence] = None,
|
||||
with_symmetry: bool = False,
|
||||
normalize: bool = True) -> np.ndarray:
|
||||
"""
|
||||
|
@ -861,8 +861,8 @@ class Orientation(Rotation,Crystal):
|
|||
|
||||
|
||||
def Schmid(self, *,
|
||||
N_slip: IntSequence = None,
|
||||
N_twin: IntSequence = None) -> np.ndarray:
|
||||
N_slip: Optional[IntSequence] = None,
|
||||
N_twin: Optional[IntSequence] = None) -> np.ndarray:
|
||||
u"""
|
||||
Calculate Schmid matrix P = d ⨂ n in the lab frame for selected deformation systems.
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ from pathlib import Path
|
|||
from functools import partial
|
||||
from collections import defaultdict
|
||||
from collections.abc import Iterable
|
||||
from typing import Union, Callable, Any, Sequence, Literal, Dict, List, Tuple, Optional
|
||||
from typing import Optional, Union, Callable, Any, Sequence, Literal, Dict, List, Tuple
|
||||
|
||||
import h5py
|
||||
import numpy as np
|
||||
|
@ -189,11 +189,11 @@ class Result:
|
|||
|
||||
def _manage_view(self,
|
||||
action: Literal['set', 'add', 'del'],
|
||||
increments: Union[int, Sequence[int], str, Sequence[str], bool] = None,
|
||||
times: Union[float, Sequence[float], str, Sequence[str], bool] = None,
|
||||
phases: Union[str, Sequence[str], bool] = None,
|
||||
homogenizations: Union[str, Sequence[str], bool] = None,
|
||||
fields: Union[str, Sequence[str], bool] = None) -> "Result":
|
||||
increments: Union[None, int, Sequence[int], str, Sequence[str], bool] = None,
|
||||
times: Union[None, float, Sequence[float], str, Sequence[str], bool] = None,
|
||||
phases: Union[None, str, Sequence[str], bool] = None,
|
||||
homogenizations: Union[None, str, Sequence[str], bool] = None,
|
||||
fields: Union[None, str, Sequence[str], bool] = None) -> "Result":
|
||||
"""
|
||||
Manages the visibility of the groups.
|
||||
|
||||
|
@ -256,8 +256,8 @@ class Result:
|
|||
|
||||
|
||||
def increments_in_range(self,
|
||||
start: Union[str, int] = None,
|
||||
end: Union[str, int] = None) -> Sequence[int]:
|
||||
start: Union[None, str, int] = None,
|
||||
end: Union[None, str, int] = None) -> Sequence[int]:
|
||||
"""
|
||||
Get all increments within a given range.
|
||||
|
||||
|
@ -280,8 +280,8 @@ class Result:
|
|||
return [i for i in self.incs if s <= i <= e]
|
||||
|
||||
def times_in_range(self,
|
||||
start: float = None,
|
||||
end: float = None) -> Sequence[float]:
|
||||
start: Optional[float] = None,
|
||||
end: Optional[float] = None) -> Sequence[float]:
|
||||
"""
|
||||
Get times of all increments within a given time range.
|
||||
|
||||
|
@ -304,12 +304,12 @@ class Result:
|
|||
|
||||
|
||||
def view(self,*,
|
||||
increments: Union[int, Sequence[int], str, Sequence[str], bool] = None,
|
||||
times: Union[float, Sequence[float], str, Sequence[str], bool] = None,
|
||||
phases: Union[str, Sequence[str], bool] = None,
|
||||
homogenizations: Union[str, Sequence[str], bool] = None,
|
||||
fields: Union[str, Sequence[str], bool] = None,
|
||||
protected: bool = None) -> "Result":
|
||||
increments: Union[None, int, Sequence[int], str, Sequence[str], bool] = None,
|
||||
times: Union[None, float, Sequence[float], str, Sequence[str], bool] = None,
|
||||
phases: Union[None, str, Sequence[str], bool] = None,
|
||||
homogenizations: Union[None, str, Sequence[str], bool] = None,
|
||||
fields: Union[None, str, Sequence[str], bool] = None,
|
||||
protected: Optional[bool] = None) -> "Result":
|
||||
"""
|
||||
Set view.
|
||||
|
||||
|
@ -361,11 +361,11 @@ class Result:
|
|||
|
||||
|
||||
def view_more(self,*,
|
||||
increments: Union[int, Sequence[int], str, Sequence[str], bool] = None,
|
||||
times: Union[float, Sequence[float], str, Sequence[str], bool] = None,
|
||||
phases: Union[str, Sequence[str], bool] = None,
|
||||
homogenizations: Union[str, Sequence[str], bool] = None,
|
||||
fields: Union[str, Sequence[str], bool] = None) -> "Result":
|
||||
increments: Union[None, int, Sequence[int], str, Sequence[str], bool] = None,
|
||||
times: Union[None, float, Sequence[float], str, Sequence[str], bool] = None,
|
||||
phases: Union[None, str, Sequence[str], bool] = None,
|
||||
homogenizations: Union[None, str, Sequence[str], bool] = None,
|
||||
fields: Union[None, str, Sequence[str], bool] = None) -> "Result":
|
||||
"""
|
||||
Add to view.
|
||||
|
||||
|
@ -404,11 +404,11 @@ class Result:
|
|||
|
||||
|
||||
def view_less(self,*,
|
||||
increments: Union[int, Sequence[int], str, Sequence[str], bool] = None,
|
||||
times: Union[float, Sequence[float], str, Sequence[str], bool] = None,
|
||||
phases: Union[str, Sequence[str], bool] = None,
|
||||
homogenizations: Union[str, Sequence[str], bool] = None,
|
||||
fields: Union[str, Sequence[str], bool] = None) -> "Result":
|
||||
increments: Union[None, int, Sequence[int], str, Sequence[str], bool] = None,
|
||||
times: Union[None, float, Sequence[float], str, Sequence[str], bool] = None,
|
||||
phases: Union[None, str, Sequence[str], bool] = None,
|
||||
homogenizations: Union[None, str, Sequence[str], bool] = None,
|
||||
fields: Union[None, str, Sequence[str], bool] = None) -> "Result":
|
||||
"""
|
||||
Remove from view.
|
||||
|
||||
|
@ -650,7 +650,7 @@ class Result:
|
|||
formula: str,
|
||||
name: str,
|
||||
unit: str = 'n/a',
|
||||
description: str = None):
|
||||
description: Optional[str] = None):
|
||||
"""
|
||||
Add result of a general formula.
|
||||
|
||||
|
@ -966,7 +966,7 @@ class Result:
|
|||
}
|
||||
def add_equivalent_Mises(self,
|
||||
T_sym: str,
|
||||
kind: str = None):
|
||||
kind: Optional[str] = None):
|
||||
"""
|
||||
Add the equivalent Mises stress or strain of a symmetric tensor.
|
||||
|
||||
|
@ -1021,7 +1021,7 @@ class Result:
|
|||
}
|
||||
def add_norm(self,
|
||||
x: str,
|
||||
ord: Union[int, float, Literal['fro', 'nuc']] = None):
|
||||
ord: Union[None, int, float, Literal['fro', 'nuc']] = None):
|
||||
"""
|
||||
Add the norm of vector or tensor.
|
||||
|
||||
|
@ -1101,8 +1101,8 @@ class Result:
|
|||
def add_pole(self,
|
||||
q: str = 'O',
|
||||
*,
|
||||
uvw: FloatSequence = None,
|
||||
hkl: FloatSequence = None,
|
||||
uvw: Optional[FloatSequence] = None,
|
||||
hkl: Optional[FloatSequence] = None,
|
||||
with_symmetry: bool = False,
|
||||
normalize: bool = True):
|
||||
"""
|
||||
|
@ -1593,7 +1593,7 @@ class Result:
|
|||
output: Union[str, List[str]] = '*',
|
||||
flatten: bool = True,
|
||||
prune: bool = True,
|
||||
constituents: IntSequence = None,
|
||||
constituents: Optional[IntSequence] = None,
|
||||
fill_float: float = np.nan,
|
||||
fill_int: int = 0) -> Optional[Dict[str,Any]]:
|
||||
"""
|
||||
|
@ -1683,7 +1683,7 @@ class Result:
|
|||
|
||||
def export_XDMF(self,
|
||||
output: Union[str, List[str]] = '*',
|
||||
target_dir: Union[str, Path] = None,
|
||||
target_dir: Union[None, str, Path] = None,
|
||||
absolute_path: bool = False):
|
||||
"""
|
||||
Write XDMF file to directly visualize data from DADF5 file.
|
||||
|
@ -1811,8 +1811,8 @@ class Result:
|
|||
def export_VTK(self,
|
||||
output: Union[str,List[str]] = '*',
|
||||
mode: str = 'cell',
|
||||
constituents: IntSequence = None,
|
||||
target_dir: Union[str, Path] = None,
|
||||
constituents: Optional[IntSequence] = None,
|
||||
target_dir: Union[None, str, Path] = None,
|
||||
fill_float: float = np.nan,
|
||||
fill_int: int = 0,
|
||||
parallel: bool = True):
|
||||
|
@ -1958,7 +1958,7 @@ class Result:
|
|||
|
||||
def export_simulation_setup(self,
|
||||
output: Union[str, List[str]] = '*',
|
||||
target_dir: Union[str, Path] = None,
|
||||
target_dir: Union[None, str, Path] = None,
|
||||
overwrite: bool = False,
|
||||
):
|
||||
"""
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import copy
|
||||
from typing import Union, Sequence, Tuple, Literal, List, TypeVar
|
||||
from typing import Optional, Union, Sequence, Tuple, Literal, List, TypeVar
|
||||
|
||||
import numpy as np
|
||||
|
||||
|
@ -99,7 +99,7 @@ class Rotation:
|
|||
|
||||
|
||||
def __copy__(self: MyType,
|
||||
rotation: Union[FloatSequence, 'Rotation'] = None) -> MyType:
|
||||
rotation: Union[None, FloatSequence, 'Rotation'] = None) -> MyType:
|
||||
"""
|
||||
Return deepcopy(self).
|
||||
|
||||
|
@ -514,7 +514,7 @@ class Rotation:
|
|||
|
||||
|
||||
def average(self: MyType,
|
||||
weights: FloatSequence = None) -> MyType:
|
||||
weights: Optional[FloatSequence] = None) -> MyType:
|
||||
"""
|
||||
Average along last array dimension.
|
||||
|
||||
|
@ -1044,8 +1044,8 @@ class Rotation:
|
|||
|
||||
|
||||
@staticmethod
|
||||
def from_random(shape: Union[int, IntSequence] = None,
|
||||
rng_seed: NumpyRngSeed = None) -> 'Rotation':
|
||||
def from_random(shape: Union[None, int, IntSequence] = None,
|
||||
rng_seed: Optional[NumpyRngSeed] = None) -> 'Rotation':
|
||||
"""
|
||||
Initialize with samples from a uniform distribution.
|
||||
|
||||
|
@ -1078,10 +1078,10 @@ class Rotation:
|
|||
@staticmethod
|
||||
def from_ODF(weights: np.ndarray,
|
||||
phi: np.ndarray,
|
||||
shape: Union[int, IntSequence] = None,
|
||||
shape: Union[None, int, IntSequence] = None,
|
||||
degrees: bool = False,
|
||||
fractions: bool = True,
|
||||
rng_seed: NumpyRngSeed = None) -> 'Rotation':
|
||||
rng_seed: Optional[NumpyRngSeed] = None) -> 'Rotation':
|
||||
"""
|
||||
Initialize with samples from a binned orientation distribution function (ODF).
|
||||
|
||||
|
@ -1135,9 +1135,9 @@ class Rotation:
|
|||
@staticmethod
|
||||
def from_spherical_component(center: 'Rotation',
|
||||
sigma: float,
|
||||
shape: Union[int, IntSequence] = None,
|
||||
shape: Union[None, int, IntSequence] = None,
|
||||
degrees: bool = False,
|
||||
rng_seed: NumpyRngSeed = None) -> 'Rotation':
|
||||
rng_seed: Optional[NumpyRngSeed] = None) -> 'Rotation':
|
||||
"""
|
||||
Initialize with samples from a Gaussian distribution around a given center.
|
||||
|
||||
|
@ -1188,9 +1188,9 @@ class Rotation:
|
|||
def from_fiber_component(crystal: IntSequence,
|
||||
sample: IntSequence,
|
||||
sigma: float = 0.,
|
||||
shape: Union[int, IntSequence] = None,
|
||||
shape: Union[None, int, IntSequence] = None,
|
||||
degrees: bool = False,
|
||||
rng_seed: NumpyRngSeed = None) -> 'Rotation':
|
||||
rng_seed: Optional[NumpyRngSeed] = None) -> 'Rotation':
|
||||
"""
|
||||
Initialize with samples from a Gaussian distribution around a given direction.
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import re
|
||||
import copy
|
||||
from typing import Union, Tuple, List, Iterable
|
||||
from typing import Optional, Union, Tuple, List, Iterable
|
||||
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
|
@ -13,8 +13,8 @@ class Table:
|
|||
|
||||
def __init__(self,
|
||||
shapes: dict = {},
|
||||
data: np.ndarray = None,
|
||||
comments: Union[str, Iterable[str]] = None):
|
||||
data: Optional[np.ndarray] = None,
|
||||
comments: Union[None, str, Iterable[str]] = None):
|
||||
"""
|
||||
New spreadsheet.
|
||||
|
||||
|
@ -188,7 +188,7 @@ class Table:
|
|||
def _add_comment(self,
|
||||
label: str,
|
||||
shape: Tuple[int, ...],
|
||||
info: str = None):
|
||||
info: Optional[str] = None):
|
||||
if info is not None:
|
||||
specific = f'{label}{" "+str(shape) if np.prod(shape,dtype=np.int64) > 1 else ""}: {info}'
|
||||
general = util.execution_stamp('Table')
|
||||
|
@ -383,7 +383,7 @@ class Table:
|
|||
def set(self,
|
||||
label: str,
|
||||
data: np.ndarray,
|
||||
info: str = None) -> 'Table':
|
||||
info: Optional[str] = None) -> 'Table':
|
||||
"""
|
||||
Add new or replace existing column data.
|
||||
|
||||
|
@ -458,7 +458,7 @@ class Table:
|
|||
def rename(self,
|
||||
old: Union[str, Iterable[str]],
|
||||
new: Union[str, Iterable[str]],
|
||||
info: str = None) -> 'Table':
|
||||
info: Optional[str] = None) -> 'Table':
|
||||
"""
|
||||
Rename column data.
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import os
|
||||
import multiprocessing as mp
|
||||
from pathlib import Path
|
||||
from typing import Union, Literal, List, Sequence
|
||||
from typing import Optional, Union, Literal, List, Sequence
|
||||
|
||||
import numpy as np
|
||||
import vtk
|
||||
|
@ -286,7 +286,7 @@ class VTK:
|
|||
|
||||
@staticmethod
|
||||
def load(fname: Union[str, Path],
|
||||
dataset_type: Literal['ImageData', 'UnstructuredGrid', 'PolyData', 'RectilinearGrid'] = None) -> 'VTK':
|
||||
dataset_type: Literal[None, 'ImageData', 'UnstructuredGrid', 'PolyData', 'RectilinearGrid'] = None) -> 'VTK':
|
||||
"""
|
||||
Load from VTK file.
|
||||
|
||||
|
@ -409,11 +409,11 @@ class VTK:
|
|||
|
||||
# Check https://blog.kitware.com/ghost-and-blanking-visibility-changes/ for missing data
|
||||
def set(self,
|
||||
label: str = None,
|
||||
data: Union[np.ndarray, np.ma.MaskedArray] = None,
|
||||
info: str = None,
|
||||
label: Optional[str] = None,
|
||||
data: Union[None, np.ndarray, np.ma.MaskedArray] = None,
|
||||
info: Optional[str] = None,
|
||||
*,
|
||||
table: 'Table' = None):
|
||||
table: Optional['Table'] = None):
|
||||
"""
|
||||
Add new or replace existing point or cell data.
|
||||
|
||||
|
@ -533,7 +533,7 @@ class VTK:
|
|||
|
||||
|
||||
def show(self,
|
||||
label: str = None,
|
||||
label: Optional[str] = None,
|
||||
colormap: Union[Colormap, str] = 'cividis'):
|
||||
"""
|
||||
Render.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
"""Functionality for generation of seed points for Voronoi or Laguerre tessellation."""
|
||||
|
||||
from typing import Tuple as _Tuple
|
||||
from typing import Optional as _Optional, Tuple as _Tuple
|
||||
|
||||
from scipy import spatial as _spatial
|
||||
import numpy as _np
|
||||
|
@ -13,8 +13,8 @@ from . import grid_filters as _grid_filters
|
|||
|
||||
def from_random(size: _FloatSequence,
|
||||
N_seeds: int,
|
||||
cells: _IntSequence = None,
|
||||
rng_seed: _NumpyRngSeed = None) -> _np.ndarray:
|
||||
cells: _Optional[_IntSequence] = None,
|
||||
rng_seed: _Optional[_NumpyRngSeed] = None) -> _np.ndarray:
|
||||
"""
|
||||
Place seeds randomly in space.
|
||||
|
||||
|
@ -54,7 +54,7 @@ def from_Poisson_disc(size: _FloatSequence,
|
|||
N_candidates: int,
|
||||
distance: float,
|
||||
periodic: bool = True,
|
||||
rng_seed: _NumpyRngSeed = None) -> _np.ndarray:
|
||||
rng_seed: _Optional[_NumpyRngSeed] = None) -> _np.ndarray:
|
||||
"""
|
||||
Place seeds according to a Poisson disc distribution.
|
||||
|
||||
|
@ -106,7 +106,7 @@ def from_Poisson_disc(size: _FloatSequence,
|
|||
|
||||
|
||||
def from_grid(grid,
|
||||
selection: _IntCollection = None,
|
||||
selection: _Optional[_IntCollection] = None,
|
||||
invert_selection: bool = False,
|
||||
average: bool = False,
|
||||
periodic: bool = True) -> _Tuple[_np.ndarray, _np.ndarray]:
|
||||
|
|
|
@ -10,8 +10,9 @@ import signal as _signal
|
|||
import fractions as _fractions
|
||||
from collections import abc as _abc
|
||||
from functools import reduce as _reduce, partial as _partial
|
||||
from typing import Callable as _Callable, Union as _Union, Iterable as _Iterable, Sequence as _Sequence, Dict as _Dict, \
|
||||
List as _List, Tuple as _Tuple, Literal as _Literal, Any as _Any, Collection as _Collection, TextIO as _TextIO
|
||||
from typing import Optional as _Optional, Callable as _Callable, Union as _Union, Iterable as _Iterable, \
|
||||
Sequence as _Sequence, Dict as _Dict, List as _List, Tuple as _Tuple, Literal as _Literal, \
|
||||
Any as _Any, Collection as _Collection, TextIO as _TextIO
|
||||
from pathlib import Path as _Path
|
||||
|
||||
import numpy as _np
|
||||
|
@ -140,8 +141,8 @@ def strikeout(msg) -> str:
|
|||
|
||||
def run(cmd: str,
|
||||
wd: str = './',
|
||||
env: _Dict[str, str] = None,
|
||||
timeout: int = None) -> _Tuple[str, str]:
|
||||
env: _Optional[_Dict[str, str]] = None,
|
||||
timeout: _Optional[int] = None) -> _Tuple[str, str]:
|
||||
"""
|
||||
Run a command.
|
||||
|
||||
|
@ -215,7 +216,7 @@ def open_text(fname: _FileHandle,
|
|||
|
||||
|
||||
def execution_stamp(class_name: str,
|
||||
function_name: str = None) -> str:
|
||||
function_name: _Optional[str] = None) -> str:
|
||||
"""Timestamp the execution of a (function within a) class."""
|
||||
now = _datetime.datetime.now().astimezone().strftime('%Y-%m-%d %H:%M:%S%z')
|
||||
_function_name = '' if function_name is None else f'.{function_name}'
|
||||
|
@ -238,7 +239,7 @@ def natural_sort(key: str) -> _List[_Union[int, str]]:
|
|||
|
||||
|
||||
def show_progress(iterable: _Iterable,
|
||||
N_iter: int = None,
|
||||
N_iter: _Optional[int] = None,
|
||||
prefix: str = '',
|
||||
bar_length: int = 50) -> _Any:
|
||||
"""
|
||||
|
@ -418,7 +419,7 @@ def project_equal_area(vector: _np.ndarray,
|
|||
|
||||
def hybrid_IA(dist: _FloatSequence,
|
||||
N: int,
|
||||
rng_seed: _NumpyRngSeed = None) -> _np.ndarray:
|
||||
rng_seed: _Optional[_NumpyRngSeed] = None) -> _np.ndarray:
|
||||
"""
|
||||
Hybrid integer approximation.
|
||||
|
||||
|
@ -540,10 +541,10 @@ def shapeblender(a: _Tuple[int, ...],
|
|||
|
||||
|
||||
def _docstringer(docstring: _Union[str, _Callable],
|
||||
extra_parameters: str = None,
|
||||
# extra_examples: str = None,
|
||||
# extra_notes: str = None,
|
||||
return_type: _Union[str, _Callable] = None) -> str:
|
||||
extra_parameters: _Optional[str] = None,
|
||||
# extra_examples: _Optional[str] = None,
|
||||
# extra_notes: _Optional[str] = None,
|
||||
return_type: _Union[None, str, _Callable] = None) -> str:
|
||||
"""
|
||||
Extend a docstring.
|
||||
|
||||
|
@ -593,8 +594,8 @@ def _docstringer(docstring: _Union[str, _Callable],
|
|||
fr'\1{return_type_}\n',
|
||||
docstring_,flags=_re.MULTILINE)
|
||||
|
||||
def extend_docstring(docstring: _Union[str, _Callable] = None,
|
||||
extra_parameters: str = None) -> _Callable:
|
||||
def extend_docstring(docstring: _Union[None, str, _Callable] = None,
|
||||
extra_parameters: _Optional[str] = None) -> _Callable:
|
||||
"""
|
||||
Decorator: Extend the function's docstring.
|
||||
|
||||
|
@ -678,8 +679,8 @@ def DREAM3D_cell_data_group(fname: _Union[str, _Path]) -> str:
|
|||
|
||||
|
||||
def Bravais_to_Miller(*,
|
||||
uvtw: _np.ndarray = None,
|
||||
hkil: _np.ndarray = None) -> _np.ndarray:
|
||||
uvtw: _Optional[_np.ndarray] = None,
|
||||
hkil: _Optional[_np.ndarray] = None) -> _np.ndarray:
|
||||
"""
|
||||
Transform 4 Miller–Bravais indices to 3 Miller indices of crystal direction [uvw] or plane normal (hkl).
|
||||
|
||||
|
@ -706,8 +707,8 @@ def Bravais_to_Miller(*,
|
|||
return _np.einsum('il,...l',basis,axis)
|
||||
|
||||
def Miller_to_Bravais(*,
|
||||
uvw: _np.ndarray = None,
|
||||
hkl: _np.ndarray = None) -> _np.ndarray:
|
||||
uvw: _Optional[_np.ndarray] = None,
|
||||
hkl: _Optional[_np.ndarray] = None) -> _np.ndarray:
|
||||
"""
|
||||
Transform 3 Miller indices to 4 Miller–Bravais indices of crystal direction [uvtw] or plane normal (hkil).
|
||||
|
||||
|
|
Loading…
Reference in New Issue