def test_GIVEN_theta_and_a_set_but_no_move_WHEN_get_changed_THEN_changed_is_true(self): theta_set = 10.0 sample = ReflectingComponent("sample", movement_strategy=LinearMovement(0, 0, 90)) theta = Theta("theta",sample) theta.sp_no_move = theta_set result = theta.sp_changed assert_that(result, is_(True))
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 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))
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))
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))
def test_GIVEN_theta_WHEN_set_set_point_and_move_THEN_readback_is_as_set_and_sample_is_at_setpoint_postion(self): theta_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 theta = Theta("theta", sample) theta.sp_no_move = theta_set theta.move = 1 result = theta.sp_rbv assert_that(result, is_(theta_set)) assert_that(sample.angle, is_(expected_sample_angle))
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))))
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_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))
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)