Skip to content

Commit 0376f1c

Browse files
committed
Bugfixes for hex EBSD meshes
1 parent 8213936 commit 0376f1c

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

src/kanapy/ebsd_hex_grid.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,23 @@ def quat_markley_mean(quats, weights=None):
112112
def resample_quat_knn_markley(quat_src, idx, dist, p=2.0):
113113
"""
114114
Quaternion resampling using k-NN, IDW weights, and Markley mean.
115-
quat_src: (N,4)
116-
idx/dist: (M,k)
117-
returns (M,4)
115+
116+
quat_src: (N, 4)
117+
idx: (M, k) or (M,)
118+
dist: (M, k) or (M,)
119+
returns: (M, 4)
118120
"""
119-
Qs = _normalize_quat(quat_src.astype(float, copy=False))
121+
Qs = _normalize_quat(np.asarray(quat_src, dtype=float))
122+
123+
idx = np.asarray(idx)
124+
dist = np.asarray(dist)
125+
126+
# Make sure idx/dist are always 2D: (M, k)
127+
if idx.ndim == 1:
128+
idx = idx[:, None]
129+
if dist.ndim == 1:
130+
dist = dist[:, None]
131+
120132
M, k = idx.shape
121133
out = np.empty((M, 4), dtype=float)
122134

@@ -127,12 +139,12 @@ def resample_quat_knn_markley(quat_src, idx, dist, p=2.0):
127139

128140
nonzero = ~zero
129141
if np.any(nonzero):
130-
w = _idw_weights(dist[nonzero], p=p) # (M', k)
131-
neigh = Qs[idx[nonzero]] # (M', k, 4)
142+
w = _idw_weights(dist[nonzero], p=p) # (M', k)
143+
neigh = Qs[idx[nonzero]] # (M', k, 4)
132144

133-
# Sign alignment: align all neighbors to the first neighbor
134-
ref = neigh[:, :1, :] # (M',1,4)
135-
sgn = np.sign(np.sum(neigh * ref, axis=2, keepdims=True)) # (M',k,1)
145+
# Align signs to first neighbor
146+
ref = neigh[:, :1, :] # (M', 1, 4)
147+
sgn = np.sign(np.sum(neigh * ref, axis=2, keepdims=True))
136148
sgn[sgn == 0] = 1.0
137149
neigh_aligned = neigh * sgn
138150

src/kanapy/texture.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,12 +1795,18 @@ def _plot_hex_rgb(xy, rgb, dx, dy=None, ax=None):
17951795
ori_e = Orientation.from_euler(self.emap[mask].orientations.in_euler_fundamental_region())
17961796
ori_q = np.stack([ori_e.a, ori_e.b, ori_e.c, ori_e.d]).T
17971797
rgb_val = ipf_key.orientation2color(ori_e)
1798-
ax = _plot_hex_rgb(xy, rgb_val, self.dx, self.dy)
1798+
#ax = _plot_hex_rgb(xy, rgb_val, self.dx, self.dy)
1799+
#xg, yg, phase_g, ci_g, quat_g = \
1800+
# resample_ebsd_to_rect_grid(xy[self.emap.is_indexed],
1801+
# self.emap.phase_id[self.emap.is_indexed],
1802+
# ori_q,
1803+
# val_ci[self.emap.is_indexed],
1804+
# nx=self.sh_y, ny=self.sh_x)
17991805
xg, yg, phase_g, ci_g, quat_g = \
1800-
resample_ebsd_to_rect_grid(xy[self.emap.is_indexed],
1801-
self.emap.phase_id[self.emap.is_indexed],
1806+
resample_ebsd_to_rect_grid(xy[mask],
1807+
self.emap.phase_id[mask],
18021808
ori_q,
1803-
val_ci[self.emap.is_indexed],
1809+
val_ci[mask],
18041810
nx=self.sh_y, ny=self.sh_x)
18051811
# get Euler Angles
18061812
q_flat = quat_g.reshape(-1, 4)

0 commit comments

Comments
 (0)