1
1
import copy
2
- from typing import Tuple , Optional , Union , TypeVar , Literal # mypy 1.11, overload
2
+ from typing import Optional , Union , TypeVar , Literal , NamedTuple # mypy 1.11, overload
3
3
4
4
import numpy as np
5
5
12
12
13
13
MyType = TypeVar ('MyType' , bound = 'Orientation' )
14
14
15
+ class DisorientationTuple (NamedTuple ):
16
+ disorientation : 'Orientation'
17
+ operators : np .ndarray
18
+
19
+
20
+ class AverageTuple (NamedTuple ):
21
+ average : 'Orientation'
22
+ cloud : 'Orientation'
23
+
24
+
25
+ class ToSSTTuple (NamedTuple ):
26
+ vector_sst : np .ndarray
27
+ operator : np .ndarray
28
+
29
+
15
30
class Orientation (Rotation ,Crystal ):
16
31
"""
17
32
Representation of crystallographic orientation as combination of rotation and either crystal family or Bravais lattice.
@@ -466,7 +481,7 @@ def larger_or_equal(v,c):
466
481
467
482
def disorientation (self : MyType ,
468
483
other : MyType ,
469
- return_operators : bool = False ) -> Union [Tuple [ MyType , np . ndarray ], MyType ]:
484
+ return_operators : bool = False ) -> Union [MyType , DisorientationTuple ]:
470
485
"""
471
486
Calculate disorientation between self and given other orientation.
472
487
@@ -477,15 +492,16 @@ def disorientation(self: MyType,
477
492
Compatible innermost dimensions will blend.
478
493
return_operators : bool, optional
479
494
Return index pair of symmetrically equivalent orientations
480
- that result in disorientation axis falling into FZ.
495
+ that result in misorientation falling into disorientation FZ.
481
496
Defaults to False.
482
497
483
498
Returns
484
499
-------
485
500
disorientation : Orientation
486
501
Disorientation between self and other.
487
502
operators : numpy.ndarray of int, shape (...,2), conditional
488
- Index of symmetrically equivalent orientation that rotated vector to the SST.
503
+ Index pair of symmetrically equivalent orientations
504
+ that result in misorientation falling into disorientation FZ.
489
505
490
506
Notes
491
507
-----
@@ -543,11 +559,11 @@ def disorientation(self: MyType,
543
559
544
560
quat = r [ok ][sort ].reshape ((* shp ,4 ))
545
561
546
- return (
547
- ( self . copy ( rotation = quat ), (np .vstack (loc [:2 ]).T )[sort ].reshape ((* shp ,2 ) ))
548
- if return_operators else
549
- self . copy ( rotation = quat )
550
- )
562
+ if return_operators :
563
+ operators = (np .vstack (loc [:2 ]).T )[sort ].reshape ((* shp , 2 ))
564
+ return DisorientationTuple ( self . copy ( rotation = quat ), operators )
565
+ else :
566
+ return self . copy ( rotation = quat )
551
567
552
568
553
569
def disorientation_angle (self : MyType ,
@@ -637,7 +653,7 @@ def disorientation_angle(self: MyType,
637
653
638
654
def average (self : MyType , # type: ignore[override]
639
655
weights : Optional [FloatSequence ] = None ,
640
- return_cloud : bool = False ) -> Union [Tuple [ MyType , MyType ], MyType ]:
656
+ return_cloud : bool = False ) -> Union [MyType , AverageTuple ]:
641
657
"""
642
658
Return orientation average over last dimension.
643
659
@@ -671,9 +687,10 @@ def average(self: MyType,
671
687
axis = 0 ),
672
688
axis = 0 ))
673
689
674
- return ((self .copy (Rotation (r ).average (weights )),self .copy (Rotation (r ))) if return_cloud else
675
- self .copy (Rotation (r ).average (weights ))
676
- )
690
+ if return_cloud :
691
+ return AverageTuple (self .copy (Rotation (r ).average (weights )),self .copy (Rotation (r )))
692
+ else :
693
+ return self .copy (Rotation (r ).average (weights ))
677
694
678
695
# mypy 1.11
679
696
#@overload
@@ -686,7 +703,7 @@ def to_SST(self,
686
703
vector : FloatSequence ,
687
704
proper : bool = False ,
688
705
# return_operators: bool = False) -> Union[np.ndarray,Tuple[np.ndarray,np.ndarray]]:
689
- return_operators : bool = False ) -> np .ndarray :
706
+ return_operator : bool = False ) -> Union [ np .ndarray , ToSSTTuple ] :
690
707
"""
691
708
Rotate lab frame vector to ensure it falls into (improper or proper) standard stereographic triangle of crystal symmetry.
692
709
@@ -699,16 +716,16 @@ def to_SST(self,
699
716
proper : bool, optional
700
717
Consider only vectors with z >= 0, hence combine two neighboring SSTs.
701
718
Defaults to False.
702
- return_operators : bool, optional
703
- Return the symmetrically equivalent orientation that rotated vector to SST.
719
+ return_operator : bool, optional
720
+ Return the index of the symmetrically equivalent orientation that rotated vector to SST.
704
721
Defaults to False.
705
722
706
723
Returns
707
724
-------
708
725
vector_SST : numpy.ndarray, shape (...,3)
709
726
Rotated vector falling into SST.
710
727
operator : numpy.ndarray of int, shape (...), conditional
711
- Index of symmetrically equivalent orientation that rotated vector to SST.
728
+ Index of the symmetrically equivalent orientation that rotated vector to SST.
712
729
713
730
"""
714
731
vector_ = np .array (vector ,float )
@@ -723,11 +740,10 @@ def to_SST(self,
723
740
loc = np .where (ok )
724
741
sort = 0 if len (loc ) == 1 else np .lexsort (loc [:0 :- 1 ])
725
742
726
- return (
727
- (poles [ok ][sort ].reshape (blend + (3 ,)), (np .vstack (loc [:1 ]).T )[sort ].reshape (blend ))
728
- if return_operators else
729
- poles [ok ][sort ].reshape (blend + (3 ,))
730
- )
743
+ if return_operator :
744
+ return ToSSTTuple (poles [ok ][sort ].reshape (blend + (3 ,)), (np .vstack (loc [:1 ]).T )[sort ].reshape (blend ))
745
+ else :
746
+ return poles [ok ][sort ].reshape (blend + (3 ,))
731
747
732
748
733
749
def in_SST (self ,
@@ -827,8 +843,8 @@ def IPF_color(self,
827
843
if np .array (vector ).shape [- 1 ] != 3 :
828
844
raise ValueError ('input is not a field of three-dimensional vectors' )
829
845
830
- vector_ = self .to_SST (vector ,proper ) if in_SST else \
831
- self @ np .broadcast_to (vector ,self .shape + (3 ,))
846
+ vector_ : np . ndarray = self .to_SST (vector ,proper ) if in_SST else \
847
+ self @ np .broadcast_to (vector ,self .shape + (3 ,)) #type: ignore
832
848
833
849
if self .standard_triangle is None : # direct exit for no symmetry
834
850
return np .zeros_like (vector_ )
0 commit comments