Пример #1
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
Пример #2
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))
Пример #3
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))
Пример #4
0
    def test_GIVEN_parameter_not_in_mode_and_not_changed_and_previous_parameter_changed_WHEN_moving_beamline_THEN_parameter_unchanged(self):
        initial_s2_height = 0.0
        super_mirror = ReflectingComponent("sm", LinearMovement(0.0, 10, 90.0))
        s2 = Component("s2", LinearMovement(initial_s2_height, 20, 90.0))

        sm_angle = ReflectionAngle("smangle", super_mirror)
        slit2_pos = TrackingPosition("slit2pos", s2)

        mode = BeamlineMode("first_param", [sm_angle.name])

        beamline = Beamline([super_mirror, s2], [sm_angle, slit2_pos], [], [mode])
        beamline.set_incoming_beam(PositionAndAngle(0, 0, 0))
        beamline.active_mode = mode
        sm_angle.sp_no_move = 10.0

        beamline.move = 1

        assert_that(s2.sp_position().y, is_(initial_s2_height))
Пример #5
0
    def test_GIVEN_a_mode_with_a_two_beamline_parameter_in_WHEN_move_first_THEN_second_beamline_parameter_is_calculated_and_moved_to(self):
        angle_to_set = 45.0
        ideal_sample_point = ReflectingComponent("ideal_sample_point", LinearMovement(y_position=0, z_position=20, angle=90))
        theta = Theta("theta", ideal_sample_point)
        super_mirror = ReflectingComponent("super mirror", LinearMovement(y_position=0, z_position=10, angle=90))
        smangle = ReflectionAngle("smangle", super_mirror)

        beamline_mode = BeamlineMode("mode name", [theta.name, smangle.name])
        beamline = Beamline([super_mirror, ideal_sample_point], [smangle, theta], [], [beamline_mode])
        beam = PositionAndAngle(0, 0, 0)
        theta.sp_no_move = angle_to_set
        smangle.sp_no_move = 0
        beamline.set_incoming_beam(beam)
        beamline.active_mode = beamline_mode
        beamline.move = 1

        smangle_to_set = -10
        smangle.sp = smangle_to_set

        assert_that(ideal_sample_point.angle, is_(smangle_to_set*2 + angle_to_set))
Пример #6
0
    def test_GIVEN_parameter_changed_and_not_in_mode_and_previous_parameter_changed_WHEN_moving_beamline_THEN_parameter_moved_to_sp(
            self):
        initial_s2_height = 0.0
        target_s2_height = 11.0
        super_mirror = ReflectingComponent("sm", LinearMovement(0.0, 10, 90.0))
        s2 = Component("s2", LinearMovement(initial_s2_height, 20, 90.0))

        sm_angle = ReflectionAngle("smangle", super_mirror)
        slit2_pos = TrackingPosition("slit2pos", s2)

        empty_mode = BeamlineMode("empty", [])

        beamline = Beamline([super_mirror, s2], [sm_angle, slit2_pos], [], [empty_mode])
        beamline.set_incoming_beam(PositionAndAngle(0, 0, 0))
        beamline.active_mode = empty_mode

        sm_angle.sp_no_move = 22.5
        slit2_pos.sp_no_move = 1.0
        beamline.move = 1

        assert_that(s2.sp_position().y, is_(close_to(target_s2_height, DEFAULT_TEST_TOLERANCE)))
    def setUp(self):
        beam_start = PositionAndAngle(y=0, z=0, angle=2.5)
        s0 = Component("s0", movement_strategy=LinearMovement(0, 0, 90))
        s1 = Component("s1", movement_strategy=LinearMovement(0, 1, 90))
        frame_overlap_mirror = ReflectingComponent(
            "FOM", movement_strategy=LinearMovement(0, 2, 90))
        frame_overlap_mirror.enabled = False
        self.polarising_mirror = ReflectingComponent(
            "Polariser", movement_strategy=LinearMovement(0, 3, 90))
        self.polarising_mirror.enabled = False
        self.polarising_mirror.angle = 0
        s2 = Component("s2", movement_strategy=LinearMovement(0, 4, 90))
        self.ideal_sample_point = ReflectingComponent(
            "ideal sample point", movement_strategy=LinearMovement(0, 5, 90))
        s3 = Component("s3", movement_strategy=LinearMovement(0, 6, 90))
        analyser = ReflectingComponent("analyser",
                                       movement_strategy=LinearMovement(
                                           0, 7, 90))
        analyser.enabled = False
        s4 = Component("s4", movement_strategy=LinearMovement(0, 8, 90))
        detector = Component("detector",
                             movement_strategy=LinearMovement(0, 10, 90))

        theta = Theta("theta", self.ideal_sample_point)
        theta.sp_no_move = 0
        smangle = ReflectionAngle("smangle", self.polarising_mirror)
        smangle.sp_no_move = 0

        self.nr_mode = BeamlineMode("NR Mode", [theta.name])
        self.polarised_mode = BeamlineMode("NR Mode",
                                           [smangle.name, theta.name])

        self.beamline = Beamline([
            s0, s1, frame_overlap_mirror, self.polarising_mirror, s2,
            self.ideal_sample_point, s3, analyser, s4, detector
        ], [smangle, theta], [], [self.nr_mode, self.polarised_mode])
        self.beamline.set_incoming_beam(beam_start)
    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)