def test_that_missing_beam_centre_is_taken_from_move_state(self): lab_z_translation_correction = 123. workspace = self._prepare_sans2d_empty_ws() move_info = _get_state_move_obj( instrument=SANSInstrument.SANS2D, z_translation=lab_z_translation_correction) # These values should be used instead of an explicitly specified beam centre move_info.detectors[DetectorType.HAB.value].sample_centre_pos1 = 26. move_info.detectors[DetectorType.HAB.value].sample_centre_pos2 = 98. # The component input is not relevant for SANS2D's initial move. All detectors are moved component = "front-detector" move_component(component_name=component, move_info=move_info, workspace=workspace, move_type=MoveTypes.INITIAL_MOVE) # These values are on the workspace and in the sample logs component_to_investigate = DetectorType.HAB.value initial_x_position = 1.1 x_correction = -0.187987540973 initial_z_position = 23.281 z_correction = 1.00575649188 total_x = initial_x_position + x_correction total_y = 0. total_z = initial_z_position + z_correction expected_position = V3D(total_x - 26., total_y - 98., total_z) expected_rotation = Quat(0.9968998362876025, 0., 0.07868110579898738, 0.) compare_expected_position(self, expected_position, expected_rotation, component_to_investigate, move_info, workspace)
def test_that_ZOOM_can_perform_move(self): beam_coordinates = [45, 25] component = "main-detector-bank" component_key = DetectorType.LAB.value workspace = load_empty_instrument("ZOOM") move_info = _get_state_move_obj(SANSInstrument.ZOOM) # Initial move move_component(component_name=component, workspace=workspace, move_info=move_info, move_type=MoveTypes.INITIAL_MOVE, beam_coordinates=beam_coordinates) initial_z_position = 20.77408 expected_position = V3D(-beam_coordinates[0], -beam_coordinates[1], initial_z_position) expected_rotation = Quat(1., 0., 0., 0.) compare_expected_position(self, expected_position, expected_rotation, component_key, move_info, workspace) # Elementary Move component_elementary_move = "LAB" component_elementary_move_key = DetectorType.LAB.value beam_coordinates_elementary_move = [120, 135] check_elementry_displacement_with_translation( self, workspace, move_info, beam_coordinates_elementary_move, component_elementary_move, component_elementary_move_key) # Reset to zero check_that_sets_to_zero(self, workspace, move_info=move_info)
def _move(self, state: AllStates, workspace, component, is_transmission=False): # First we set the workspace to zero, since it might have been moved around by the user in the ADS # Second we use the initial move to bring the workspace into the correct position move_component(state=state, component_name='', move_type=MoveTypes.RESET_POSITION, workspace=workspace) move_component(component_name=component, state=state, move_type=MoveTypes.INITIAL_MOVE, workspace=workspace, is_transmission_workspace=is_transmission) return workspace
def perform_move(state, workspace): move_info = state.move move_component(move_info=move_info, component_name='', workspace=workspace, move_type=MoveTypes.RESET_POSITION) move_component(component_name=None, move_info=move_info, workspace=workspace, move_type=MoveTypes.INITIAL_MOVE)
def check_that_sets_to_zero(instance, workspace, state: AllStates, comp_name=None): def _get_components_to_compare(_key, inst_info, _component_names): if _key in inst_info.detector_names: _name = inst_info.detector_names[_key].detector_name if _name: _component_names.append(_name) # Reset the position to zero move_component(component_name=comp_name, state=state, workspace=workspace, move_type=MoveTypes.RESET_POSITION) # Get the components to compare inst_info = state.instrument_info if comp_name is None: component_names = list(inst_info.monitor_names.values()) hab_name = DetectorType.HAB.value lab_name = DetectorType.LAB.value, _get_components_to_compare(hab_name, inst_info, component_names) _get_components_to_compare(lab_name, inst_info, component_names) component_names.append("some-sample-holder") else: component_names = [comp_name] # Ensure that the positions on the base instrument and the instrument are the same instrument = workspace.getInstrument() base_instrument = instrument.getBaseInstrument() for component_name in component_names: # Confirm that the positions are the same component = instrument.getComponentByName(component_name) base_component = base_instrument.getComponentByName(component_name) # If we are dealing with a monitor which has not been implemented we need to continue if component is None or base_component is None: continue position = component.getPos() position_base = base_component.getPos() for index in range(0, 3): instance.assertAlmostEqual(position[index], position_base[index], delta=1e-4) rotation = component.getRotation() rotation_base = base_component.getRotation() for index in range(0, 4): instance.assertAlmostEqual(rotation[index], rotation_base[index], delta=1e-4)
def check_elementry_displacement_with_translation(instance, workspace, move_info, coordinates, component, component_key): # Get position and rotation before the move position_before_move, rotation_before_move = _get_position_and_rotation( workspace, move_info, component_key) expected_position_elementary_move = V3D( position_before_move[0] - coordinates[0], position_before_move[1] - coordinates[1], position_before_move[2]) expected_rotation = rotation_before_move move_component(component_name=component, move_info=move_info, workspace=workspace, beam_coordinates=coordinates, move_type=MoveTypes.ELEMENTARY_DISPLACEMENT) compare_expected_position(instance, expected_position_elementary_move, expected_rotation, component_key, move_info, workspace)
def test_that_missing_beam_centre_is_taken_from_lab_move_state_when_no_component_is_specified( self): lab_z_translation_correction = 123. workspace = self._prepare_sans2d_empty_ws() move_info = _get_state_move_obj( instrument=SANSInstrument.SANS2D, z_translation=lab_z_translation_correction) # These values should be used instead of an explicitly specified beam centre x_offset = 26. y_offset = 98. move_info.detectors[ DetectorType.LAB.value].sample_centre_pos1 = x_offset move_info.detectors[ DetectorType.LAB.value].sample_centre_pos2 = y_offset # The component input is not relevant for SANS2D's initial move. All detectors are moved component = None move_component(component_name=component, move_info=move_info, workspace=workspace, move_type=MoveTypes.INITIAL_MOVE) # Assert for initial move for low angle bank # These values are on the workspace and in the sample logs, component_to_investigate = DetectorType.LAB.value initial_z_position = 23.281 rear_det_z = 11.9989755859 offset = 4. total_x = 0. total_y = 0. total_z = initial_z_position + rear_det_z - offset + lab_z_translation_correction expected_position = V3D(total_x - x_offset, total_y - y_offset, total_z) expected_rotation = Quat(1., 0., 0., 0.) compare_expected_position(self, expected_position, expected_rotation, component_to_investigate, move_info, workspace)
def test_that_LOQ_can_perform_move(self): lab_x_translation_correction = 123. beam_coordinates = [45, 25] component = "main-detector-bank" component_key = DetectorType.LAB.value workspace = load_empty_instrument("LOQ") state = _get_state_obj(SANSInstrument.LOQ, lab_x_translation_correction) # Initial move move_component(component_name=component, workspace=workspace, state=state, move_type=MoveTypes.INITIAL_MOVE, beam_coordinates=beam_coordinates) center_position = state.move.center_position initial_z_position = 15.15 expected_position = V3D( center_position - beam_coordinates[0] + lab_x_translation_correction, center_position - beam_coordinates[1], initial_z_position) expected_rotation = Quat(1., 0., 0., 0.) compare_expected_position(self, expected_position, expected_rotation, component_key, state.instrument_info, workspace) # Elementary Move component_elementary_move = "HAB" component_elementary_move_key = DetectorType.HAB.value beam_coordinates_elementary_move = [120, 135] check_elementry_displacement_with_translation( self, workspace, state, beam_coordinates_elementary_move, component_elementary_move, component_elementary_move_key) # Reset to zero check_that_sets_to_zero(self, workspace, state=state)
def _perform_initial_move(self, workspaces, state): # If beam centre was specified then use it beam_coordinates = self.getProperty("BeamCoordinates").value # The workspaces are stored in a dict: workspace_names (sample_scatter, etc) : ListOfWorkspaces for key, workspace_list in workspaces.items(): is_trans = key in [ SANSDataType.CAN_DIRECT, SANSDataType.CAN_TRANSMISSION, SANSDataType.SAMPLE_TRANSMISSION, SANSDataType.SAMPLE_DIRECT ] for workspace in workspace_list: move_component(component_name="", state=state, workspace=workspace, move_type=MoveTypes.RESET_POSITION) move_component(component_name="LAB", state=state, beam_coordinates=beam_coordinates, move_type=MoveTypes.INITIAL_MOVE, workspace=workspace, is_transmission_workspace=is_trans)
def test_that_LARMOR_new_style_can_move(self): lab_x_translation_correction = 123. workspace = load_empty_instrument("LARMOR") # Taken from LARMOR00002260 AddSampleLog(Workspace=workspace, LogName="Bench_Rot", LogText="0.000973305") # Note that the first entry is an angle while the second is a translation (in meter) beam_coordinates = [24., 38.] # Act for initial move component = None move_info = _get_state_move_obj( instrument=SANSInstrument.LARMOR, x_translation=lab_x_translation_correction) move_component(component_name=component, workspace=workspace, move_info=move_info, move_type=MoveTypes.INITIAL_MOVE, beam_coordinates=beam_coordinates) # Assert low angle bank for initial move # These values are on the workspace and in the sample logs component_to_investigate = DetectorType.LAB.value # The rotation couples the movements, hence we just insert absolute value, to have a type of regression test. expected_position = V3D(0, -38, 25.3) expected_rotation = Quat(0.978146, 0, -0.20792, 0) compare_expected_position(self, expected_position, expected_rotation, component_to_investigate, move_info, workspace) check_that_sets_to_zero(self, workspace, move_info, comp_name=None)
def test_that_SANS2D_can_move(self): workspace = self._prepare_sans2d_empty_ws() lab_z_translation_correction = 123. beam_coordinates = [0.1076, -0.0835] # All detectors are moved on SANS2D component = None move_info = _get_state_move_obj( SANSInstrument.SANS2D, z_translation=lab_z_translation_correction) move_component(component_name=component, workspace=workspace, move_info=move_info, move_type=MoveTypes.INITIAL_MOVE, beam_coordinates=beam_coordinates) # Assert for initial move for low angle bank # These values are on the workspace and in the sample logs, component_to_investigate = DetectorType.LAB.value initial_z_position = 23.281 rear_det_z = 11.9989755859 offset = 4. total_x = 0. total_y = 0. total_z = initial_z_position + rear_det_z - offset + lab_z_translation_correction expected_position = V3D(total_x - beam_coordinates[0], total_y - beam_coordinates[1], total_z) expected_rotation = Quat(1., 0., 0., 0.) compare_expected_position(self, expected_position, expected_rotation, component_to_investigate, move_info, workspace) # Assert for initial move for high angle bank # These values are on the workspace and in the sample logs component_to_investigate = DetectorType.HAB.value initial_x_position = 1.1 x_correction = -0.187987540973 initial_z_position = 23.281 z_correction = 1.00575649188 total_x = initial_x_position + x_correction total_y = 0. total_z = initial_z_position + z_correction expected_position = V3D(total_x - beam_coordinates[0], total_y - beam_coordinates[1], total_z) expected_rotation = Quat(0.9968998362876025, 0., 0.07868110579898738, 0.) compare_expected_position(self, expected_position, expected_rotation, component_to_investigate, move_info, workspace) # Act + Assert for elementary move component_elementary_move = "rear-detector" component_elementary_move_key = DetectorType.LAB.value beam_coordinates_elementary_move = [120, 135] check_elementry_displacement_with_translation( self, workspace, move_info, beam_coordinates_elementary_move, component_elementary_move, component_elementary_move_key) # # Act + Assert for setting to zero position for all check_that_sets_to_zero(self, workspace, move_info, comp_name=None)
def _perform_move(self, state, workspace): move_component(state=state, component_name='', workspace=workspace, move_type=MoveTypes.RESET_POSITION) move_component(component_name=None, state=state, workspace=workspace, move_type=MoveTypes.INITIAL_MOVE)