Beispiel #1
0
    def test_GIVEN_theta_WHEN_set_set_point_THEN_sample_hasnt_moved(self):
        theta_set = 10.0
        sample = ReflectingComponent("sample", movement_strategy=LinearMovement(0, 0, 90))
        mirror_pos = -100
        sample.angle = mirror_pos
        theta = Theta("theta", sample)

        theta.sp_no_move = theta_set

        assert_that(theta.sp, is_(theta_set))
        assert_that(sample.angle, is_(mirror_pos))
 def setup_beamline(self, initial_mirror_angle, mirror_position,
                    beam_start):
     jaws = Component("jaws", movement_strategy=LinearMovement(0, 0, 90))
     mirror = ReflectingComponent("mirror",
                                  movement_strategy=LinearMovement(
                                      0, mirror_position, 90))
     mirror.angle = initial_mirror_angle
     jaws3 = Component("jaws3", movement_strategy=LinearMovement(0, 20, 90))
     beamline = Beamline([jaws, mirror, jaws3], [], [], [])
     beamline.set_incoming_beam(beam_start)
     return beamline, mirror
Beispiel #3
0
    def test_GIVEN_mode_has_initial_value_for_param_not_in_beamline_WHEN_setting_mode_THEN_keyerror_raised(self):
        sm_angle = 0.0
        super_mirror = ReflectingComponent("super mirror", LinearMovement(z_position=10, y_position=0, angle=90))
        super_mirror.angle = sm_angle
        smangle = ReflectionAngle("smangle", super_mirror)
        smangle.sp_no_move = sm_angle
        sp_inits = {"nonsense name": sm_angle}
        beamline_mode = BeamlineMode("mode name", [smangle.name], sp_inits)
        beamline = Beamline([super_mirror], [smangle], [], [beamline_mode])

        with self.assertRaises(KeyError):
            beamline.active_mode = beamline_mode
Beispiel #4
0
    def test_GIVEN_reflection_angle_WHEN_set_set_point_and_move_THEN_readback_is_as_set_and_sample_is_at_setpoint_postion(self):

        angle_set = 10.0
        expected_sample_angle = 10.0
        sample = ReflectingComponent("sample", movement_strategy=LinearMovement(0, 0, 90))
        sample.set_incoming_beam(PositionAndAngle(0, 0, 0))
        mirror_pos = -100
        sample.angle = mirror_pos
        reflection_angle = ReflectionAngle("theta", sample)

        reflection_angle.sp_no_move = angle_set
        reflection_angle.move = 1
        result = reflection_angle.sp_rbv

        assert_that(result, is_(angle_set))
        assert_that(sample.angle, is_(expected_sample_angle))
Beispiel #5
0
    def test_GIVEN_theta_set_WHEN_set_point_set_and_move_THEN_readback_is_as_original_value_but_setpoint_is_new_value(self):

        original_theta = 1.0
        theta_set = 10.0
        sample = ReflectingComponent("sample", movement_strategy=LinearMovement(0, 0, 90))
        sample.set_incoming_beam(PositionAndAngle(0, 0, 0))
        mirror_pos = -100
        sample.angle = mirror_pos
        theta = Theta("theta", sample)
        theta.sp = original_theta

        theta.sp_no_move = theta_set
        result = theta.sp_rbv

        assert_that(result, is_(original_theta))
        assert_that(theta.sp, is_(theta_set))
Beispiel #6
0
    def test_GIVEN_mode_has_initial_parameter_value_WHEN_setting_mode_THEN_component_sp_updated_but_rbv_unchanged(self):
        sm_angle = 0.0
        sm_angle_to_set = 45.0
        super_mirror = ReflectingComponent("super mirror", LinearMovement(z_position=10, y_position=0, angle=90))
        super_mirror.angle = sm_angle
        smangle = ReflectionAngle("smangle", super_mirror)
        smangle.sp_no_move = sm_angle
        sp_inits = {smangle.name: sm_angle_to_set}
        beamline_mode = BeamlineMode("mode name", [smangle.name], sp_inits)
        beamline = Beamline([super_mirror], [smangle], [], [beamline_mode])
        beamline.set_incoming_beam(PositionAndAngle(0, 0, 0))

        beamline.active_mode = beamline_mode

        assert_that(smangle.sp, is_(sm_angle_to_set))
        assert_that(smangle.sp_changed, is_(True))
        assert_that(super_mirror.angle, is_(sm_angle))
Beispiel #7
0
    def test_GIVEN_angled_mirror_is_disabled_WHEN_get_beam_out_THEN_outgoing_beam_is_incoming_beam(
            self):
        mirror_z_position = 10
        mirror_angle = 15
        beam_start = PositionAndAngle(y=0, z=0, angle=0)
        expected = beam_start

        mirror = ReflectingComponent("component",
                                     movement_strategy=LinearMovement(
                                         0, mirror_z_position, 90))
        mirror.angle = mirror_angle
        mirror.set_incoming_beam(beam_start)
        mirror.enabled = False

        result = mirror.get_outgoing_beam()

        assert_that(result, is_(position_and_angle(expected)))
Beispiel #8
0
    def test_GIVEN_mirror_with_input_beam_at_WHEN_get_beam_out_THEN_beam_output_correct(
            self, beam_angle, mirror_angle, outgoing_angle):
        beam_start = PositionAndAngle(y=0, z=0, angle=beam_angle)
        expected = PositionAndAngle(y=0, z=0, angle=outgoing_angle)

        mirror = ReflectingComponent("component",
                                     movement_strategy=LinearMovement(
                                         0, 0, 90))
        mirror.angle = mirror_angle
        mirror.set_incoming_beam(beam_start)

        result = mirror.get_outgoing_beam()

        assert_that(
            result, is_(position_and_angle(expected)),
            "beam_angle: {}, mirror_angle: {}".format(beam_angle,
                                                      mirror_angle))
Beispiel #9
0
    def test_GIVEN_mirror_with_input_beam_at_0_deg_and_z0_y0_WHEN_get_beam_out_THEN_beam_output_z_is_zmirror_y_is_ymirror_angle_is_input_angle_plus_device_angle(
            self):
        mirror_z_position = 10
        mirror_angle = 15
        beam_start = PositionAndAngle(y=0, z=0, angle=0)
        expected = PositionAndAngle(y=0,
                                    z=mirror_z_position,
                                    angle=2 * mirror_angle)

        mirror = ReflectingComponent("component",
                                     movement_strategy=LinearMovement(
                                         0, mirror_z_position, 90))
        mirror.angle = mirror_angle
        mirror.set_incoming_beam(beam_start)

        result = mirror.get_outgoing_beam()

        assert_that(result, is_(position_and_angle(expected)))
    def test_GIVEN_multiple_components_in_beamline_WHEN_triggering_move_THEN_components_move_at_speed_of_slowest_axis(
            self):
        sm_angle = 0.0
        sm_angle_to_set = 22.5
        supermirror = ReflectingComponent("supermirror",
                                          movement_strategy=LinearMovement(
                                              y_position=0.0,
                                              z_position=10.0,
                                              angle=90.0))
        sm_height_axis = create_mock_axis("SM:HEIGHT", 0.0, 10.0)
        sm_angle_axis = create_mock_axis("SM:ANGLE", sm_angle, 10.0)
        supermirror.angle = sm_angle
        supermirror_driver = HeightAndAngleDriver(supermirror, sm_height_axis,
                                                  sm_angle_axis)

        slit_2 = Component("slit_2",
                           movement_strategy=LinearMovement(y_position=0.0,
                                                            z_position=20.0,
                                                            angle=90.0))
        slit_2_height_axis = create_mock_axis("SLIT2:HEIGHT", 0.0, 10.0)
        slit_2_driver = HeightDriver(slit_2, slit_2_height_axis)

        slit_3 = Component("slit_3",
                           movement_strategy=LinearMovement(y_position=0.0,
                                                            z_position=30.0,
                                                            angle=90.0))
        slit_3_height_axis = create_mock_axis("SLIT3:HEIGHT", 0.0, 10.0)
        slit_3_driver = HeightDriver(slit_3, slit_3_height_axis)

        detector = TiltingJaws(
            "jaws",
            movement_strategy=LinearMovement(y_position=0.0,
                                             z_position=40.0,
                                             angle=90.0))
        detector_height_axis = create_mock_axis("DETECTOR:HEIGHT", 0.0, 10.0)
        detector_tilt_axis = create_mock_axis("DETECTOR:TILT", 0.0, 10.0)
        detector_driver = HeightAndTiltDriver(detector, detector_height_axis,
                                              detector_tilt_axis)

        smangle = ReflectionAngle("smangle", supermirror)
        slit_2_pos = TrackingPosition("s2_pos", slit_2)
        slit_3_pos = TrackingPosition("s3_pos", slit_3)
        det_pos = TrackingPosition("det_pos", detector)
        components = [supermirror, slit_2, slit_3, detector]
        beamline_parameters = [smangle, slit_2_pos, slit_3_pos, det_pos]
        drivers = [
            supermirror_driver, slit_2_driver, slit_3_driver, detector_driver
        ]
        mode = BeamlineMode(
            "mode name",
            [smangle.name, slit_2_pos.name, slit_3_pos.name, det_pos.name])
        beamline = Beamline(components, beamline_parameters, drivers, [mode])

        beamline.active_mode = mode

        beam_start = PositionAndAngle(0.0, 0.0, 0.0)
        beamline.set_incoming_beam(beam_start)
        slit_2_pos.sp_no_move = 0.0
        slit_3_pos.sp_no_move = 0.0
        det_pos.sp_no_move = 0.0

        # detector angle axis takes longest
        expected_max_duration = 4.5

        smangle.sp_no_move = sm_angle_to_set
        with patch.object(beamline, '_move_drivers') as mock:
            beamline.move = 1

            mock.assert_called_with(expected_max_duration)