From aeb94baad0950e7db8d314f11accc5fab7c55eca Mon Sep 17 00:00:00 2001 From: "donald e. boyce" Date: Sun, 11 Aug 2024 19:38:09 -0400 Subject: [PATCH 1/8] first test (theta, eta) for gvec_xy --- tests/test_transforms.py | 192 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 192 insertions(+) diff --git a/tests/test_transforms.py b/tests/test_transforms.py index 79417834a..3b5f5f3c7 100644 --- a/tests/test_transforms.py +++ b/tests/test_transforms.py @@ -1,3 +1,4 @@ +from collections import namedtuple import copy import json @@ -8,6 +9,13 @@ from common import convert_axis_angle_to_rmat +_flds = [ + "tvec_c", "tvec_d", "tvec_s","rmat_c", "rmat_d", "rmat_s", + "gvec_c", "beam_vec", "xy" +] +GvecXYData = namedtuple("GvecData", _flds) + + def test_gvec_to_xy(test_data_dir): with open(test_data_dir / 'gvec_to_xy.json') as rf: test_data = json.load(rf) @@ -36,3 +44,187 @@ def test_gvec_to_xy(test_data_dir): result = gvec_to_xy(**rotated_kwargs) assert np.allclose(result, expected) + + +class TestGvecXY: + """Test gvec_to_xy and xy_to_gvec""" + + # Base Case: sample and crystal align with lab frame; + # detector distance = 10; gvec = beam, no diffraction. + base = GvecXYData( + tvec_c = np.zeros(3), + tvec_d = np.array([0., 0., -10]), + tvec_s = np.zeros(3), + rmat_c = np.identity(3), + rmat_d = np.identity(3), + rmat_s = np.identity(3), + gvec_c = np.array([0, 0, -1.0]), + beam_vec = np.array([0, 0, -1.0]), + xy = np.array((np.nan, np.nan)) + ) + + @staticmethod + def to_array(a): + return np.array(a, dtype=float) + + def run_test(prob): + """Run a test problem""" + xy_d = gvec_to_xy( + np.array(prob.gvec_c), + np.array(prob.rmat_d), + np.array(prob.rmat_s), + np.array(prob.rmat_c), + np.array(prob.tvec_d), + np.array(prob.tvec_s), + np.array(prob.tvec_c), + beam_vec=np.array(prob.beam_vec), + ) + assert np.allclose(xy_d, prob.xy, equal_nan=True) + + + @staticmethod + def gvec_dvec(theta_deg, eta_deg=0): + """Return diffraction vector + + PARAMETERS + ---------- + theta_deg: float + diffraction angle theta, in degrees + eta_degrees: float + azimuthal angle, in degrees + + RETURNS + ------- + gvec: array(3): + diffraction vector relative to beam in -z-direction + dvec: array(3): + direction (unit vector) of diffracted beam + """ + eta = np.radians(eta_deg) + ce, se = np.cos(eta), np.sin(eta) + + # Diffraction vector makes angle theta with plane normal. + normal_ang = np.radians(90 - theta_deg) + cna, sna = np.cos(normal_ang), np.sin(normal_ang) + gvec = np.array((ce * sna, se * sna, cna)) + + # Diffracted beam direction makes angle 2-theta with beam. + two_theta = np.radians(2 * theta_deg) + c2t, s2t = np.cos(two_theta), np.sin(two_theta) + dvec = np.array((ce * s2t, se * s2t, -c2t)) + + return gvec, dvec + + + @classmethod + def test_theta_eta(cls): + """Vary diffraction angle in simple case + + TEST PARAMETERS + --------------- + theta_deg: float + diffraction angle in degrees + eta_deg: float, default=0 + azimuthal angle in degrees + """ + ThetaEta = namedtuple("ThetaEta", ["theta_deg", "eta_deg"]) + tests = [ + ThetaEta(0, 0), ThetaEta(10, 0), ThetaEta(44.9, 0), + ThetaEta(46, 0), ThetaEta(10, 45), ThetaEta(10, -45), + ] + + p0_l = (0, 0, 0) + d0_l = cls.base.tvec_d + nv_l = (0, 0, 1) + for t in tests: + gvec, dvec = cls.gvec_dvec(t.theta_deg, t.eta_deg) + det_x = line_plane_intersect( + p0_l, dvec, d0_l, nv_l + ) + if t.theta_deg <= 0: + answer = np.array((np.nan, np.nan)) + else: + answer = det_x[:2] + + cls.run_test(cls.base._replace( + gvec_c=gvec, xy=answer + )) + + + +def unit_vector(v): + return v/np.linalg.norm(v) + + +def make_unit_vector(theta, phi): + """Make a unit vector from spherical coordinates + + PARAMETERS + ---------- + theta: float + azimuth angle + phi: float + angle with north pole + + RETURNS + ------- + array(3) + unit vector + """ + return ( + np.sin(phi) * np.cos(theta), np.sin(phi) * np.sin(theta), np.cos(phi) + ) + + +def make_rmat(angle, axis): + """Make a rotation matrix + + PARAMETERS + ---------- + angle: float + rotation angle in degrees + axis: array(3) + axis of rotation (not normalized to unit vector) + + RETURNS + ------- + array(3, 3): + rotation matrix + """ + n = unit_vector(np.array(axis, dtype=float)) + ang = np.radians(angle) + c, s = np.cos(0.5 * ang), np.sin(0.5 * ang) + q = np.array((c, s * n[0], s * n[1], s * n[2])) + rmat = rotMatOfQuat(q.reshape(4, 1)) + # check_rmat(rmat.T) + return rmat + + + +def line_plane_intersect(p0, dvec, d0, nvec): + """Solve line/plane intersection + + PARAMETERS + ---------- + p0: array/3-tuple of floats + a point on the line + dvec: array/3-tuple of floats + direction (unit) vector of line + d0: array/3-tuple of floats + origin of detector + nvec: array/3-tuple of floats + normal vector to detector + + RETURNS + ------- + xyz: 3-tuple + intersection point + + NOTES + ----- + From geometry, t = (d0 - p0).n/(d.n), and x = p0 + td + """ + p0_, d = np.array([p0, dvec]) + t = np.dot((d0 - p0_), nvec)/np.dot(d, nvec) + x = p0_ + t * d + return x From 0a7ce1ae9df4536c4c0b42d3b5fee6f2ab10f899 Mon Sep 17 00:00:00 2001 From: "donald e. boyce" Date: Mon, 12 Aug 2024 09:11:10 -0400 Subject: [PATCH 2/8] test gvec-xy: theta-eta --- tests/test_transforms.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/test_transforms.py b/tests/test_transforms.py index 3b5f5f3c7..a7461e9ce 100644 --- a/tests/test_transforms.py +++ b/tests/test_transforms.py @@ -128,15 +128,20 @@ def test_theta_eta(cls): azimuthal angle in degrees """ ThetaEta = namedtuple("ThetaEta", ["theta_deg", "eta_deg"]) + nan_tests = [ + ThetaEta(0, 0), ThetaEta(46, 0), + ] + tests = [ - ThetaEta(0, 0), ThetaEta(10, 0), ThetaEta(44.9, 0), - ThetaEta(46, 0), ThetaEta(10, 45), ThetaEta(10, -45), + ThetaEta(10, 0), ThetaEta(44.9, 0), + ThetaEta(10, 45), ThetaEta(10, -45), ] p0_l = (0, 0, 0) d0_l = cls.base.tvec_d nv_l = (0, 0, 1) for t in tests: + print("test: ", t) gvec, dvec = cls.gvec_dvec(t.theta_deg, t.eta_deg) det_x = line_plane_intersect( p0_l, dvec, d0_l, nv_l From eb2eeca5094932a11dd2145cc2afcd661e8f1f6f Mon Sep 17 00:00:00 2001 From: "donald e. boyce" Date: Mon, 12 Aug 2024 09:57:57 -0400 Subject: [PATCH 3/8] gvex-xy: beam --- tests/test_transforms.py | 88 ++++++++++++++++++++++++++++------------ 1 file changed, 62 insertions(+), 26 deletions(-) diff --git a/tests/test_transforms.py b/tests/test_transforms.py index a7461e9ce..e759ae4c5 100644 --- a/tests/test_transforms.py +++ b/tests/test_transforms.py @@ -83,7 +83,7 @@ def run_test(prob): @staticmethod - def gvec_dvec(theta_deg, eta_deg=0): + def gvec_dvec(theta_deg, eta_deg): """Return diffraction vector PARAMETERS @@ -115,6 +115,25 @@ def gvec_dvec(theta_deg, eta_deg=0): return gvec, dvec + @staticmethod + def make_rmat(angle_deg, axis): + """Make a rotation matrix + + PARAMETERS + ---------- + angle: float + rotation angle in degrees + axis: array(3) + axis of rotation (not normalized to unit vector) + + RETURNS + ------- + array(3, 3): + rotation matrix + """ + return convert_axis_angle_to_rmat( + np.array(axis), np.radians(angle_deg) + ) @classmethod def test_theta_eta(cls): @@ -155,6 +174,48 @@ def test_theta_eta(cls): gvec_c=gvec, xy=answer )) + @classmethod + def test_beam(cls): + """Vary beam direction + + The beam is rotated by a specified rotation matrix, determined + from an angle/axis pair. + + TEST PARAMETERS + --------------- + aa: 2-tuple + angle/axis pairs + """ + TestData = namedtuple("TestData", ["angle", "axis"]) + tests =[ + TestData(90, (1, 0, 0)), + TestData(90, (0, 1, 0)), + TestData(45, (1, 0, 0)), + TestData(45, (0, 0, 1)) + ] + + theta_deg, eta_deg = 5, 0 + gvec, dvec = cls.gvec_dvec(theta_deg, eta_deg) + + p0_l = (0, 0, 0) + d0_l = cls.base.tvec_d + nv_d = (0, 0, 1) + for t in tests: + print("test: ", t) + rmat_d = cls.make_rmat(t.angle, t.axis) + gvec_l = rmat_d @ gvec + dvec_l = rmat_d @ dvec + tvec_l = rmat_d @ cls.base.tvec_d + beam = rmat_d @ cls.base.beam_vec + det_x = line_plane_intersect( + p0_l, dvec_l, tvec_l, rmat_d @ nv_d + ) + x_d = rmat_d.T @ (det_x - tvec_l) + + cls.run_test(cls.base._replace( + beam_vec=beam, tvec_d=tvec_l, gvec_c=gvec_l, + rmat_d=rmat_d, xy=x_d[:2], + )) def unit_vector(v): @@ -181,31 +242,6 @@ def make_unit_vector(theta, phi): ) -def make_rmat(angle, axis): - """Make a rotation matrix - - PARAMETERS - ---------- - angle: float - rotation angle in degrees - axis: array(3) - axis of rotation (not normalized to unit vector) - - RETURNS - ------- - array(3, 3): - rotation matrix - """ - n = unit_vector(np.array(axis, dtype=float)) - ang = np.radians(angle) - c, s = np.cos(0.5 * ang), np.sin(0.5 * ang) - q = np.array((c, s * n[0], s * n[1], s * n[2])) - rmat = rotMatOfQuat(q.reshape(4, 1)) - # check_rmat(rmat.T) - return rmat - - - def line_plane_intersect(p0, dvec, d0, nvec): """Solve line/plane intersection From 42336f02e7692de2efb905ddec4c02e6624d94c1 Mon Sep 17 00:00:00 2001 From: "donald e. boyce" Date: Mon, 12 Aug 2024 11:04:36 -0400 Subject: [PATCH 4/8] gvec-xy: translations --- tests/test_transforms.py | 62 ++++++++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 9 deletions(-) diff --git a/tests/test_transforms.py b/tests/test_transforms.py index e759ae4c5..4a2f930b1 100644 --- a/tests/test_transforms.py +++ b/tests/test_transforms.py @@ -67,17 +67,19 @@ class TestGvecXY: def to_array(a): return np.array(a, dtype=float) - def run_test(prob): + @classmethod + def run_test(cls, prob): """Run a test problem""" + print("prob: ", prob) xy_d = gvec_to_xy( - np.array(prob.gvec_c), - np.array(prob.rmat_d), - np.array(prob.rmat_s), - np.array(prob.rmat_c), - np.array(prob.tvec_d), - np.array(prob.tvec_s), - np.array(prob.tvec_c), - beam_vec=np.array(prob.beam_vec), + cls.to_array(prob.gvec_c), + cls.to_array(prob.rmat_d), + cls.to_array(prob.rmat_s), + cls.to_array(prob.rmat_c), + cls.to_array(prob.tvec_d), + cls.to_array(prob.tvec_s), + cls.to_array(prob.tvec_c), + beam_vec=cls.to_array(prob.beam_vec), ) assert np.allclose(xy_d, prob.xy, equal_nan=True) @@ -217,6 +219,48 @@ def test_beam(cls): rmat_d=rmat_d, xy=x_d[:2], )) + @classmethod + def test_translations(cls): + """Vary translation vectors + + TEST PARAMETERS + --------------- + td: array(3)/3-tuple + detector translation in lab frame + ts: + sample translation in lab frame + tc: + crystal translation in sample frame + """ + _flds = ["td", "ts", "tc"] + TvecData = namedtuple("TvecData", _flds) + + tests = [ + TvecData(td=(0, 0, -10), ts=(0, 0, 0), tc=(0, 0, 0)), + TvecData(td=(0, 0, -10), ts=(0, 0, 7), tc=(0, 0, 0)), + TvecData(td=(2, 3, -10), ts=(0, 0, 0), tc=(0, 0, -3)), + TvecData(td=(0, 0, -10), ts=(0, 1, 2), tc=(2, 3, -4)), + ] + + nv_l = (0, 0, 1) + theta_deg, eta_deg = 7.5, 0 + gvec, dvec = cls.gvec_dvec(theta_deg, eta_deg) + for t in tests: + print("test data:\n", t) + td = np.array(t.td) + ts = np.array(t.ts) + tc = np.array(t.tc) + p0_l = ts + tc + det_x = line_plane_intersect( + p0_l, dvec, td, nv_l + ) + xy = det_x[:2] - td[:2] + + cls.run_test(cls.base._replace( + gvec_c=gvec, tvec_d=td, tvec_s=ts, tvec_c=tc, + xy=xy + )) + def unit_vector(v): return v/np.linalg.norm(v) From a589f16ce08c3f8e3fce6b6ed4738a2236cc1b9c Mon Sep 17 00:00:00 2001 From: "donald e. boyce" Date: Mon, 12 Aug 2024 11:23:18 -0400 Subject: [PATCH 5/8] gvec-xy: detector orientations --- tests/test_transforms.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/tests/test_transforms.py b/tests/test_transforms.py index 4a2f930b1..a4e480969 100644 --- a/tests/test_transforms.py +++ b/tests/test_transforms.py @@ -70,7 +70,6 @@ def to_array(a): @classmethod def run_test(cls, prob): """Run a test problem""" - print("prob: ", prob) xy_d = gvec_to_xy( cls.to_array(prob.gvec_c), cls.to_array(prob.rmat_d), @@ -261,6 +260,42 @@ def test_translations(cls): xy=xy )) + @classmethod + def test_detector_orientation(cls): + """Vary detector orientation + + TEST PARAMETERS + --------------- + rd: 2-tuple + angle/axis pairs + """ + RmatData = namedtuple("RmatData", ["angle_deg", "axis"]) + nan_tests = [ + RmatData(90, (0, 1, 0)), + ] + tests =[ + RmatData(90, (1, 0, 0)), + RmatData(45, (1, 0, 0)), + RmatData(45, (0, 0, 1)) + ] + + theta_deg, eta_deg = 5, 0 + gvec, dvec = cls.gvec_dvec(theta_deg, eta_deg) + + p0_l = (0, 0, 0) + d0_l = cls.base.tvec_d + nv_l = (0, 0, 1) + for t in tests: + print(t) + tvec_l= -cls.base.tvec_d + rmat_d = cls.make_rmat(t.angle_deg, t.axis) + det_x = line_plane_intersect( + p0_l, dvec, d0_l, rmat_d @ nv_l + ) + x_d = rmat_d.T @ (det_x - d0_l) + cls.run_test(cls.base._replace( + gvec_c=gvec, rmat_d=rmat_d, xy=x_d[:2] + )) def unit_vector(v): return v/np.linalg.norm(v) From a4999492064fbbfa02e6bbde47c1deb0ca9deefc Mon Sep 17 00:00:00 2001 From: "donald e. boyce" Date: Mon, 12 Aug 2024 13:33:09 -0400 Subject: [PATCH 6/8] gvec-xy: sample/crystal orientations --- tests/test_transforms.py | 46 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tests/test_transforms.py b/tests/test_transforms.py index a4e480969..6e0f38edb 100644 --- a/tests/test_transforms.py +++ b/tests/test_transforms.py @@ -297,6 +297,52 @@ def test_detector_orientation(cls): gvec_c=gvec, rmat_d=rmat_d, xy=x_d[:2] )) + @classmethod + def test_sample_crystal_orientations(cls): + """Vary sample and crystal orientations + + TEST PARAMETERS + ---------- + data: named_tuple + angle/axis pairs for sample and crystal rotation + """ + _flds = ["aa_s", "aa_c"] + SampleCrystalData = namedtuple("SampleCrystalData", _flds) + + ex, ey, ez = (1, 0, 0), (0, 1, 0), (0, 0, 1) + ang = 10 + tests =[ + SampleCrystalData((0, ex), (0, ex)), + SampleCrystalData((ang, ex), (-ang, ex)), + SampleCrystalData((ang, ey), (-ang, ey)), + SampleCrystalData((ang, ez), (-ang, ez)), + SampleCrystalData((ang, ex), (0, ex)), + SampleCrystalData((ang, ey), (0, ey)), + SampleCrystalData((ang, ez), (0, ez)), + SampleCrystalData((0, ex), (ang, ex)), + SampleCrystalData((0, ey), (ang, ey)), + SampleCrystalData((0, ez), (ang, ez)), + ] + + theta_deg, eta_deg = 5, 90 + gvec_l, dvec_l = cls.gvec_dvec(theta_deg, eta_deg) + for t in tests: + print(t) + ang_s, ax_s = t.aa_s + rmat_s = cls.make_rmat(ang_s, ax_s) + ang_c, ax_c = t.aa_c + rmat_c = cls.make_rmat(ang_c, ax_c) + + gvec_c = rmat_c.T @ rmat_s.T @ gvec_l + det_x = line_plane_intersect( + (0, 0, 0), dvec_l, cls.base.tvec_d, (0, 0, 1) + ) + xy = det_x[:2] + + cls.run_test(cls.base._replace( + gvec_c=gvec_c, rmat_s=rmat_s, rmat_c=rmat_c, xy=xy + )) + def unit_vector(v): return v/np.linalg.norm(v) From f57824d4812c9cb82027d4c705c7528af3596392 Mon Sep 17 00:00:00 2001 From: "donald e. boyce" Date: Mon, 12 Aug 2024 15:31:53 -0400 Subject: [PATCH 7/8] gvec-xy: clean-up --- tests/test_transforms.py | 91 +++++++++++++++------------------------- 1 file changed, 34 insertions(+), 57 deletions(-) diff --git a/tests/test_transforms.py b/tests/test_transforms.py index 6e0f38edb..6f6bf2725 100644 --- a/tests/test_transforms.py +++ b/tests/test_transforms.py @@ -136,6 +136,35 @@ def make_rmat(angle_deg, axis): np.array(axis), np.radians(angle_deg) ) + @staticmethod + def line_plane_intersect(p0, dvec, d0, nvec): + """Solve line/plane intersection + + PARAMETERS + ---------- + p0: array/3-tuple of floats + a point on the line + dvec: array/3-tuple of floats + direction (unit) vector of line + d0: array/3-tuple of floats + origin of detector + nvec: array/3-tuple of floats + normal vector to detector + + RETURNS + ------- + xyz: 3-tuple + intersection point + + NOTES + ----- + From geometry, t = (d0 - p0).n/(d.n), and x = p0 + td + """ + p0_, d = np.array([p0, dvec]) + t = np.dot((d0 - p0_), nvec)/np.dot(d, nvec) + x = p0_ + t * d + return x + @classmethod def test_theta_eta(cls): """Vary diffraction angle in simple case @@ -163,7 +192,7 @@ def test_theta_eta(cls): for t in tests: print("test: ", t) gvec, dvec = cls.gvec_dvec(t.theta_deg, t.eta_deg) - det_x = line_plane_intersect( + det_x = cls.line_plane_intersect( p0_l, dvec, d0_l, nv_l ) if t.theta_deg <= 0: @@ -208,7 +237,7 @@ def test_beam(cls): dvec_l = rmat_d @ dvec tvec_l = rmat_d @ cls.base.tvec_d beam = rmat_d @ cls.base.beam_vec - det_x = line_plane_intersect( + det_x = cls.line_plane_intersect( p0_l, dvec_l, tvec_l, rmat_d @ nv_d ) x_d = rmat_d.T @ (det_x - tvec_l) @@ -250,7 +279,7 @@ def test_translations(cls): ts = np.array(t.ts) tc = np.array(t.tc) p0_l = ts + tc - det_x = line_plane_intersect( + det_x = cls.line_plane_intersect( p0_l, dvec, td, nv_l ) xy = det_x[:2] - td[:2] @@ -289,7 +318,7 @@ def test_detector_orientation(cls): print(t) tvec_l= -cls.base.tvec_d rmat_d = cls.make_rmat(t.angle_deg, t.axis) - det_x = line_plane_intersect( + det_x = cls.line_plane_intersect( p0_l, dvec, d0_l, rmat_d @ nv_l ) x_d = rmat_d.T @ (det_x - d0_l) @@ -334,7 +363,7 @@ def test_sample_crystal_orientations(cls): rmat_c = cls.make_rmat(ang_c, ax_c) gvec_c = rmat_c.T @ rmat_s.T @ gvec_l - det_x = line_plane_intersect( + det_x = cls.line_plane_intersect( (0, 0, 0), dvec_l, cls.base.tvec_d, (0, 0, 1) ) xy = det_x[:2] @@ -342,55 +371,3 @@ def test_sample_crystal_orientations(cls): cls.run_test(cls.base._replace( gvec_c=gvec_c, rmat_s=rmat_s, rmat_c=rmat_c, xy=xy )) - -def unit_vector(v): - return v/np.linalg.norm(v) - - -def make_unit_vector(theta, phi): - """Make a unit vector from spherical coordinates - - PARAMETERS - ---------- - theta: float - azimuth angle - phi: float - angle with north pole - - RETURNS - ------- - array(3) - unit vector - """ - return ( - np.sin(phi) * np.cos(theta), np.sin(phi) * np.sin(theta), np.cos(phi) - ) - - -def line_plane_intersect(p0, dvec, d0, nvec): - """Solve line/plane intersection - - PARAMETERS - ---------- - p0: array/3-tuple of floats - a point on the line - dvec: array/3-tuple of floats - direction (unit) vector of line - d0: array/3-tuple of floats - origin of detector - nvec: array/3-tuple of floats - normal vector to detector - - RETURNS - ------- - xyz: 3-tuple - intersection point - - NOTES - ----- - From geometry, t = (d0 - p0).n/(d.n), and x = p0 + td - """ - p0_, d = np.array([p0, dvec]) - t = np.dot((d0 - p0_), nvec)/np.dot(d, nvec) - x = p0_ + t * d - return x From a6af2f3ada6412c219f22850a2789e9967e317e9 Mon Sep 17 00:00:00 2001 From: "donald e. boyce" Date: Wed, 4 Sep 2024 12:16:13 -0400 Subject: [PATCH 8/8] PEP8 --- tests/test_transforms.py | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/tests/test_transforms.py b/tests/test_transforms.py index 6f6bf2725..9e739dbfd 100644 --- a/tests/test_transforms.py +++ b/tests/test_transforms.py @@ -10,7 +10,7 @@ _flds = [ - "tvec_c", "tvec_d", "tvec_s","rmat_c", "rmat_d", "rmat_s", + "tvec_c", "tvec_d", "tvec_s", "rmat_c", "rmat_d", "rmat_s", "gvec_c", "beam_vec", "xy" ] GvecXYData = namedtuple("GvecData", _flds) @@ -52,14 +52,14 @@ class TestGvecXY: # Base Case: sample and crystal align with lab frame; # detector distance = 10; gvec = beam, no diffraction. base = GvecXYData( - tvec_c = np.zeros(3), - tvec_d = np.array([0., 0., -10]), - tvec_s = np.zeros(3), - rmat_c = np.identity(3), - rmat_d = np.identity(3), - rmat_s = np.identity(3), - gvec_c = np.array([0, 0, -1.0]), - beam_vec = np.array([0, 0, -1.0]), + tvec_c=np.zeros(3), + tvec_d=np.array([0., 0., -10]), + tvec_s=np.zeros(3), + rmat_c=np.identity(3), + rmat_d=np.identity(3), + rmat_s=np.identity(3), + gvec_c=np.array([0, 0, -1.0]), + beam_vec=np.array([0, 0, -1.0]), xy = np.array((np.nan, np.nan)) ) @@ -82,7 +82,6 @@ def run_test(cls, prob): ) assert np.allclose(xy_d, prob.xy, equal_nan=True) - @staticmethod def gvec_dvec(theta_deg, eta_deg): """Return diffraction vector @@ -196,7 +195,7 @@ def test_theta_eta(cls): p0_l, dvec, d0_l, nv_l ) if t.theta_deg <= 0: - answer = np.array((np.nan, np.nan)) + answer = np.array((np.nan, np.nan)) else: answer = det_x[:2] @@ -217,7 +216,7 @@ def test_beam(cls): angle/axis pairs """ TestData = namedtuple("TestData", ["angle", "axis"]) - tests =[ + tests = [ TestData(90, (1, 0, 0)), TestData(90, (0, 1, 0)), TestData(45, (1, 0, 0)), @@ -302,7 +301,7 @@ def test_detector_orientation(cls): nan_tests = [ RmatData(90, (0, 1, 0)), ] - tests =[ + tests = [ RmatData(90, (1, 0, 0)), RmatData(45, (1, 0, 0)), RmatData(45, (0, 0, 1)) @@ -316,7 +315,7 @@ def test_detector_orientation(cls): nv_l = (0, 0, 1) for t in tests: print(t) - tvec_l= -cls.base.tvec_d + tvec_l = -cls.base.tvec_d rmat_d = cls.make_rmat(t.angle_deg, t.axis) det_x = cls.line_plane_intersect( p0_l, dvec, d0_l, rmat_d @ nv_l @@ -340,7 +339,7 @@ def test_sample_crystal_orientations(cls): ex, ey, ez = (1, 0, 0), (0, 1, 0), (0, 0, 1) ang = 10 - tests =[ + tests = [ SampleCrystalData((0, ex), (0, ex)), SampleCrystalData((ang, ex), (-ang, ex)), SampleCrystalData((ang, ey), (-ang, ey)), @@ -354,7 +353,7 @@ def test_sample_crystal_orientations(cls): ] theta_deg, eta_deg = 5, 90 - gvec_l, dvec_l = cls.gvec_dvec(theta_deg, eta_deg) + gvec_l, dvec_l = cls.gvec_dvec(theta_deg, eta_deg) for t in tests: print(t) ang_s, ax_s = t.aa_s