def beamline_with_3_empty_parameters():
        """

        Returns: a beamline with three empty parameters, all in a mode

        """
        one = EmptyBeamlineParameter("one")
        two = EmptyBeamlineParameter("two")
        three = EmptyBeamlineParameter("three")
        beamline_parameters = [one, two, three]
        mode = BeamlineMode("all", [
            beamline_parameter.name
            for beamline_parameter in beamline_parameters
        ])
        naught_and_two = BeamlineMode(
            "components1and3",
            [beamline_parameters[0].name, beamline_parameters[2].name])
        two = BeamlineMode("just2", [beamline_parameters[2].name])

        beamline = Beamline([], beamline_parameters, [],
                            [mode, naught_and_two, two])

        beamline.active_mode = mode.name

        return beamline_parameters, beamline
Esempio n. 2
0
    def test_GIVEN_mode_selected_which_has_not_got_a_correction_WHEN_from_axis_THEN_correction_is_default_mode(self):
        self.mock_beamline.trigger_listeners(ActiveModeUpdate(BeamlineMode("another mode", [])))

        result = self.mode_selection_correction.from_axis(0, 0)

        assert_that(result, is_(-self.default_offset))
        assert_that(self.correction_update.correction, is_(self.default_offset))
        assert_that(self.correction_update.description, is_("Mode Selected: {}".format(self.default_correction.description)))
Esempio n. 3
0
    def setUp(self) -> None:
        self.update = None
        self.correction_update = None

        self.mode1 = BeamlineMode("mode1", [])
        self.mode2 = BeamlineMode("mode2", [])
        self.default_offset = 1
        self.mode1_offset = 11
        self.mode2_offset = 22
        self.default_correction = ConstantCorrection(self.default_offset)
        self.mode_selection_correction = ModeSelectCorrection(self.default_correction,
                                                              {self.mode1.name: (ConstantCorrection(self.mode1_offset)),
                                                               self.mode2.name: (ConstantCorrection(self.mode2_offset))})
        self.mock_beamline = MockBeamline()
        self.mode_selection_correction.set_observe_mode_change_on(self.mock_beamline)
        self.mode_selection_correction.add_listener(CorrectionRecalculate, self.get_update)
        self.mode_selection_correction.add_listener(CorrectionUpdate, self.get_correction_update)
    def setUp(self):
        beam_start = PositionAndAngle(y=0, z=0, angle=2.5)
        s0 = Component("s0", setup=PositionAndAngle(0, 0, 90))
        s1 = Component("s1", setup=PositionAndAngle(0, 1, 90))
        frame_overlap_mirror = ReflectingComponent("FOM",
                                                   setup=PositionAndAngle(
                                                       0, 2, 90))
        frame_overlap_mirror.beam_path_set_point.is_in_beam = False
        self.polarising_mirror = ReflectingComponent("Polariser",
                                                     setup=PositionAndAngle(
                                                         0, 3, 90))
        self.polarising_mirror.beam_path_set_point.is_in_beam = False
        s2 = Component("s2", setup=PositionAndAngle(0, 4, 90))
        self.ideal_sample_point = ReflectingComponent("ideal sample point",
                                                      setup=PositionAndAngle(
                                                          0, 5, 90))
        s3 = Component("s3", setup=PositionAndAngle(0, 6, 90))
        analyser = ReflectingComponent("analyser",
                                       setup=PositionAndAngle(0, 7, 90))
        analyser.beam_path_set_point.is_in_beam = False
        s4 = Component("s4", setup=PositionAndAngle(0, 8, 90))
        detector = Component("detector", setup=PositionAndAngle(0, 10, 90))

        theta = create_parameter_with_initial_value(0, AxisParameter, "theta",
                                                    self.ideal_sample_point,
                                                    ChangeAxis.ANGLE)
        theta.sp_no_move = 0
        smangle = create_parameter_with_initial_value(0, AxisParameter,
                                                      "smangle",
                                                      self.polarising_mirror,
                                                      ChangeAxis.ANGLE)
        smangle.sp_no_move = 0

        self.nr_mode = BeamlineMode("NR Mode", [theta.name])
        self.polarised_mode = BeamlineMode("Polarised 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],
                                 beam_start)
 def beamline_with_one_mode_init_param_in_mode_and_at_off_init(
         init_sm_angle, off_init, param_name):
     super_mirror = ReflectingComponent(
         "super mirror", PositionAndAngle(z=10, y=0, angle=90))
     smangle = AxisParameter(param_name, super_mirror, ChangeAxis.ANGLE)
     beamline_mode = BeamlineMode("mode name", [smangle.name],
                                  {smangle.name: init_sm_angle})
     beamline = Beamline([super_mirror], [smangle], [], [beamline_mode])
     beamline.active_mode = beamline_mode.name
     smangle.sp = off_init
     return Beamline([super_mirror], [smangle], [], [beamline_mode])
    def setUp(self) -> None:
        self.param_name = "ENUM"
        self.pvname = "PARAM:{}".format(self.param_name)
        self.opt1 = "opt1"
        options = [self.opt1, "opt2"]
        self.index_of_opt1 = 0
        self.param = EnumParameter(self.param_name, options)
        bl = Beamline([], [self.param], [], [BeamlineMode("mode", [])])

        pvmanager = PVManager()
        pvmanager.set_beamline(bl)

        self.driver_helper = DriverParamHelper(pvmanager, bl)
    def beamline_s1_gap_theta_s3_gap_detector(spacing):
        """
        Create beamline with Slits 1 and 3 a theta and a detector
        Args:
            spacing: spacing between components

        Returns: beamline, axes

        """
        # DRIVERS
        s1_gap_axis = create_mock_axis("MOT:MTR0101", 0, 1)
        s3_gap_axis = create_mock_axis("MOT:MTR0103", 0, 1)
        axes = {"s1_gap_axis": s1_gap_axis}
        drives = []

        # COMPONENTS
        theta = ThetaComponent("ThetaComp_comp",
                               PositionAndAngle(0.0, 2 * spacing, 90))
        detector = TiltingComponent("Detector_comp",
                                    PositionAndAngle(0.0, 4 * spacing, 90))
        theta.add_angle_to(detector)
        comps = [theta]

        # BEAMLINE PARAMETERS
        s1_gap = create_parameter_with_initial_value(0, SlitGapParameter,
                                                     "s1_gap", s1_gap_axis)
        theta_ang = create_parameter_with_initial_value(
            0, AxisParameter, "theta", theta, ChangeAxis.ANGLE)
        s3_gap = create_parameter_with_initial_value(0, SlitGapParameter,
                                                     "s3_gap", s3_gap_axis)
        detector_position = create_parameter_with_initial_value(
            0, AxisParameter, "det", detector, ChangeAxis.POSITION)
        detector_angle = create_parameter_with_initial_value(
            0, AxisParameter, "det_angle", detector, ChangeAxis.ANGLE)
        params = [s1_gap, theta_ang, s3_gap, detector_position, detector_angle]

        # MODES
        nr_inits = {}
        nr_mode = [
            BeamlineMode("NR", [param.name for param in params], nr_inits)
        ]
        beam_start = PositionAndAngle(0.0, 0.0, 0.0)
        bl = Beamline(comps, params, drives, nr_mode, beam_start)

        # Initialise motor positions to get rbv call backs set
        s1_gap_axis.sp = 0
        s3_gap_axis.sp = 0

        return bl, axes
def _create_beamline_in_error(error_message):
    """
    Args:
        error_message: error message to set for beamline
    Returns: a blank beamline with an error status set

    """
    error_mode = BeamlineMode("No modes", [])
    beamline = Beamline([], [], [], [error_mode])
    try:
        STATUS_MANAGER.update_active_problems(
            ProblemInfo(
                "Error reading configuration: {}".format(error_message),
                "Configuration", Severity.MAJOR_ALARM))
    except Exception as e:
        print(e)
    return beamline
Esempio n. 9
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)))
def create_beamline():
    """

    Returns: example beamline

    """
    perp_to_floor = 90.0
    beam_start = PositionAndAngle(y=0, z=0, angle=-2.5)
    s0 = Component("s0", setup=PositionAndAngle(0, 0, perp_to_floor))
    s1 = Component("s1", setup=PositionAndAngle(0, 1, perp_to_floor))
    frame_overlap_mirror = ReflectingComponent("FOM",
                                               setup=PositionAndAngle(
                                                   0, 2, perp_to_floor))
    frame_overlap_mirror.beam_path_set_point.is_in_beam = False
    polarising_mirror = ReflectingComponent("Polarising mirror",
                                            setup=PositionAndAngle(
                                                0, 3, perp_to_floor))
    polarising_mirror.beam_path_set_point.is_in_beam = False
    s2 = Component("s2", setup=PositionAndAngle(0, 4, perp_to_floor))
    ideal_sample_point = ReflectingComponent("Ideal Sample Point",
                                             setup=PositionAndAngle(
                                                 0, 5, perp_to_floor))
    s3 = Component("s3", setup=PositionAndAngle(0, 6, perp_to_floor))
    analyser = ReflectingComponent("analyser",
                                   setup=PositionAndAngle(0, 7, perp_to_floor))
    analyser.beam_path_set_point.is_in_beam = False
    s4 = Component("s4", setup=PositionAndAngle(0, 8, perp_to_floor))
    detector = Component("detector",
                         setup=PositionAndAngle(0, 10, perp_to_floor))

    theta = AxisParameter("theta", ideal_sample_point, ChangeAxis.ANGLE)
    nr_mode = BeamlineMode("NR", ["theta"])
    beamline = Beamline([
        s0, s1, frame_overlap_mirror, polarising_mirror, s2,
        ideal_sample_point, s3, analyser, s4, detector
    ], [theta], [], [nr_mode], beam_start)

    beamline.active_mode = nr_mode.name

    return beamline
    def create_beamline(self, param):
        bl = Beamline([], [param], [], [BeamlineMode("mode", [])])
        pvmanager = PVManager()
        pvmanager.set_beamline(bl)

        return pvmanager
Esempio n. 12
0
class DataMother:
    """
    Test data for various tests.
    """
    BEAMLINE_MODE_NEUTRON_REFLECTION = BeamlineMode(
        "Neutron reflection",
        ["slit2height", "height", "theta", "detectorheight"])

    BEAMLINE_MODE_EMPTY = BeamlineMode("Empty", [])

    @staticmethod
    def beamline_with_3_empty_parameters():
        """

        Returns: a beamline with three empty parameters, all in a mode

        """
        one = EmptyBeamlineParameter("one")
        two = EmptyBeamlineParameter("two")
        three = EmptyBeamlineParameter("three")
        beamline_parameters = [one, two, three]
        mode = BeamlineMode("all", [
            beamline_parameter.name
            for beamline_parameter in beamline_parameters
        ])
        naught_and_two = BeamlineMode(
            "components1and3",
            [beamline_parameters[0].name, beamline_parameters[2].name])
        two = BeamlineMode("just2", [beamline_parameters[2].name])

        beamline = Beamline([], beamline_parameters, [],
                            [mode, naught_and_two, two])

        beamline.active_mode = mode.name

        return beamline_parameters, beamline

    @staticmethod
    def beamline_s1_s3_theta_detector(spacing, initilise_mode_nr=True):
        """
        Create beamline with Slits 1 and 3 a theta and a detector
        Args:
            spacing: spacing between components

        Returns: beamline, axes

        """
        ConfigHelper.reset()

        nr = add_mode("NR")
        disabled = add_mode("DISABLED", is_disabled=True)

        # s1
        s1 = add_component(
            Component("s1_comp", PositionAndAngle(0.0, 1 * spacing, 90)))
        add_parameter(AxisParameter("s1", s1, ChangeAxis.POSITION), modes=[nr])
        s1_axis = create_mock_axis("MOT:MTR0101", 0, 1)
        add_driver(IocDriver(s1, ChangeAxis.POSITION, s1_axis))

        # theta
        theta = add_component(
            ThetaComponent("ThetaComp_comp",
                           PositionAndAngle(0.0, 2 * spacing, 90)))
        add_parameter(AxisParameter("theta", theta, ChangeAxis.ANGLE),
                      modes=[nr, disabled])

        # s3
        s3 = add_component(
            Component("s3_comp", PositionAndAngle(0.0, 3 * spacing, 90)))
        add_parameter(AxisParameter("s3", s3, ChangeAxis.POSITION), modes=[nr])
        s3_axis = create_mock_axis("MOT:MTR0102", 0, 1)
        add_driver(IocDriver(s3, ChangeAxis.POSITION, s3_axis))

        # detector
        detector = add_component(
            TiltingComponent("Detector_comp",
                             PositionAndAngle(0.0, 4 * spacing, 90)))
        theta.add_angle_to(detector)
        add_parameter(AxisParameter("det", detector, ChangeAxis.POSITION),
                      modes=[nr, disabled])
        add_parameter(AxisParameter("det_angle", detector, ChangeAxis.ANGLE),
                      modes=[nr, disabled])
        det_axis = create_mock_axis("MOT:MTR0104", 0, 1)
        add_driver(IocDriver(detector, ChangeAxis.POSITION, det_axis))
        det_angle_axis = create_mock_axis("MOT:MTR0105", 0, 1)
        add_driver(IocDriver(detector, ChangeAxis.ANGLE, det_angle_axis))

        axes = {
            "s1_axis": s1_axis,
            "s3_axis": s3_axis,
            "det_axis": det_axis,
            "det_angle_axis": det_angle_axis
        }

        add_beam_start(PositionAndAngle(0.0, 0.0, 0.0))
        bl = get_configured_beamline()
        if initilise_mode_nr:
            bl.active_mode = nr
        return bl, axes

    @staticmethod
    def beamline_s1_gap_theta_s3_gap_detector(spacing):
        """
        Create beamline with Slits 1 and 3 a theta and a detector
        Args:
            spacing: spacing between components

        Returns: beamline, axes

        """
        # DRIVERS
        s1_gap_axis = create_mock_axis("MOT:MTR0101", 0, 1)
        s3_gap_axis = create_mock_axis("MOT:MTR0103", 0, 1)
        axes = {"s1_gap_axis": s1_gap_axis}
        drives = []

        # COMPONENTS
        theta = ThetaComponent("ThetaComp_comp",
                               PositionAndAngle(0.0, 2 * spacing, 90))
        detector = TiltingComponent("Detector_comp",
                                    PositionAndAngle(0.0, 4 * spacing, 90))
        theta.add_angle_to(detector)
        comps = [theta]

        # BEAMLINE PARAMETERS
        s1_gap = create_parameter_with_initial_value(0, SlitGapParameter,
                                                     "s1_gap", s1_gap_axis)
        theta_ang = create_parameter_with_initial_value(
            0, AxisParameter, "theta", theta, ChangeAxis.ANGLE)
        s3_gap = create_parameter_with_initial_value(0, SlitGapParameter,
                                                     "s3_gap", s3_gap_axis)
        detector_position = create_parameter_with_initial_value(
            0, AxisParameter, "det", detector, ChangeAxis.POSITION)
        detector_angle = create_parameter_with_initial_value(
            0, AxisParameter, "det_angle", detector, ChangeAxis.ANGLE)
        params = [s1_gap, theta_ang, s3_gap, detector_position, detector_angle]

        # MODES
        nr_inits = {}
        nr_mode = [
            BeamlineMode("NR", [param.name for param in params], nr_inits)
        ]
        beam_start = PositionAndAngle(0.0, 0.0, 0.0)
        bl = Beamline(comps, params, drives, nr_mode, beam_start)

        # Initialise motor positions to get rbv call backs set
        s1_gap_axis.sp = 0
        s3_gap_axis.sp = 0

        return bl, axes

    @staticmethod
    def beamline_sm_theta_detector(sm_angle,
                                   theta,
                                   det_offset=0,
                                   autosave_theta_not_offset=True,
                                   beam_angle=0.0,
                                   sm_angle_engineering_correction=False):
        """
        Create beamline with supermirror, theta and a tilting detector.

        Args:
            sm_angle (float): The initialisation value for supermirror angle
            theta (float): The initialisation value for theta
            det_offset (float): The initialisation value for detector offset
            autosave_theta_not_offset (bool): true to autosave theta and not the offset, false otherwise
            beam_angle (float): angle of the beam, worked out as the angle the components run along + 90

        Returns: beamline, axes
        """
        beam_start = PositionAndAngle(0.0, 0.0, 0.0)
        perp_to_floor_angle_in_mantid = 90 + beam_angle

        # COMPONENTS
        z_sm_to_sample = 1
        z_sample_to_det = 2
        sm_comp = ReflectingComponent(
            "sm_comp", PositionAndAngle(0.0, 0, perp_to_floor_angle_in_mantid))
        detector_comp = TiltingComponent(
            "detector_comp",
            PositionAndAngle(0.0, z_sm_to_sample + z_sample_to_det,
                             perp_to_floor_angle_in_mantid))
        theta_comp = ThetaComponent(
            "theta_comp",
            PositionAndAngle(0.0, z_sm_to_sample,
                             perp_to_floor_angle_in_mantid))
        theta_comp.add_angle_to(detector_comp)

        comps = [sm_comp, theta_comp, detector_comp]

        # BEAMLINE PARAMETERS
        sm_angle_param = AxisParameter("sm_angle", sm_comp, ChangeAxis.ANGLE)
        theta_param = AxisParameter("theta",
                                    theta_comp,
                                    ChangeAxis.ANGLE,
                                    autosave=autosave_theta_not_offset)
        detector_position_param = AxisParameter(
            "det_pos",
            detector_comp,
            ChangeAxis.POSITION,
            autosave=not autosave_theta_not_offset)
        detector_angle_param = AxisParameter("det_angle", detector_comp,
                                             ChangeAxis.ANGLE)

        params = [
            sm_angle_param, theta_param, detector_position_param,
            detector_angle_param
        ]

        # DRIVERS
        # engineering correction
        if sm_angle_engineering_correction:
            grid_data_provider = GridDataFileReader("linear_theta")
            grid_data_provider.variables = ["Theta"]
            grid_data_provider.points = np.array([[
                -90,
            ], [
                0.0,
            ], [
                90.0,
            ]])
            grid_data_provider.corrections = np.array([-45, 0.0, 45])
            grid_data_provider.read = lambda: None
            correction = InterpolateGridDataCorrectionFromProvider(
                grid_data_provider, theta_param)
            size_of_correction = theta / 2.0
        else:
            correction = None
            size_of_correction = 0

        # setup motors
        beam_angle_after_sample = theta * 2 + sm_angle * 2
        supermirror_segment = (z_sm_to_sample, sm_angle)
        theta_segment = (z_sample_to_det, theta)
        reflection_offset = DataMother._calc_reflection_offset(
            beam_angle, [supermirror_segment, theta_segment])
        sm_axis = create_mock_axis("MOT:MTR0101",
                                   sm_angle + size_of_correction, 1)
        det_axis = create_mock_axis("MOT:MTR0104",
                                    reflection_offset + det_offset, 1)
        det_angle_axis = create_mock_axis(
            "MOT:MTR0105", beam_start.angle + beam_angle_after_sample, 1)

        axes = {
            "sm_axis": sm_axis,
            "det_axis": det_axis,
            "det_angle_axis": det_angle_axis
        }

        drives = [
            IocDriver(sm_comp,
                      ChangeAxis.ANGLE,
                      sm_axis,
                      engineering_correction=correction),
            IocDriver(detector_comp, ChangeAxis.POSITION, det_axis),
            IocDriver(detector_comp, ChangeAxis.ANGLE, det_angle_axis)
        ]

        # MODES
        nr_inits = {}
        nr_mode = BeamlineMode("NR", [param.name for param in params],
                               nr_inits)
        modes = [nr_mode]
        beam_start = PositionAndAngle(0.0, 0.0, 0.0)
        bl = Beamline(comps, params, drives, modes, beam_start)
        bl.active_mode = nr_mode.name
        return bl, axes

    @staticmethod
    def _calc_reflection_offset(beam_angle, segments):
        """
        Calculates a position offset to the beam intercept for a linear axis given an ordered list of beam segments,
        each of which adds an angle to the beam.

        Params:
            beam_angle (float): The angle of the straight through beam to the linear motion axes
            segments (tuple[float, float]): A list of beam segments made of tuples with (segment_length, added angle)

        Returns: The total offset for the linear axis
        """
        total_offset = 0.0

        reflection_angles = []
        for distance, added_angle in segments:
            reflection_angles.append(added_angle)

            cumulative_reflection_angle = 0
            for reflection_angle in reflection_angles:
                cumulative_reflection_angle += 2 * reflection_angle

            offset_1 = distance * sin(radians(beam_angle))
            offset_2 = distance * cos(radians(beam_angle)) * tan(
                radians(cumulative_reflection_angle - beam_angle))
            total_offset += offset_1 + offset_2

        return total_offset

    @staticmethod
    def beamline_sm_theta_bench(sm_angle,
                                theta_angle,
                                driver_bench_offset,
                                autosave_bench_not_theta=False,
                                natural_angle=0.0):

        ConfigHelper.reset()
        test = add_mode("TEST")

        add_beam_start(PositionAndAngle(0, 0, 0))
        perp_to_floor_angle = 90.0 + natural_angle

        sm = add_component(
            ReflectingComponent("SM",
                                PositionAndAngle(0, 0, perp_to_floor_angle)))
        add_parameter(AxisParameter("sm_angle", sm, ChangeAxis.ANGLE))
        sm_axis = create_mock_axis("MOT:MTR0101", sm_angle, sm_angle)
        add_driver(IocDriver(sm, ChangeAxis.ANGLE, sm_axis))
        sm_axis.trigger_rbv_change()

        theta = add_component(
            ThetaComponent("THETA", PositionAndAngle(0, 10,
                                                     perp_to_floor_angle)))
        add_parameter(
            AxisParameter("theta",
                          theta,
                          ChangeAxis.ANGLE,
                          autosave=not autosave_bench_not_theta))

        bench = add_component(
            get_standard_bench(with_z_position=10,
                               with_angle=0,
                               perp_to_floor_angle=perp_to_floor_angle))
        add_parameter(
            AxisParameter("bench_angle",
                          bench,
                          ChangeAxis.ANGLE,
                          autosave=autosave_bench_not_theta))
        add_parameter(AxisParameter("bench_offset", bench,
                                    ChangeAxis.POSITION))
        bench_angle = radians(driver_bench_offset + theta_angle * 2 +
                              sm_angle * 2)
        bench_jack_front = create_mock_axis(
            "MOT:MTR0102",
            tan(bench_angle) * PIVOT_TO_J1 - PIVOT_TO_BEAM *
            (1 - cos(bench_angle)), 1)
        bench_jack_rear = create_mock_axis(
            "MOT:MTR0103",
            tan(bench_angle) * PIVOT_TO_J2 - PIVOT_TO_BEAM *
            (1 - cos(bench_angle)), 1)
        add_driver(IocDriver(bench, ChangeAxis.JACK_REAR, bench_jack_rear))
        add_driver(IocDriver(bench, ChangeAxis.JACK_FRONT, bench_jack_front))
        bench_jack_rear.trigger_rbv_change()
        bench_jack_front.trigger_rbv_change()
        theta.add_angle_of(bench)

        return get_configured_beamline(), {
            "bench_jack_rear": bench_jack_rear,
            "bench_jack_front": bench_jack_front,
            "sm_angle": sm_axis
        }

    @staticmethod
    def beamline_sm_theta_ang_det(sm_angle,
                                  theta_angle,
                                  driver_comp_offset,
                                  autosave_bench_not_theta=False):

        ConfigHelper.reset()
        test = add_mode("TEST")

        add_beam_start(PositionAndAngle(0, 0, 0))

        sm = add_component(
            ReflectingComponent("SM", PositionAndAngle(0, 0, 90)))
        add_parameter(AxisParameter("sm_angle", sm, ChangeAxis.ANGLE))
        sm_axis = create_mock_axis("MOT:MTR0101", sm_angle, sm_angle)
        add_driver(IocDriver(sm, ChangeAxis.ANGLE, sm_axis))
        sm_axis.trigger_rbv_change()

        theta = add_component(
            ThetaComponent("THETA", PositionAndAngle(0, 10, 90)))
        add_parameter(
            AxisParameter("theta",
                          theta,
                          ChangeAxis.ANGLE,
                          autosave=not autosave_bench_not_theta))

        DIST = 10
        bench = add_component(
            TiltingComponent("comp", PositionAndAngle(0, DIST, 90)))
        add_parameter(
            AxisParameter("comp_angle",
                          bench,
                          ChangeAxis.ANGLE,
                          autosave=autosave_bench_not_theta))
        comp_angle = driver_comp_offset + theta_angle * 2 + sm_angle * 2
        comp_height = create_mock_axis("MOT:MTR0102",
                                       tan(radians(comp_angle)) * DIST, 1)
        comp_ang = create_mock_axis("MOT:MTR0103", comp_angle, 1)
        add_driver(IocDriver(bench, ChangeAxis.HEIGHT, comp_height))
        add_driver(IocDriver(bench, ChangeAxis.ANGLE, comp_ang))
        comp_ang.trigger_rbv_change()
        comp_height.trigger_rbv_change()
        theta.add_angle_of(bench)

        return get_configured_beamline(), {
            "comp_ang": comp_ang,
            "comp_height": comp_height,
            "sm_angle": sm_axis
        }

    @staticmethod
    def beamline_theta_detector(out_of_beam_pos_z, inital_pos_z,
                                out_of_beam_pos_ang, initial_pos_ang):
        ConfigHelper.reset()
        theta_comp = add_component(
            ThetaComponent("theta", PositionAndAngle(0, 0, 90)))
        theta = add_parameter(
            AxisParameter("theta", theta_comp, ChangeAxis.ANGLE))
        detector_comp = TiltingComponent("detector",
                                         PositionAndAngle(0, 1, 90))
        axis_det_z = create_mock_axis("det_z", inital_pos_z, 1)
        add_driver(
            IocDriver(
                detector_comp,
                ChangeAxis.POSITION,
                axis_det_z,
                out_of_beam_positions=[OutOfBeamPosition(out_of_beam_pos_z)]))
        axis_det_ang = create_mock_axis("det_ang", initial_pos_ang, 1)
        add_driver(
            IocDriver(detector_comp,
                      ChangeAxis.ANGLE,
                      axis_det_ang,
                      out_of_beam_positions=[
                          OutOfBeamPosition(out_of_beam_pos_ang)
                      ]))
        det_in = add_parameter(InBeamParameter("det_in", detector_comp))
        theta_comp.add_angle_to(detector_comp)
        get_configured_beamline()
        return det_in, theta

    @staticmethod
    def beamline_with_one_mode_init_param_in_mode_and_at_off_init(
            init_sm_angle, off_init, param_name):
        super_mirror = ReflectingComponent(
            "super mirror", PositionAndAngle(z=10, y=0, angle=90))
        smangle = AxisParameter(param_name, super_mirror, ChangeAxis.ANGLE)
        beamline_mode = BeamlineMode("mode name", [smangle.name],
                                     {smangle.name: init_sm_angle})
        beamline = Beamline([super_mirror], [smangle], [], [beamline_mode])
        beamline.active_mode = beamline_mode.name
        smangle.sp = off_init
        return Beamline([super_mirror], [smangle], [], [beamline_mode])
Esempio n. 13
0
    def beamline_sm_theta_detector(sm_angle,
                                   theta,
                                   det_offset=0,
                                   autosave_theta_not_offset=True,
                                   beam_angle=0.0,
                                   sm_angle_engineering_correction=False):
        """
        Create beamline with supermirror, theta and a tilting detector.

        Args:
            sm_angle (float): The initialisation value for supermirror angle
            theta (float): The initialisation value for theta
            det_offset (float): The initialisation value for detector offset
            autosave_theta_not_offset (bool): true to autosave theta and not the offset, false otherwise
            beam_angle (float): angle of the beam, worked out as the angle the components run along + 90

        Returns: beamline, axes
        """
        beam_start = PositionAndAngle(0.0, 0.0, 0.0)
        perp_to_floor_angle_in_mantid = 90 + beam_angle

        # COMPONENTS
        z_sm_to_sample = 1
        z_sample_to_det = 2
        sm_comp = ReflectingComponent(
            "sm_comp", PositionAndAngle(0.0, 0, perp_to_floor_angle_in_mantid))
        detector_comp = TiltingComponent(
            "detector_comp",
            PositionAndAngle(0.0, z_sm_to_sample + z_sample_to_det,
                             perp_to_floor_angle_in_mantid))
        theta_comp = ThetaComponent(
            "theta_comp",
            PositionAndAngle(0.0, z_sm_to_sample,
                             perp_to_floor_angle_in_mantid))
        theta_comp.add_angle_to(detector_comp)

        comps = [sm_comp, theta_comp, detector_comp]

        # BEAMLINE PARAMETERS
        sm_angle_param = AxisParameter("sm_angle", sm_comp, ChangeAxis.ANGLE)
        theta_param = AxisParameter("theta",
                                    theta_comp,
                                    ChangeAxis.ANGLE,
                                    autosave=autosave_theta_not_offset)
        detector_position_param = AxisParameter(
            "det_pos",
            detector_comp,
            ChangeAxis.POSITION,
            autosave=not autosave_theta_not_offset)
        detector_angle_param = AxisParameter("det_angle", detector_comp,
                                             ChangeAxis.ANGLE)

        params = [
            sm_angle_param, theta_param, detector_position_param,
            detector_angle_param
        ]

        # DRIVERS
        # engineering correction
        if sm_angle_engineering_correction:
            grid_data_provider = GridDataFileReader("linear_theta")
            grid_data_provider.variables = ["Theta"]
            grid_data_provider.points = np.array([[
                -90,
            ], [
                0.0,
            ], [
                90.0,
            ]])
            grid_data_provider.corrections = np.array([-45, 0.0, 45])
            grid_data_provider.read = lambda: None
            correction = InterpolateGridDataCorrectionFromProvider(
                grid_data_provider, theta_param)
            size_of_correction = theta / 2.0
        else:
            correction = None
            size_of_correction = 0

        # setup motors
        beam_angle_after_sample = theta * 2 + sm_angle * 2
        supermirror_segment = (z_sm_to_sample, sm_angle)
        theta_segment = (z_sample_to_det, theta)
        reflection_offset = DataMother._calc_reflection_offset(
            beam_angle, [supermirror_segment, theta_segment])
        sm_axis = create_mock_axis("MOT:MTR0101",
                                   sm_angle + size_of_correction, 1)
        det_axis = create_mock_axis("MOT:MTR0104",
                                    reflection_offset + det_offset, 1)
        det_angle_axis = create_mock_axis(
            "MOT:MTR0105", beam_start.angle + beam_angle_after_sample, 1)

        axes = {
            "sm_axis": sm_axis,
            "det_axis": det_axis,
            "det_angle_axis": det_angle_axis
        }

        drives = [
            IocDriver(sm_comp,
                      ChangeAxis.ANGLE,
                      sm_axis,
                      engineering_correction=correction),
            IocDriver(detector_comp, ChangeAxis.POSITION, det_axis),
            IocDriver(detector_comp, ChangeAxis.ANGLE, det_angle_axis)
        ]

        # MODES
        nr_inits = {}
        nr_mode = BeamlineMode("NR", [param.name for param in params],
                               nr_inits)
        modes = [nr_mode]
        beam_start = PositionAndAngle(0.0, 0.0, 0.0)
        bl = Beamline(comps, params, drives, modes, beam_start)
        bl.active_mode = nr_mode.name
        return bl, axes