def test_coverage_ROA(self): """Acquire a megafield (ROA), which does not match an integer multiple of fields. Check that the acquired ROA exceeds the requested ROA.""" x_fields = 3 y_fields = 4 self.multibeam.resolution.value = (6400, 6400) # don't change res_x, res_y = self.multibeam.resolution.value # single field size px_size_x, px_size_y = self.multibeam.pixelSize.value # some extra pixels (< 1 field) to be added to the ROA x_margin, y_margin = (res_x / 10, res_y / 20) coordinates = (0, 0, res_x * px_size_x * x_fields + x_margin * px_size_x, res_y * px_size_y * y_fields + y_margin * px_size_y) # in m roc_2 = fastem.FastEMROC("roc_2", coordinates) roc_3 = fastem.FastEMROC("roc_3", coordinates) roa_name = time.strftime("test_megafield_id-%Y-%m-%d-%H-%M-%S") roa = fastem.FastEMROA(roa_name, coordinates, roc_2, roc_3, self.asm, self.multibeam, self.descanner, self.mppc) path_storage = os.path.join(datetime.today().strftime('%Y-%m-%d'), "test_project_field_indices") f = fastem.acquire(roa, path_storage, self.scanner, self.multibeam, self.descanner, self.mppc, self.stage, self.ccd, self.beamshift, self.lens) data, e = f.result() self.assertIsNone(e) # check no exceptions were returned # check data returned contains the correct number of field images # expect plus 1 field in x and y respectively self.assertEqual(len(data), (x_fields + 1) * (y_fields + 1)) self.assertIsInstance(data[(0, 0)], model.DataArray)
def test_progress_ROA(self): """Check if some progress is reported between the field images acquired for the ROA (megafield).""" x_fields = 2 y_fields = 3 res_x, res_y = self.multibeam.resolution.value # single field size px_size_x, px_size_y = self.multibeam.pixelSize.value coordinates = (0, 0, res_x * px_size_x * x_fields, res_y * px_size_y * y_fields) # in m roc_2 = fastem.FastEMROC("roc_2", coordinates) roc_3 = fastem.FastEMROC("roc_3", coordinates) roa_name = time.strftime("test_megafield_id-%Y-%m-%d-%H-%M-%S") roa = fastem.FastEMROA(roa_name, coordinates, roc_2, roc_3, self.asm, self.multibeam, self.descanner, self.mppc) path_storage = os.path.join(datetime.today().strftime('%Y-%m-%d'), "test_project_progress") self.updates = 0 # updated in callback on_progress_update f = fastem.acquire(roa, path_storage, self.scanner, self.multibeam, self.descanner, self.mppc, self.stage, self.ccd, self.beamshift, self.lens) f.add_update_callback(self.on_progress_update) # callback executed every time f.set_progress is called f.add_done_callback(self.on_done) # callback executed when f.set_result is called (via bindFuture) data, e = f.result() self.assertIsNone(e) # check no exceptions were returned self.assertIsInstance(data[(0, 0)], model.DataArray) self.assertTrue(self.done) self.assertGreaterEqual(self.updates, 6) # at least one update per field
def test_calculate_field_indices(self): """Check that the correct number and order of field indices is returned and that row and column are in the correct order.""" x_fields = 3 y_fields = 2 self.multibeam.resolution.value = (6400, 6400) # don't change res_x, res_y = self.multibeam.resolution.value # single field size px_size_x, px_size_y = self.multibeam.pixelSize.value coordinates = (0, 0, res_x * px_size_x * x_fields, res_y * px_size_y * y_fields) # in m, don't change roc_2 = fastem.FastEMROC("roc_2", coordinates) roc_3 = fastem.FastEMROC("roc_3", coordinates) roa_name = time.strftime("test_megafield_id-%Y-%m-%d-%H-%M-%S") roa = fastem.FastEMROA(roa_name, coordinates, roc_2, roc_3, self.asm, self.multibeam, self.descanner, self.mppc) expected_indices = [(0, 0), (1, 0), (2, 0), (0, 1), (1, 1), (2, 1)] # (col, row) field_indices = roa._calculate_field_indices() self.assertListEqual(expected_indices, field_indices)
def test_stage_movement(self): """Test that the stage move corresponds to one field image (excluding over-scanned pixels).""" x_fields = 2 y_fields = 3 res_x, res_y = self.multibeam.resolution.value # single field size px_size_x, px_size_y = self.multibeam.pixelSize.value # FIXME: This test does not consider yet, that ROA coordinates need to be transformed into the # correct coordinate system. Replace role='stage' with role='stage-scan' when function available. # Note: Do not change those values; _calculate_field_indices handles floating point errors the same way # as an ROA that does not match an integer number of field indices by just adding an additional row or column # of field images. xmin = -0.002 # top corner coordinate of ROA in stage coordinates in meter ymin = +0.001 # left corner coordinate of ROA in stage coordinates in meter xmax = xmin + res_x * px_size_x * x_fields ymax = ymin + res_y * px_size_y * y_fields coordinates = (xmin, ymin, xmax, ymax) # in m roc_2 = fastem.FastEMROC("roc_2", coordinates) roc_3 = fastem.FastEMROC("roc_3", coordinates) roa_name = time.strftime("test_megafield_id-%Y-%m-%d-%H-%M-%S") roa = fastem.FastEMROA(roa_name, coordinates, roc_2, roc_3, self.asm, self.multibeam, self.descanner, self.mppc) path_storage = os.path.join(datetime.today().strftime('%Y-%m-%d'), "test_project_stage_move") f = fastem.acquire(roa, path_storage, self.scanner, self.multibeam, self.descanner, self.mppc, self.stage, self.ccd, self.beamshift, self.lens) data, e = f.result() self.assertIsNone(e) # check no exceptions were returned # total expected stage movement in x and y during the acquisition # half a field to start at center of first field image exp_move_x = res_x / 2. * px_size_x + res_x * px_size_x * (x_fields - 1) exp_move_y = res_y / 2. * px_size_y + res_y * px_size_y * (y_fields - 1) # FIXME Needs to be updated when role="stage" is replaced with role="stage-scan" # In role="stage" coordinate system: # Move in the positive x direction, because the second field should be right of the first. # Move in the negative y direction, because the second field should be below the first. exp_position = (xmin + exp_move_x, ymax - exp_move_y) # get the last stage position (it is the center of the last field) cur_position = (self.stage.position.value['x'], self.stage.position.value['y']) # check stage position is matching expected position (Note: stage accuracy is ~ TODO fix decimal accordingly) numpy.testing.assert_almost_equal(exp_position, cur_position, decimal=6)
def test_estimate_acquisition_time(self): """Check that the estimated time for one ROA (megafield) is calculated correctly.""" # Use float for number of fields, in order to not end up with additional fields scanned and thus an # incorrectly estimated roa acquisition time. x_fields = 2.9 y_fields = 3.2 n_fields = math.ceil(x_fields) * math.ceil(y_fields) res_x, res_y = self.multibeam.resolution.value # single field size px_size_x, px_size_y = self.multibeam.pixelSize.value coordinates = (0, 0, res_x * px_size_x * x_fields, res_y * px_size_y * y_fields) # in m roc_2 = fastem.FastEMROC("roc_2", coordinates) roc_3 = fastem.FastEMROC("roc_3", coordinates) roa_name = time.strftime("test_megafield_id-%Y-%m-%d-%H-%M-%S") for dwell_time in [400e-9, 1e-6, 10e-6]: self.multibeam.dwellTime.value = dwell_time roa = fastem.FastEMROA(roa_name, coordinates, roc_2, roc_3, self.asm, self.multibeam, self.descanner, self.mppc) cell_res = self.mppc.cellCompleteResolution.value flyback = self.descanner.physicalFlybackTime.value # extra time per line scan # calculate expected roa (megafield) acquisition time # (number of pixels per line * dwell time + flyback time) * number of lines * number of cells in x and y estimated_line_time = cell_res[0] * dwell_time # Remainder of the line scan time, part which is not a whole multiple of the descan periods. remainder_scanning_time = estimated_line_time % self.descanner.clockPeriod.value if remainder_scanning_time is not 0: # Adjusted the flyback time if there is a remainder of scanning time by adding one setpoint to ensure # the line scan time is equal to a whole multiple of the descanner clock period flyback = flyback + (self.descanner.clockPeriod.value - remainder_scanning_time) # Round to prevent floating point errors estimated_line_time = numpy.round(estimated_line_time + flyback, 9) # The estimated ROA time is the line time multiplied with the cell resolution and the number of fields. # Additionally, 1.5s overhead per field image and the first field image is acquired twice. estimated_roa_acq_time = (estimated_line_time * cell_res[1] + 1.5) * (n_fields + 1) # get roa acquisition time roa_acq_time = estimate_acquisition_time(roa) self.assertAlmostEqual(estimated_roa_acq_time, roa_acq_time)
def test_acquire_ROA(self): """Acquire a small mega field image with ROA matching integer multiple of single field size.""" x_fields = 2 y_fields = 3 self.multibeam.resolution.value = (6400, 6400) # don't change res_x, res_y = self.multibeam.resolution.value # single field size px_size_x, px_size_y = self.multibeam.pixelSize.value # Note: Do not change those values; _calculate_field_indices handles floating point errors the same way # as an ROA that does not match an integer number of field indices by just adding an additional row or column # of field images. top = -0.002 # top corner coordinate of ROA in stage coordinates in meter left = +0.001 # left corner coordinate of ROA in stage coordinates in meter coordinates = (top, left, top + res_x * px_size_x * x_fields, left + res_y * px_size_y * y_fields) # in m roc = fastem.FastEMROC("roc_name", coordinates) roa_name = time.strftime("test_megafield_id-%Y-%m-%d-%H-%M-%S") roa = fastem.FastEMROA(roa_name, coordinates, roc, self.asm, self.multibeam, self.descanner, self.mppc) path_storage = os.path.join(datetime.today().strftime('%Y-%m-%d'), "test_project_megafield") f = fastem.acquire(roa, path_storage, self.scanner, self.multibeam, self.descanner, self.mppc, self.stage, self.ccd, self.beamshift, self.lens) data, e = f.result() self.assertIsNone(e) # check no exceptions were returned # check data returned contains the correct number of field images self.assertEqual(len(data), x_fields * y_fields) self.assertIsInstance(data[(0, 0)], model.DataArray)
def test_estimate_acquisition_time(self): """Check that the estimated time for one ROA (megafield) is calculated correctly.""" # Use float for number of fields, in order to not end up with additional fields scanned and thus an # incorrectly estimated roa acquisition time. x_fields = 2.9 y_fields = 3.2 res_x, res_y = self.multibeam.resolution.value # single field size px_size_x, px_size_y = self.multibeam.pixelSize.value coordinates = (0, 0, res_x * px_size_x * x_fields, res_y * px_size_y * y_fields) # in m roc = fastem.FastEMROC("roc_name", coordinates) roa_name = time.strftime("test_megafield_id-%Y-%m-%d-%H-%M-%S") roa = fastem.FastEMROA(roa_name, coordinates, roc, self.asm, self.multibeam, self.descanner, self.mppc) cell_res = self.mppc.cellCompleteResolution.value dwell_time = self.multibeam.dwellTime.value flyback = self.descanner.physicalFlybackTime.value # extra time per line scan # calculate expected roa (megafield) acquisition time # (number of pixels per line * dwell time + flyback time) * number of lines * number of cells in x and y estimated_roa_acq_time = (cell_res[0] * dwell_time + flyback) * cell_res[1] \ * math.ceil(x_fields) * math.ceil(y_fields) # get roa acquisition time roa_acq_time = roa.estimate_acquisition_time() self.assertAlmostEqual(estimated_roa_acq_time, roa_acq_time)
def test_cancel_ROA(self): """Test if it is possible to cancel between field images acquired for one ROA.""" x_fields = 2 y_fields = 3 res_x, res_y = self.multibeam.resolution.value # single field size px_size_x, px_size_y = self.multibeam.pixelSize.value coordinates = (0, 0, res_x * px_size_x * x_fields, res_y * px_size_y * y_fields) # in m roc_2 = fastem.FastEMROC("roc_2", coordinates) roc_3 = fastem.FastEMROC("roc_3", coordinates) roa_name = time.strftime("test_megafield_id-%Y-%m-%d-%H-%M-%S") roa = fastem.FastEMROA(roa_name, coordinates, roc_2, roc_3, self.asm, self.multibeam, self.descanner, self.mppc) path_storage = os.path.join(datetime.today().strftime('%Y-%m-%d'), "test_project_cancel") self.end = None # updated in callback on_progress_update self.updates = 0 # updated in callback on_progress_update self.done = False # updated in callback on_done f = fastem.acquire(roa, path_storage, self.scanner, self.multibeam, self.descanner, self.mppc, self.stage, self.ccd, self.beamshift, self.lens) f.add_update_callback(self.on_progress_update) # callback executed every time f.set_progress is called f.add_done_callback(self.on_done) # callback executed when f.set_result is called (via bindFuture) time.sleep(1) # make sure it's started self.assertTrue(f.running()) f.cancel() with self.assertRaises(CancelledError): f.result(timeout=5) # add timeout = 5s in case cancellation error was not raised self.assertGreaterEqual(self.updates, 3) # at least one update at cancellation self.assertLessEqual(self.end, time.time()) self.assertTrue(self.done) self.assertTrue(f.cancelled())
def test_stage_movement(self): """Test that the stage move corresponds to one field image (excluding over-scanned pixels).""" x_fields = 2 y_fields = 3 res_x, res_y = self.multibeam.resolution.value # single field size px_size_x, px_size_y = self.multibeam.pixelSize.value # FIXME: It is not clear in which coordinate system the coordinates of the ROA are!!! # Note: the coordinates are in the stage coordinate system with role='stage' and not role='stage-scan'. # However, for fast em acquisitions we use stage-scan, which scans along the multiprobe axes. # FIXME: This test does not consider yet, that ROA coordinates need to be transformed into the # correct coordinate system. Replace role='stage' with role='stage-scan' when function available. # Note: Do not change those values; _calculate_field_indices handles floating point errors the same way # as an ROA that does not match an integer number of field indices by just adding an additional row or column # of field images. top = -0.002 # top corner coordinate of ROA in stage coordinates in meter left = +0.001 # left corner coordinate of ROA in stage coordinates in meter coordinates = (top, left, top + res_x * px_size_x * x_fields, left + res_y * px_size_y * y_fields) # in m roc = fastem.FastEMROC("roc_name", coordinates) roa_name = time.strftime("test_megafield_id-%Y-%m-%d-%H-%M-%S") roa = fastem.FastEMROA(roa_name, coordinates, roc, self.asm, self.multibeam, self.descanner, self.mppc) path_storage = os.path.join(datetime.today().strftime('%Y-%m-%d'), "test_project_stage_move") f = fastem.acquire(roa, path_storage, self.multibeam, self.descanner, self.mppc, self.stage) data, e = f.result() self.assertIsNone(e) # check no exceptions were returned # total expected stage movement in x and y during the acquisition # half a field to start at center of first field image exp_move_x = res_x / 2. * px_size_x + res_x * px_size_x * (x_fields - 1) exp_move_y = res_y / 2. * px_size_y + res_y * px_size_y * (y_fields - 1) # TODO these comments are true, when stage is replaced with stage-scan # Move in the negative x direction, because the second field should be right of the first. # Move in positive y direction, because the second field should be bottom of the first. exp_position = (top - exp_move_x, left + exp_move_y) # get the last stage position (it is the center of the last field) cur_position = (self.stage.position.value['x'], self.stage.position.value['y']) # check stage position is matching expected position (Note: stage accuracy is ~ TODO fix decimal accordingly) numpy.testing.assert_almost_equal(exp_position, cur_position, decimal=6)