def generate_snake_scan(self, trajectory):
        """
        Generate a snake trajectory scan with dynamic velocity for turnarounds and
        trigger setting

        Args:
            trajectory(dict): A dictionary containing the move_time, width & length of
            the snake_scan area and direction (not implemented yet)

        """

        move_time = trajectory['move_time']
        start = trajectory['start']
        stop = trajectory['stop']
        num = trajectory['num']
        direction = trajectory['direction']

        step = int(stop[0] - start[0]) / (num[0] - 1)
        width = (int(stop[0] - start[0]) / step) + 1

        self.point_set = {'time': [], 'x': [], 'y': []}

        if direction == 0:
            xs = LineGenerator("x", "mm", start[0], stop[0], num[0],
                               alternate_direction=True)
            ys = LineGenerator("y", "mm", start[1], stop[1], num[1])
            gen = CompoundGenerator([ys, xs], [], [])
        else:
            raise NotImplementedError("Reverse not implemented")

        for point in gen.iterator():
            self.point_set['x'].append(point.positions['x'])
        for point in gen.iterator():
            self.point_set['y'].append(point.positions['y'])

        trigger = 0
        for i, point in enumerate(self.point_set['x']):

            if (i+1) % width == 0 and i > 0:
                vel_mode = 1
            elif i % width == 0 and i > 0:
                vel_mode = 2
            else:
                vel_mode = 0

            if i % width == 0:
                subroutine = 0
            else:
                if (point/step) % 2 == 0 or (i+1) % width == 0:
                    subroutine = 2
                    trigger = 0
                else:
                    subroutine = 1
                    trigger = 1

            self.point_set['time'].append({'time_val': move_time, 'vel_mode': vel_mode, 'subroutine': subroutine})
Exemplo n.º 2
0
 def test_validate(self):
     generator = CompoundGenerator([], [], [], 0.0102)
     axesToMove = ["x"]
     part_info = self.make_part_info()
     ret = self.o.validate(part_info, generator, axesToMove)
     expected = 0.010166
     assert ret.value.duration == expected
Exemplo n.º 3
0
    def test_run_returns_in_ABORTED_state_when_aborted(self):
        # Add our forever running part
        forever_part = RunForeverPart(mri="childBlock",
                                      name="forever_part",
                                      initial_visibility=True)
        self.c.add_part(forever_part)

        # Configure our block
        duration = 0.1
        line1 = LineGenerator("y", "mm", 0, 2, 3)
        line2 = LineGenerator("x", "mm", 0, 2, 2, alternate=True)
        compound = CompoundGenerator([line1, line2], [], [], duration)
        self.b.configure(generator=compound, axesToMove=["x"])

        # Spawn the abort thread
        abort_thread = cothread.Spawn(self.abort_after_1s, raise_on_wait=True)

        # Do the run, which will be aborted
        with self.assertRaises(AbortedError):
            self.b.run()

        self.checkState(self.ss.ABORTED)

        # Check the abort thread didn't raise
        abort_thread.Wait(1.0)
Exemplo n.º 4
0
 def prepare_half_run(self, duration=0.01, exception=0):
     line1 = LineGenerator('y', 'mm', 0, 2, 3)
     line2 = LineGenerator('x', 'mm', 0, 2, 2)
     compound = CompoundGenerator([line1, line2], [], [], duration)
     self.b.configure(generator=compound,
                      axesToMove=['x'],
                      exceptionStep=exception)
Exemplo n.º 5
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)
Exemplo n.º 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)
Exemplo n.º 7
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)
Exemplo n.º 8
0
 def prepare_half_run(self, duration=0.01, exception=0):
     line1 = LineGenerator("y", "mm", 0, 2, 3)
     line2 = LineGenerator("x", "mm", 0, 2, 2, alternate=True)
     compound = CompoundGenerator([line1, line2], [], [], duration)
     self.b.configure(generator=compound,
                      axesToMove=["x"],
                      exceptionStep=exception)
Exemplo n.º 9
0
    def test_configure_cycle(self):
        self.set_motor_attributes()
        nCycles = 1
        generator = CompoundGenerator([StaticPointGenerator(nCycles)], [], [],
                                      duration=4.0)
        generator.prepare()
        self.o.on_configure(self.context, 0, nCycles, {}, generator, [])

        assert generator.duration == 1.5

        assert self.child.handled_requests.mock_calls == [
            call.post("writeProfile",
                      csPort="CS1",
                      timeArray=[0.002],
                      userPrograms=[8]),
            call.post("executeProfile"),
            call.post("moveCS1",
                      a=-0.125,
                      moveTime=pytest.approx(0.790, abs=1e-3)),
            # pytest.approx to allow sensible compare with numpy arrays
            call.post(
                "writeProfile",
                a=pytest.approx([
                    0.0, 0.25, 0.5, 0.625, 0.625, 0.5, 0.25, 0.0, -0.125,
                    -0.125, 0.0
                ]),
                csPort="CS1",
                timeArray=pytest.approx([
                    250000,
                    250000,
                    250000,
                    250000,
                    1000000,
                    250000,
                    250000,
                    250000,
                    250000,
                    1000000,
                    250000,
                ]),
                userPrograms=pytest.approx([1, 4, 2, 8, 8, 1, 4, 2, 8, 8, 1]),
                velocityMode=pytest.approx([1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 3]),
            ),
        ]
        assert self.o.completed_steps_lookup == [
            0, 0, 1, 1, 1, 1, 1, 2, 3, 3, 3
        ]
    def test_horrible_scan(self):
        lissajous = LissajousGenerator(
            ["j1", "j2"], "mm", [-0.5, 0.7], [2, 3.5], 7, 100)
        line2 = LineGenerator(["l2"], "mm", -3, 3, 7, True)
        line1 = LineGenerator(["l1"], "mm", -1, 2, 5, True)
        spiral = SpiralGenerator(["s1", "s2"], "mm", [1, 2], 5, 2.5, True)
        r1 = CircularROI([1, 1], 2)
        r2 = CircularROI([-1, -1], 4)
        r3 = CircularROI([1, 1], 2)
        e1 = ROIExcluder([r1], ["j1", "l2"])
        e2 = ROIExcluder([r2], ["s2", "l1"])
        e3 = ROIExcluder([r3], ["s1", "s2"])
        g = CompoundGenerator([lissajous, line2, line1, spiral], [e1, e2, e3], [])
        g.prepare()

        l2_f = True
        l1_f = True
        s_f = True
        points = []
        for (j1, j2) in zip(lissajous.positions["j1"], lissajous.positions["j2"]):
            l2p = line2.positions["l2"] if l2_f else line2.positions["l2"][::-1]
            l2_f = not l2_f
            for l2 in l2p:
                l1p = line1.positions["l1"] if l1_f else line1.positions["l1"][::-1]
                l1_f = not l1_f
                for l1 in l1p:
                    sp = zip(spiral.positions["s1"], spiral.positions["s2"]) if s_f \
                        else zip(spiral.positions["s1"][::-1], spiral.positions["s2"][::-1])
                    s_f = not s_f
                    for (s1, s2) in sp:
                        points.append((s1, s2, l1, l2, j1, j2))

        self.assertEqual(lissajous.size * line2.size * line1.size * spiral.size, len(points))
        points = [(s1, s2, l1, l2, j1, j2) for (s1, s2, l1, l2, j1, j2) in points if
            (j1-1)**2 + (l2-1)**2 <= 4 and
            (s2+1)**2 + (l1+1)**2 <= 16 and
            (s1-1)**2 + (s2-1)**2 <= 4]
        self.assertEqual(len(points), g.size)
        generated_points = list(g.iterator())
        self.assertEqual(len(points), len(generated_points))

        actual = [p.positions for p in generated_points]
        expected = [{"j1":j1, "j2":j2, "l2":l2, "l1":l1, "s1":s1, "s2":s2}
            for (s1, s2, l1, l2, j1, j2) in points]
        for e, a in zip(expected, actual):
            self.assertEqual(e, a)
        self.assertEqual((181, 10), g.shape)
Exemplo n.º 11
0
 def test_configure_multiple_no_exposure(self):
     xs = LineGenerator("x", "mm", 0.0, 0.3, 4)
     ys = LineGenerator("y", "mm", 0.0, 0.1, 2)
     generator = CompoundGenerator([ys, xs], [], [], 1.0)
     generator.prepare()
     detectors = DetectorTable.from_rows([[True, "det", "DET", 0.0, 5]])
     self.o.on_configure(self.context, generator, detectors)
     assert self.o.generator_duration == 1.0
     assert self.o.frames_per_step == 5
     # Detector would normally be configured by DetectorChildPart
     detector = self.process.block_view("DET")
     spg = StaticPointGenerator(5, axes=["det_frames_per_step"])
     ex = SquashingExcluder(axes=["det_frames_per_step", "x"])
     generatormultiplied = CompoundGenerator([ys, xs, spg], [ex], [], 0.2)
     detector.configure(generatormultiplied, self.tmpdir)
     self.o.on_post_configure()
     self.check_pulse_mocks(0.19899, 0.2, 0.000505, 5)
Exemplo n.º 12
0
 def validate(self, value):
     if value is None or isinstance(value, CompoundGenerator):
         return value
     elif isinstance(value, (OrderedDict, dict)):
         return CompoundGenerator.from_dict(value)
     else:
         raise TypeError(
             "Value %s must be a Generator object or dictionary" % value)
Exemplo n.º 13
0
 def test_validate(self):
     generator = CompoundGenerator([], [], [], 0.0102)
     axesToMove = ["x"]
     # servoFrequency() return value
     self.child.handled_requests.post.return_value = 4919.300698316487
     ret = self.o.on_validate(self.context, generator, axesToMove, {})
     expected = 0.010166
     assert ret.value.duration == expected
Exemplo n.º 14
0
 def prepare_half_run(self):
     line1 = LineGenerator('AxisOne', 'mm', 0, 2, 3)
     line2 = LineGenerator('AxisTwo', 'mm', 0, 2, 2)
     compound = CompoundGenerator([line1, line2], [], [], 1.0)
     params = ScanTickerPart.configure.MethodMeta.prepare_input_map(
         generator=compound, axesToMove=['AxisTwo'])
     params.generator.prepare()
     self.o.configure(MagicMock(), 0, 2, MagicMock(), params)
Exemplo n.º 15
0
def lissajous_rectangle_check():

    bounding_box = dict(centre=[0.0, 0.0], span=[1.0, 1.0], lobes=2)
    lissajous = LissajousGenerator(['x', 'y'], ["mm", "mm"], **bounding_box)
    rectangle = ROIExcluder([RectangularROI([0.0, 0.0], 0.8, 0.8)], ['x', 'y'])
    gen = CompoundGenerator([lissajous], [rectangle], [])

    plot_generator(gen, rectangle)
Exemplo n.º 16
0
def spiral_rectangle_check():

    spiral = SpiralGenerator(['x', 'y'], ["mm", "mm"], [0.0, 0.0], 10.0)
    rectangle = ROIExcluder([RectangularROI([0.0, 0.0], 10.0, 10.0)],
                            ['x', 'y'])
    gen = CompoundGenerator([spiral], [rectangle], [])

    plot_generator(gen, rectangle)
Exemplo n.º 17
0
 def validate(self, generator: AGenerator) -> UInfos:
     if generator.duration < 0.1:
         serialized = generator.to_dict()
         new_generator = CompoundGenerator.from_dict(serialized)
         new_generator.duration = 0.1
         return ParameterTweakInfo("generator", new_generator)
     else:
         return None
Exemplo n.º 18
0
    def test_validate_with_no_min_acquire_period_does_not_tweak(self):
        xs = LineGenerator("x", "mm", 0.0, 0.5, 3, alternate=True)
        ys = LineGenerator("y", "mm", 0.0, 0.1, 2)
        generator = CompoundGenerator([ys, xs], [], [], 1.0)

        tweaks = self.o.on_validate(self.context, generator)

        assert tweaks is None, "Shouldn't have tweaked anything"
 def test_two_dim_inner_alternates(self):
     wg = LineGenerator("w", "mm", 0, 1, 2)
     zg = LineGenerator("z", "mm", 0, 1, 2)
     yg = LineGenerator("y", "mm", 1, 3, 3, True)
     xg = LineGenerator("x", "mm", 0, 1, 2, True)
     r1 = EllipticalROI([0, 1], [1, 2])
     r2 = SectorROI([0, 0], [0.2, 1], [0, 7])
     e1 = ROIExcluder([r1], ['x', 'y'])
     e2 = ROIExcluder([r2], ['w', 'z'])
     g = CompoundGenerator([wg, zg, yg, xg], [e1, e2], [])
     g.prepare()
     actual = [p.positions for p in g.iterator()]
     expected = [(0, 3, 1, 0), (0, 2, 1, 0), (1, 1, 1, 0), (0, 1, 1, 0),
         (0, 1, 0, 1), (1, 1, 0, 1), (0, 2, 0, 1), (0, 3, 0, 1)]
     expected = [{"x":float(x), "y":float(y), "z":float(z), "w":float(w)}
         for (x, y, z, w) in expected]
     self.assertEqual(expected, actual)
 def test_simple_mask_alternating_spiral(self):
     z = LineGenerator("z", "mm", 0.0, 4.0, 5)
     spiral = SpiralGenerator(['x', 'y'],
                              "mm", [0.0, 0.0],
                              3,
                              alternate=True)  #29 points
     r = RectangularROI([-2, -2], 3, 4)
     e = ROIExcluder([r], ["x", "y"])
     g = CompoundGenerator([z, spiral], [e], [])
     g.prepare()
     p = list(zip(spiral.positions['x'], spiral.positions['y']))
     expected = [x >= -2 and x < 1 and y >= -2 and y < 2 for (x, y) in p]
     expected_r = [
         x >= -2 and x < 1 and y >= -2 and y < 2 for (x, y) in p[::-1]
     ]
     actual = g.dimensions[1].mask.tolist()
     self.assertEqual(expected, actual)
Exemplo n.º 21
0
def grid_circle_check():

    x = LineGenerator("x", "mm", 0.0, 4.0, 5, alternate=True)
    y = LineGenerator("y", "mm", 0.0, 3.0, 4)
    circle = ROIExcluder([CircularROI([2.0, 1.0], 2.0)], ['x', 'y'])
    gen = CompoundGenerator([y, x], [circle], [])

    plot_generator(gen, circle)
Exemplo n.º 22
0
 def test_validate_fails(self):
     params = MagicMock()
     xs = LineGenerator("x", "mm", 0.0, 0.5, 3, alternate=True)
     ys = LineGenerator("y", "mm", 0.0, 0.1, 2)
     params.generator = CompoundGenerator([ys, xs], [], [], 0.00009)
     params.generator.prepare()
     with self.assertRaises(AssertionError):
         self.o.validate(ANY, ANY, params)
 def validate(self, value):
     if value is None or isinstance(value, CompoundGenerator):
         return value
     elif isinstance(value, (OrderedDict, dict)):
         return CompoundGenerator.from_dict(value)
     else:
         raise TypeError(
             "Value %s must be a Generator object or dictionary" % value)
Exemplo n.º 24
0
 def test_validate(self):
     params = Mock()
     params.generator = CompoundGenerator([], [], [], 0.0102)
     params.axesToMove = ["x"]
     part_info = self.make_part_info()
     ret = self.o.validate(self.context, part_info, params)
     expected = 0.010166
     assert ret[0].value.duration == expected
Exemplo n.º 25
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)
Exemplo n.º 26
0
 def test_validate(self):
     params = Mock()
     params.generator = CompoundGenerator([], [], [], 0.0102)
     params.axesToMove = ["x"]
     part_info = self.make_part_info()
     ret = self.o.validate(None, part_info, params)
     expected = 0.010166
     self.assertEqual(ret[0].value.duration, expected)
    def test_multi_roi_excluder(self):
        x = LineGenerator("x", "mm", 0.0, 4.0, 5, alternate=True)
        y = LineGenerator("y", "mm", 0.0, 3.0, 4)
        circles = ROIExcluder(
            [CircularROI([1.0, 2.0], 2.0),
             CircularROI([1.0, 2.0], 2.0)], ["x", "y"])
        expected_positions = [{
            'x': 1.0,
            'y': 0.0
        }, {
            'x': 2.0,
            'y': 1.0
        }, {
            'x': 1.0,
            'y': 1.0
        }, {
            'x': 0.0,
            'y': 1.0
        }, {
            'x': 0.0,
            'y': 2.0
        }, {
            'x': 1.0,
            'y': 2.0
        }, {
            'x': 2.0,
            'y': 2.0
        }, {
            'x': 3.0,
            'y': 2.0
        }, {
            'x': 2.0,
            'y': 3.0
        }, {
            'x': 1.0,
            'y': 3.0
        }, {
            'x': 0.0,
            'y': 3.0
        }]

        g = CompoundGenerator([y, x], [circles], [])
        g.prepare()
        positions = [point.positions for point in list(g.iterator())]

        self.assertEqual(positions, expected_positions)
Exemplo n.º 28
0
    def test_bs(self):
        b = self.context.block_view("SCAN")
        generator = CompoundGenerator([LineGenerator("x", "mm", 0, 1, 10)], [], [], 0.1)
        b.configure(generator)

        self.o.on_configure(self.context)

        assert self.child.handled_requests.mock_calls == [call.put("demand", 50)]
 def test_double_mask_spiral(self):
     zgen = LineGenerator("z", "mm", 0.0, 4.0, 5)
     spiral = SpiralGenerator(['x', 'y'], "mm", [0.0, 0.0], 3)  #29 points
     r1 = RectangularROI([-2, -2], 4, 3)
     r2 = RectangularROI([-2, 0], 4, 3)
     e1 = ROIExcluder([r1], ["y", "x"])
     e2 = ROIExcluder([r2], ["y", "z"])
     g = CompoundGenerator([zgen, spiral], [e1, e2], [])
     g.prepare()
     p = list(zip(spiral.positions['x'], spiral.positions['y']))
     p = [(x, y, z) for z in range_(0, 5) for (x, y) in p]
     expected = [
         x >= -2 and x <= 1 and y >= -2 and y <= 2 and z >= 0 and z <= 3
         for (x, y, z) in p
     ]
     actual = g.dimensions[0].mask.tolist()
     self.assertEqual(expected, actual)
 def test_simple_mask_alternating(self):
     x = LineGenerator("x", "mm", -1.0, 1.0, 5, alternate=True)
     y = LineGenerator("y", "mm", -1.0, 1.0, 5, alternate=True)
     r = CircularROI([0.5, 0], 1)
     e = ROIExcluder([r], ["x", "y"])
     g = CompoundGenerator([y, x], [e], [])
     g.prepare()
     reverse = False
     p = []
     for y in range_(-2, 3):
         if reverse:
             p += [(x / 2., y / 2.) for x in range_(2, -3, -1)]
         else:
             p += [(x / 2., y / 2.) for x in range_(-2, 3)]
         reverse = not reverse
     expected_mask = [(x - 0.5)**2 + y**2 <= 1**2 for (x, y) in p]
     self.assertEqual(expected_mask, g.dimensions[0].mask.tolist())
 def test_configure(self):
     params = Mock()
     params.info_table = Table(info_table_meta)
     params.info_table.name = ["x", "y"]
     params.info_table.cs_axis = ["A", "B"]
     params.info_table.cs_port = ["CS1", "CS1"]
     params.info_table.acceleration_time = [0.1, 0.1]
     params.info_table.resolution = [0.001, 0.001]
     params.info_table.offset = [0, 0]
     params.info_table.max_velocity = [1.0, 1.0]
     params.info_table.current_position = [0.5, 0.0]
     params.start_step = 0
     xs = LineGenerator("x", "mm", 0.0, 0.5, 3, alternate_direction=True)
     ys = LineGenerator("y", "mm", 0.0, 0.1, 2)
     params.generator = CompoundGenerator([ys, xs], [], [])
     params.exposure = 1.0
     params.axes_to_move = ["x", "y"]
     task = Mock()
     self.o.configure(task, params)
     self.assertEqual(task.put.call_count, 4)
     self.assertEqual(task.post.call_count, 3)
     self.check_resolutions_and_use(task.put.call_args_list[0][0][0])
     self.assertEqual(
         task.put.call_args_list[1][0][0], {
             self.child["time_array"]: [400, 1750, 400],
             self.child["velocity_mode"]: [2, 1, 3],
             self.child["user_programs"]: [0, 0, 0],
             self.child["num_points"]: 3,
             self.child["positionsA"]:
             [0.45, -0.087500000000000008, -0.1375],
             self.child["positionsB"]: [0.0, 0.0, 0.0]
         })
     self.assertEqual(task.post.call_args_list[0],
                      call(self.child["build_profile"]))
     self.assertEqual(task.post.call_args_list[1],
                      call(self.child["execute_profile"]))
     self.check_resolutions_and_use(task.put.call_args_list[2][0][0])
     self.assertEqual(
         task.put.call_args_list[3][0][0], {
             self.child["time_array"]: [
                 400, 2000, 2000, 2000, 2000, 2000, 2000, 400, 400, 2000,
                 2000, 2000, 2000, 2000, 2000, 400
             ],
             self.child["velocity_mode"]:
             [2, 0, 0, 0, 0, 0, 1, 0, 2, 0, 0, 0, 0, 0, 1, 3],
             self.child["user_programs"]:
             [3, 4, 3, 4, 3, 4, 2, 8, 3, 4, 3, 4, 3, 4, 2, 8],
             self.child["num_points"]:
             16,
             self.child["positionsA"]: [
                 -0.125, 0.0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.6375, 0.625,
                 0.5, 0.375, 0.25, 0.125, 0.0, -0.125, -0.1375
             ],
             self.child["positionsB"]: [
                 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.05, 0.1, 0.1, 0.1,
                 0.1, 0.1, 0.1, 0.1, 0.1
             ]
         })
    def test_abort_does_not_throw_exception_if_no_seq_reset_exported(self):
        original_exports = self.panda.exports.value.rows()
        exports = ExportTable.from_rows(
            [row for row in original_exports if row[1] != "seqReset"])
        self.panda.set_exports(exports)

        xs = LineGenerator("x", "mm", 0.0, 0.3, 4, alternate=True)
        ys = LineGenerator("y", "mm", 0.0, 0.1, 2)
        generator = CompoundGenerator([ys, xs], [], [], 1.0)
        generator.prepare()
        completed_steps = 0
        steps_to_do = generator.size
        self.set_motor_attributes()
        axes_to_move = ["x", "y"]

        self.o.on_configure(self.context, completed_steps, steps_to_do, {},
                            generator, axes_to_move)
        self.o.on_abort(self.context)
 def __init__(self, iterators, excluders, mutators):
     super(JCompoundGenerator, self).__init__()
     
     try:  # If JavaIteratorWrapper
         generators = [iterator.generator for iterator in iterators]
     except AttributeError:  # Else call get*() of Java iterator
         generators = [iterator.getPyIterator().generator for iterator in iterators]
     logging.debug("Generators passed to JCompoundGenerator:")
     logging.debug([generator.to_dict() for generator in generators])
     
     excluders = [excluder.py_excluder for excluder in excluders]
     mutators = [mutator.py_mutator for mutator in mutators]
     
     extracted_generators = []
     for generator in generators:
         if generator.__class__.__name__ == "CompoundGenerator":
             extracted_generators.extend(generator.generators)
         else:
             extracted_generators.append(generator)
     generators = extracted_generators
     
     self.index_locations = {}
     self.dimension_names = ArrayList()
     self.axes_ordering = []
     for index, generator in enumerate(generators):
         
         scan_name = ArrayList()
         for axis in generator.axes:
             self.index_locations[axis] = index
             self.axes_ordering.append(axis)
             scan_name.add(axis)
             
         self.dimension_names.add(scan_name)
     
     logging.debug("Index Locations:")
     logging.debug(self.index_locations)
     logging.debug("Axes Ordering:")
     logging.debug(self.axes_ordering)
     
     self.generator = CompoundGenerator(generators, excluders, mutators)
     self.generator.prepare()
     
     logging.debug("CompoundGenerator:")
     logging.debug(self.generator.to_dict())
class JCompoundGenerator(JavaIteratorWrapper):
    """
    Create a CompoundGenerator and wrap the points into java Point objects
    """

    def __init__(self, iterators, excluders, mutators):
        super(JCompoundGenerator, self).__init__()
        
        try:  # If JavaIteratorWrapper
            generators = [iterator.generator for iterator in iterators]
        except AttributeError:  # Else call get*() of Java iterator
            generators = [iterator.getPyIterator().generator for iterator in iterators]
        logging.debug("Generators passed to JCompoundGenerator:")
        logging.debug([generator.to_dict() for generator in generators])
        
        excluders = [excluder.py_excluder for excluder in excluders]
        mutators = [mutator.py_mutator for mutator in mutators]
        
        extracted_generators = []
        for generator in generators:
            if generator.__class__.__name__ == "CompoundGenerator":
                extracted_generators.extend(generator.generators)
            else:
                extracted_generators.append(generator)
        generators = extracted_generators
        
        self.index_locations = {}
        self.dimension_names = ArrayList()
        self.axes_ordering = []
        for index, generator in enumerate(generators):
            
            scan_name = ArrayList()
            for axis in generator.axes:
                self.index_locations[axis] = index
                self.axes_ordering.append(axis)
                scan_name.add(axis)
                
            self.dimension_names.add(scan_name)
        
        logging.debug("Index Locations:")
        logging.debug(self.index_locations)
        logging.debug("Axes Ordering:")
        logging.debug(self.axes_ordering)
        
        self.generator = CompoundGenerator(generators, excluders, mutators)
        self.generator.prepare()
        
        logging.debug("CompoundGenerator:")
        logging.debug(self.generator.to_dict())
    
    def _iterator(self):
        
        for point in self.generator.iterator():
            
            if len(point.positions.keys()) == 1:
                name = point.positions.keys()[0]
                index = point.indexes[0]
                position = point.positions[name]
                java_point = Scalar(name, index, position)
                
            elif len(point.positions.keys()) == 2:
                logging.debug([point.indexes, point.positions])
                
                names = []
                indexes = []
                values = []
                for axis in self.axes_ordering:
                    index = self.index_locations[axis]
                    indexes.append(point.indexes[index])
                    logging.debug([axis, index])
                    values.append(point.positions[axis])
                    names.append(axis)
                    
                java_point = Point(names[1], indexes[1], values[1], 
                                   names[0], indexes[0], values[0])
                java_point.setDimensionNames(self.dimension_names)
            else:
                java_point = MapPosition()
                
                for axis in self.axes_ordering:
                    index = self.index_locations[axis]
                    logging.debug([axis, index])
                    value = point.positions[axis]
                    java_point.put(axis, value)
                    java_point.putIndex(axis, point.indexes[index])
                
                java_point.setDimensionNames(self.dimension_names)
                
            yield java_point