Skip to content

Commit 1d82b1e

Browse files
authored
Merge pull request FABLE-3DXRD#473 from haixing0a/master
small update with grainmaps.py and pars_conversion
2 parents 84afc7d + 15a1eac commit 1d82b1e

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

ImageD11/forward_model/grainmaps.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ def DS_merge_and_identify_grains_sub(DS, FirstGrainID = 0, min_misori = 3.0, dis
382382
neigb_vol = DS['labels'] == id_neigb_j
383383
indices_neigb = np.array(np.where(neigb_vol)).T
384384

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)
386386
U1 = ori_converter.quat2u(ori_converter.rod2quat(r1))
387387
the_angle, _, _ = disorientation(U0, U1, crystal_structure=crystal_structure)
388388

@@ -876,7 +876,7 @@ def read_intensity_info(text):
876876
return data
877877

878878

879-
def get_mean_rod(rod, kmeans_flag=False):
879+
def get_mean_rod(rod, kmeans_flag=False, auto_check = True):
880880
"""
881881
Compute the mean Rodrigues vector with optional k-means clustering.
882882
@@ -890,8 +890,10 @@ def get_mean_rod(rod, kmeans_flag=False):
890890
rod = np.array(rod)
891891

892892
# 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):
894894
rod = rod.T
895+
# Remove rows with any NaN values
896+
rod = rod[~np.isnan(rod).any(axis=1)]
895897

896898
if kmeans_flag and len(rod) > 1:
897899
# Perform k-means clustering

ImageD11/forward_model/pars_conversion.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ def convert_ImageD11pars2p(pars, verbose = 1):
3737
p['rawfile'] = pars.parameters['filename']
3838
except Exception as e:
3939
# sometime there is no "filename" key
40-
logging.info("An unexpected error occurred: {}".format(e))
40+
if verbose > 1:
41+
logging.info("An unexpected error occurred: {}".format(e))
4142
p['Lsam2det'] = pars.parameters['distance']/1000.0
4243
p['tilt_xyz'] = [np.rad2deg(pars.parameters['tilt_x']), np.rad2deg(pars.parameters['tilt_y']), np.rad2deg(pars.parameters['tilt_z'])] # [deg]
4344
p['RotDet'] = get_det_R(pars.parameters['tilt_x'], pars.parameters['tilt_y'], pars.parameters['tilt_z'], verbose)

0 commit comments

Comments
 (0)