@@ -382,7 +382,7 @@ def DS_merge_and_identify_grains_sub(DS, FirstGrainID = 0, min_misori = 3.0, dis
382
382
neigb_vol = DS ['labels' ] == id_neigb_j
383
383
indices_neigb = np .array (np .where (neigb_vol )).T
384
384
385
- r1 = get_mean_rod (DS ['Rod' ][indices_neigb [:, 0 ], indices_neigb [:, 1 ], indices_neigb [:, 2 ], :]. T )
385
+ r1 = get_mean_rod (DS ['Rod' ][indices_neigb [:, 0 ], indices_neigb [:, 1 ], indices_neigb [:, 2 ], :], auto_check = False )
386
386
U1 = ori_converter .quat2u (ori_converter .rod2quat (r1 ))
387
387
the_angle , _ , _ = disorientation (U0 , U1 , crystal_structure = crystal_structure )
388
388
@@ -876,7 +876,7 @@ def read_intensity_info(text):
876
876
return data
877
877
878
878
879
- def get_mean_rod (rod , kmeans_flag = False ):
879
+ def get_mean_rod (rod , kmeans_flag = False , auto_check = True ):
880
880
"""
881
881
Compute the mean Rodrigues vector with optional k-means clustering.
882
882
@@ -890,8 +890,10 @@ def get_mean_rod(rod, kmeans_flag=False):
890
890
rod = np .array (rod )
891
891
892
892
# Ensure rod has shape (n, 3)
893
- if rod .shape [1 ] != 3 and rod .shape [0 ] == 3 :
893
+ if auto_check and ( rod .shape [1 ] != 3 and rod .shape [0 ] == 3 ) :
894
894
rod = rod .T
895
+ # Remove rows with any NaN values
896
+ rod = rod [~ np .isnan (rod ).any (axis = 1 )]
895
897
896
898
if kmeans_flag and len (rod ) > 1 :
897
899
# Perform k-means clustering
0 commit comments