[skip ci] changed almost all function definition lines to multiline

This commit is contained in:
Daniel Otto de Mentock 2022-01-26 15:09:09 +01:00
parent 777f2e7868
commit 0fe51f58a8
2 changed files with 60 additions and 24 deletions

View File

@ -123,7 +123,8 @@ class Orientation(Rotation,Crystal):
return '\n'.join([Crystal.__repr__(self), return '\n'.join([Crystal.__repr__(self),
Rotation.__repr__(self)]) Rotation.__repr__(self)])
def __copy__(self,rotation: Union[FloatSequence, Rotation] = None) -> "Orientation": def __copy__(self,
rotation: Union[FloatSequence, Rotation] = None) -> "Orientation":
"""Create deep copy.""" """Create deep copy."""
dup = copy.deepcopy(self) dup = copy.deepcopy(self)
if rotation is not None: if rotation is not None:
@ -134,7 +135,8 @@ class Orientation(Rotation,Crystal):
def __eq__(self, other: object) -> bool: def __eq__(self,
other: object) -> bool:
""" """
Equal to other. Equal to other.
@ -151,7 +153,8 @@ class Orientation(Rotation,Crystal):
self.parameters == other.parameters self.parameters == other.parameters
return np.logical_and(matching_type,super(self.__class__,self.reduced).__eq__(other.reduced)) return np.logical_and(matching_type,super(self.__class__,self.reduced).__eq__(other.reduced))
def __ne__(self, other: object) -> bool: def __ne__(self,
other: object) -> bool:
""" """
Not equal to other. Not equal to other.
@ -230,7 +233,8 @@ class Orientation(Rotation,Crystal):
return np.all(self.isclose(other,rtol,atol,equal_nan)) return np.all(self.isclose(other,rtol,atol,equal_nan))
def __mul__(self, other: Union[Rotation, "Orientation"]) -> "Orientation": def __mul__(self,
other: Union[Rotation, "Orientation"]) -> "Orientation":
""" """
Compose this orientation with other. Compose this orientation with other.
@ -252,7 +256,8 @@ class Orientation(Rotation,Crystal):
@staticmethod @staticmethod
def _split_kwargs(kwargs: Dict[str, Any], target: Callable) -> Tuple[Dict[str, Any], ...]: def _split_kwargs(kwargs: Dict[str, Any],
target: Callable) -> Tuple[Dict[str, Any], ...]:
""" """
Separate keyword arguments in 'kwargs' targeted at 'target' from general keyword arguments of Orientation objects. Separate keyword arguments in 'kwargs' targeted at 'target' from general keyword arguments of Orientation objects.
@ -492,7 +497,9 @@ class Orientation(Rotation,Crystal):
else: else:
return np.ones_like(rho[...,0],dtype=bool) return np.ones_like(rho[...,0],dtype=bool)
def disorientation(self, other, return_operators = False): def disorientation(self,
other,
return_operators = False):
""" """
Calculate disorientation between myself and given other orientation. Calculate disorientation between myself and given other orientation.
@ -576,7 +583,9 @@ class Orientation(Rotation,Crystal):
) )
def average(self, weights = None, return_cloud = False): def average(self,
weights = None,
return_cloud = False):
""" """
Return orientation average over last dimension. Return orientation average over last dimension.
@ -659,7 +668,9 @@ class Orientation(Rotation,Crystal):
) )
def in_SST(self, vector: np.ndarray, proper: bool = False) -> Union[np.bool_, np.ndarray]: def in_SST(self,
vector: np.ndarray,
proper: bool = False) -> Union[np.bool_, np.ndarray]:
""" """
Check whether given crystal frame vector falls into standard stereographic triangle of own symmetry. Check whether given crystal frame vector falls into standard stereographic triangle of own symmetry.
@ -700,7 +711,10 @@ class Orientation(Rotation,Crystal):
return np.all(components >= 0.0,axis=-1) return np.all(components >= 0.0,axis=-1)
def IPF_color(self, vector: np.ndarray, in_SST: bool = True, proper: bool = False) -> np.ndarray: def IPF_color(self,
vector: np.ndarray,
in_SST: bool = True,
proper: bool = False) -> np.ndarray:
""" """
Map vector to RGB color within standard stereographic triangle of own symmetry. Map vector to RGB color within standard stereographic triangle of own symmetry.
@ -925,7 +939,8 @@ class Orientation(Rotation,Crystal):
@ np.broadcast_to(P.reshape(util.shapeshifter(P.shape,shape)),shape) @ np.broadcast_to(P.reshape(util.shapeshifter(P.shape,shape)),shape)
def related(self, model: str) -> "Orientation": def related(self,
model: str) -> "Orientation":
""" """
Orientations derived from the given relationship. Orientations derived from the given relationship.

View File

@ -64,7 +64,8 @@ class Rotation:
__slots__ = ['quaternion'] __slots__ = ['quaternion']
def __init__(self, rotation: Union[FloatSequence, "Rotation"] = np.array([1.0,0.0,0.0,0.0])): def __init__(self,
rotation: Union[FloatSequence, "Rotation"] = np.array([1.0,0.0,0.0,0.0])):
""" """
New rotation. New rotation.
@ -91,7 +92,8 @@ class Rotation:
+ str(self.quaternion) + str(self.quaternion)
def __copy__(self, rotation: Union[FloatSequence, "Rotation"] = None) -> "Rotation": def __copy__(self,
rotation: Union[FloatSequence, "Rotation"] = None) -> "Rotation":
"""Create deep copy.""" """Create deep copy."""
dup = copy.deepcopy(self) dup = copy.deepcopy(self)
if rotation is not None: if rotation is not None:
@ -101,7 +103,8 @@ class Rotation:
copy = __copy__ copy = __copy__
def __getitem__(self, item: Union[Tuple[int], int, bool, np.bool_, np.ndarray]): def __getitem__(self,
item: Union[Tuple[int], int, bool, np.bool_, np.ndarray]):
"""Return slice according to item.""" """Return slice according to item."""
return self.copy() \ return self.copy() \
if self.shape == () else \ if self.shape == () else \
@ -139,7 +142,11 @@ class Rotation:
return np.logical_not(self==other) return np.logical_not(self==other)
def isclose(self, other: "Rotation", rtol: float = 1e-5, atol: float = 1e-8, equal_nan: bool = True) -> bool: def isclose(self,
other: "Rotation",
rtol: float = 1e-5,
atol: float = 1e-8,
equal_nan: bool = True) -> bool:
""" """
Report where values are approximately equal to corresponding ones of other Rotation. Report where values are approximately equal to corresponding ones of other Rotation.
@ -166,7 +173,11 @@ class Rotation:
np.all(np.isclose(s,-1.0*o,rtol,atol,equal_nan),axis=-1)) np.all(np.isclose(s,-1.0*o,rtol,atol,equal_nan),axis=-1))
def allclose(self, other: "Rotation", rtol: float = 1e-5, atol: float = 1e-8, equal_nan: bool = True) -> Union[np.bool_, bool]: def allclose(self,
other: "Rotation",
rtol: float = 1e-5,
atol: float = 1e-8,
equal_nan: bool = True) -> Union[np.bool_, bool]:
""" """
Test whether all values are approximately equal to corresponding ones of other Rotation. Test whether all values are approximately equal to corresponding ones of other Rotation.
@ -330,7 +341,7 @@ class Rotation:
Rotated vector or tensor, i.e. transformed to frame defined by rotation. Rotated vector or tensor, i.e. transformed to frame defined by rotation.
""" """
if isinstance(other,np.ndarray): if isinstance(other, np.ndarray):
if self.shape + (3,) == other.shape: if self.shape + (3,) == other.shape:
q_m = self.quaternion[...,0] q_m = self.quaternion[...,0]
p_m = self.quaternion[...,1:] p_m = self.quaternion[...,1:]
@ -350,7 +361,7 @@ class Rotation:
return np.einsum('...im,...jn,...ko,...lp,...mnop',R,R,R,R,other) return np.einsum('...im,...jn,...ko,...lp,...mnop',R,R,R,R,other)
else: else:
raise ValueError('Can only rotate vectors, 2nd order tensors, and 4th order tensors') raise ValueError('Can only rotate vectors, 2nd order tensors, and 4th order tensors')
elif isinstance(other,Rotation): elif isinstance(other, Rotation):
raise TypeError('Use "R1*R2", i.e. multiplication, to compose rotations "R1" and "R2"') raise TypeError('Use "R1*R2", i.e. multiplication, to compose rotations "R1" and "R2"')
else: else:
raise TypeError(f'Cannot rotate {type(other)}') raise TypeError(f'Cannot rotate {type(other)}')
@ -364,7 +375,9 @@ class Rotation:
return self return self
def append(self, other: Union["Rotation", List["Rotation"]]) -> "Rotation": def append(self,
other: Union["Rotation",
List["Rotation"]]) -> "Rotation":
""" """
Extend array along first dimension with other array(s). Extend array along first dimension with other array(s).
@ -377,7 +390,8 @@ class Rotation:
[self]+other if isinstance(other,list) else [self,other])))) [self]+other if isinstance(other,list) else [self,other]))))
def flatten(self, order: Literal['C','F','A'] = 'C') -> "Rotation": def flatten(self,
order: Literal['C','F','A'] = 'C') -> "Rotation":
""" """
Flatten array. Flatten array.
@ -390,7 +404,9 @@ class Rotation:
return self.copy(rotation=self.quaternion.reshape((-1,4),order=order)) return self.copy(rotation=self.quaternion.reshape((-1,4),order=order))
def reshape(self,shape: Union[int, Tuple[int, ...]], order: Literal['C','F','A'] = 'C') -> "Rotation": def reshape(self,
shape: Union[int, Tuple[int, ...]],
order: Literal['C','F','A'] = 'C') -> "Rotation":
""" """
Reshape array. Reshape array.
@ -404,7 +420,9 @@ class Rotation:
return self.copy(rotation=self.quaternion.reshape(tuple(shape)+(4,),order=order)) return self.copy(rotation=self.quaternion.reshape(tuple(shape)+(4,),order=order))
def broadcast_to(self, shape: Union[int, Tuple[int, ...]], mode: Literal["left", "right"] = 'right') -> "Rotation": def broadcast_to(self,
shape: Union[int, Tuple[int, ...]],
mode: Literal["left", "right"] = 'right') -> "Rotation":
""" """
Broadcast array. Broadcast array.
@ -427,7 +445,8 @@ class Rotation:
shape+(4,))) shape+(4,)))
def average(self, weights: np.ndarray = None) -> "Rotation": def average(self,
weights: np.ndarray = None) -> "Rotation":
""" """
Average along last array dimension. Average along last array dimension.
@ -466,7 +485,8 @@ class Rotation:
accept_homomorph = True) accept_homomorph = True)
def misorientation(self, other: "Rotation") -> "Rotation": def misorientation(self,
other: "Rotation") -> "Rotation":
""" """
Calculate misorientation to other Rotation. Calculate misorientation to other Rotation.
@ -1649,7 +1669,8 @@ class Rotation:
@staticmethod @staticmethod
def _get_pyramid_order(xyz: np.ndarray, direction: Literal['forward', 'backward']) -> np.ndarray: def _get_pyramid_order(xyz: np.ndarray,
direction: Literal['forward', 'backward']) -> np.ndarray:
""" """
Get order of the coordinates. Get order of the coordinates.