예제 #1
0
    def test_GIVEN_beamline_with_engineering_correction_containing_a_mode_update_correction_WHEN_init_THEN_set_point_includes_correction(self, autosave):
        autosave.read_parameter = Mock(return_value=self.mode1.name)
        comp = Component("comp", PositionAndAngle(0, 0, 90))
        param = AxisParameter("comp", comp, ChangeAxis.POSITION)
        mock_axis = create_mock_axis("mock", 0, 1)
        driver = IocDriver(comp, ChangeAxis.POSITION, mock_axis, engineering_correction=self.mode_selection_correction)

        bl = Beamline(components=[comp], beamline_parameters=[param], drivers=[driver], modes=[self.mode1, self.mode2])

        assert_that(param.sp, is_(-self.mode1_offset))  # readback is -11 so sp must be set to this
예제 #2
0
    def test_GIVEN_interp_with_1D_points_based_on_setpoint_of_beamline_parameter_WHEN_column_name_not_beamline_name_THEN_error_in_initialise(self):
        grid_data_provider = GridDataFileReader("Test")
        grid_data_provider.variables = ["Theta"]
        grid_data_provider.points = np.array([[1.0, ], [2.0, ], [3.0, ]])
        grid_data_provider.corrections = np.array([1.234, 4.0, 6.0])
        grid_data_provider.read = lambda: None

        comp = Component("param_comp", setup=PositionAndAngle(0, 0, 90))
        beamline_parameter = AxisParameter("not theta", comp, ChangeAxis.POSITION)

        assert_that(
            calling(InterpolateGridDataCorrectionFromProvider).with_args(grid_data_provider, beamline_parameter),
            raises(ValueError))
예제 #3
0
    def test_GIVEN_beamline_with_engineering_correction_containing_a_mode_update_correction_WHEN_update_mode_THEN_correct_readback_updated_fired(self):

        comp = Component("comp", PositionAndAngle(0, 0, 90))
        param = AxisParameter("comp", comp, ChangeAxis.POSITION)
        mock_axis = create_mock_axis("mock", 0, 1)
        driver = IocDriver(comp, ChangeAxis.POSITION, mock_axis, engineering_correction=self.mode_selection_correction)
        mock_axis.trigger_rbv_change()
        bl = Beamline(components=[comp], beamline_parameters=[param], drivers=[driver], modes=[self.mode1, self.mode2])

        bl.active_mode = self.mode1.name

        assert_that(self.correction_update.correction, is_(self.mode1_offset))

        bl.active_mode = self.mode2.name

        assert_that(self.correction_update.correction, is_(self.mode2_offset))
예제 #4
0
    def test_GIVEN_interp_with_1D_points_based_on_setpoint_of_beamline_parameter_which_has_not_been_initialised_WHEN_request_a_point_THEN_correction_0_returned(self):
        grid_data_provider = GridDataFileReader("Test")
        grid_data_provider.variables = ["Theta"]
        grid_data_provider.points = np.array([[1.0, ], [2.0, ], [3.0, ]])
        grid_data_provider.corrections = np.array([1.234, 4.0, 6.0])
        grid_data_provider.read = lambda: None

        comp = Component("param_comp", setup=PositionAndAngle(0, 0, 90))
        beamline_parameter = AxisParameter("theta", comp, ChangeAxis.POSITION)

        interp = InterpolateGridDataCorrectionFromProvider(grid_data_provider, beamline_parameter)
        interp.grid_data_provider = grid_data_provider

        result = interp.correction(0)

        assert_that(result, is_(close_to(0, FLOAT_TOLERANCE)))
예제 #5
0
    def test_GIVEN_interp_with_2D_points_based_on_setpoint_of_beamline_parameter_WHEN_request_a_point_THEN_correction_returned_for_that_point_with_interpolation_if_needed(self, value, theta, expected_correction):
        grid_data_provider = GridDataFileReader("Test")
        grid_data_provider.variables = ["driver", "Theta"]
        grid_data_provider.points = np.array([[1.0, 1.0], [2.0, 1.0], [3.0, 1.0], [1.0, 6.0], [2.0, 6.0], [3.0, 6.0]])
        grid_data_provider.corrections = np.array([1.234, 4.0, 6.0, 2.234, 5.0, 7.0])
        grid_data_provider.read = lambda: None

        comp = Component("param_comp", setup=PositionAndAngle(0, 0, 90))
        beamline_parameter = AxisParameter("theta", comp, ChangeAxis.POSITION)
        beamline_parameter.sp = theta

        interp = InterpolateGridDataCorrectionFromProvider(grid_data_provider, beamline_parameter)

        result = interp.correction(value)

        assert_that(result, is_(close_to(expected_correction, FLOAT_TOLERANCE)))
예제 #6
0
    def test_GIVEN_beam_line_where_autosave_and_engineering_correction_on_displacement_WHEN_init_THEN_beamline_is_at_given_place(self, param_float_autosave):
        expected_setpoint = 1.0
        multiple = 2.0
        param_float_autosave.read_parameter.return_value = expected_setpoint
        offset = expected_setpoint / multiple
        comp = Component("comp", PositionAndAngle(0.0, 0, 90))
        param = AxisParameter("param", comp, ChangeAxis.POSITION, autosave=True)
        axis = create_mock_axis("MOT:MTR0101", offset + expected_setpoint, 1)
        driver = IocDriver(comp, ChangeAxis.POSITION, axis,
                           engineering_correction=UserFunctionCorrection(lambda sp: sp / multiple))
        nr_mode = BeamlineMode("NR", [param.name], {})
        bl = Beamline([comp], [param], [driver], [nr_mode])
        bl.active_mode = nr_mode.name

        result = comp.beam_path_set_point.axis[ChangeAxis.POSITION].get_displacement()

        assert_that(result, is_(close_to(expected_setpoint, 1e-6)))
예제 #7
0
    def test_GIVEN_user_function_engineering_correction_which_adds_setpoint_and_beamline_param_WHEN_set_value_on_axis_THEN_value_is_twice_value_plus_beamline_parameter_value(self):
        def _test_correction(setpoint, beamline_parameter):
            return setpoint + beamline_parameter

        parameter_value = 2
        comp = Component("param_comp", setup=PositionAndAngle(0, 0, 90))
        beamline_parameter = AxisParameter("param", comp, ChangeAxis.POSITION)
        beamline_parameter.sp = parameter_value

        value = 1
        expected_correction = value * 2 + parameter_value

        engineering_correction = UserFunctionCorrection(_test_correction, beamline_parameter)

        result = engineering_correction.to_axis(value)

        assert_that(result, is_(close_to(expected_correction, FLOAT_TOLERANCE)))