def setUp(self): self.focus = TMCLController(name="test_focus", role="focus", port="/dev/fake3", axes=["z"], ustepsize=[1e-6], rng=[ [-3000e-6, 3000e-6], ], refproc="Standard")
def test_cryo_feature_overlay(self): """ Test behavior of CryoFeatureOverlay """ cnvs = miccanvas.DblMicroscopeCanvas(self.panel) self.add_control(cnvs, wx.EXPAND, proportion=1, clear=True) tab_mod = self.create_cryo_tab_model() # Create a dummy stage & focus to attach to the view stage = TMCLController(name="test_stage", role="stage", port="/dev/fake3", axes=["x", "y"], ustepsize=[1e-6, 1e-6], rng=[[-3e-3, 3e-3], [-3e-3, 3e-3]], refproc="Standard") focus = TMCLController(name="test_focus", role="focus", port="/dev/fake3", axes=["z"], ustepsize=[1e-6], rng=[[-3e-3, 3e-3]], refproc="Standard") tab_mod.main.stage = stage tab_mod.main.focus = focus fview = FeatureOverviewView("fakeview", stage=stage) tab_mod.views.value.append(fview) tab_mod.focussedView.value = fview cnvs.setView(fview, tab_mod) # Save current empty canvas img = wx.Bitmap.ConvertToImage(cnvs._bmp_buffer) buffer_clear = wxImage2NDImage(img) cryofeature_overlay = wol.CryoFeatureOverlay(cnvs, tab_mod) cnvs.add_world_overlay(cryofeature_overlay) cryofeature_overlay.active.value = True # Add features to the tab's features list tab_mod.add_new_feature(0, 0) tab_mod.add_new_feature(0.001, 0.001) cnvs._dc_buffer.SelectObject(wx.NullBitmap) # Flush the buffer cnvs._dc_buffer.SelectObject(cnvs._bmp_buffer) img = wx.Bitmap.ConvertToImage(cnvs._bmp_buffer) buffer_feature = wxImage2NDImage(img) # Compare empty canvas with the added _features_va assert_array_not_equal( buffer_clear, buffer_feature, msg= "Buffers are equal, which means the added _features_va didn't appear on the canvas." ) test.gui_loop()
def test_current_pos_crosshair_overlay(self): """ Test behaviour of CurrentPosCrossHairOverlay """ cnvs = miccanvas.DblMicroscopeCanvas(self.panel) self.add_control(cnvs, wx.EXPAND, proportion=1, clear=True) tab_mod = self.create_simple_tab_model() # create a dummy stage to attach to the view stage = TMCLController(name="test", role="test", port="/dev/fake3", axes=["x", "y"], ustepsize=[1e-6, 1e-6], rng=[[-3e-3, 3e-3], [-3e-3, 3e-3]], refproc="Standard") # Add a tiled area view to the tab model logging.debug(stage.position.value) fview = FeatureOverviewView("fakeview", stage=stage) tab_mod.views.value.append(fview) tab_mod.focussedView.value = fview cnvs.setView(fview, tab_mod) cnvs.view.show_crosshair.value = False slol = wol.CurrentPosCrossHairOverlay(cnvs) slol.active.value = True cnvs.add_world_overlay(slol) # stage start at 0,0 (cross hair at center) -> move bt 1mm, 1mm -> then back to 0,0 stage.moveAbs({'x': 1e-3, 'y': 1e-3}).result() img = wx.Bitmap.ConvertToImage(cnvs._bmp_buffer) buffer_ch_move = wxImage2NDImage(img) test.gui_loop(1) stage.moveAbs({'x': 0, 'y': 0}).result() cnvs.update_drawing() cnvs._dc_buffer.SelectObject(wx.NullBitmap) # Flush the buffer cnvs._dc_buffer.SelectObject(cnvs._bmp_buffer) img = wx.Bitmap.ConvertToImage(cnvs._bmp_buffer) buffer_ch_center = wxImage2NDImage(img) assert_array_not_equal( buffer_ch_center, buffer_ch_move, msg= "Buffers are equal, which means the crosshair didn't change on stage movement." ) test.gui_loop()
def test_stage_point_select_mode_overlay(self): """ Test behavior of StagePointSelectOverlay """ cnvs = miccanvas.DblMicroscopeCanvas(self.panel) self.add_control(cnvs, wx.EXPAND, proportion=1, clear=True) tab_mod = self.create_simple_tab_model() # create a dummy stage to attach to the view stage = TMCLController(name="test", role="test", port="/dev/fake3", axes=["x", "y"], ustepsize=[1e-6, 1e-6], rng=[[-3e-3, 3e-3], [-3e-3, 3e-3]], refproc="Standard") # Add a tiled area view to the tab model logging.debug(stage.position.value) fview = FeatureOverviewView("fakeview", stage=stage) tab_mod.views.value.append(fview) tab_mod.focussedView.value = fview cnvs.setView(fview, tab_mod) slol = wol.StagePointSelectOverlay(cnvs) slol.active.value = True cnvs.add_world_overlay(slol) initial_pos = copy.deepcopy(stage.position.value) # simulate double click by passing the mouse event to on_dbl_click evt = wx.MouseEvent() evt.x = 10 evt.y = 10 slol.on_dbl_click(evt) test.gui_loop(1) # stage should have been moved from initial position assert_pos_not_almost_equal(stage.position.value, initial_pos) logging.debug(stage.position.value) test.gui_loop()
class TestGenerateZlevels(unittest.TestCase): def setUp(self): self.focus = TMCLController(name="test_focus", role="focus", port="/dev/fake3", axes=["z"], ustepsize=[1e-6], rng=[ [-3000e-6, 3000e-6], ], refproc="Standard") def test_zero_zstep(self): self.focus.moveAbsSync({"z": 1300e-6}) zMin = -500e-6 zMax = 500e-6 zrange = [zMin, zMax] zStep = 0e-6 with self.assertRaises(ZeroDivisionError): generate_zlevels(self.focus, zrange, zStep) def test_zmax_and_zmin_both_zeros(self): self.focus.moveAbsSync({"z": 1300e-6}) zMin = -0e-6 zMax = 0e-6 zrange = [zMin, zMax] zStep = 10e-6 actual = generate_zlevels(self.focus, zrange, zStep) expected = self.focus.position.value self.assertAlmostEqual(expected["z"], actual) def test_zrange_not_in_proper_order(self): self.focus.moveAbsSync({"z": 1300e-6}) zMin = -10e-6 zMax = 10e-6 zrange = [zMax, zMin] zStep = 10e-6 with self.assertRaises(ValueError): generate_zlevels(self.focus, zrange, zStep) def test_zstep_greater_than_zmax_and_zmin(self): self.focus.moveAbsSync({"z": 1300e-6}) zMin = -10e-6 zMax = 10e-6 zrange = [zMin, zMax] zStep = 70e-6 actual = generate_zlevels(self.focus, zrange, zStep) expected = numpy.asarray([-10e-6, 10e-6 ]) + self.focus.position.value["z"] numpy.testing.assert_array_almost_equal(actual, expected) def test_normal_zlevels_output_with_positive_zstep(self): self.focus.moveAbsSync({"z": 1000e-6}) zMax = 100e-6 zMin = -250e-6 zrange = [zMin, zMax] zStep = 50e-6 expected = numpy.asarray([ -250e-6, -200e-6, -150e-6, -100e-6, -50e-6, 0e-6, 50e-6, 100e-6 ]) + self.focus.position.value["z"] actual = generate_zlevels(self.focus, zrange, zStep) numpy.testing.assert_array_almost_equal(expected, actual) def test_normal_zlevels_output_with_negative_zstep(self): self.focus.moveAbsSync({"z": 1000e-6}) zMax = 100e-6 zMin = -250e-6 zrange = [zMin, zMax] zStep = -50e-6 expected = numpy.asarray([ 1.0e-04, 5.0e-05, 0.0, -5.0e-05, -1.0e-04, -1.5e-04, -2.0e-04, -2.5e-04 ]) + self.focus.position.value["z"] actual = generate_zlevels(self.focus, zrange, zStep) numpy.testing.assert_array_almost_equal(expected, actual) def test_normal_zlevels_output_with_rounding_down(self): self.focus.moveAbsSync({"z": 1000e-6}) zMax = 10e-6 zMin = -10e-6 zrange = [zMin, zMax] zStep = 6e-6 expected = numpy.asarray([-10e-6, -3.33e-6, 3.33e-6, 10e-6 ]) + self.focus.position.value["z"] actual = generate_zlevels(self.focus, zrange, zStep) numpy.testing.assert_array_almost_equal(expected, actual) def test_normal_zlevels_output_with_rounding_up(self): self.focus.moveAbsSync({"z": 1000e-6}) zMax = 24e-6 zMin = -24e-6 zrange = [zMin, zMax] zStep = 17e-6 expected = numpy.asarray([-24e-6, -8e-6, 8e-6, 24e-6]) + \ self.focus.position.value["z"] actual = generate_zlevels(self.focus, zrange, zStep) numpy.testing.assert_array_almost_equal(expected, actual) def test_large_number_of_levels(self): self.focus.moveAbsSync({"z": 1000e-6}) zMax = 100e-6 zMin = -100e-6 zrange = [zMin, zMax] zStep = 0.5e-6 output = generate_zlevels(self.focus, zrange, zStep) self.assertEqual(len(output), 401) def test_clipping_zmin_on_actuator_lower_limit(self): self.focus.moveAbsSync({"z": -2800e-6}) zMax = 0e-6 zMin = -300e-6 zrange = [zMin, zMax] zStep = 100e-6 expected = numpy.asarray([-200e-6, -100e-6, 0e-6]) + \ self.focus.position.value["z"] actual = generate_zlevels(self.focus, zrange, zStep) numpy.testing.assert_array_almost_equal(expected, actual) def test_clipping_zmax_on_actuator_upper_limit(self): self.focus.moveAbsSync({"z": 2800e-6}) zMax = 300e-6 zMin = 0e-6 zrange = [zMin, zMax] zStep = 100e-6 expected = numpy.asarray([0e-6, 100e-6, 200e-6]) + \ self.focus.position.value["z"] actual = generate_zlevels(self.focus, zrange, zStep) numpy.testing.assert_array_almost_equal(expected, actual)