Skip to content

Commit 98dc783

Browse files
committed
Ensure compatible ordering of unique vectors
1 parent 54b6f07 commit 98dc783

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

diffsims/crystallography/reciprocal_lattice_vector.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,15 +1529,19 @@ def unique(self, use_symmetry=False, return_index=False, return_inverse=False):
15291529
# TODO: Reduce floating point precision in orix!
15301530
def miller_unique(miller, use_symmetry=False):
15311531
v, idx, inv = Vector3d(miller).unique(return_index=True, return_inverse=True)
1532-
idx = idx[::-1]
1533-
inv = inv[::-1]
15341532

15351533
if use_symmetry:
15361534
operations = miller.phase.point_group
15371535
n_v = v.size
1538-
v2 = operations.outer(v[::-1]).flatten().reshape(*(n_v, operations.size))
1539-
data = v2.data.round(6) # Reduced precision
1540-
_, idx, inv = np.unique(data, return_index=True, return_inverse=True, axis=0)
1536+
v2 = operations.outer(v).flatten().reshape(*(n_v, operations.size))
1537+
data = v2.data.round(8) # Reduced precision
1538+
# To check for uniqueness, sort the equivalent vectors from each operation
1539+
data_sorted = np.zeros_like(data)
1540+
for i in range(n_v):
1541+
a = data[i]
1542+
order = np.lexsort(a.T) # Sort by column 1, 2, then 3
1543+
data_sorted[i] = a[order[::-1]] # Reverse to preserve order
1544+
_, idx, inv = np.unique(data_sorted, return_index=True, return_inverse=True, axis=0)
15411545
v = v[idx]
15421546

15431547
m = miller.__class__(xyz=v.data, phase=miller.phase)

diffsims/tests/crystallography/test_diffracting_vector.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ def test_slicing(self, ferrite_phase):
4141

4242
def test_structure_factor(self, ferrite_phase):
4343
rlv = DiffractingVector.from_min_dspacing(ferrite_phase, 1.5)
44-
with pytest.raises(NotImplementedError):
45-
rlv.calculate_structure_factor()
44+
rlv.calculate_structure_factor()
45+
assert np.all(~np.isnan(rlv.structure_factor))
4646

4747
def test_hkl(self, ferrite_phase):
4848
rlv = ReciprocalLatticeVector(ferrite_phase, hkl=[[1, 1, 1], [2, 0, 0]])

0 commit comments

Comments
 (0)