def test_ndarray2listmode(l2sdata): # HACK hard-coded test data, need to figure out elegant way of data-driven test. listmode = ndarray2listmode(l2sdata['input']) assert len(listmode) == 100 assert isinstance(listmode[0].fst, PositionEvent) assert isinstance(listmode[0].snd, PositionEvent) assert listmode[0].fst.position == Point(l2sdata['input'][0, :3]) assert listmode[0].snd.position == Point(l2sdata['input'][0, 3:6])
def pos_and_ids(stir_data_root): data = np.load(stir_data_root / 'position2detectorids.npz') return { 'input': List([PositionEvent(Point(r)) for r in data['position']]), 'expect': List([DetectorIdEvent(r[0], r[1] // 10, r[1]) for r in data['ids']]) }
def vertices(b: Box): from dxl.shape.data import Point from itertools import product from dxl.shape.function.api import rotate_by_matrix from dxl.shape.function.rotation.matrix import axis_to_axis ps = [] for signs in product(*[(-1, 1)] * 3): ps.append([sign * size / 2 for sign, size in zip(signs, b.shape)]) ps = [Point(p) for p in ps] m = axis_to_axis([0.0, 0.0, 1.0], b.normal) ps = [rotate_by_matrix(p, m) for p in ps] ps = [p.translate(b.origin) for p in ps] return ps
def parse_positional_event(row) -> LoR: return LoR(PositionEvent(Point(row[:3])), PositionEvent(Point(row[3:6])))
def test_is_collision(self): p1 = Point([0, 0, 0]) p2 = Point([20, 0, 0]) b = Box([10, 10, 10], [0, 0, 0], [0, 0, 1]) self.assertIs(b.is_collision(p1), True) self.assertIs(b.is_collision(p2), False)
def test_collision_in(self): p = Point([0, 0, 0]) b = Box([10, 10, 10], [0, 0, 0], [0, 0, 1]) assert is_collision(p, b)
def _(p, m): return Point([email protected])
def test_rotate_not_origin(self): p = Point(origin=Vector([0.0, 2.0, 0.0])) axis = Axis(normal=[0.0, 0.0, 1.0], origin=[0.0, 1.0, 0.0]) assert testing.all_close(p.rotate(axis, math.pi / 2), Point([-1.0, 1.0, 0.0]))
def test_is_in(self): p1 = Point([0, 0, 0]) p2 = Point([20, 0, 0]) b = Box([10, 10, 10], [0, 0, 0], [0, 0, 1]) self.assertIs(p1.is_in(b), True) self.assertIs(p2.is_in(b), False)
def test_rotate_x(self): p = Point(origin=Vector([0.0, 2.0, 0.0])) assert testing.all_close(p.rotate(AXES3.x, math.pi / 2), Point([0.0, 0.0, 2.0]))
def test_translate(self): p = Point(origin=[1.0, 2.0, 0.0]) assert testing.all_close(p.translate(-Vector([1.0, 1.0, 3.0])), Point([0.0, 1.0, -3.0]))
def test_ndim(self): p = Point(origin=Vector([1.0, 2.0, 0.0])) self.assertEqual(p.ndim, 3)
def test_init(self): p = Point([1.0, 2.0, 0.0]) assert isinstance(p.origin, Vector) assert all_close(p.origin, [1.0, 2.0, 0.0])
def center_of_crystal(crystal_id: int, nb_detectors: int) -> Point: x = np.sin((0.5 + crystal_id) * (2 * np.pi) / nb_detectors) y = np.cos((0.5 + crystal_id) * (2 * np.pi) / nb_detectors) return Point([x, y])