class Dialog(wx.Dialog):
	def __init__(self, parent, title, target=None, targetname='Relative target'):
		wx.Dialog.__init__(self, parent, -1, title)
		sbsztarget = wx.StaticBoxSizer(wx.StaticBox(self, -1, 'Target'),
																		wx.VERTICAL)

		self.targetname = targetname
		self.iex = IntEntry(self, -1, chars=4)
		self.iey = IntEntry(self, -1, chars=4)

		if target is not None:
			if not parent.validate(target):
				raise ValueError
			x, y = target
			self.iex.SetValue(x)
			self.iey.SetValue(y)

		sztarget = wx.GridBagSizer(5, 5)
		label = wx.StaticText(self, -1, 'x')
		sztarget.Add(label, (0, 1), (1, 1), wx.ALIGN_CENTER)
		label = wx.StaticText(self, -1, 'y')
		sztarget.Add(label, (0, 2), (1, 1), wx.ALIGN_CENTER)
		label = wx.StaticText(self, -1, self.targetname)
		sztarget.Add(label, (1, 0), (1, 1), wx.ALIGN_CENTER_VERTICAL)
		sztarget.Add(self.iex, (1, 1), (1, 1), wx.ALIGN_CENTER|wx.FIXED_MINSIZE)
		sztarget.Add(self.iey, (1, 2), (1, 1), wx.ALIGN_CENTER|wx.FIXED_MINSIZE)
		label = wx.StaticText(self, -1, 'pixels')
		sztarget.Add(label, (1, 3), (1, 1), wx.ALIGN_CENTER_VERTICAL)

		sbsztarget.Add(sztarget, 1, wx.EXPAND|wx.ALL, 5)

		self.bok = wx.Button(self, wx.ID_OK, 'OK')
		self.bcancel = wx.Button(self, wx.ID_CANCEL, 'Cancel')

		szbutton = wx.GridBagSizer(5, 5)
		szbutton.Add(self.bok, (0, 0), (1, 1),
									wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
		szbutton.Add(self.bcancel, (0, 1), (1, 1), wx.ALIGN_CENTER)
		szbutton.AddGrowableCol(0)

		sz = wx.GridBagSizer(5, 5)
		sz.Add(sbsztarget, (0, 0), (1, 1), wx.EXPAND|wx.ALL, 10)
		sz.Add(szbutton, (1, 0), (1, 1), wx.EXPAND|wx.ALL, 10)

		self.SetSizerAndFit(sz)

		self.Bind(wx.EVT_BUTTON, self.onOK, self.bok)

	def onOK(self, evt):
		target = (self.iex.GetValue(), self.iey.GetValue())
		if not self.GetParent().validate(target):
			dialog = wx.MessageDialog(self, 'Invalid target dimensions', 'Error',
																wx.OK|wx.ICON_ERROR)
			dialog.ShowModal()
			dialog.Destroy()
		else:
			self.target = target
			evt.Skip()
Beispiel #2
0
class Dialog(wx.Dialog):
    def __init__(self, parent, title, ring=None):
        wx.Dialog.__init__(self, parent, -1, title)
        sbszring = wx.StaticBoxSizer(wx.StaticBox(self, -1, 'Ring'),
                                     wx.VERTICAL)

        self.ieinside = IntEntry(self, -1, min=0, chars=4)
        self.ieoutside = IntEntry(self, -1, min=0, chars=4)

        if ring is not None:
            if not parent.validate(ring):
                raise ValueError
            inside, outside = ring
            self.ieinside.SetValue(inside)
            self.ieoutside.SetValue(outside)

        szring = wx.GridBagSizer(5, 5)
        label = wx.StaticText(self, -1, 'Inside')
        szring.Add(label, (0, 1), (1, 1), wx.ALIGN_CENTER)
        label = wx.StaticText(self, -1, 'Outside')
        szring.Add(label, (0, 2), (1, 1), wx.ALIGN_CENTER)
        label = wx.StaticText(self, -1, 'Diameter')
        szring.Add(label, (1, 0), (1, 1), wx.ALIGN_CENTER_VERTICAL)
        szring.Add(self.ieinside, (1, 1), (1, 1),
                   wx.ALIGN_CENTER | wx.FIXED_MINSIZE)
        szring.Add(self.ieoutside, (1, 2), (1, 1),
                   wx.ALIGN_CENTER | wx.FIXED_MINSIZE)
        label = wx.StaticText(self, -1, 'pixels')
        szring.Add(label, (1, 3), (1, 1), wx.ALIGN_CENTER_VERTICAL)
        sbszring.Add(szring, 1, wx.EXPAND | wx.ALL, 5)

        self.bok = wx.Button(self, wx.ID_OK, 'OK')
        self.bcancel = wx.Button(self, wx.ID_CANCEL, 'Cancel')

        szbutton = wx.GridBagSizer(5, 5)
        szbutton.Add(self.bok, (0, 0), (1, 1),
                     wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
        szbutton.Add(self.bcancel, (0, 1), (1, 1), wx.ALIGN_CENTER)
        szbutton.AddGrowableCol(0)

        sz = wx.GridBagSizer(5, 5)
        sz.Add(sbszring, (0, 0), (1, 1), wx.EXPAND | wx.ALL, 10)
        sz.Add(szbutton, (1, 0), (1, 1), wx.EXPAND | wx.ALL, 10)

        self.SetSizerAndFit(sz)

        self.Bind(wx.EVT_BUTTON, self.onOK, self.bok)

    def onOK(self, evt):
        ring = (self.ieinside.GetValue(), self.ieoutside.GetValue())
        if not self.GetParent().validate(ring):
            dialog = wx.MessageDialog(self, 'Invalid ring dimensions', 'Error',
                                      wx.OK | wx.ICON_ERROR)
            dialog.ShowModal()
            dialog.Destroy()
        else:
            self.ring = ring
            evt.Skip()
class ReproTestDialog(wx.Dialog):
    def __init__(self, parent):
        self.node = parent.node

        wx.Dialog.__init__(self, parent, -1, 'Test Reproducibiltiy')

        self.measure = wx.Button(self, -1, 'Run')
        self.Bind(wx.EVT_BUTTON, self.onMeasureButton, self.measure)

        szbutton = wx.GridBagSizer(5, 5)
        szbutton.Add(self.measure, (0, 0), (1, 1), wx.EXPAND)

        sbsz = wx.GridBagSizer(5, 5)

        label = wx.StaticText(self, -1, 'Label:')
        self.labvalue = Entry(self, -1, chars=20, value='test1')
        sbsz.Add(label, (0, 0), (1, 1))
        sbsz.Add(self.labvalue, (0, 1), (1, 1))

        label = wx.StaticText(self, -1, 'Moves:')
        self.movesvalue = IntEntry(self,
                                   -1,
                                   allownone=False,
                                   chars=5,
                                   value='10')
        sbsz.Add(label, (1, 0), (1, 1))
        sbsz.Add(self.movesvalue, (1, 1), (1, 1))

        label = wx.StaticText(self, -1, 'Distance:')
        self.distvalue = FloatEntry(self,
                                    -1,
                                    allownone=False,
                                    chars=5,
                                    value='1e-5')
        sbsz.Add(label, (2, 0), (1, 1))
        sbsz.Add(self.distvalue, (2, 1), (1, 1))

        label = wx.StaticText(self, -1, 'Angle:')
        self.angvalue = FloatEntry(self, -1, allownone=True, chars=5, value='')
        sbsz.Add(label, (3, 0), (1, 1))
        sbsz.Add(self.angvalue, (3, 1), (1, 1))

        self.sizer = wx.GridBagSizer(5, 5)
        self.sizer.Add(sbsz, (0, 0), (1, 1), wx.EXPAND | wx.ALL, 10)
        self.sizer.Add(self.measure, (1, 0), (1, 1),
                       wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.ALL, 10)

        self.SetSizerAndFit(self.sizer)

    def onMeasureButton(self, evt):
        self.Close()
        label = self.labvalue.GetValue()
        moves = self.movesvalue.GetValue()
        distance = self.distvalue.GetValue()
        angle = self.angvalue.GetValue()
        threading.Thread(target=self.node.move_away_move_back,
                         args=(label, moves, distance, angle)).start()
class C2SizeDialog(leginon.gui.wx.Dialog.Dialog):
	def __init__(self, parent, title):
		self.node = parent.node
		leginon.gui.wx.Dialog.Dialog.__init__(self, parent, title, style=wx.DEFAULT_DIALOG_STYLE)

	def onInitialize(self):
		c2sizer = wx.GridBagSizer(5, 5)
		label = wx.StaticText(self, -1, 'C2 size: ')
		c2sizer.Add(label, (0, 0), (1, 1), wx.ALIGN_LEFT)
		self.c2sizectrl = IntEntry(self, -1, chars=6)
		c2sizer.Add(self.c2sizectrl, (0, 1), (1, 1), wx.ALIGN_RIGHT)
		label = wx.StaticText(self, -1, 'um')
		c2sizer.Add(label, (0, 2), (1, 1), wx.ALIGN_LEFT)

		self.sz.Add(c2sizer, (0, 0), (1, 1), wx.EXPAND|wx.ALL,10)
		savebtn = wx.Button(self, -1, 'Save')
		self.sz.Add(savebtn, (1, 0), (1, 1), wx.EXPAND|wx.ALL,5)
		self.sz.AddGrowableCol(0)

		self.Bind(wx.EVT_BUTTON, self.onSave, savebtn)

	def onSave(self,evt):
		args = (self.c2sizectrl.GetValue(),)
		threading.Thread(target=self.node.uiSetC2Size,args=args).start()
Beispiel #5
0
class CustomDialog(wx.Dialog):
    def __init__(self, parent, geometry):
        wx.Dialog.__init__(self, parent, -1, 'Custom')
        sb = wx.StaticBox(self, -1, 'Camera Configuration')
        self.sbsz = wx.StaticBoxSizer(sb, wx.VERTICAL)

        stx = wx.StaticText(self, -1, 'x')
        sty = wx.StaticText(self, -1, 'y')
        stdimension = wx.StaticText(self, -1, 'Dimension:')
        self.iexdimension = IntEntry(self,
                                     -1,
                                     min=1,
                                     max=parent.size['x'],
                                     chars=len(str(parent.size['x'])))
        self.ieydimension = IntEntry(self,
                                     -1,
                                     min=1,
                                     max=parent.size['y'],
                                     chars=len(str(parent.size['y'])))
        stbinning = wx.StaticText(self, -1, 'Binning:')
        self.cxbinning = wx.Choice(self,
                                   -1,
                                   choices=map(str, parent.binnings['x']))
        self.cybinning = wx.Choice(self,
                                   -1,
                                   choices=map(str, parent.binnings['y']))
        stoffset = wx.StaticText(self, -1, 'Offset:')
        self.iexoffset = IntEntry(self,
                                  -1,
                                  min=0,
                                  max=parent.size['x'],
                                  chars=len(str(parent.size['x'])))
        self.ieyoffset = IntEntry(self,
                                  -1,
                                  min=0,
                                  max=parent.size['y'],
                                  chars=len(str(parent.size['y'])))
        self.szxy = wx.GridBagSizer(5, 5)
        self.szxy.Add(stx, (0, 1), (1, 1), wx.ALIGN_CENTER)
        self.szxy.Add(sty, (0, 2), (1, 1), wx.ALIGN_CENTER)
        self.szxy.Add(stdimension, (1, 0), (1, 1), wx.ALIGN_CENTER_VERTICAL)
        self.szxy.Add(self.iexdimension, (1, 1), (1, 1),
                      wx.ALIGN_CENTER_VERTICAL | wx.FIXED_MINSIZE | wx.ALL)
        self.szxy.Add(self.ieydimension, (1, 2), (1, 1),
                      wx.ALIGN_CENTER_VERTICAL | wx.FIXED_MINSIZE | wx.ALL)
        self.szxy.Add(stbinning, (2, 0), (1, 1), wx.ALIGN_CENTER_VERTICAL)
        self.szxy.Add(self.cxbinning, (2, 1), (1, 1), wx.ALIGN_CENTER | wx.ALL)
        self.szxy.Add(self.cybinning, (2, 2), (1, 1), wx.ALIGN_CENTER | wx.ALL)
        self.szxy.Add(stoffset, (3, 0), (1, 1), wx.ALIGN_CENTER_VERTICAL)
        self.szxy.Add(self.iexoffset, (3, 1), (1, 1),
                      wx.ALIGN_CENTER_VERTICAL | wx.FIXED_MINSIZE | wx.ALL)
        self.szxy.Add(self.ieyoffset, (3, 2), (1, 1),
                      wx.ALIGN_CENTER_VERTICAL | wx.FIXED_MINSIZE | wx.ALL)

        bok = wx.Button(self, wx.ID_OK, 'OK')
        bcancel = wx.Button(self, wx.ID_CANCEL, 'Cancel')
        szbutton = wx.GridBagSizer(5, 5)
        szbutton.Add(bok, (0, 0), (1, 1), wx.ALIGN_CENTER)
        szbutton.Add(bcancel, (0, 1), (1, 1), wx.ALIGN_CENTER)

        self.sbsz.Add(self.szxy, 0, wx.ALIGN_CENTER)

        sz = wx.GridBagSizer(5, 5)
        sz.Add(self.sbsz, (0, 0), (1, 1), wx.ALIGN_CENTER | wx.ALL, border=5)
        sz.Add(szbutton, (1, 0), (1, 1), wx.ALIGN_RIGHT | wx.ALL, border=5)

        if geometry is not None:
            self.iexdimension.SetValue(int(geometry['dimension']['x']))
            self.ieydimension.SetValue(int(geometry['dimension']['y']))
            self.cxbinning.SetStringSelection(str(geometry['binning']['x']))
            self.cybinning.SetStringSelection(str(geometry['binning']['y']))
            self.iexoffset.SetValue(int(geometry['offset']['x']))
            self.ieyoffset.SetValue(int(geometry['offset']['y']))

        self.SetSizerAndFit(sz)

        self.Bind(wx.EVT_BUTTON, self.onOK, bok)

    def getGeometry(self):
        geometry = {'dimension': {}, 'binning': {}, 'offset': {}}
        geometry['dimension']['x'] = self.iexdimension.GetValue()
        geometry['dimension']['y'] = self.ieydimension.GetValue()
        geometry['binning']['x'] = int(self.cxbinning.GetStringSelection())
        geometry['binning']['y'] = int(self.cybinning.GetStringSelection())
        geometry['offset']['x'] = self.iexoffset.GetValue()
        geometry['offset']['y'] = self.ieyoffset.GetValue()
        return geometry

    def onOK(self, evt):
        geometry = self.getGeometry()
        if geometry is not None and self.GetParent().validateGeometry(
                geometry):
            evt.Skip()
        else:
            dialog = wx.MessageDialog(self, 'Invalid camera geometry', 'Error',
                                      wx.OK | wx.ICON_ERROR)
            dialog.ShowModal()
            dialog.Destroy()
Beispiel #6
0
class CameraPanel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, -1)
        sb = wx.StaticBox(self, -1, 'Camera Configuration')
        self.sbsz = wx.StaticBoxSizer(sb, wx.VERTICAL)
        self.size = None
        self.binmethod = 'exact'
        self.geometry = None
        self.binnings = {'x': [1, 2, 3, 4, 6, 8], 'y': [1, 2, 3, 4, 6, 8]}
        self.defaultexptime = 1000.0
        self.defaultsaveframes = False
        self.defaultframetime = 200
        self.defaultalignframes = False
        self.defaultalignfilter = 'None'
        self.defaultuseframes = ''
        self.defaultreadoutdelay = 0
        self.common = {}
        self.setfuncs = {
            'exposure time': self._setExposureTime,
            'save frames': self._setSaveFrames,
            'frame time': self._setFrameTime,
            'align frames': self._setAlignFrames,
            'align filter': self._setAlignFilter,
            'use frames': self._setUseFrames,
            'readout delay': self._setReadoutDelay,
        }
        self.getfuncs = {
            'exposure time': self._getExposureTime,
            'save frames': self._getSaveFrames,
            'frame time': self._getFrameTime,
            'align frames': self._getAlignFrames,
            'align filter': self._getAlignFilter,
            'use frames': self._getUseFrames,
            'readout delay': self._getReadoutDelay,
        }

        # geometry
        self.ccommon = wx.Choice(self, -1, choices=['(None)'])
        self.ccommon.SetSelection(0)
        bcustom = wx.Button(self, -1, 'Custom...')

        std = wx.StaticText(self, -1, 'Dimension:')
        self.stdimension = wx.StaticText(self, -1, '')

        sto = wx.StaticText(self, -1, 'Offset:')
        self.stoffset = wx.StaticText(self, -1, '')

        stb = wx.StaticText(self, -1, 'Binning:')
        self.stbinning = wx.StaticText(self, -1, '')

        self.szmain = wx.GridBagSizer(3, 3)

        sz = wx.GridBagSizer(5, 5)
        sz.Add(self.ccommon, (0, 0), (1, 1),
               wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
        sz.Add(bcustom, (0, 1), (1, 1), wx.ALIGN_CENTER_VERTICAL)
        sz.AddGrowableRow(0)
        sz.AddGrowableCol(0)
        sz.AddGrowableCol(1)
        self.szmain.Add(sz, (0, 0), (1, 2), wx.EXPAND)

        self.szmain.Add(std, (1, 0), (1, 1), wx.ALIGN_CENTER_VERTICAL)
        self.szmain.Add(self.stdimension, (1, 1), (1, 1), wx.ALIGN_CENTER)

        self.szmain.Add(sto, (2, 0), (1, 1), wx.ALIGN_CENTER_VERTICAL)
        self.szmain.Add(self.stoffset, (2, 1), (1, 1), wx.ALIGN_CENTER)

        self.szmain.Add(stb, (3, 0), (1, 1), wx.ALIGN_CENTER_VERTICAL)
        self.szmain.Add(self.stbinning, (3, 1), (1, 1), wx.ALIGN_CENTER)

        # exposure time
        stet = wx.StaticText(self, -1, 'Exposure time:')
        self.feexposuretime = FloatEntry(self, -1, min=0.0, chars=7)
        stms = wx.StaticText(self, -1, 'ms')

        self.szmain.Add(stet, (4, 0), (1, 1), wx.ALIGN_CENTER_VERTICAL)
        sz = wx.GridBagSizer(0, 3)
        sz.Add(self.feexposuretime, (0, 0), (1, 1),
               wx.ALIGN_CENTER_VERTICAL | wx.FIXED_MINSIZE)
        sz.Add(stms, (0, 1), (1, 1), wx.ALIGN_CENTER_VERTICAL)
        self.szmain.Add(sz, (4, 1), (1, 2), wx.ALIGN_CENTER | wx.EXPAND)

        sb = wx.StaticBox(self, -1, 'Camera with Movie Mode')
        ddsb = wx.StaticBoxSizer(sb, wx.VERTICAL)
        ddsz = wx.GridBagSizer(5, 5)
        # save frames
        self.saveframes = wx.CheckBox(self, -1, 'Save frames')
        ddsz.Add(self.saveframes, (0, 0), (1, 2), wx.ALIGN_CENTER | wx.EXPAND)

        # frame time
        stet = wx.StaticText(self, -1, 'Exposure time per Frame:')
        self.frametime = FloatEntry(self, -1, min=0.01, chars=7)
        stms = wx.StaticText(self, -1, 'ms')

        ddsz.Add(stet, (1, 0), (1, 1), wx.ALIGN_CENTER_VERTICAL)
        ftsz = wx.GridBagSizer(0, 3)
        ftsz.Add(self.frametime, (0, 0), (1, 1),
                 wx.ALIGN_CENTER_VERTICAL | wx.FIXED_MINSIZE)
        ftsz.Add(stms, (0, 1), (1, 1), wx.ALIGN_CENTER_VERTICAL)
        ddsz.Add(ftsz, (1, 1), (1, 2), wx.ALIGN_CENTER | wx.EXPAND)
        # use raw frames
        label = wx.StaticText(self, -1, 'Frames to use:')
        self.useframes = Entry(self, -1)
        ddsz.Add(label, (2, 0), (1, 1), wx.ALIGN_CENTER_VERTICAL)
        ddsz.Add(self.useframes, (2, 1), (1, 1), wx.ALIGN_CENTER | wx.EXPAND)

        # readout delay
        strd = wx.StaticText(self, -1, 'Readout delay:')
        self.readoutdelay = IntEntry(self, -1, chars=7)
        stms = wx.StaticText(self, -1, 'ms')
        sz = wx.BoxSizer(wx.HORIZONTAL)
        sz.Add(strd)
        sz.Add(self.readoutdelay)
        sz.Add(stms)
        ddsz.Add(sz, (3, 0), (1, 2), wx.ALIGN_CENTER | wx.EXPAND)

        # align frames box
        sb = wx.StaticBox(self, -1, 'Frame-Aligning Camera Only')
        afsb = wx.StaticBoxSizer(sb, wx.VERTICAL)
        afsz = wx.GridBagSizer(3, 3)
        # align frames
        self.alignframes = wx.CheckBox(self, -1, 'Align frames')
        afsz.Add(self.alignframes, (0, 0), (1, 2), wx.ALIGN_CENTER | wx.EXPAND)

        # align frame filter
        label = wx.StaticText(self, -1, 'c-correlation filter:')
        self.alignfilter = wx.Choice(self, -1, choices=self.getAlignFilters())
        self.alignfilter.SetSelection(0)
        afsz.Add(label, (1, 0), (1, 1), wx.ALIGN_CENTER_VERTICAL)
        afsz.Add(self.alignfilter, (1, 1), (1, 1), wx.ALIGN_CENTER | wx.EXPAND)
        afsb.Add(afsz, 0, wx.EXPAND | wx.ALL, 2)

        ddsz.Add(afsb, (4, 0), (3, 2), wx.ALIGN_CENTER | wx.EXPAND)

        ddsb.Add(ddsz, 0, wx.EXPAND | wx.ALL, 2)
        self.szmain.Add(ddsb, (7, 0), (1, 3), wx.ALIGN_CENTER | wx.EXPAND)

        ddsz.AddGrowableCol(1)
        self.szmain.AddGrowableCol(1)
        self.szmain.AddGrowableCol(2)

        self.sbsz.Add(self.szmain, 0, wx.EXPAND | wx.ALL, 2)

        self.SetSizerAndFit(self.sbsz)

        self.Bind(wx.EVT_CHOICE, self.onCommonChoice, self.ccommon)
        self.Bind(wx.EVT_BUTTON, self.onCustomButton, bcustom)
        self.Bind(EVT_ENTRY, self.onExposureTime, self.feexposuretime)
        self.Bind(wx.EVT_CHECKBOX, self.onSaveFrames, self.saveframes)
        self.Bind(EVT_ENTRY, self.onFrameTime, self.frametime)
        self.Bind(EVT_ENTRY, self.onUseFrames, self.useframes)
        self.Bind(EVT_ENTRY, self.onReadoutDelay, self.readoutdelay)
        self.Bind(EVT_SET_CONFIGURATION, self.onSetConfiguration)

        #self.Enable(False)

    def setGeometryLimits(self, limitdict):
        if limitdict is None:
            self.setSize(None)
        if 'binnings' in limitdict.keys():
            self.binnings['x'] = limitdict['binnings']
            self.binnings['y'] = limitdict['binnings']
        if 'binmethod' in limitdict.keys():
            self.binmethod = limitdict['binmethod']
        if 'size' in limitdict.keys():
            self.setSize(limitdict['size'])
        else:
            self.setSize(None)

    def setSize(self, size):
        if size is None:
            self.size = None
            self.Freeze()
            self.choices, self.common = None, None
            self.ccommon.Clear()
            self.ccommon.Append('(None)')
            self.szmain.Layout()
            #self.Enable(False)
            self.Thaw()
        else:
            self.size = dict(size)
            self.Freeze()
            self.choices, self.common = self.getCenteredGeometries()
            self.ccommon.Clear()
            self.ccommon.AppendItems(self.choices)
            if self.geometry is None or not self.validateGeometry():
                self.ccommon.SetSelection(len(self.choices) - 1)
                self.setGeometry(
                    self.common[self.ccommon.GetStringSelection()])
            else:
                self.setCommonChoice()
            if self.feexposuretime.GetValue() is None:
                self.feexposuretime.SetValue(self.defaultexptime)
            #self.Enable(True)
            self.szmain.Layout()
            self.Thaw()

    def clear(self):
        if self.size is None:
            return
        self.Freeze()
        self.ccommon.SetSelection(len(self.choices) - 1)
        self.setGeometry(self.common[self.ccommon.GetStringSelection()])
        self.feexposuretime.SetValue(self.defaultexptime)
        self.saveframes.SetValue(self.defaultsaveframes)
        self.frametime.SetValue(self.defaultframetime)
        self.alignframes.SetValue(self.defaultalignframes)
        self.alignfilter.SetValue(self.defaultalignfilter)
        self.useframes.SetValue(self.defaultuseframes)
        self.readoutdelay.SetValue(self.defaultreadoutdelay)
        #self.Enable(False)
        self.Thaw()

    def onConfigurationChanged(self):
        evt = ConfigurationChangedEvent(self.getConfiguration(), self)
        self.GetEventHandler().AddPendingEvent(evt)

    def onExposureTime(self, evt):
        self.onConfigurationChanged()

    def onSaveFrames(self, evt):
        self.onConfigurationChanged()

    def onFrameTime(self, evt):
        self.onConfigurationChanged()

    def onUseFrames(self, evt):
        self.onConfigurationChanged()

    def onReadoutDelay(self, evt):
        self.onConfigurationChanged()

    def setCommonChoice(self):
        for key, geometry in self.common.items():
            flag = True
            for i in ['dimension', 'offset', 'binning']:
                if self.geometry[i] != geometry[i]:
                    flag = False
                    break
            if flag:
                self.ccommon.SetStringSelection(key)
                return
        if self.ccommon.FindString('(Custom)') is wx.NOT_FOUND:
            self.ccommon.Insert('(Custom)', 0)
            self.ccommon.SetSelection(0)

    def _getDimension(self):
        return self.geometry['dimension']

    def _setDimension(self, value):
        self.geometry['dimension'] = value
        self.setCommonChoice()

    def _getOffset(self):
        return self.geometry['offset']

    def _setOffset(self, value):
        self.geometry['offset'] = value
        self.setCommonChoice()

    def _getBinning(self):
        return self.geometry['binning']

    def _setBinning(self, value):
        self.geometry['binning'] = value
        self.setCommonChoice()

    def _getExposureTime(self):
        return self.feexposuretime.GetValue()

    def _setExposureTime(self, value):
        self.feexposuretime.SetValue(value)

    def _getSaveFrames(self):
        return self.saveframes.GetValue()

    def _setSaveFrames(self, value):
        value = bool(value)
        self.saveframes.SetValue(value)

    def _getFrameTime(self):
        return self.frametime.GetValue()

    def _setFrameTime(self, value):
        self.frametime.SetValue(value)

    def _getAlignFrames(self):
        return self.alignframes.GetValue()

    def _setAlignFrames(self, value):
        value = bool(value)
        self.alignframes.SetValue(value)

    def getAlignFilters(self):
        return [
            'None', 'Hanning Window (default)', 'Bandpass Filter (default)',
            'Sobel Filter (default)', 'Combined Filter (default)'
        ]

    def _getAlignFilter(self):
        return self.alignfilter.GetStringSelection()

    def _setAlignFilter(self, value):
        if value:
            value = str(value)
        else:
            value = 'None'
        self.alignfilter.SetStringSelection(value)

    def _getUseFrames(self):
        frames_str = self.useframes.GetValue()
        numbers = re.split('\D+', frames_str)
        numbers = filter(None, numbers)
        if numbers:
            numbers = map(int, numbers)
            numbers = tuple(numbers)
        else:
            numbers = ()
        return numbers

    def _setUseFrames(self, value):
        if value:
            value = str(value)
        else:
            value = ''
        self.useframes.SetValue(value)

    def _getReadoutDelay(self):
        return self.readoutdelay.GetValue()

    def _setReadoutDelay(self, value):
        return self.readoutdelay.SetValue(value)

    def onCommonChoice(self, evt):
        key = evt.GetString()
        if key == '(Custom)' or key.startswith('-'):
            return
        if self.setGeometry(self.common[key]):
            self.onConfigurationChanged()
        n = self.ccommon.FindString('(Custom)')
        if n is not wx.NOT_FOUND:
            self.ccommon.Delete(n)

    def onCustomButton(self, evt):
        dialog = CustomDialog(self, self.getGeometry())
        if dialog.ShowModal() == wx.ID_OK:
            if self.setGeometry(dialog.getGeometry()):
                self.onConfigurationChanged()
            self.setCommonChoice()
        dialog.Destroy()

    def getCenteredGeometry(self, dimension, binning):
        offset = {}
        for axis in ['x', 'y']:
            offset[axis] = int((self.size[axis] / binning - dimension) / 2)

        geometry = {
            'dimension': {
                'x': dimension,
                'y': dimension
            },
            'offset': {
                'x': offset['x'],
                'y': offset['y']
            },
            'binning': {
                'x': binning,
                'y': binning
            }
        }
        return geometry

    def getFullGeometry(self, binning):
        if self.binmethod == 'exact' and ((self.size['x'] % binning) or
                                          (self.size['y'] % binning)):
            return None
        dimx = self.size['x'] / binning
        dimy = self.size['y'] / binning
        geometry = {
            'dimension': {
                'x': dimx,
                'y': dimy
            },
            'offset': {
                'x': 0,
                'y': 0
            },
            'binning': {
                'x': binning,
                'y': binning
            }
        }
        return geometry

    def getCenteredGeometries(self):
        geometries = {}
        keys = []
        show_sections = False
        if self.size['x'] != self.size['y']:
            show_sections = True
            keys.append('--- Full ---')
            for binning in self.binnings['x']:
                dimx = self.size['x'] / binning
                dimy = self.size['y'] / binning
                key = '%d x %d bin %d' % (dimx, dimy, binning)
                geo = self.getFullGeometry(binning)
                if geo is not None:
                    geometries[key] = geo
                    keys.append(key)
        if self.binnings['x'] != self.binnings['y']:
            return geometries
        self.minsize = min(self.size['x'], self.size['y'])
        dimensions = [int(self.minsize / float(b)) for b in self.binnings['x']]

        def good(dim):
            return not bool(numpy.modf(dim)[1] - dim)

        def filtergood(input, mask):
            result = []
            for i, inval in enumerate(input):
                if mask[i]:
                    result.append(inval)
            return result

        if self.binmethod == 'exact':
            mask = [good(dim) for dim in dimensions]
        else:
            mask = [True for dim in dimensions]
        dimensions = filtergood(dimensions, mask)

        def minsize(size):
            return size >= self.minsize / max(self.binnings['x'])

        dimensions = filter(minsize, dimensions)
        dimensions = map((lambda x: primefactor.getAllEvenPrimes(x)[-1]),
                         dimensions)
        binnings = filtergood(self.binnings['x'], mask)
        dimensions.reverse()
        if show_sections:
            keys.append('--- Center ---')
        for d in dimensions:
            for b in self.binnings['x']:
                if d * b <= self.minsize:
                    key = '%d x %d bin %d' % (d, d, b)
                    geometries[key] = self.getCenteredGeometry(d, b)
                    keys.append(key)
                else:
                    break
        return keys, geometries

    def validateGeometry(self, geometry=None):
        if geometry is None:
            geometry = self.geometry
        for a in ['x', 'y']:
            try:
                if geometry['dimension'][a] < 1 or geometry['offset'][a] < 0:
                    return False
                if geometry['binning'][a] not in self.binnings[a]:
                    return False
                size = geometry['dimension'][a] + geometry['offset'][a]
                size *= geometry['binning'][a]
                if size > self.size[a]:
                    return False
            except:
                return False
        return True

    def cmpGeometry(self, geometry):
        if self.geometry == geometry:
            return True
        for g in ['dimension', 'offset', 'binning']:
            try:
                for a in ['x', 'y']:
                    if self.geometry[g][a] != geometry[g][a]:
                        return False
            except (KeyError, TypeError):
                return False
        return True

    def setGeometry(self, geometry):
        if self.cmpGeometry(geometry):
            return False

        if self.size is not None and not self.validateGeometry(geometry):
            raise ValueError

        self._setGeometry(geometry)

        return True

    def getGeometry(self):
        return self.geometry

    def getConfiguration(self):
        g = self.getGeometry()
        if g is None:
            return None
        c = copy.deepcopy(g)
        for key, func in self.getfuncs.items():
            c[key] = func()
        return c

    def _setGeometry(self, geometry):
        if self.geometry is None:
            self.geometry = {}
        else:
            self.geometry = copy.deepcopy(self.geometry)
        self.Freeze()
        for g in ['dimension', 'offset', 'binning']:
            if g not in self.geometry:
                self.geometry[g] = {}
            try:
                self.geometry[g].update(dict(geometry[g]))
                if g == 'offset':
                    label = '(%d, %d)'
                else:
                    #label = '%d × %d'
                    label = '%d x %d'
                label = label % (self.geometry[g]['x'], self.geometry[g]['y'])
                getattr(self, 'st' + g).SetLabel(label)
            except:
                pass
        self.szmain.Layout()
        self.Thaw()
        return True

    def _setConfiguration(self, value):
        for key, func in self.setfuncs.items():
            if key in value:
                func(value[key])
        self._setGeometry(value)
        self.setCommonChoice()

    def setConfiguration(self, value):
        for key, func in self.setfuncs.items():
            if key in value:
                func(value[key])
        self.setGeometry(value)
        if self.size is not None:
            self.setCommonChoice()
        #if not self.IsEnabled():
        #       self.Enable(True)

    def onSetConfiguration(self, evt):
        self.setConfiguration(evt.configuration)
Beispiel #7
0
class AutoFillTargets(wx.Dialog):
    def __init__(self, parent, title, targetname='Relative target'):
        wx.Dialog.__init__(self, parent, -1, title)

        self.targetname = targetname
        self.numtargets = IntEntry(self, -1, chars=4, value='1')
        self.radius = IntEntry(self, -1, chars=4, value='100')
        self.angleoffset = IntEntry(self, -1, chars=4, value='0')
        self.targets = []

        valueentry = wx.GridBagSizer(5, 5)
        label = wx.StaticText(self, -1, 'number of targets')
        valueentry.Add(label, (0, 0), (1, 1), wx.ALIGN_LEFT | wx.ALL, 3)
        valueentry.Add(self.numtargets, (0, 1), (1, 1),
                       wx.ALIGN_CENTER | wx.FIXED_MINSIZE | wx.ALL, 3)

        label = wx.StaticText(self, -1, 'radius (pixels)')
        valueentry.Add(label, (1, 0), (1, 1), wx.ALIGN_LEFT | wx.ALL, 3)
        valueentry.Add(self.radius, (1, 1), (1, 1),
                       wx.ALIGN_CENTER | wx.FIXED_MINSIZE | wx.ALL, 3)

        label = wx.StaticText(self, -1, 'angle offset (degrees)')
        valueentry.Add(label, (2, 0), (1, 1), wx.ALIGN_LEFT | wx.ALL, 3)
        valueentry.Add(self.angleoffset, (2, 1), (1, 1),
                       wx.ALIGN_CENTER | wx.FIXED_MINSIZE | wx.ALL, 3)

        self.bok = wx.Button(self, wx.ID_OK, 'OK')
        self.Bind(wx.EVT_BUTTON, self.onOK, self.bok)
        self.bcancel = wx.Button(self, wx.ID_CANCEL, 'Cancel')

        szbutton = wx.GridBagSizer(5, 5)
        szbutton.Add(self.bok, (0, 0), (1, 1),
                     wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
        szbutton.Add(self.bcancel, (0, 1), (1, 1), wx.ALIGN_CENTER)
        szbutton.AddGrowableCol(0)

        sz = wx.GridBagSizer(5, 5)
        sz.Add(valueentry, (0, 0), (1, 1), wx.EXPAND | wx.ALL, 10)
        sz.Add(szbutton, (1, 0), (1, 1), wx.EXPAND | wx.ALL, 10)

        self.SetSizerAndFit(sz)

    def onOK(self, evt):
        numtargets = float(self.numtargets.GetValue())
        if numtargets > 7:
            self.Close()
            dialog = wx.MessageDialog(
                self, "Too many targets:\n'%d' is greater than 7" % numtargets,
                'Error', wx.OK | wx.ICON_ERROR)
            dialog.ShowModal()
            dialog.Destroy()
            evt.Skip()
            return
        radius = float(self.radius.GetValue())
        degoffset = float(self.angleoffset.GetValue())
        deg = 0.0
        degincr = 360.0 / numtargets
        while (deg < 359.9):
            rad = (deg + degoffset) * math.pi / 180.0
            x = int(math.cos(rad) * radius)
            y = int(math.sin(rad) * radius)
            target = (x, y)
            if not self.GetParent().validate(target):
                dialog = wx.MessageDialog(
                    self, 'Invalid target dimensions (%d,%d)' % x, y, 'Error',
                    wx.OK | wx.ICON_ERROR)
                dialog.ShowModal()
                dialog.Destroy()
            self.targets.append(target)
            deg += degincr
        evt.Skip()
        return
Beispiel #8
0
class FitThetaDialog(wx.Dialog):
    #==================
    def __init__(self, parent):
        self.parent = parent
        self.theta = self.parent.data['theta']
        wx.Dialog.__init__(self, self.parent.frame, -1,
                           "Measure Tilt Angle, Theta")

        inforow = wx.FlexGridSizer(3, 3, 15, 15)
        thetastr = ("****** %3.3f ******" % self.theta)
        label = wx.StaticText(self,
                              -1,
                              "Current tilt angle: ",
                              style=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
        self.tiltvalue = wx.StaticText(self,
                                       -1,
                                       thetastr,
                                       style=wx.ALIGN_CENTER
                                       | wx.ALIGN_CENTER_VERTICAL)
        #self.tiltvalue = FloatEntry(self, -1, allownone=True, chars=5, value=thetastr)
        label3 = wx.StaticText(self,
                               -1,
                               "degrees",
                               style=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
        inforow.Add(label, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
        inforow.Add(
            self.tiltvalue, 0,
            wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 3)
        inforow.Add(label3, 0,
                    wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 3)

        arealimstr = str(int(self.parent.data['arealim']))
        label = wx.StaticText(self,
                              -1,
                              "Minimum Triangle Area: ",
                              style=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
        self.arealimit = IntEntry(self,
                                  -1,
                                  allownone=False,
                                  chars=8,
                                  value=arealimstr)
        label2 = wx.StaticText(self,
                               -1,
                               "square pixels",
                               style=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
        inforow.Add(label, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
        inforow.Add(
            self.arealimit, 0,
            wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 3)
        inforow.Add(label2, 0,
                    wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 3)

        label = wx.StaticText(self,
                              -1,
                              "Triangles Used: ",
                              style=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
        self.trilabel1 = wx.StaticText(self,
                                       -1,
                                       " ",
                                       style=wx.ALIGN_LEFT
                                       | wx.ALIGN_CENTER_VERTICAL)
        self.trilabel2 = wx.StaticText(self,
                                       -1,
                                       " ",
                                       style=wx.ALIGN_LEFT
                                       | wx.ALIGN_CENTER_VERTICAL)
        inforow.Add(label, 0,
                    wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 3)
        inforow.Add(self.trilabel1, 0,
                    wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 3)
        inforow.Add(self.trilabel2, 0,
                    wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 3)

        self.canceltiltang = wx.Button(self, wx.ID_CANCEL, '&Cancel')
        self.applytiltang = wx.Button(self, wx.ID_APPLY, '&Apply')
        self.runtiltang = wx.Button(self, -1, '&Run')
        self.Bind(wx.EVT_BUTTON, self.onRunTiltAng, self.runtiltang)
        self.Bind(wx.EVT_BUTTON, self.onApplyTiltAng, self.applytiltang)
        buttonrow = wx.GridSizer(1, 3)
        buttonrow.Add(self.canceltiltang, 0,
                      wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 0)
        buttonrow.Add(self.applytiltang, 0,
                      wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 0)
        buttonrow.Add(self.runtiltang, 0,
                      wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 0)

        self.sizer = wx.FlexGridSizer(2, 1)
        self.sizer.Add(inforow, 0, wx.EXPAND | wx.ALL, 10)
        self.sizer.Add(buttonrow, 0, wx.EXPAND | wx.ALL, 5)
        self.SetSizerAndFit(self.sizer)

    #==================
    def onRunTiltAng(self, evt):
        arealim = self.arealimit.GetValue()
        self.parent.data['arealim'] = arealim
        targets1 = self.parent.panel1.getTargets('Picked')
        a1 = self.parent.targetsToArray(targets1)
        targets2 = self.parent.panel2.getTargets('Picked')
        a2 = self.parent.targetsToArray(targets2)
        na1 = numpy.array(a1, dtype=numpy.int32)
        na2 = numpy.array(a2, dtype=numpy.int32)
        self.fittheta = radermacher.tiltang(na1, na2, arealim)
        #pprint.pprint(self.fittheta)
        if self.fittheta and 'wtheta' in self.fittheta:
            self.fittheta['point1'], self.fittheta['point2'] = \
                    apTiltTransform.getPointsFromArrays(a1, a2, self.parent.data['shiftx'], self.parent.data['shifty'])
            self.theta = self.fittheta['wtheta']
            self.thetadev = self.fittheta['wthetadev']
            thetastr = ("%3.3f +/- %2.2f" % (self.theta, self.thetadev))
            self.tiltvalue.SetLabel(label=thetastr)
            tristr = apDisplay.orderOfMag(
                self.fittheta['numtri']) + " of " + apDisplay.orderOfMag(
                    self.fittheta['tottri'])
            self.trilabel1.SetLabel(label=tristr)
            percent = str("%")
            tristr = (" (%3.1f " % (100.0 * self.fittheta['numtri'] /
                                    float(self.fittheta['tottri']))) + "%) "
            self.trilabel2.SetLabel(label=tristr)

    #==================
    def onApplyTiltAng(self, evt):
        self.Close()
        self.parent.data['theta'] = self.theta
        self.parent.data['tiltanglefitdata'] = self.fittheta
        self.parent.data['point1'] = self.fittheta['point1']
        self.parent.data['point2'] = self.fittheta['point2']
        self.parent.data['thetarun'] = True
        self.parent.onUpdate(evt)
Beispiel #9
0
class DogPickerDialog(wx.Dialog):
    #==================
    def __init__(self, parent):
        self.parent = parent
        wx.Dialog.__init__(self, self.parent.frame, -1,
                           "DoG Auto Particle Picker")

        inforow = wx.FlexGridSizer(3, 3, 10, 10)

        inforow.Add((1, 1), 0, 3)
        inforow.Add((1, 1), 0, 3)
        inforow.Add((1, 1), 0, 3)

        ### standard options
        box = wx.StaticBox(self, -1, 'Standard Options')
        boxrow = wx.StaticBoxSizer(box, wx.VERTICAL)

        hbox1 = wx.FlexGridSizer(1, 2, 10, 10)
        label = wx.StaticText(self,
                              -1,
                              "Particle diameter (pixels): ",
                              style=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
        self.diam = FloatEntry(self,
                               -1,
                               allownone=False,
                               chars=5,
                               value="100.0")
        hbox1.Add(label, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
        hbox1.Add(
            self.diam, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_HORIZONTAL
            | wx.ALIGN_CENTER_VERTICAL, 3)
        hbox1.AddGrowableCol(0)
        boxrow.Add(hbox1, 0, wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)

        boxrow.Add((3, 3), 0)

        hbox2 = wx.FlexGridSizer(1, 2, 10, 10)
        label = wx.StaticText(self,
                              -1,
                              "Min Threshold: ",
                              style=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
        self.minthresh = FloatEntry(self,
                                    -1,
                                    allownone=False,
                                    chars=5,
                                    value="0.7")
        hbox2.Add(label, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
        hbox2.Add(self.minthresh, 0,
                  wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 3)
        hbox2.AddGrowableCol(0)
        boxrow.Add(hbox2, 0, wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)

        boxrow.Add((3, 3), 0)

        label = wx.StaticText(self,
                              -1,
                              "Particle contrast: ",
                              style=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
        boxrow.Add(label, 0,
                   wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, 3)

        hbox8 = wx.FlexGridSizer(1, 2, 10, 10)
        self.whitePart = wx.RadioButton(self,
                                        -1,
                                        'Light on Dark (stain)', (10, 10),
                                        style=wx.RB_GROUP)
        self.blackPart = wx.RadioButton(self, -1, 'Dark on Light (ice)',
                                        (10, 30))
        self.Bind(wx.EVT_RADIOBUTTON,
                  self.partContrast,
                  id=self.whitePart.GetId())
        self.Bind(wx.EVT_RADIOBUTTON,
                  self.partContrast,
                  id=self.blackPart.GetId())
        self.partContrast(True)
        hbox8.Add(self.whitePart, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
        hbox8.Add(self.blackPart, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
        boxrow.Add(hbox8, 0, wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)

        boxrow.Add((3, 3), 0)

        inforow.Add((1, 1), 0, 3)
        inforow.Add(
            boxrow, 0,
            wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
            3)
        inforow.Add((1, 1), 0, 3)
        ### end standard options

        ### advanced options
        box = wx.StaticBox(self, -1, 'Advanded Options')
        boxrow = wx.StaticBoxSizer(box, wx.VERTICAL)

        hbox3 = wx.FlexGridSizer(1, 2, 10, 10)
        label = wx.StaticText(self,
                              -1,
                              "Diameter range (pixels): ",
                              style=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
        self.srange = FloatEntry(self,
                                 -1,
                                 allownone=False,
                                 chars=5,
                                 value="20.0")
        hbox3.Add(label, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
        hbox3.Add(self.srange, 0,
                  wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 3)
        hbox3.AddGrowableCol(0)
        boxrow.Add(hbox3, 0, wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)

        hbox4 = wx.FlexGridSizer(1, 2, 10, 10)
        label = wx.StaticText(self,
                              -1,
                              "Number of sizes: ",
                              style=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
        self.numslices = IntEntry(self,
                                  -1,
                                  allownone=False,
                                  chars=3,
                                  value="2")
        hbox4.Add(label, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
        hbox4.Add(self.numslices, 0,
                  wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 3)
        hbox4.AddGrowableCol(0)
        boxrow.Add(hbox4, 0, wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)

        hbox5 = wx.FlexGridSizer(1, 2, 10, 10)
        label = wx.StaticText(self,
                              -1,
                              "Max threshold: ",
                              style=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
        self.maxthresh = FloatEntry(self,
                                    -1,
                                    allownone=False,
                                    chars=5,
                                    value="1.5")
        hbox5.Add(label, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
        hbox5.Add(self.maxthresh, 0,
                  wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 3)
        hbox5.AddGrowableCol(0)
        boxrow.Add(hbox5, 0, wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)

        hbox6 = wx.FlexGridSizer(1, 2, 10, 10)
        label = wx.StaticText(self,
                              -1,
                              "Max peak area (% πr^2): ",
                              style=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
        self.peakarea = FloatEntry(self,
                                   -1,
                                   allownone=False,
                                   chars=5,
                                   value="0.3")
        hbox6.Add(label, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
        hbox6.Add(self.peakarea, 0,
                  wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 3)
        hbox6.AddGrowableCol(0)
        boxrow.Add(hbox6, 0, wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)

        hbox9 = wx.FlexGridSizer(1, 2, 10, 10)
        label = wx.StaticText(self,
                              -1,
                              "Max peaks: ",
                              style=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
        self.maxpeaks = IntEntry(self,
                                 -1,
                                 allownone=False,
                                 chars=5,
                                 value="500")
        hbox9.Add(label, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
        hbox9.Add(self.maxpeaks, 0,
                  wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 3)
        hbox9.AddGrowableCol(0)
        boxrow.Add(hbox9, 0, wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)

        boxrow.Add((3, 3), 0)

        inforow.Add((1, 1), 0, 3)
        inforow.Add(
            boxrow, 0,
            wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
            3)
        inforow.Add((1, 1), 0, 3)
        ### end advanced options

        self.canceldog = wx.Button(self, wx.ID_CANCEL, '&Cancel')
        self.rundog = wx.Button(self, wx.ID_OK, '&Run')
        self.Bind(wx.EVT_BUTTON, self.onRunDogPicker, self.rundog)
        buttonrow = wx.FlexGridSizer(1, 2, 10, 10)
        buttonrow.Add(self.canceldog, 0,
                      wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL,
                      10)
        buttonrow.Add(self.rundog, 0,
                      wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL,
                      10)

        self.sizer = wx.FlexGridSizer(3, 1, 10, 10)
        self.sizer.Add(inforow, 0, wx.ALIGN_CENTER_HORIZONTAL, border=10)
        self.sizer.Add(buttonrow, 0, wx.ALIGN_CENTER_HORIZONTAL, border=10)
        label = wx.StaticText(self,
                              -1,
                              "Check command line after running",
                              style=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
        self.sizer.Add(label, 0, wx.EXPAND, 5)

        self.SetSizerAndFit(self.sizer)

    #==================
    def partContrast(self, evt):
        if self.whitePart.GetValue() is True:
            return False
        return True

    #==================
    def onRunDogPicker(self, evt):
        apDisplay.printColor("===============\nRunning experimental DoGPicker",
                             "cyan")

        ### remove existing maps
        lefts = glob.glob("maps/leftimage.dogmap*.jpg")
        for imgname in lefts:
            apFile.removeFile(imgname, warn=False)
        rights = glob.glob("maps/rightimage.dogmap*.jpg")
        for imgname in rights:
            apFile.removeFile(imgname, warn=False)

        pixdiam = self.diam.GetValue()
        sizerange = self.srange.GetValue()
        minthresh = self.minthresh.GetValue()
        maxthresh = self.maxthresh.GetValue()
        peakarea = self.peakarea.GetValue()
        invert = self.partContrast(None)
        maxpeaks = self.maxpeaks.GetValue()
        numslices = self.numslices.GetValue()

        if invert is True:
            apDisplay.printMsg(
                "Picking dark particles on light backgound, i.e. ice")
        else:
            apDisplay.printMsg(
                "Picking light particles on dark backgound, i.e. stain")

        self.Close()

        apParam.createDirectory("maps")
        #1. set DoG parameters / hack to use existing pipeline function
        dogparams = {
            'apix': 1.0,  # set to 1 because we are using pixels
            'bin': 1.0,  # set to 1 because we are using pixels
            'diam': pixdiam,  # diameter of particles
            'sizerange': sizerange,  # diameter range of particles
            'numslices': numslices,  # number of slices to perform
            'kfactor': 1.2,  # does not matter
            'overlapmult': 1.5,
            'rundir': os.getcwd(),
            'maxpeaks': maxpeaks,
            'maxthresh': maxthresh,
            'thresh': minthresh,
            'maxsize': peakarea,
            'peaktype': 'maximum',
            'background': False,
            'doubles': False,
        }

        #2a. get image 1
        img1 = numpy.asarray(self.parent.panel1.imagedata, dtype=numpy.float32)
        if invert is True:
            img1 = apImage.invertImage(img1)

        #3a. run DoG picker on image 1
        dogarrays1 = apDog.diffOfGaussParam(img1, dogparams)

        #4a: threshold & find peaks image 1
        imgdict1 = {
            'filename': 'leftimage',
            'image': img1,
        }
        peaktree1 = apPeaks.findPeaks(imgdict1,
                                      dogarrays1,
                                      dogparams,
                                      maptype="dogmap",
                                      pikfile=False)

        #5a: insert into self.parent.picks1
        self.parent.picks1 = self.peaktreeToPicks(peaktree1)

        #===

        #2b: get image 2
        img2 = numpy.asarray(self.parent.panel2.imagedata, dtype=numpy.float32)
        if invert is True:
            img2 = apImage.invertImage(img2)

        #3b. run DoG picker on image 2
        dogarrays2 = apDog.diffOfGaussParam(img2, dogparams)

        #4b: threshold & find peaks image 2
        imgdict2 = {
            'filename': 'rightimage',
            'image': img2,
        }
        peaktree2 = apPeaks.findPeaks(imgdict2,
                                      dogarrays2,
                                      dogparams,
                                      maptype="dogmap",
                                      pikfile=False)

        #5b: insert into self.parent.picks2
        self.parent.picks2 = self.peaktreeToPicks(peaktree2)

        self.parent.onImportPicks(None, pixdiam, showmaps=True)
        apDisplay.printColor("Finished DoGPicker\n===================", "cyan")

    #==================
    def peaktreeToPicks(self, peaktree):
        picks = []
        for p in peaktree:
            picks.append((p['xcoord'], p['ycoord']))
        npicks = numpy.asarray(picks, dtype=numpy.float32)
        return npicks
Beispiel #10
0
class EditPlanDialog(wx.Dialog):
    def __init__(self, parent):
        wx.Dialog.__init__(self, parent.GetParent(), -1, 'Edit Plan')
        self.parent = parent
        self.plan = parent.plan

        strows = wx.StaticText(self, -1, 'Bad rows:')
        stcolumns = wx.StaticText(self, -1, 'Bad columns:')
        stpixels = wx.StaticText(self, -1, 'Bad Pixel (x,y):')

        pixels = ', '.join(map(str, self.plan['pixels']))
        rows = ', '.join(map(str, self.plan['rows']))
        columns = ', '.join(map(str, self.plan['columns']))

        self.tcrows = wx.TextCtrl(self, -1, rows)
        self.tccolumns = wx.TextCtrl(self, -1, columns)
        self.tcpixels = wx.TextCtrl(self, -1, pixels)

        self.cdespike = wx.CheckBox(self, -1, 'Despike images')
        self.cdespike_size = IntEntry(self, -1, min=1, chars=4)
        self.cdespike_threshold = FloatEntry(self, -1, min=0, chars=4)
        self.cdespike.SetValue(self.plan['despike'])
        self.cdespike_size.SetValue(self.plan['despike size'])
        self.cdespike_threshold.SetValue(self.plan['despike threshold'])

        szdespike = wx.GridBagSizer(5, 5)
        szdespike.Add(self.cdespike, (0, 0), (1, 2), wx.ALIGN_CENTER_VERTICAL)
        label = wx.StaticText(self, -1, 'Neighborhood size:')
        szdespike.Add(label, (1, 0), (1, 1), wx.ALIGN_CENTER_VERTICAL)
        szdespike.Add(
            self.cdespike_size, (1, 1), (1, 1),
            wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.FIXED_MINSIZE)
        label = wx.StaticText(self, -1, 'Threshold:')
        szdespike.Add(label, (2, 0), (1, 1), wx.ALIGN_CENTER_VERTICAL)
        szdespike.Add(
            self.cdespike_threshold, (2, 1), (1, 1),
            wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.FIXED_MINSIZE)
        szdespike.AddGrowableCol(1)

        bsave = wx.Button(self, wx.ID_OK, 'Save')
        bcancel = wx.Button(self, wx.ID_CANCEL, 'Cancel')
        szbutton = wx.GridBagSizer(5, 5)
        szbutton.Add(bsave, (0, 0), (1, 1), wx.ALIGN_CENTER)
        szbutton.Add(bcancel, (0, 1), (1, 1), wx.ALIGN_CENTER)

        szplan = wx.GridBagSizer(5, 5)
        szplan.Add(strows, (0, 0), (1, 1), wx.ALIGN_CENTER_VERTICAL)
        szplan.Add(self.tcrows, (0, 1), (1, 1), wx.ALIGN_CENTER_VERTICAL)
        szplan.Add(stcolumns, (1, 0), (1, 1), wx.ALIGN_CENTER_VERTICAL)
        szplan.Add(self.tccolumns, (1, 1), (1, 1), wx.ALIGN_CENTER_VERTICAL)
        szplan.Add(stpixels, (2, 0), (1, 1), wx.ALIGN_CENTER_VERTICAL)
        szplan.Add(self.tcpixels, (2, 1), (1, 1), wx.ALIGN_CENTER_VERTICAL)
        szplan.Add(szdespike, (3, 0), (1, 2), wx.EXPAND)

        sz = wx.GridBagSizer(5, 5)
        sz.Add(szplan, (0, 0), (1, 1), wx.ALIGN_RIGHT | wx.ALL, border=5)
        sz.Add(szbutton, (1, 0), (1, 1), wx.ALIGN_RIGHT | wx.ALL, border=5)

        self.SetSizerAndFit(sz)

        self.Bind(wx.EVT_BUTTON, self.onSave, bsave)

    def onSave(self, evt):
        try:
            rows = str2plan(self.tcrows.GetValue())
            columns = str2plan(self.tccolumns.GetValue())
            pixels = str2pixels(self.tcpixels.GetValue())
        except ValueError:
            dialog = wx.MessageDialog(self, 'Invalid plan', 'Error',
                                      wx.OK | wx.ICON_ERROR)
            dialog.ShowModal()
            dialog.Destroy()
        else:
            self.plan = {
                'rows': rows,
                'columns': columns,
                'pixels': pixels,
                'despike': self.cdespike.GetValue(),
                'despike size': self.cdespike_size.GetValue(),
                'despike threshold': self.cdespike_threshold.GetValue()
            }
            evt.Skip()
Beispiel #11
0
class PixelToPixelDialog(leginon.gui.wx.Dialog.Dialog):
    def __init__(self, parent, title):
        self.node = parent.node
        leginon.gui.wx.Dialog.Dialog.__init__(self,
                                              parent,
                                              title,
                                              style=wx.DEFAULT_DIALOG_STYLE)

    def onInitialize(self):
        mag1lab = wx.StaticText(self, -1, 'Mag 1:')
        self.mag1 = IntEntry(self, -1, chars=8)
        mag2lab = wx.StaticText(self, -1, 'Mag 2:')
        self.mag2 = IntEntry(self, -1, chars=8)
        p1lab = wx.StaticText(self, -1, 'Pixel 1:')
        self.p1row = FloatEntry(self, -1, chars=4)
        self.p1col = FloatEntry(self, -1, chars=4)
        p2lab = wx.StaticText(self, -1, 'Pixel 2:')
        self.p2row = FloatEntry(self, -1, chars=4)
        self.p2col = FloatEntry(self, -1, chars=4)

        angle1lab = wx.StaticText(self, -1, 'Angle 1')
        self.angle1 = wx.StaticText(self, -1, '')
        len1lab = wx.StaticText(self, -1, 'Length 1')
        self.len1 = wx.StaticText(self, -1, '')
        angle2lab = wx.StaticText(self, -1, 'Angle 2')
        self.angle2 = wx.StaticText(self, -1, '')
        len2lab = wx.StaticText(self, -1, 'Length 2')
        self.len2 = wx.StaticText(self, -1, '')

        calcp1 = wx.Button(self, -1, 'Calculate')
        self.Bind(wx.EVT_BUTTON, self.calcp1, calcp1)
        calcp2 = wx.Button(self, -1, 'Calculate')
        self.Bind(wx.EVT_BUTTON, self.calcp2, calcp2)

        self.sz.Add(mag1lab, (0, 0), (1, 1), wx.ALIGN_CENTER_VERTICAL)
        self.sz.Add(self.mag1, (0, 1), (1, 2), wx.ALIGN_CENTER_VERTICAL)
        self.sz.Add(mag2lab, (0, 3), (1, 1), wx.ALIGN_CENTER_VERTICAL)
        self.sz.Add(self.mag2, (0, 4), (1, 2), wx.ALIGN_CENTER_VERTICAL)
        self.sz.Add(p1lab, (1, 0), (1, 1), wx.ALIGN_CENTER_VERTICAL)
        self.sz.Add(self.p1row, (1, 1), (1, 1), wx.ALIGN_CENTER_VERTICAL)
        self.sz.Add(self.p1col, (1, 2), (1, 1), wx.ALIGN_CENTER_VERTICAL)
        self.sz.Add(p2lab, (1, 3), (1, 1), wx.ALIGN_CENTER_VERTICAL)
        self.sz.Add(self.p2row, (1, 4), (1, 1), wx.ALIGN_CENTER_VERTICAL)
        self.sz.Add(self.p2col, (1, 5), (1, 1), wx.ALIGN_CENTER_VERTICAL)

        self.sz.Add(angle1lab, (2, 0), (1, 1), wx.ALIGN_CENTER_VERTICAL)
        self.sz.Add(self.angle1, (2, 1), (1, 1), wx.ALIGN_CENTER_VERTICAL)
        self.sz.Add(angle2lab, (2, 3), (1, 1), wx.ALIGN_CENTER_VERTICAL)
        self.sz.Add(self.angle2, (2, 4), (1, 1), wx.ALIGN_CENTER_VERTICAL)
        self.sz.Add(len1lab, (3, 0), (1, 1), wx.ALIGN_CENTER_VERTICAL)
        self.sz.Add(self.len1, (3, 1), (1, 1), wx.ALIGN_CENTER_VERTICAL)
        self.sz.Add(len2lab, (3, 3), (1, 1), wx.ALIGN_CENTER_VERTICAL)
        self.sz.Add(self.len2, (3, 4), (1, 1), wx.ALIGN_CENTER_VERTICAL)

        self.sz.Add(calcp1, (4, 0), (1, 3), wx.ALIGN_CENTER_VERTICAL)
        self.sz.Add(calcp2, (4, 3), (1, 3), wx.ALIGN_CENTER_VERTICAL)

    def calcp1(self, evt):
        p2row = self.p2row.GetValue()
        p2col = self.p2col.GetValue()
        mag1 = self.mag1.GetValue()
        mag2 = self.mag2.GetValue()
        p2 = p2row, p2col
        p1 = self.node.pixelToPixel(mag2, mag1, p2)
        self.p1row.SetValue(p1[0])
        self.p1col.SetValue(p1[1])
        a, n = self.angle_len(p1)
        self.angle1.SetLabel(str(a))
        self.len1.SetLabel(str(n))

    def calcp2(self, evt):
        p1row = self.p1row.GetValue()
        p1col = self.p1col.GetValue()
        mag1 = self.mag1.GetValue()
        mag2 = self.mag2.GetValue()
        p1 = p1row, p1col
        p2 = self.node.pixelToPixel(mag1, mag2, p1)
        self.p2row.SetValue(p2[0])
        self.p2col.SetValue(p2[1])
        a, n = self.angle_len(p2)
        self.angle2.SetLabel(str(a))
        self.len2.SetLabel(str(n))

    def angle_len(self, vect):
        angle = numpy.arctan2(*tuple(vect))
        angle = math.degrees(angle)
        len = numpy.hypot(*tuple(vect))
        return angle, len
class MeasureTiltAxisDialog(wx.Dialog):
        def __init__(self, parent):
                self.node = parent.node

                wx.Dialog.__init__(self, parent, -1, "Measure Stage Tilt Axis Location")
                sb = wx.StaticBox(self, -1, 'Tilt Axis Params')
                sbsz2 = wx.StaticBoxSizer(sb, wx.VERTICAL)

                sbsz = wx.GridBagSizer(3,6)

                row = int(0)
                label = wx.StaticText(self, -1, "Tilt angle: ", style=wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL)
                self.tiltvalue = FloatEntry(self, -1, allownone=False, chars=5, value='15.0')
                label2 = wx.StaticText(self, -1, " degrees", style=wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL)
                sbsz.Add(label, (row,0), (1,1), wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL)
                sbsz.Add(self.tiltvalue, (row,1), (1,1), wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL)
                sbsz.Add(label2, (row,2), (1,1), wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL)

                row += 1
                self.tilttwice = wx.CheckBox(self, -1, "Tilt both directions")
                sbsz.Add(self.tilttwice, (row,0), (1,3), wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL)

                row += 1
                label = wx.StaticText(self, -1, "Average ", style=wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL)
                label2 = wx.StaticText(self, -1, " tilts", style=wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL)
                self.numtilts = IntEntry(self, -1, allownone=False, chars=1, value='1')
                sbsz.Add(label, (row,0), (1,1), wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL)
                sbsz.Add(self.numtilts, (row,1), (1,1), wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL)
                sbsz.Add(label2, (row,2), (1,1), wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL)

                row += 1
                label = wx.StaticText(self, -1, "SNR cutoff: ", style=wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL)
                self.snrvalue = FloatEntry(self, -1, allownone=False, chars=5, value='10.0')
                label2 = wx.StaticText(self, -1, " levels")
                sbsz.Add(label, (row,0), (1,1), wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL)
                sbsz.Add(self.snrvalue, (row,1), (1,1), wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL)
                sbsz.Add(label2, (row,2), (1,1), wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL)

                row += 1
                label = wx.StaticText(self, -1, "Correlation: ", style=wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL)
                self.phasecorr = wx.RadioButton(self, -1, "Phase", style=wx.RB_GROUP|wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL)
                self.crosscorr = wx.RadioButton(self, -1, "Cross", style=wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL)
                sbsz.Add(label, (row,0), (1,1))
                sbsz.Add(self.phasecorr, (row,1), (1,1))
                sbsz.Add(self.crosscorr, (row,2), (1,1))

                row += 1
                self.medfilt = wx.CheckBox(self, -1, "Median filter phase correlation")
                self.medfilt.SetValue(True)
                sbsz.Add(self.medfilt, (row,0), (1,3), wx.EXPAND|wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL)

                self.measurecancel = wx.Button(self, wx.ID_CANCEL, 'Cancel')
                self.measureinit = wx.Button(self,  -1, 'Initial\nOffset')
                self.Bind(wx.EVT_BUTTON, self.onMeasureButtonInit, self.measureinit)
                self.measureupdate = wx.Button(self,  -1, 'Update\nOffset')
                self.Bind(wx.EVT_BUTTON, self.onMeasureButtonUpdate, self.measureupdate)

                sbsz2.Add(sbsz, 0, wx.EXPAND|wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 1)

                buttonrow = wx.GridSizer(1,3)
                self.measurecancel.SetMinSize((85, 46))
                self.measureinit.SetMinSize((85, 46))
                self.measureupdate.SetMinSize((85, 46))
                buttonrow.Add(self.measurecancel, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 0)
                buttonrow.Add(self.measureinit, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
                buttonrow.Add(self.measureupdate, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)

                self.sizer = wx.FlexGridSizer(3,1)
                sbsz2.SetMinSize((270, 200))
                self.sizer.Add(sbsz2, 0, wx.EXPAND|wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 3)
                #self.sizer.Add((10, 10), 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE|wx.ALL, 3)
                self.sizer.Add(buttonrow, 0, wx.EXPAND|wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE|wx.ALL, 3)

                self.SetSizerAndFit(self.sizer)

        def onMeasureButtonInit(self, evt):
                self.node.logger.info('Obtain new beam tilt axis')
                self.onMeasure(evt, update=False)

        def onMeasureButtonUpdate(self, evt):
                self.node.logger.info('Updating beam tilt axis')
                self.onMeasure(evt, update=True)

        def onMeasure(self, evt, update):
                self.Close()
                atilt = self.tiltvalue.GetValue()
                asnr  = self.snrvalue.GetValue()
                if asnr <= 0:
                        self.node.logger.error('SNR cannot be less than or equal to zero')
                        return
                amedfilt = self.medfilt.GetValue()
                anumtilts = self.numtilts.GetValue()
                if(self.crosscorr.GetValue() and not self.phasecorr.GetValue()):
                        acorr = 'cross'
                else:
                        acorr = 'phase'
                atilttwice = self.tilttwice.GetValue()
                #RUN THE Measurement
                threading.Thread(target=self.node.measureTiltAxis, args=(atilt, anumtilts, atilttwice, update, asnr, acorr, amedfilt)).start()