def __init__(self, parent, dsviewer): wx.Panel.__init__(self, parent, -1) dirname = os.path.dirname(__file__) self.do = dsviewer.do self.dsviewer = dsviewer self.bmStartSeek = wx.Bitmap( resources.getIconPath('media-skip-backward.png')) self.bmPlay = wx.Bitmap( resources.getIconPath('media-playback-start.png')) self.bmPause = wx.Bitmap( resources.getIconPath('media-playback-pause.png')) self.mode = 'HORIZ' self.moving = False #timer for playback self.tPlay = mytimer() self.tPlay.WantNotification.append(self.OnFrame) self.do.WantChangeNotification.append(self.update) self.genContents(self.mode) self.Bind(wx.EVT_SIZE, self.OnSize)
def __init__(self, parent, options=None): AUIFrame.__init__(self, id=wx.ID_ANY, name='smiMainFrame', parent=parent, pos=wx.Point(20, 20), size=wx.Size(600, 800), style=wx.DEFAULT_FRAME_STYLE, title=getattr(options, 'window_title', 'PYME Acquire')) self._create_menu() self.options = options self.snapNum = 0 self.Bind(wx.EVT_CLOSE, self.OnCloseWindow) self.MainFrame = self #reference to this window for use in scripts etc... protocol.MainFrame = self self.toolPanels = [] self.camPanels = [] self.aqPanels = [] self.anPanels = [] self.postInit = [] self.initDone = False self.scope = microscope.microscope() self.splash = splashScreen.SplashScreen(self, self.scope) self.splash.Show() self.sh = wx.py.shell.Shell( id=-1, parent=self, size=wx.Size(-1, -1), style=0, locals=self.__dict__, introText= 'PYMEAcquire - note that help, license, etc. below is for Python, not PYME\n\n' ) self.AddPage(self.sh, caption='Shell') self.CreateToolPanel(getattr(options, 'gui_mode', 'default')) self.SetSize((1030, 895)) self.roi_on = False self.bin_on = False self.time1 = mytimer.mytimer() self.time1.Start(50) wx.CallAfter(self._initialize_hardware) #self.time1.WantNotification.append(self.runInitScript) self.time1.WantNotification.append(self.splash.Tick)
def __init__(self, dsviewer): self.dsviewer = dsviewer self.image = dsviewer.image self.view = dsviewer.view self.do = dsviewer.do if not _check_complete_mdh(self.image.mdh): logger.warning( 'Series does not seem to have metadata needed for localization analysis' ) self.analysisController = AnalysisController(self.image.mdh) self.analysisSettingsView = AnalysisSettingsView( self.dsviewer, self.analysisController, self) self._fitdefaults = FitDefaults(self.dsviewer, self.analysisController) self.analysisController.onImagesPushed.connect(self.OnImagesPushed) self.queueName = None if 'fitResults' in dir(self.image): self.fitResults = self.image.fitResults else: self.fitResults = [] if 'resultsMdh' in dir(self.image): self.resultsMdh = self.image.resultsMdh #a timer object to update for us self.timer = mytimer() self.timer.Start(5000) self.numAnalysed = 0 self.numEvents = 0 if self.image.filename.upper().startswith('PYME-CLUSTER:'): self.newStyleTaskDistribution = True else: self.newStyleTaskDistribution = NEW_STYLE_DISTRIBUTION dsviewer.pipeline = pipeline.Pipeline() self.ds = None dsviewer.paneHooks.append(self.GenFitStatusPanel) dsviewer.updateHooks.append(self.update) dsviewer.statusHooks.append(self.GetStatusText) if 'bgRange' in dir(self.image.data): self.dsviewer.AddMenuItem('View', "SubtractBackground", self.OnToggleBackground)
def __init__(self, image, parent=None, title='', mode='LM', size = (800,700), glCanvas=None): AUIFrame.__init__(self,parent, -1, title,size=size, pos=wx.DefaultPosition) self.mode = mode self.glCanvas = glCanvas self.updateHooks = [] self.statusHooks = [] self.installedModules = [] # will store weakrefs to things that modules previously injected into our namespace #self._module_injections = weakref.WeakValueDictionary() self.dataChangeHooks = [] self.updating = False if glCanvas: self.glCanvas.wantViewChangeNotification.add(self) self.timer = mytimer() self.timer.Start(10000) self.image = image #self.image = ImageStack(data = dstack, mdh = mdh, filename = filename, queueURI = queueURI, events = None) if not self.image.filename is None and title == '': self.SetTitle(self.image.filename) self.do = DisplayOpts(self.image.data) if self.image.data.shape[1] == 1: self.do.slice = self.do.SLICE_XZ self.do.Optimise() if self.image.mdh and 'ChannelNames' in self.image.mdh.getEntryNames(): chan_names = self.image.mdh.getEntry('ChannelNames') if len(chan_names) == self.image.data.shape[3]: self.do.names = chan_names #self.vp = ArraySettingsAndViewPanel(self, self.image.data, wantUpdates=[self.update], mdh=self.image.mdh) #self.view = ArrayViewPanel(self, do=self.do) #self.AddPage(self.view, True, 'Data') #self._mgr.AddPane(self.vp, aui.AuiPaneInfo(). # Name("Data").Caption("Data").Centre().CloseButton(False).CaptionVisible(False)) self.mainFrame = weakref.ref(self) #self.do = self.vp.do tmp_menu = wx.Menu() tmp_menu.Append(wx.ID_OPEN, '&Open', "", wx.ITEM_NORMAL) tmp_menu.Append(wx.ID_SAVE, "&Save As", "", wx.ITEM_NORMAL) tmp_menu.Append(wx.ID_SAVEAS, "&Export Cropped", "", wx.ITEM_NORMAL) #a submenu for modules to hook and install saving functions into self.save_menu = wx.Menu() self._menus['Save'] = self.save_menu tmp_menu.AppendMenu(-1, 'Save &Results', self.save_menu) #tmp_menu.AppendSeparator() #tmp_menu.Append(wx.ID_CLOSE, "Close", "", wx.ITEM_NORMAL) self.menubar.Append(tmp_menu, "File") self._menus['File'] = tmp_menu self.view_menu = wx.Menu() self.menubar.Append(self.view_menu, "&View") self._menus['View'] = self.view_menu #'extras' menu for modules to install stuff into self.mProcessing = wx.Menu() self.menubar.Append(self.mProcessing, "&Processing") self._menus['Processing'] = self.mProcessing # Menu Bar end self.Bind(wx.EVT_MENU, self.OnOpen, id=wx.ID_OPEN) self.Bind(wx.EVT_MENU, self.OnSave, id=wx.ID_SAVE) self.Bind(wx.EVT_MENU, self.OnExport, id=wx.ID_SAVEAS) #self.Bind(wx.EVT_MENU, lambda e: self.Close(), id=wx.ID_CLOSE) self.Bind(wx.EVT_CLOSE, self.OnCloseWindow) self.statusbar = self.CreateStatusBar(1, wx.STB_SIZEGRIP) self.panesToMinimise = [] modules.loadMode(self.mode, self) self.CreateModuleMenu() self.add_common_menu_items() self.optionspanel = OptionsPanel(self, self.do, thresholdControls=True) self.optionspanel.SetSize(self.optionspanel.GetBestSize()) pinfo = aui.AuiPaneInfo().Name("optionsPanel").Right().Caption('Display Settings').CloseButton(False).MinimizeButton(True).MinimizeMode(aui.AUI_MINIMIZE_CAPT_SMART|aui.AUI_MINIMIZE_POS_RIGHT)#.CaptionVisible(False) self._mgr.AddPane(self.optionspanel, pinfo) self.panesToMinimise.append(pinfo) self._mgr.AddPane(self.optionspanel.CreateToolBar(self), aui.AuiPaneInfo().Name("ViewTools").Caption("View Tools").CloseButton(False). ToolbarPane().Right().GripperTop()) if self.do.ds.shape[2] > 1: from PYME.DSView.modules import playback self.playbackpanel = playback.PlayPanel(self, self) self.playbackpanel.SetSize(self.playbackpanel.GetBestSize()) pinfo1 = aui.AuiPaneInfo().Name("playbackPanel").Bottom().Caption('Playback').CloseButton(False).MinimizeButton(True).MinimizeMode(aui.AUI_MINIMIZE_CAPT_SMART|aui.AUI_MINIMIZE_POS_RIGHT)#.CaptionVisible(False) self._mgr.AddPane(self.playbackpanel, pinfo1) self.do.WantChangeNotification.append(self.playbackpanel.update) #self.mWindows = wx.Menu() #self.menubar.append(self.mWindows, '&Composite With') self.do.WantChangeNotification.append(self.update) self.CreateFoldPanel() for pn in self.panesToMinimise: self._mgr.MinimizePane(pn) #self._mgr.MinimizePane(pinfo2) self.Layout() if 'view' in dir(self): sc = np.floor(np.log2(1.0*self.view.Size[0]/self.do.ds.shape[0])) #print self.view.Size[0], self.do.ds.shape[0], sc self.do.SetScale(sc) self.view.Refresh() self.update() self.drop = dt() self.SetDropTarget(self.drop) self.AddMenuItem('Save', 'To Cluster', self.OnSaveToCluster) openViewers[self.image.filename] = self
def OnDeconvICTM(self, event, beadMode=False): from PYME.Deconv.deconvDialogs import DeconvSettingsDialog, DeconvProgressPanel dlg = DeconvSettingsDialog(self.dsviewer, beadMode, self.image.data.shape[3]) if dlg.ShowModal() == wx.ID_OK: from PYME.Deconv import dec, decThread, richardsonLucy nIter = dlg.GetNumIterationss() regLambda = dlg.GetRegularisationLambda() decMDH = MetaDataHandler.NestedClassMDHandler(self.image.mdh) decMDH['Deconvolution.NumIterations'] = nIter decMDH['Deconvolution.OriginalFile'] = self.image.filename vx, vy, vz = self.image.voxelsize_nm if beadMode: from PYME.Deconv import beadGen psf = beadGen.genBeadImage(dlg.GetBeadRadius(), (vx, vy, vz)) decMDH['Deconvolution.BeadRadius'] = dlg.GetBeadRadius() else: psfFilename, psf, vs = dlg.GetPSF(vshint=vx) if psf.shape[2] < 2: raise RuntimeError( 'Expepected a 3D PSF for 3D deconvolution. For 2D deconvolution use the DeconvMovie function' ) decMDH['Deconvolution.PSFFile'] = dlg.GetPSFFilename() if not (vs.x == vx and vs.y == vy and vs.z == vz): #rescale psf to match data voxel size psf = ndimage.zoom(psf, [vs.x / vx, vs.y / vy, vs.z / vz]) #crop PSF in z if bigger than stack if psf.shape[2] > self.image.data.shape[2]: dz = psf.shape[2] - self.image.data.shape[2] psf = psf[:, :, int(numpy.floor(dz / 2)):int(psf.shape[2] - numpy.ceil(dz / 2))] decMDH['Deconvolution.Offset'] = dlg.GetOffset() bg = dlg.GetBackground() decMDH['Deconvolution.Background'] = bg if beadMode and self.image.data.shape[3] > 1: #special case for deconvolving multi-channel PSFs data = np.concatenate([ self.image.data[:, :, :, i].astype('f') - dlg.GetOffset() for i in range(self.image.data.shape[3]) ], 0) else: data = self.image.data[:, :, :, dlg.GetChannel()].astype( 'f') - dlg.GetOffset() if dlg.GetPadding(): padsize = numpy.array(dlg.GetPadSize()) decMDH['Deconvolution.Padding'] = padsize dp = numpy.ones(numpy.array(data.shape) + 2 * padsize, 'f') * data.mean() weights = numpy.zeros_like(dp) px, py, pz = padsize dp[px:-px, py:-py, pz:-pz] = data weights[px:-px, py:-py, pz:-pz] = 1. weights = weights.ravel() else: dp = data weights = 1 if dlg.GetBlocking(): decMDH['Deconvolution.Method'] = 'Blocked ICTM' self.checkTQ() from PYME.Deconv import tq_block_dec bs = dlg.GetBlockSize() self.decT = tq_block_dec.blocking_deconv(self.tq, data, psf, self.image.seriesName, blocksize={ 'y': bs, 'x': bs, 'z': 256 }) self.decT.go() else: decMDH['Deconvolution.Method'] = dlg.GetMethod() if dlg.GetMethod() == 'ICTM': decMDH['Deconvolution.RegularisationParameter'] = regLambda if beadMode: self.dec = dec.dec_bead() else: self.dec = dec.dec_conv() else: if beadMode: self.dec = richardsonLucy.rlbead() else: self.dec = richardsonLucy.dec_conv() self.dec.psf_calc(psf, dp.shape) self.decT = decThread.decThread(self.dec, dp, regLambda, nIter, weights, bg=bg) self.decT.start() tries = 0 while not hasattr(self.dec, 'fs'): if tries > 60: self.decT.kill() raise RuntimeError( 'Initialization not complete after 60s, giving up.' ) time.sleep(1) tries += 1 if dlg.GetPadding() and dlg.GetRemovePadding(): fs = self.dec.fs[px:-px, py:-py, pz:-pz] else: fs = self.dec.fs if beadMode and self.image.data.shape[3] > 1: #special case for bead deconvolution - unwind the stacking nChans = self.image.data.shape[3] xs = int(fs.shape[0] / nChans) #NOTE: this relies on the slicing returning a view into the underlying data, not a copy fs = [ fs[(i * xs):((i + 1) * xs), :, :] for i in range(nChans) ] im = ImageStack(data=fs, mdh=decMDH, titleStub='Deconvolution Result') mode = 'lite' if beadMode and im.data.shape[1] < 100: mode = 'psf' im.defaultExt = '*.psf' #we want to save as PSF by default self.res = ViewIm3D(im, mode=mode, parent=wx.GetTopLevelParent(self.dsviewer)) #self.res = View3D(fs, 'Deconvolution Result', mdh=decMDH, parent=wx.GetTopLevelParent(self.dsviewer), mode=mode) self.dlgDeconProg = DeconvProgressPanel(self.res, nIter) self.pinfo1 = aui.AuiPaneInfo().Name("deconvPanel").Top( ).Caption('Deconvolution Progress').DestroyOnClose( True ).CloseButton( False ) #.MinimizeButton(True).MinimizeMode(aui.AUI_MINIMIZE_CAPT_SMART|aui.AUI_MINIMIZE_POS_RIGHT)#.CaptionVisible(False) self.res._mgr.AddPane(self.dlgDeconProg, self.pinfo1) self.res._mgr.Update() self.deconTimer = mytimer() self.deconTimer.WantNotification.append(self.OnDeconTimer) self.deconTimer.Start(500)
def __init__(self, parent, sourceImage, destImage): from PYME.Deconv import wiener wx.Panel.__init__(self, parent) self.dw = wiener.dec_wiener() self.sourceImage = sourceImage self.destImage = destImage self.havePSF = False self.decT = None #GUI stuff sizer2 = wx.BoxSizer(wx.VERTICAL) sizer3 = wx.BoxSizer(wx.HORIZONTAL) sizer3.Add(wx.StaticText(self, -1, 'PSF:'), 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5) self.fpPSF = wx.FilePickerCtrl(self, -1, wildcard='*.psf|*.tif', style=wx.FLP_OPEN | wx.FLP_FILE_MUST_EXIST) self.fpPSF.Bind(wx.EVT_FILEPICKER_CHANGED, self.OnPSFFileChanged) sizer3.Add(self.fpPSF, 1, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5) sizer2.Add(sizer3, 0, wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 0) sizer3 = wx.BoxSizer(wx.HORIZONTAL) sizer3.Add(wx.StaticText(self, -1, 'Offset:'), 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5) self.tOffset = wx.TextCtrl(self, -1, '0') sizer3.Add(self.tOffset, 1, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5) sizer2.Add(sizer3, 0, wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 0) sizer3 = wx.BoxSizer(wx.HORIZONTAL) sizer3.Add(wx.StaticText(self, -1, u'Regularisation \u03BB:'), 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5) self.tRegLambda = wx.TextCtrl(self, -1, '1e-8') sizer3.Add(self.tRegLambda, 1, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5) sizer2.Add(sizer3, 0, wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 0) sizer3 = wx.BoxSizer(wx.HORIZONTAL) sizer3.AddSpacer(10) self.bCalculate = wx.Button(self, -1, 'Apply') self.bCalculate.Bind(wx.EVT_BUTTON, self.OnCalculate) self.bCalculate.Enable(False) sizer3.Add(self.bCalculate, 1, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5) sizer2.Add(sizer3, 0, wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 0) self.SetSizerAndFit(sizer2) self.deconTimer = mytimer() self.deconTimer.WantNotification.append(self.OnDeconTimer) self.deconTimer.Start(500)