def __init__(self, microscope, main_app): # Called when the plugin is loaed (ie, at GUI initialisation) super(Correlator2D, self).__init__(microscope, main_app) if not microscope or microscope.role not in ("sparc", "sparc2"): return try: self.ebeam = model.getComponent(role="e-beam") self.correlator = model.getComponent(role="time-correlator") self.sed = model.getComponent(role="se-detector") except LookupError: logging.debug("Hardware not found, cannot use the plugin") return # the SEM survey stream (will be updated when showing the window) self._survey_s = None # Create a stream for correlator spectral measurement self._correlator_s = CorrelatorScanStream("Correlator data", self.correlator, self.sed, self.ebeam, main_app.main_data.opm) # For reading the ROA and anchor ROI self._acqui_tab = main_app.main_data.getTabByName( "sparc_acqui").tab_data_model self.dwellTime = self._correlator_s.dwellTime self.pixelDuration = self._correlator_s.pixelDuration self.syncOffset = self._correlator_s.syncOffset self.syncDiv = self._correlator_s.syncDiv # The scanning positions are defined by ROI (as selected in the acquisition tab) + stepsize # Based on these values, the scanning resolution is computed self.roi = self._correlator_s.roi self.stepsize = self._correlator_s.stepsize self.cropvalue = self._correlator_s.cropvalue self.xres = model.IntVA(1, unit="px") self.yres = model.IntVA(1, unit="px") self.nDC = self._correlator_s.nDC self.filename = model.StringVA("a.h5") self.expectedDuration = model.VigilantAttribute(1, unit="s", readonly=True) # Update the expected duration when values change, depends both dwell time and # of pixels self.dwellTime.subscribe(self._update_exp_dur) self.stepsize.subscribe(self._update_exp_dur) self.nDC.subscribe(self._update_exp_dur) # subscribe to update X/Y res self.stepsize.subscribe(self._update_res) self.roi.subscribe(self._update_res) self.addMenu("Acquisition/CL time correlator scan...", self.start)
def __init__(self, microscope, main_app): super(SpikeRemovalPlugin, self).__init__(microscope, main_app) self.addMenu("Data correction/Spike removal...", self.start) self._dlg = None self._spec_stream = None # create VA for threshold self.threshold = model.FloatContinuous(8, range=(1, 20), unit="") self.npixels = model.IntVA(0, unit="", readonly=True) self.nspikes = model.IntVA(0, unit="", readonly=True)
def test_unsubscribe(self): prop = model.IntVA(2) self.called = 0 prop.subscribe(self.callback_test_notify) # now count prop.value = 3 # +1 prop.unsubscribe(self.callback_test_notify) prop.value = 0 # +0 prop.value = 0 # +0 prop.value = 1 # +0 prop.value = 0 # +0 self.assertTrue(prop.value == 0) self.assertTrue(self.called == 1) # Bounded and unbounded methods are treated differently, so test both def unbound_func(v): self.called += 1 self.called = 0 prop.subscribe(unbound_func) # now count prop.value = 3 # +1 prop.unsubscribe(unbound_func) prop.value = 0 # +0 prop.value = 0 # +0 prop.value = 1 # +0 prop.value = 0 # +0 self.assertTrue(prop.value == 0) self.assertTrue(self.called == 1)
def __init__(self, *args, **kwargs): model.HwComponent.__init__(self, *args, **kwargs) self.data = FakeDataFlow() # TODO automatically register the property when serializing the Component self.prop = model.IntVA(42) self.cont = model.FloatContinuous(2.0, [-1, 3.4]) self.enum = model.StringEnumerated("a", {"a", "c", "bfds"})
def test_spectrum_line_select_overlay(self): cnvs = miccanvas.DblMicroscopeCanvas(self.panel) tab_mod = self.create_simple_tab_model() view = tab_mod.focussedView.value self.add_control(cnvs, wx.EXPAND, proportion=1, clear=True) cnvs.setView(view, tab_mod) cnvs.current_mode = TOOL_POINT slol = wol.SpectrumLineSelectOverlay(cnvs) slol.activate() cnvs.add_world_overlay(slol) slol.set_data_properties(1e-05, (0.0, 0.0), (17, 19)) width_va = model.IntVA(1) line_va = model.TupleVA(((None, None), (None, None))) slol.connect_selection(line_va, width_va) view.mpp.value = 1e-06 test.gui_loop() # Tool toggle for debugging tol = vol.TextViewOverlay(cnvs) tol.add_label("Right click to toggle tool", (10, 30)) cnvs.add_view_overlay(tol) test.gui_loop() line_va.value = ((0, 0), (8, 8)) test.gui_loop() # Also connect the pixel va pixel_va = model.TupleVA((8, 8)) slol.connect_selection(line_va, width_va, pixel_va) test.gui_loop() def toggle(evt): if slol.active: slol.deactivate() else: slol.activate() evt.Skip() cnvs.Bind(wx.EVT_RIGHT_UP, toggle) cnvs.disable_drag() def on_key(evt): k = evt.GetKeyCode() if k == wx.WXK_DOWN and width_va.value > 1: width_va.value -= 1 elif k == wx.WXK_UP: width_va.value += 1 else: pass cnvs.Bind(wx.EVT_KEY_UP, on_key)
def test_del(self): """ Test that the VA is properly deleted. """ prop = model.IntVA(2) ref = weakref.ref(prop) del prop self.assertEqual(ref(), None)
def __init__(self, name, daemon): model.Component.__init__(self, name=name, daemon=daemon) self.executor = futures.ThreadPoolExecutor(max_workers=1) self.number_futures = 0 self.startAcquire = model.Event() # triggers when the acquisition of .data starts self.data = FakeDataFlow(sae=self.startAcquire) self.datas = SynchronizableDataFlow() self.data_count = 0 self._df = None # TODO automatically register the property when serializing the Component self.prop = model.IntVA(42) self.cont = model.FloatContinuous(2.0, [-1, 3.4], unit="C") self.enum = model.StringEnumerated("a", {"a", "c", "bfds"}) self.cut = model.IntVA(0, setter=self._setCut) self.listval = model.ListVA([2, 65])
def test_pixel_select_overlay(self): cnvs = miccanvas.DblMicroscopeCanvas(self.panel) tab_mod = self.create_simple_tab_model() view = tab_mod.focussedView.value self.add_control(cnvs, wx.EXPAND, proportion=1, clear=True) # FIXME: when setView is called *before* the add_control, the picture goes black and no # pixels are visible cnvs.setView(view, tab_mod) cnvs.current_mode = TOOL_POINT psol = wol.PixelSelectOverlay(cnvs) psol.activate() psol.enabled = True cnvs.add_world_overlay(psol) psol.set_data_properties(1e-05, (0.0, 0.0), (17, 19)) width_va = model.IntVA(1) psol.connect_selection(model.TupleVA(), width_va) view.mpp.value = 1e-06 psol._selected_pixel_va.value = (8, 8) test.gui_loop() # Tool toggle for debugging tol = vol.TextViewOverlay(cnvs) tol.add_label("Right click to toggle tool", (10, 30)) cnvs.add_view_overlay(tol) def toggle(evt): if psol.active: psol.deactivate() else: psol.activate() evt.Skip() cnvs.Bind(wx.EVT_RIGHT_UP, toggle) cnvs.disable_drag() def on_key(evt): k = evt.GetKeyCode() if k == wx.WXK_DOWN and width_va.value > 1: width_va.value -= 1 elif k == wx.WXK_UP: width_va.value += 1 else: pass cnvs.Bind(wx.EVT_KEY_UP, on_key)
def test_pretty_str(self): prop = model.IntVA(2) pretty_str = str(prop) self.assertIn("IntVA", pretty_str) self.assertIn(str(prop.value), pretty_str) prop = model.ListVA([2, 3], unit=u"µm") pretty_str = str(prop) self.assertIn("ListVA", pretty_str) self.assertIn(str(prop.value), pretty_str) prop = model.FloatContinuous(2.3, unit=u"µm", range=(1.0, 9)) pretty_str = str(prop) self.assertIn("FloatContinuous", pretty_str) self.assertIn(str(prop.value), pretty_str)
def test_notify_noinit(self): prop = model.IntVA(2) self.called = 0 prop.subscribe(self.callback_test_notify) # now count prop.value = 3 # +1 prop.value = 0 # +1 prop.value = 0 # nothing because same value try: prop.value = 7.5 self.fail("Assigning float to a int should not be allowed.") except TypeError: pass # as it should be prop.unsubscribe(self.callback_test_notify) self.assertTrue(prop.value == 0) self.assertTrue(self.called == 2)