def test_init(self):
     genone = LineGenerator("x", "mm", 1.0, 9.0, 5)
     gentwo = LineGenerator("x", "mm", 13, 20, 5)
     g = ConcatGenerator([genone, gentwo])
     self.assertEqual(["x"], g.axes)
     self.assertEqual(dict(x="mm"), g.axis_units())
     self.assertEqual(10, g.size)
 def test_init_two_dim(self):
     genone = LineGenerator(["x", "y"], ["mm", "mm"], [2., -2.],
                            [4., -4.], 3)
     gentwo = LineGenerator(["x", "y"], ["mm", "mm"], [6., -6.],
                            [8., -8.], 3)
     g = ConcatGenerator([genone, gentwo])
     self.assertEqual(["x", "y"], g.axes)
     self.assertEqual({"x": "mm", "y": "mm"}, g.axis_units())
 def test_to_dict(self):
     genone = LineGenerator("x", "mm", 1.0, 9.0, 5)
     gentwo = LineGenerator("x", "mm", 13, 20, 5)
     g = ConcatGenerator([genone, gentwo])
     expected_dict = dict()
     expected_dict['typeid'] = "scanpointgenerator:generator/ConcatGenerator:1.0"
     expected_dict['generators'] = [{'typeid': 'scanpointgenerator:generator/LineGenerator:1.0',
                                     'alternate': False,
                                     'axes': ['x'],
                                     'stop': [9.0],
                                     'start': [1.0],
                                     'units': ['mm'],
                                     'size': 5},
                                    {'typeid': 'scanpointgenerator:generator/LineGenerator:1.0',
                                     'alternate': False,
                                     'axes': ['x'],
                                     'stop': [20],
                                     'start': [13],
                                     'units': ['mm'],
                                     'size': 5}]
     expected_dict['alternate'] = False
     d = g.to_dict()
     self.assertEqual(expected_dict, d)
     comp = CompoundGenerator([g], [], [])
     expected_dict = dict()
     expected_dict['typeid'] = "scanpointgenerator:generator/CompoundGenerator:1.0"
     expected_dict['generators'] = [{'typeid': 'scanpointgenerator:generator/ConcatGenerator:1.0',
                                     'alternate': False,
                                     'generators': [{'typeid': 'scanpointgenerator:generator/LineGenerator:1.0',
                                                     'alternate': False,
                                                     'axes': ['x'],
                                                     'stop': [9.0],
                                                     'start': [1.0],
                                                     'units': ['mm'],
                                                     'size': 5},
                                                    {'typeid': 'scanpointgenerator:generator/LineGenerator:1.0',
                                                     'alternate': False,
                                                     'axes': ['x'],
                                                     'stop': [20],
                                                     'start': [13],
                                                     'units': ['mm'],
                                                     'size': 5}]}]
     expected_dict['excluders'] = []
     expected_dict['mutators'] = []
     expected_dict['duration'] = -1.0
     expected_dict['continuous'] = True
     expected_dict['delay_after'] = 0
     d = comp.to_dict()
     self.assertEqual(expected_dict, d)
示例#4
0
    def test_breakpoints_helical_scan(self):
        line1 = LineGenerator(["y", "x"], ["mm", "mm"], [-0.555556, -10],
                              [-0.555556, -10], 5)
        line2 = LineGenerator(["y", "x"], ["mm", "mm"], [0, 0], [10, 180], 10)
        line3 = LineGenerator(["y", "x"], ["mm", "mm"], [10.555556, 190],
                              [10.555556, 190], 2)
        duration = 0.01
        concat = ConcatGenerator([line1, line2, line3])

        breakpoints = [2, 3, 10, 2]
        self.b.configure(
            generator=CompoundGenerator([concat], [], [], duration),
            axesToMove=["y", "x"],
            breakpoints=breakpoints,
        )

        assert self.c.configure_params.generator.size == 17

        self.checkState(self.ss.ARMED)
        self.checkSteps(2, 0, 17)

        self.b.run()
        self.checkSteps(5, 2, 17)
        self.checkState(self.ss.ARMED)

        self.b.run()
        self.checkSteps(15, 5, 17)
        self.checkState(self.ss.ARMED)

        self.b.run()
        self.checkSteps(17, 15, 17)
        self.checkState(self.ss.ARMED)

        self.b.run()
        self.checkState(self.ss.FINISHED)
示例#5
0
    def test_breakpoints_without_last(self):
        line1 = LineGenerator("x", "mm", -10, -10, 5)
        line2 = LineGenerator("x", "mm", 0, 180, 10)
        line3 = LineGenerator("x", "mm", 190, 190, 2)
        duration = 0.01
        concat = ConcatGenerator([line1, line2, line3])
        breakpoints = [2, 3, 10]
        self.b.configure(
            generator=CompoundGenerator([concat], [], [], duration),
            axesToMove=["x"],
            breakpoints=breakpoints,
        )

        assert self.c.configure_params.generator.size == 17
        self.checkSteps(2, 0, 17)
        self.checkState(self.ss.ARMED)

        self.b.run()
        self.checkSteps(5, 2, 17)
        self.checkState(self.ss.ARMED)

        self.b.run()
        self.checkSteps(15, 5, 17)
        self.checkState(self.ss.ARMED)

        self.b.run()
        self.checkSteps(17, 15, 17)
        self.checkState(self.ss.ARMED)

        self.b.run()
        self.checkSteps(17, 17, 17)
        self.checkState(self.ss.FINISHED)
示例#6
0
    def test_breakpoints_repeat_rocking_tomo(self):
        line1 = LineGenerator("x", "mm", -10, -10, 5)
        line2 = LineGenerator("x", "mm", 0, 180, 10)
        line3 = LineGenerator("x", "mm", 190, 190, 2)
        line4 = LineGenerator("x", "mm", 180, 0, 10)
        concat = ConcatGenerator([line1, line2, line3, line4])

        staticGen = StaticPointGenerator(2)

        duration = 0.01
        breakpoints = [2, 3, 10, 2, 10, 2, 3, 10, 2, 10]
        self.b.configure(
            generator=CompoundGenerator([staticGen, concat], [], [], duration),
            axesToMove=["x"],
            breakpoints=breakpoints,
        )

        assert self.c.configure_params.generator.size == 54

        self.checkState(self.ss.ARMED)
        self.checkSteps(2, 0, 54)

        self.b.run()
        self.checkSteps(5, 2, 54)
        self.checkState(self.ss.ARMED)

        self.b.run()
        self.checkSteps(15, 5, 54)
        self.checkState(self.ss.ARMED)

        self.b.run()
        self.checkSteps(17, 15, 54)
        self.checkState(self.ss.ARMED)

        self.b.run()
        self.checkSteps(27, 17, 54)
        self.checkState(self.ss.ARMED)

        self.b.run()
        self.checkSteps(29, 27, 54)
        self.checkState(self.ss.ARMED)

        self.b.run()
        self.checkSteps(32, 29, 54)
        self.checkState(self.ss.ARMED)

        self.b.run()
        self.checkSteps(42, 32, 54)
        self.checkState(self.ss.ARMED)

        self.b.run()
        self.checkSteps(44, 42, 54)
        self.checkState(self.ss.ARMED)

        self.b.run()
        self.checkSteps(54, 44, 54)
        self.checkState(self.ss.ARMED)

        self.b.run()
        self.checkState(self.ss.FINISHED)
示例#7
0
    def make_generator_breakpoints(self):
        line1 = LineGenerator("x", "mm", -10, -10, 5)
        line2 = LineGenerator("x", "mm", 0, 180, 10)
        line3 = LineGenerator("x", "mm", 190, 190, 2)
        duration = 0.01
        concat = ConcatGenerator([line1, line2, line3])

        return CompoundGenerator([concat], [], [], duration)
 def test_array_positions_from_line_non_matching_bounds(self):
     genone = LineGenerator("x", "mm", 1.0, 9.0, 5)
     gentwo = LineGenerator("x", "mm", 20, 24, 5)
     g = ConcatGenerator([genone, gentwo])
     g.prepare_positions()
     with self.assertRaises(AssertionError):
         g.prepare_bounds()
    def test_from_dict(self):
        genone = LineGenerator("x", "mm", 1.0, 9.0, 5)
        g1_dict = genone.to_dict()
        gentwo = LineGenerator("x", "mm", 13, 20, 5)
        g2_dict = gentwo.to_dict()
        _dict = dict()
        _dict['generators'] = [g1_dict, g2_dict]
        _dict['alternate'] = False
        gen = ConcatGenerator.from_dict(_dict)
        self.assertEqual(gen.generators[0].to_dict(), genone.to_dict())
        self.assertEqual(gen.generators[1].to_dict(), gentwo.to_dict())

        g = ConcatGenerator([genone, gentwo])
        g_dict = g.to_dict()
        _dict = dict()
        _dict['generators'] = [g_dict]
        _dict['excluders'] = []
        _dict['mutators'] = []
        _dict['duration'] = 10
        _dict['continuous'] = False
        gen = CompoundGenerator.from_dict(_dict)
        self.assertEqual(gen.generators[0].to_dict(), g.to_dict())
示例#10
0
    def test_breakpoints_repeat_with_static(self):
        line1 = LineGenerator("x", "mm", -10, -10, 5)
        line2 = LineGenerator("x", "mm", 0, 180, 10)
        line3 = LineGenerator("x", "mm", 190, 190, 2)
        duration = 0.01
        concat = ConcatGenerator([line1, line2, line3])

        staticGen = StaticPointGenerator(2)
        breakpoints = [2, 3, 10, 2, 2, 3, 10, 2]

        self.b.configure(
            generator=CompoundGenerator([staticGen, concat], [], [], duration),
            axesToMove=["x"],
            breakpoints=breakpoints,
        )

        assert self.c.configure_params.generator.size == 34

        self.checkState(self.ss.ARMED)
        self.checkSteps(2, 0, 34)

        self.b.run()
        self.checkSteps(5, 2, 34)
        self.checkState(self.ss.ARMED)

        self.b.run()
        self.checkSteps(15, 5, 34)
        self.checkState(self.ss.ARMED)

        self.b.run()
        self.checkSteps(17, 15, 34)
        self.checkState(self.ss.ARMED)

        self.b.run()
        self.checkSteps(19, 17, 34)
        self.checkState(self.ss.ARMED)

        self.b.run()
        self.checkSteps(22, 19, 34)
        self.checkState(self.ss.ARMED)

        self.b.run()
        self.checkSteps(32, 22, 34)
        self.checkState(self.ss.ARMED)

        self.b.run()
        self.checkSteps(34, 32, 34)
        self.checkState(self.ss.ARMED)

        self.b.run()
        self.checkState(self.ss.FINISHED)
示例#11
0
    def test_steps_per_run_concat(self):
        line1 = LineGenerator("x", "mm", -10, -10, 5)
        line2 = LineGenerator("x", "mm", 0, 180, 10)
        line3 = LineGenerator("x", "mm", 190, 190, 2)
        duration = 0.01
        concat = ConcatGenerator([line1, line2, line3])
        compound = CompoundGenerator([concat], [], [], duration)
        compound.prepare()
        breakpoints = [2, 3, 10, 2]

        steps_per_run = self.c.get_steps_per_run(generator=compound,
                                                 axes_to_move=["x"],
                                                 breakpoints=breakpoints)
        assert steps_per_run == breakpoints
 def test_concat_three_oneD_lines(self):
     genone = LineGenerator("x", "mm", 1.0, 9.0, 5)
     gentwo = LineGenerator("x", "mm", 11, 19, 5)
     genthree = LineGenerator("x", "mm", 19.5, 13.5, 7)
     lines = ConcatGenerator([genone, gentwo, genthree])
     g = CompoundGenerator([lines], [], [], duration=0.5)
     x_positions = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 19.5, 18.5, 17.5,
                    16.5, 15.5, 14.5, 13.5]
     expected_pos = []
     for i in range(len(x_positions)):
         expected_pos.append({"x": x_positions[i]})
     g.prepare()
     points = list(g.iterator())
     self.assertEqual(expected_pos, [p.positions for p in points])
 def test_compound_of_two_lines(self):
     genone = LineGenerator("x", "mm", 1.0, 9.0, 5)
     gentwo = LineGenerator("x", "mm", 11, 19, 5)
     lines = ConcatGenerator([genone, gentwo])
     g = CompoundGenerator([lines], [], [], duration=0.5)
     g.prepare()
     x_positions = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
     expected_pos = []
     for i in range(len(x_positions)):
         expected_pos.append({"x": x_positions[i]})
     points = list(g.iterator())
     self.assertEqual(expected_pos, [p.positions for p in points])
     data = []
     for vals in expected_pos:
         data.append(vals["x"])
 def test_array_positions_from_array(self):
     genone = ArrayGenerator("x", "mm", [1.0, 2.0, 3.0, 4.0, 5.0])
     gentwo = ArrayGenerator("x", "mm", [6.0, 7.0, 8.0, 9.0, 0.0])
     g = ConcatGenerator([genone, gentwo])
     positions = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 0.0]
     bounds = [0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 4.5, -4.5]
     g.prepare_positions()
     g.prepare_bounds()
     self.assertEqual(positions, g.positions['x'].tolist())
     self.assertEqual(bounds, g.bounds['x'].tolist())
 def test_array_positions_from_line(self):
     genone = LineGenerator("x", "mm", 1.0, 9.0, 5)
     gentwo = LineGenerator("x", "mm", 11, 19, 5)
     g = ConcatGenerator([genone, gentwo])
     positions = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
     bounds = [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
     g.prepare_positions()
     g.prepare_bounds()
     self.assertEqual(positions, g.positions['x'].tolist())
     self.assertEqual(bounds, g.bounds['x'].tolist())
示例#16
0
    def test_breakpoints_2d_inner_scan_with_outer_axis(self):
        # Outer axes we don't move
        outer_steps = 2
        line_outer = LineGenerator("z", "mm", 0, 1, outer_steps)

        # Y-axis
        line_y = LineGenerator("y", "mm", 0, 1, 2)

        # X-axis
        line_x_1 = LineGenerator("x", "mm", -10, -10, 5)
        line_x_2 = LineGenerator("x", "mm", 0, 180, 10)
        line_x_3 = LineGenerator("x", "mm", 190, 190, 2)
        line_x = ConcatGenerator([line_x_1, line_x_2, line_x_3])

        compound = CompoundGenerator([line_outer, line_y, line_x], [], [],
                                     duration=0.01)
        breakpoints = [2, 3, 10, 2, 17]
        total_steps = sum(breakpoints) * outer_steps

        # Configure the scan
        self.b.configure(generator=compound,
                         axesToMove=["x", "y"],
                         breakpoints=breakpoints)
        self.checkSteps(2, 0, total_steps)
        self.checkState(self.ss.ARMED)

        # Check we have the full amount of configured steps
        assert self.c.configure_params.generator.size == total_steps

        # Check our breakpoints steps
        expected_breakpoint_steps = [2, 5, 15, 17, 34, 36, 39, 49, 51, 68]
        self.assertEqual(expected_breakpoint_steps, self.c.breakpoint_steps)

        # Run our controller through all but last breakpoint
        breakpoints = len(expected_breakpoint_steps)
        for index in range(breakpoints - 1):
            self.b.run()
            self.checkSteps(
                expected_breakpoint_steps[index + 1],
                expected_breakpoint_steps[index],
                total_steps,
            )
            self.checkState(self.ss.ARMED)

        # Final breakpoint
        self.b.run()
        self.checkSteps(total_steps, total_steps, total_steps)
        self.checkState(self.ss.FINISHED)
 def test_array_positions_from_three_(self):
     genone = LineGenerator("x", "mm", 1.0, 9.0, 5)
     gentwo = LineGenerator("x", "mm", 11, 19, 5)
     genthree = LineGenerator("x", "mm", 21, 29, 5)
     g = ConcatGenerator([genone, gentwo, genthree])
     positions = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]
     bounds = [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]
     g.prepare_positions()
     g.prepare_bounds()
     self.assertEqual(positions, g.positions['x'].tolist())
     self.assertEqual(bounds, g.bounds['x'].tolist())
示例#18
0
    def test_breakpoints_tomo_with_outer_axis(self):
        # Outer axis we don't move
        outer_steps = 2
        line_outer = LineGenerator("y", "mm", 0, 1, outer_steps)

        # ConcatGenerator we do move
        line1 = LineGenerator("x", "mm", -10, -10, 5)
        line2 = LineGenerator("x", "mm", 0, 180, 10)
        line3 = LineGenerator("x", "mm", 190, 190, 2)
        concat = ConcatGenerator([line1, line2, line3])

        compound = CompoundGenerator([line_outer, concat], [], [],
                                     duration=0.01)
        breakpoints = [2, 3, 10, 2]
        inner_steps = sum(breakpoints)
        total_steps = inner_steps * outer_steps

        self.b.configure(generator=compound,
                         axesToMove=["x"],
                         breakpoints=breakpoints)
        # Configured, completed, total
        self.checkSteps(2, 0, total_steps)
        self.checkState(self.ss.ARMED)

        # Check we have the full configured steps
        assert self.c.configure_params.generator.size == total_steps

        # Check our breakpoints steps
        expected_breakpoint_steps = [2, 5, 15, 17, 19, 22, 32, 34]
        self.assertEqual(expected_breakpoint_steps, self.c.breakpoint_steps)

        # Run our controller through all but last breakpoint
        breakpoints = len(expected_breakpoint_steps)
        for index in range(breakpoints - 1):
            self.b.run()
            self.checkSteps(
                expected_breakpoint_steps[index + 1],
                expected_breakpoint_steps[index],
                total_steps,
            )
            self.checkState(self.ss.ARMED)

        # Final breakpoint
        self.b.run()
        self.checkSteps(total_steps, total_steps, total_steps)
        self.checkState(self.ss.FINISHED)
示例#19
0
    def test_breakpoints_sum_larger_than_total_steps_raises_AssertionError(
            self):
        line1 = LineGenerator("x", "mm", -10, -10, 5)
        line2 = LineGenerator("x", "mm", 0, 180, 10)
        line3 = LineGenerator("x", "mm", 190, 190, 2)
        duration = 0.01
        concat = ConcatGenerator([line1, line2, line3])

        breakpoints = [2, 3, 100, 2]

        self.assertRaises(
            AssertionError,
            self.b.configure,
            generator=CompoundGenerator([concat], [], [], duration),
            axesToMove=["x"],
            breakpoints=breakpoints,
        )
 def test_array_positions_from_2D_line(self):
     genone = LineGenerator(["x", "y"], ["mm", "mm"], [2., -2.],
                            [4., -4.], 3)
     gentwo = LineGenerator(["x", "y"], ["mm", "mm"], [5., -4.],
                            [7., -2.], 3)
     g = ConcatGenerator([genone, gentwo])
     x_positions = [2.0, 3.0, 4.0, 5.0, 6.0, 7.0]
     y_positions = [-2.0, -3.0, -4.0, -4.0, -3.0, -2.0]
     x_bounds = [1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5]
     y_bounds = [-1.5, -2.5, -3.5, -4.5, -3.5, -2.5, -1.5]
     g.prepare_positions()
     g.prepare_bounds()
     self.assertEqual(x_positions, g.positions['x'].tolist())
     self.assertEqual(y_positions, g.positions['y'].tolist())
     self.assertEqual(x_bounds, g.bounds['x'].tolist())
     self.assertEqual(y_bounds, g.bounds['y'].tolist())
    def test_concat_five_twoD_lines(self):
        lineone = LineGenerator(["x", "y"], ["mm", "mm"], [0, 0], [10, 10], 6)
        linetwo = LineGenerator(["x", "y"], ["mm", "mm"], [12, 11], [22, 11], 6)
        linethree = LineGenerator(["x", "y"], ["mm", "mm"], [24, 10],
                                  [34, 0], 6)
        linefour = LineGenerator(["x", "y"], ["mm", "mm"], [32.5, -1], [2.5, -1], 7)
        linefive = LineGenerator(["x", "y"], ["mm", "mm"], [5, 1], [55, 21], 6)

        lines = ConcatGenerator([lineone, linetwo, linethree,
                                linefour, linefive])
        g = CompoundGenerator([lines], [], [], duration=0.5)
        x_positions = [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20,
                       22, 24, 26, 28, 30, 32, 34, 32.5, 27.5, 22.5, 17.5, 12.5,
                       7.5, 2.5, 5.0, 15.0, 25, 35, 45, 55]
        y_positions = [0, 2, 4, 6, 8, 10, 11, 11, 11, 11, 11, 11, 10,
                       8, 6, 4, 2, 0,  -1, -1, -1, -1, -1, -1, -1, 1, 5,
                       9, 13, 17, 21]
        expected_pos = []
        for i in range(len(x_positions)):
            expected_pos.append({"x": x_positions[i], "y": y_positions[i]})
        g.prepare()
        points = list(g.iterator())
        self.assertEqual(expected_pos, [p.positions for p in points])
 def test_init_none(self):
     with self.assertRaises(AssertionError):
         ConcatGenerator([])
 def test_init_alternate_set(self):
     genone = LineGenerator("x", "mm", 1.0, 9.0, 5, alternate=True)
     gentwo = LineGenerator("x", "mm", 13, 20, 5, alternate=True)
     with self.assertRaises(AssertionError):
         ConcatGenerator([genone, gentwo])