def test_moving_from_grid2_to_grid1_in_fm_imaging_Area(self): f = cryoSwitchSamplePosition(LOADING) f.result() # move to the fm imaging area f = cryoSwitchSamplePosition(FM_IMAGING) f.result() current_imaging_mode = getCurrentPositionLabel( self.stage.position.value, self.stage) self.assertEqual(FM_IMAGING, current_imaging_mode) # move to the grid2 f = cryoSwitchSamplePosition(GRID_2) f.result() current_grid = getCurrentGridLabel(self.stage.position.value, self.stage) self.assertEqual(GRID_2, current_grid) # move back to the grid1 f = cryoSwitchSamplePosition(GRID_1) f.result() current_grid = getCurrentGridLabel(self.stage.position.value, self.stage) self.assertEqual(GRID_1, current_grid) # make sure we are still in fm imaging area current_imaging_mode = getCurrentPositionLabel( self.stage.position.value, self.stage) self.assertEqual(FM_IMAGING, current_imaging_mode)
def test_tilting_procedures(self): """ Test moving the sample stage from imaging position to tilting position and back to imaging """ stage = self.stage align = self.aligner # Test tilting from imaging # Get the stage to imaging position cryoSwitchSamplePosition(LOADING).result() cryoSwitchSamplePosition(IMAGING).result() # Tilt the stage on rx only f = cryoTiltSample(rx=self.rx_angle) f.result() test.assert_pos_almost_equal(stage.position.value, {'rx': self.rx_angle}, match_all=False, atol=ATOL_ROTATION_POS) # Tilt the stage on rx and rz f = cryoTiltSample(rx=self.rx_angle, rz=self.rz_angle) f.result() test.assert_pos_almost_equal(stage.position.value, { 'rx': self.rx_angle, 'rz': self.rz_angle }, match_all=False, atol=ATOL_ROTATION_POS) # align should be in deactive position test.assert_pos_almost_equal(align.position.value, self.align_deactive, atol=ATOL_LINEAR_POS)
def test_invalid_switch_movements(self): """ Test it's not possible to do some disallowed switch movements """ # Test tilting from loading cryoSwitchSamplePosition(LOADING).result() with self.assertRaises(ValueError): f = cryoTiltSample(rx=self.rx_angle, rz=self.rz_angle) f.result()
def test_moving_to_grid2_in_sem_imaging_area_after_loading(self): # move the stage to the loading position f = cryoSwitchSamplePosition(LOADING) f.result() # move the stage to grid2 f = cryoSwitchSamplePosition(GRID_2) f.result() position_label = getCurrentPositionLabel(self.stage.position.value, self.stage) grid_label = getCurrentGridLabel(self.stage.position.value, self.stage) self.assertEqual(position_label, SEM_IMAGING) self.assertEqual(grid_label, GRID_2)
def test_moving_to_grid1_in_fm_imaging_area_after_loading(self): # move the stage to the loading position f = cryoSwitchSamplePosition(LOADING) f.result() # move the stage to the fm imaging area, and grid1 will be chosen by default f = cryoSwitchSamplePosition(FM_IMAGING) f.result() position_label = getCurrentPositionLabel(self.stage.position.value, self.stage) grid_label = getCurrentGridLabel(self.stage.position.value, self.stage) self.assertEqual(position_label, FM_IMAGING) self.assertEqual(grid_label, GRID_1)
def test_moving_to_sem_from_fm(self): f = cryoSwitchSamplePosition(LOADING) f.result() # move to the fm imaging area f = cryoSwitchSamplePosition(FM_IMAGING) f.result() current_imaging_mode = getCurrentPositionLabel(self.stage.position.value, self.stage) self.assertEqual(FM_IMAGING, current_imaging_mode) # move to sem f = cryoSwitchSamplePosition(SEM_IMAGING) f.result() current_imaging_mode = getCurrentPositionLabel(self.stage.position.value, self.stage) self.assertEqual(SEM_IMAGING, current_imaging_mode)
def test_smaract_stage_fallback_movement(self): """ Test behaviour of smaract 5dof stage when the linear axes are near the maximum range """ # 1. Move to imaging position cryoSwitchSamplePosition(IMAGING).result() # 2. Move the stage linear axes to their max range + move rx from 0 cryoSwitchAlignPosition(LOADING).result() self.stage.moveAbs({'x': self.stage.axes['x'].range[1], 'y': self.stage.axes['y'].range[1], 'z': self.stage.axes['z'].range[1], 'rx': 0.15}).result() # 3. Move to loading where the ordered submoves would start from rx/rx, resulting in an invalid move # exception if it's not handled cryoSwitchSamplePosition(LOADING).result() test.assert_pos_almost_equal(self.stage.position.value, self.stage_deactive, atol=ATOL_LINEAR_POS)
def test_cancel_tilting(self): """ Test cryoTiltSample movement cancellation is handled correctly """ stage = self.stage cryoSwitchSamplePosition(LOADING).result() cryoSwitchSamplePosition(IMAGING).result() f = cryoTiltSample(rx=self.rx_angle, rz=self.rz_angle) time.sleep(2) cancelled = f.cancel() self.assertTrue(cancelled) test.assert_pos_not_almost_equal(stage.position.value, {'rx': self.rx_angle, 'rz': self.rz_angle}, match_all=False, atol=ATOL_ROTATION_POS)
def test_sample_switch_procedures(self): """ Test moving the sample stage from loading position to both imaging, alignment and coating, then back to loading """ stage = self.stage align = self.aligner # Get the stage to loading position cryoSwitchSamplePosition(LOADING).result() test.assert_pos_almost_equal(stage.position.value, self.stage_deactive, atol=ATOL_LINEAR_POS) # Align should be parked test.assert_pos_almost_equal(align.position.value, self.align_deactive, atol=ATOL_LINEAR_POS) # Get the stage to imaging position cryoSwitchSamplePosition(IMAGING).result() test.assert_pos_almost_equal(stage.position.value, self.stage_active, atol=ATOL_LINEAR_POS, match_all=False) # align should be in active position test.assert_pos_almost_equal(align.position.value, self.align_active, atol=ATOL_LINEAR_POS) # Get the stage to coating position f = cryoSwitchSamplePosition(COATING) f.result() filter_dict = lambda keys, d: {key: d[key] for key in keys} test.assert_pos_almost_equal(filter_dict({'x', 'y', 'z'}, stage.position.value), filter_dict({'x', 'y', 'z'}, self.stage_coating), atol=ATOL_LINEAR_POS) test.assert_pos_almost_equal(filter_dict({'rx', 'rz'}, stage.position.value), filter_dict({'rx', 'rz'}, self.stage_coating), atol=ATOL_LINEAR_POS) # align should be in deactive position test.assert_pos_almost_equal(align.position.value, self.align_deactive, atol=ATOL_LINEAR_POS) # Get the stage to alignment position f = cryoSwitchSamplePosition(ALIGNMENT) f.result() test.assert_pos_almost_equal(stage.position.value, self.stage_alignment, atol=ATOL_LINEAR_POS, match_all=False) # Get the stage to 3beams position f = cryoSwitchSamplePosition(THREE_BEAMS) f.result() test.assert_pos_almost_equal(stage.position.value, self.stage_3beams, atol=ATOL_LINEAR_POS, match_all=False) test.assert_pos_almost_equal(align.position.value, self.align_3beams, atol=ATOL_LINEAR_POS) # Get the stage to alignment position f = cryoSwitchSamplePosition(SEM_IMAGING) f.result() test.assert_pos_almost_equal(stage.position.value, self.stage_sem_imaging, atol=ATOL_LINEAR_POS, match_all=False) # Switch back to loading position cryoSwitchSamplePosition(LOADING).result() test.assert_pos_almost_equal(stage.position.value, self.stage_deactive, atol=ATOL_LINEAR_POS)
def test_moving_from_grid1_to_grid2_in_sem_imaging_area(self): # move to loading position f = cryoSwitchSamplePosition(LOADING) f.result() # move the stage to the sem imaging area f = cryoSwitchSamplePosition(SEM_IMAGING) f.result() current_imaging_mode = getCurrentPositionLabel(self.stage.position.value, self.stage) self.assertEqual(SEM_IMAGING, current_imaging_mode) # now the selected grid is already the grid1 current_grid = getCurrentGridLabel(self.stage.position.value, self.stage) self.assertEqual(GRID_1, current_grid) # move the stage to grid2 f = cryoSwitchSamplePosition(GRID_2) f.result() current_grid = getCurrentGridLabel(self.stage.position.value, self.stage) self.assertEqual(GRID_2, current_grid) # make sure we are still in sem imaging area current_imaging_mode = getCurrentPositionLabel(self.stage.position.value, self.stage) self.assertEqual(SEM_IMAGING, current_imaging_mode)
def test_cancel_loading(self): """ Test cryoSwitchSamplePosition movement cancellation is handled correctly """ stage = self.stage cryoSwitchSamplePosition(LOADING).result() f = cryoSwitchSamplePosition(IMAGING) time.sleep(2) cancelled = f.cancel() self.assertTrue(cancelled) test.assert_pos_not_almost_equal(stage.position.value, self.stage_deactive, atol=ATOL_LINEAR_POS) stage = self.stage cryoSwitchSamplePosition(LOADING).result() f = cryoSwitchSamplePosition(COATING) time.sleep(2) cancelled = f.cancel() self.assertTrue(cancelled) test.assert_pos_not_almost_equal(stage.position.value, self.stage_coating, atol=ATOL_LINEAR_POS)
def test_get_current_position(self): """ Test getCurrentPositionLabel function behaves as expected """ stage = self.stage # Move to loading position cryoSwitchSamplePosition(LOADING).result() pos_label = getCurrentPositionLabel(stage.position.value, stage) self.assertEqual(pos_label, LOADING) # Move to imaging position and cancel the movement before reaching there f = cryoSwitchSamplePosition(IMAGING) # abit long wait for the loading-imaging referencing to finish time.sleep(7) f.cancel() pos_label = getCurrentPositionLabel(stage.position.value, stage) self.assertEqual(pos_label, LOADING_PATH) # Move to imaging position cryoSwitchSamplePosition(LOADING).result() cryoSwitchSamplePosition(IMAGING).result() pos_label = getCurrentPositionLabel(stage.position.value, stage) self.assertEqual(pos_label, IMAGING) # Move to alignment f = cryoSwitchSamplePosition(ALIGNMENT) f.result() pos_label = getCurrentPositionLabel(stage.position.value, stage) self.assertEqual(pos_label, ALIGNMENT) # Move to SEM imaging f = cryoSwitchSamplePosition(SEM_IMAGING) f.result() pos_label = getCurrentPositionLabel(stage.position.value, stage) self.assertEqual(pos_label, SEM_IMAGING) # Move to coating position cryoSwitchSamplePosition(LOADING).result() f = cryoSwitchSamplePosition(COATING) f.result() pos_label = getCurrentPositionLabel(stage.position.value, stage) self.assertEqual(pos_label, COATING) # Return to loading and cancel before reaching f = cryoSwitchSamplePosition(LOADING) time.sleep(4) f.cancel() pos_label = getCurrentPositionLabel(stage.position.value, stage) self.assertEqual(pos_label, LOADING_PATH)