From a6e83c70ece1de13e989b49419daa62c6459d075 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 6 Feb 2022 17:11:18 +0100 Subject: [PATCH] adjustments to follow de-facto standard in other parts of the python library --- python/damask/_crystal.py | 5 +++-- python/damask/_orientation.py | 22 +++++++++++----------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/python/damask/_crystal.py b/python/damask/_crystal.py index 0b1c00458..ad5b9ed31 100644 --- a/python/damask/_crystal.py +++ b/python/damask/_crystal.py @@ -2,6 +2,7 @@ from typing import Union, Dict, List, Tuple import numpy as np +from ._typehints import FloatSequence from . import util from . import Rotation @@ -341,8 +342,8 @@ class Crystal(): def to_frame(self, *, - uvw: np.ndarray = None, - hkl: np.ndarray = None) -> np.ndarray: + uvw: FloatSequence = None, + hkl: FloatSequence = None) -> np.ndarray: """ Calculate crystal frame vector along lattice direction [uvw] or plane normal (hkl). diff --git a/python/damask/_orientation.py b/python/damask/_orientation.py index d90cc70e6..c28332012 100644 --- a/python/damask/_orientation.py +++ b/python/damask/_orientation.py @@ -1,15 +1,15 @@ import inspect import copy +from typing import Union, Callable, Dict, Any, Tuple import numpy as np +from ._typehints import FloatSequence, IntSequence from . import Rotation from . import Crystal from . import util from . import tensor -from typing import Union, Callable, Dict, Any, Tuple, List -from ._typehints import FloatSequence, IntSequence _parameter_doc = \ @@ -165,7 +165,7 @@ class Orientation(Rotation,Crystal): Orientation to check for equality. """ - return np.logical_not(self==other) if isinstance(other, Orientation) else NotImplemented + return np.logical_not(self==other) def isclose(self, @@ -206,7 +206,7 @@ class Orientation(Rotation,Crystal): other: object, rtol: float = 1e-5, atol: float = 1e-8, - equal_nan: bool = True) -> Union[bool, np.bool_]: + equal_nan: bool = True) -> bool: """ Test whether all values are approximately equal to corresponding ones of other Orientation. @@ -227,9 +227,7 @@ class Orientation(Rotation,Crystal): Whether all values are close between both orientations. """ - if not isinstance(other, Orientation): - raise TypeError - return np.all(self.isclose(other,rtol,atol,equal_nan)) + return bool(np.all(self.isclose(other,rtol,atol,equal_nan))) def __mul__(self, @@ -411,6 +409,7 @@ class Orientation(Rotation,Crystal): sort = 0 if len(loc) == 1 else np.lexsort(loc[:0:-1]) return eq[ok][sort].reshape(self.shape) + @property def in_FZ(self) -> Union[np.bool_, np.ndarray]: """ @@ -574,6 +573,7 @@ class Orientation(Rotation,Crystal): loc = np.where(ok) sort = 0 if len(loc) == 2 else np.lexsort(loc[:1:-1]) quat = r[ok][sort].reshape(blend+(4,)) + return ( (self.copy(rotation=quat), (np.vstack(loc[:2]).T)[sort].reshape(blend+(2,))) @@ -783,7 +783,7 @@ class Orientation(Rotation,Crystal): @property def symmetry_operations(self) -> Rotation: """Symmetry operations as Rotations.""" - _symmetry_operations: Dict[str, List[List]] = { + _symmetry_operations = { 'cubic': [ [ 1.0, 0.0, 0.0, 0.0 ], [ 0.0, 1.0, 0.0, 0.0 ], @@ -854,8 +854,8 @@ class Orientation(Rotation,Crystal): # functions that require lattice, not just family def to_pole(self, *, - uvw: np.ndarray = None, - hkl: np.ndarray = None, + uvw: FloatSequence = None, + hkl: FloatSequence = None, with_symmetry: bool = False) -> np.ndarray: """ Calculate lab frame vector along lattice direction [uvw] or plane normal (hkl). @@ -926,7 +926,7 @@ class Orientation(Rotation,Crystal): if active == '*': active = [len(a) for a in kinematics['direction']] if not active: - raise RuntimeError + raise RuntimeError # ToDo d = self.to_frame(uvw=np.vstack([kinematics['direction'][i][:n] for i,n in enumerate(active)])) p = self.to_frame(hkl=np.vstack([kinematics['plane'][i][:n] for i,n in enumerate(active)])) P = np.einsum('...i,...j',d/np.linalg.norm(d,axis=1,keepdims=True),