Пример #1
0
    def test_GIVEN_unpolarised_mode_and_beamline_parameters_are_set_WHEN_move_THEN_components_move_onto_beam_line(self):
        slit2 = Component("s2", LinearMovement(0, z_position=10, angle=90))
        ideal_sample_point = ReflectingComponent("ideal_sample_point", LinearMovement(0, z_position=20, angle=90))
        detector = Component("detector", LinearMovement(0, z_position=30, angle=90))
        components = [slit2, ideal_sample_point, detector]

        parameters = [
            TrackingPosition("slit2height", slit2),
            TrackingPosition("height", ideal_sample_point),
            Theta("theta", ideal_sample_point),
            TrackingPosition("detectorheight", detector)]
                      #parameters["detectorAngle": TrackingAngle(detector)
        beam = PositionAndAngle(0, 0, -45)
        beamline = Beamline(components, parameters, [], [DataMother.BEAMLINE_MODE_NEUTRON_REFLECTION])
        beamline.set_incoming_beam(beam)
        beamline.active_mode = DataMother.BEAMLINE_MODE_NEUTRON_REFLECTION
        beamline.parameter("theta").sp_no_move = 45
        beamline.parameter("height").sp_no_move = 0
        beamline.parameter("slit2height").sp_no_move = 0
        beamline.parameter("detectorheight").sp_no_move = 0

        beamline.move = 1

        assert_that(slit2.sp_position(), is_(position(Position(-10, 10))))
        assert_that(ideal_sample_point.sp_position(), is_(position(Position(-20, 20))))
        assert_that(detector.sp_position(), is_(position(Position(-10, 30))))
Пример #2
0
def create_beamline():
    perp_to_floor = 90.0
    beam_start = PositionAndAngle(y=0, z=0, angle=-2.5)
    s0 = Component("s0", movement_strategy=LinearMovement(0, 0, perp_to_floor))
    s1 = Component("s1", movement_strategy=LinearMovement(0, 1, perp_to_floor))
    frame_overlap_mirror = ReflectingComponent(
        "FOM", movement_strategy=LinearMovement(0, 2, perp_to_floor))
    frame_overlap_mirror.enabled = False
    polarising_mirror = ReflectingComponent("Polarising mirror",
                                            movement_strategy=LinearMovement(
                                                0, 3, perp_to_floor))
    polarising_mirror.enabled = False
    s2 = Component("s2", movement_strategy=LinearMovement(0, 4, perp_to_floor))
    ideal_sample_point = ReflectingComponent("Ideal Sample Point",
                                             movement_strategy=LinearMovement(
                                                 0, 5, perp_to_floor))
    s3 = Component("s3", movement_strategy=LinearMovement(0, 6, perp_to_floor))
    analyser = ReflectingComponent("analyser",
                                   movement_strategy=LinearMovement(
                                       0, 7, perp_to_floor))
    analyser.enabled = False
    s4 = Component("s4", movement_strategy=LinearMovement(0, 8, perp_to_floor))
    detector = Component("detector",
                         movement_strategy=LinearMovement(
                             0, 10, perp_to_floor))

    theta = Theta("theta", ideal_sample_point)
    beamline = Beamline([
        s0, s1, frame_overlap_mirror, polarising_mirror, s2,
        ideal_sample_point, s3, analyser, s4, detector
    ], [theta], [])
    beamline.set_incoming_beam(beam_start)
    beamline.active_mode = BeamlineMode("NR", ["theta"])

    return beamline
    def test_GIVEN_move_duration_and_target_position_set_WHEN_moving_multiple_axes_THEN_computed_axis_velocity_is_correct_and_setpoint_set_for_all_axes(
            self):
        beam_angle = 45.0
        beam = PositionAndAngle(0.0, 0.0, beam_angle)
        target_duration = 10.0
        expected_velocity_height = 1.0
        target_position_height = 10.0
        expected_velocity_tilt = 4.5
        target_position_tilt = 135.0
        self.tilting_jaws.set_incoming_beam(beam)
        self.tilting_jaws.set_position_relative_to_beam(
            0.0)  # move component into beam

        self.tilting_jaws_driver.perform_move(target_duration)

        assert_that(
            fabs(self.height_axis.velocity -
                 expected_velocity_height) <= FLOAT_TOLERANCE)
        assert_that(
            fabs(self.height_axis.value -
                 target_position_height) <= FLOAT_TOLERANCE)
        assert_that(
            fabs(self.tilt_axis.velocity -
                 expected_velocity_tilt) <= FLOAT_TOLERANCE)
        assert_that(
            fabs(self.tilt_axis.value -
                 target_position_tilt) <= FLOAT_TOLERANCE)
Пример #4
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))
    def test_GIVEN_beam_line_contains_multiple_component_WHEN_beam_set_THEN_each_component_has_beam_out_which_is_effected_by_each_component_in_turn(
            self):
        beam_start = PositionAndAngle(y=0, z=0, angle=0)
        mirror_position = 10
        initial_mirror_angle = 45
        beamline, mirror = self.setup_beamline(initial_mirror_angle,
                                               mirror_position, beam_start)
        bounced_beam = PositionAndAngle(y=0,
                                        z=mirror_position,
                                        angle=initial_mirror_angle * 2)
        expected_beams = [beam_start, bounced_beam, bounced_beam]

        results = [component.get_outgoing_beam() for component in beamline]

        for index, (result,
                    expected_beam) in enumerate(zip(results, expected_beams)):
            assert_that(result, position_and_angle(expected_beam),
                        "in component {}".format(index))
Пример #6
0
    def test_GIVEN_movement_and_beam_at_the_same_angle_WHEN_get_intercept_THEN_raises_calc_error(
            self):
        angle = 12.3
        movement = LinearMovement(1, 1, angle)
        beam = PositionAndAngle(0, 0, angle)

        assert_that(
            calling(movement.calculate_interception).with_args(beam),
            raises(ValueError))
Пример #7
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)))
Пример #8
0
    def test_GIVEN_movement_45_to_z_at_beam_angle_along_z_WHEN_get_intercept_THEN_position_is_initial_position(
            self, angle):
        y = 0
        z = 10
        movement = LinearMovement(y, z, 45)
        beam = PositionAndAngle(0, 0, angle)

        result = movement.calculate_interception(beam)

        assert_that(result, is_(position(Position(y, z))))
Пример #9
0
    def test_GIVEN_movement_perpendicular_to_z_at_beam_angle_0_WHEN_get_intercept_THEN_position_is_initial_position(
            self):
        y = 0
        z = 10
        movement = LinearMovement(y, z, 90)
        beam = PositionAndAngle(0, 0, 0)

        result = movement.calculate_interception(beam)

        assert_that(result, is_(position(Position(y, z))))
Пример #10
0
    def test_GIVEN_movement_and_beam_at_the_opposite_angles_within_tolerance_WHEN_get_intercept_THEN_raises_calc_error(
            self):
        angle = 12.3 + 180.0
        tolerance = ANGULAR_TOLERANCE
        movement = LinearMovement(1, 1, angle + tolerance * 0.99)
        beam = PositionAndAngle(0, 0, angle)

        assert_that(
            calling(movement.calculate_interception).with_args(beam),
            raises(ValueError))
    def test_GIVEN_beam_line_contains_one_passive_component_WHEN_beam_set_THEN_component_has_beam_out_same_as_beam_in(
            self):
        beam_start = PositionAndAngle(y=0, z=0, angle=0)
        jaws = Component("jaws", movement_strategy=LinearMovement(0, 2, 90))
        beamline = Beamline([jaws], [], [], [])
        beamline.set_incoming_beam(beam_start)

        result = beamline[0].get_outgoing_beam()

        assert_that(result, is_(position_and_angle(beam_start)))
    def test_GIVEN_multiple_axes_need_to_move_WHEN_computing_move_duration_THEN_maximum_duration_is_returned(
            self):
        beam_angle = 45.0
        expected = 4.5
        beam = PositionAndAngle(0.0, 0.0, beam_angle)
        self.tilting_jaws.set_incoming_beam(beam)

        result = self.tilting_jaws_driver.get_max_move_duration()

        assert_that(result, is_(expected))
    def get_outgoing_beam(self):
        """
        Returns: the outgoing beam based on the last set incoming beam and any interaction with the component
        """
        if not self._enabled:
            return self.incoming_beam

        target_position = self.calculate_beam_interception()
        angle_between_beam_and_component = (self._angle - self.incoming_beam.angle)
        angle = angle_between_beam_and_component * 2 + self.incoming_beam.angle
        return PositionAndAngle(target_position.y, target_position.z, angle)
Пример #14
0
    def test_GIVEN_tilting_jaw_input_beam_is_at_60_deg_WHEN_get_angle_THEN_angle_is_150_degrees(
            self):
        beam_angle = 60.0
        expected_angle = 60.0 + 90.0
        beam_start = PositionAndAngle(y=0, z=0, angle=beam_angle)
        jaws = TiltingJaws("tilting jaws",
                           movement_strategy=LinearMovement(0, 20, 90))
        jaws.set_incoming_beam(beam_start)

        result = jaws.calculate_tilt_angle()

        assert_that(result, is_(expected_angle))
Пример #15
0
    def test_GIVEN_jaw_input_beam_is_at_0_deg_and_z0_y0_WHEN_get_beam_out_THEN_beam_output_is_same_as_beam_input(
            self):
        jaws_z_position = 10
        beam_start = PositionAndAngle(y=0, z=0, angle=0)
        jaws = Component("component",
                         movement_strategy=LinearMovement(
                             0, jaws_z_position, 90))
        jaws.set_incoming_beam(beam_start)

        result = jaws.get_outgoing_beam()

        assert_that(result, is_(position_and_angle(beam_start)))
Пример #16
0
    def test_GIVEN_movement_0_to_z_and_beam_angle_45_WHEN_get_intercept_THEN_position_is_on_movement_axis(
            self):
        y = 20
        z = 10
        movement = LinearMovement(y, z, 0)
        beam = PositionAndAngle(0, 0, 45)
        expected_y = y
        expected_z = y

        result = movement.calculate_interception(beam)

        assert_that(result, is_(position(Position(expected_y, expected_z))))
Пример #17
0
    def test_GIVEN_theta_and_a_set_and_move_WHEN_get_changed_THEN_changed_is_false(self):

        theta_set = 10.0
        sample = ReflectingComponent("sample", movement_strategy=LinearMovement(0, 0, 90))
        sample.set_incoming_beam(PositionAndAngle(0, 0, 0))
        theta = Theta("theta",sample)

        theta.sp_no_move = theta_set
        theta.move = 1
        result = theta.sp_changed

        assert_that(result, is_(False))
Пример #18
0
    def test_GIVEN_movement_anti_perpendicular_to_z_at_beam_angle_10_WHEN_get_intercept_THEN_position_is_z_as_initial_y_as_right_angle_triangle(
            self):
        y = 0
        z = 10
        beam_angle = 10
        movement = LinearMovement(y, z, -90)
        beam = PositionAndAngle(0, 0, beam_angle)
        expected_y = z * tan(radians(beam_angle))

        result = movement.calculate_interception(beam)

        assert_that(result, is_(position(Position(expected_y, z))))
    def setUp(self):
        start_position = 0.0
        max_velocity = 10.0
        self.height_axis = create_mock_axis("JAWS:HEIGHT", start_position,
                                            max_velocity)

        self.jaws = Component("component",
                              movement_strategy=LinearMovement(
                                  0.0, 10.0, 90.0))
        self.jaws.set_incoming_beam(PositionAndAngle(0.0, 0.0, 0.0))

        self.jaws_driver = HeightDriver(self.jaws, self.height_axis)
Пример #20
0
    def test_GIVEN_jaw_at_10_input_beam_is_at_0_deg_and_z0_y0_WHEN_get_position_THEN_z_is_jaw_position_y_is_0(
            self):
        jaws_z_position = 10
        beam_start = PositionAndAngle(y=0, z=0, angle=0)
        expected_position = Position(y=0, z=jaws_z_position)
        jaws = Component("component",
                         movement_strategy=LinearMovement(
                             0, jaws_z_position, 90))
        jaws.set_incoming_beam(beam_start)

        result = jaws.calculate_beam_interception()

        assert_that(result, is_(position(expected_position)))
    def test_GIVEN_beam_line_contains_multiple_component_WHEN_angle_on_mirror_changed_THEN_beam_positions_are_all_recalculated(
            self):
        beam_start = PositionAndAngle(y=0, z=0, angle=0)
        mirror_position = 10
        initial_mirror_angle = 0

        beamline, mirror = self.setup_beamline(initial_mirror_angle,
                                               mirror_position, beam_start)

        mirror_final_angle = 45
        bounced_beam = PositionAndAngle(y=0,
                                        z=mirror_position,
                                        angle=mirror_final_angle * 2)
        expected_beams = [beam_start, bounced_beam, bounced_beam]

        mirror.angle = mirror_final_angle
        results = [component.get_outgoing_beam() for component in beamline]

        for index, (result,
                    expected_beam) in enumerate(zip(results, expected_beams)):
            assert_that(result, position_and_angle(expected_beam),
                        "in component index {}".format(index))
    def set_position_relative_to_beam(self, beam_intercept, value):
        """
        Set the position of the component relative to the beam for the given value based on its movement strategy.
        For instance this could set the height above the beam for a vertically moving component
        Args:
            beam_intercept: the current beam position of the item
            value: the value to set away from the beam, e.g. height
        """
        angle = self._angle_and_position.angle
        y_value = beam_intercept.y + value * sin(radians(angle))
        z_value = beam_intercept.z + value * cos(radians(angle))

        self._angle_and_position = PositionAndAngle(y_value, z_value, angle)
Пример #23
0
    def test_GIVEN_a_mode_with_a_single_beamline_parameter_in_WHEN_move_THEN_beamline_parameter_is_calculated_on_move(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)
        beamline_mode = BeamlineMode("mode name", [theta.name])
        beamline = Beamline([ideal_sample_point], [theta], [], [beamline_mode])
        beam = PositionAndAngle(0, 0, 0)

        theta.sp_no_move = angle_to_set
        beamline.set_incoming_beam(beam)
        beamline.active_mode = beamline_mode
        beamline.move = 1

        assert_that(ideal_sample_point.angle, is_(angle_to_set))
Пример #24
0
    def test_GIVEN_movement_20_to_z_and_beam_angle_45_WHEN_get_intercept_THEN_position_is_on_movement_axis(
            self):
        beam = PositionAndAngle(0, 0, 45)
        expected_y = 4
        expected_z = 4

        move_angle = 20
        move_z = 2
        move_y = expected_y - (expected_z - move_z) * tan(radians(move_angle))
        movement = LinearMovement(move_y, move_z, move_angle)

        result = movement.calculate_interception(beam)

        assert_that(result, is_(position(Position(expected_y, expected_z))))
Пример #25
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))
Пример #26
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))
Пример #27
0
    def test_GIVEN_parameter_in_mode_and_not_changed_and_no_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, True)
        slit2_pos = TrackingPosition("slit2pos", s2, True)

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

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

        beamline.move = 1

        assert_that(s2.sp_position().y, is_(initial_s2_height))
Пример #28
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))
Пример #29
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)))
Пример #30
0
    def test_GIVEN_jaw_height_WHEN_set_set_point_and_move_THEN_readback_is_as_set_and_jaws_are_at_setpoint_postion(self):

        height_set = 10.0
        beam_height = 5
        expected_height = beam_height + height_set
        jaws_z = 5.0
        jaws = Component("jaws", movement_strategy=LinearMovement(0, jaws_z, 90))
        jaws.set_incoming_beam(PositionAndAngle(beam_height, 0, 0))
        tracking_height = TrackingPosition("theta",jaws)

        tracking_height.sp_no_move = height_set
        tracking_height.move = 1
        result = tracking_height.sp_rbv

        assert_that(result, is_(height_set))
        assert_that(jaws.sp_position().y, is_(expected_height))
        assert_that(jaws.sp_position().z, is_(close_to(jaws_z, DEFAULT_TEST_TOLERANCE)))