From b84587427315d761605ab972e70edb236be9f9aa Mon Sep 17 00:00:00 2001 From: Jonathan Wright Date: Tue, 18 Jun 2024 12:10:27 +0200 Subject: [PATCH 1/3] try to get positive volumes out --- ImageD11/lattice_reduction.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ImageD11/lattice_reduction.py b/ImageD11/lattice_reduction.py index 65fb451c..1d0cd792 100644 --- a/ImageD11/lattice_reduction.py +++ b/ImageD11/lattice_reduction.py @@ -120,6 +120,9 @@ def reduce(v1, v2, v3, min_vec2=MIN_VEC2): # choose the "bigger" compared to -v for i in range(3): vn[i] = sortvec_xyz( [vn[i], -vn[i]] )[0] + if np.linalg.det(vn) < 0: + vn[2] = -vn[2] + assert np.linalg.det(vn) > 0 return vn From 5aa40a89285c6e72082ff5f5c3c678d46fa45ffd Mon Sep 17 00:00:00 2001 From: Jonathan Wright Date: Tue, 18 Jun 2024 14:09:21 +0200 Subject: [PATCH 2/3] add testcase --- test/test_index_unknown/test_index_unknown.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/test_index_unknown/test_index_unknown.py b/test/test_index_unknown/test_index_unknown.py index 15c4908a..f97fad3b 100644 --- a/test/test_index_unknown/test_index_unknown.py +++ b/test/test_index_unknown/test_index_unknown.py @@ -3,6 +3,7 @@ import unittest, os, sys from ImageD11 import indexing +import ImageD11.grain import numpy as np """ >>> from ImageD11.indexing import readubis, write_ubi_file @@ -97,6 +98,8 @@ def test1(self): e = SCRIPT +' -g "%s" '%(fname)+cmd print ("\n",e) assert os.system(e) == 0 + grains = ImageD11.grain.read_grain_file(cmd.split()[3]) + def tearDown(self): """ explicitely leave the files here for debugging """ From 4358bcc5d6ae03e598ffe5f82a99b38fee5cabf8 Mon Sep 17 00:00:00 2001 From: Jonathan Wright Date: Tue, 18 Jun 2024 14:53:28 +0200 Subject: [PATCH 3/3] fixes #285 --- ImageD11/lattice_reduction.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ImageD11/lattice_reduction.py b/ImageD11/lattice_reduction.py index 1d0cd792..7e46789d 100644 --- a/ImageD11/lattice_reduction.py +++ b/ImageD11/lattice_reduction.py @@ -6,7 +6,7 @@ from numpy import dot, round_, array, allclose, asarray, fabs,\ argmin, argmax, sqrt, argsort, take, sum, where, ndarray, eye,\ zeros, cross, pi, arccos, floor -from numpy.linalg import inv, LinAlgError +from numpy.linalg import inv, LinAlgError, det import logging @@ -120,9 +120,6 @@ def reduce(v1, v2, v3, min_vec2=MIN_VEC2): # choose the "bigger" compared to -v for i in range(3): vn[i] = sortvec_xyz( [vn[i], -vn[i]] )[0] - if np.linalg.det(vn) < 0: - vn[2] = -vn[2] - assert np.linalg.det(vn) > 0 return vn @@ -198,11 +195,15 @@ def __init__(self, v1, v2, v3, direction=None, min_vec2=MIN_VEC2): if direction == 'col': # print "Supplied col direction vectors" self.r2c = array(vl) + if det( self.r2c ) < 0: + self.r2c = array( [vl[0], vl[2], vl[1] ] ) self.c2r = inv(self.r2c) elif direction == 'row': # Supplied with g-vectors # print "Supplied row direction vectors" self.c2r = array(vl).T + if det( self.c2r ) < 0: + self.c2r = array( [vl[0], vl[2], vl[1] ] ).T self.r2c = inv(self.c2r) else: raise Exception("Direction must be row or col "+str(direction))