Пример #1
0
    def OnChooseTargetFiles(self, evt):
        """
        set reference files
        """
        confdic = C.readConfig()
        wildcard = confdic.get('lastwildcard', FILTER)

        ll = self.listTgt

        if os.name == 'posix':
            dlg = G.FileSelectorDialog(self, self.lastpath, wildcard=wildcard)
        else:
            dlg = wx.FileDialog(self, 'Choose %s files' % listtype, defaultDir=self.lastpath, style=wx.FD_MULTIPLE)
            
        if dlg.ShowModal() == wx.ID_OK:
            fns = dlg.GetPaths()

            if not fns:
                return
            if os.name == 'posix':
                wildcard = dlg.fnPat
            if isinstance(fns, basestring):
                fns = [fns]

            ll.addFiles(fns)
            
            self.lastpath = os.path.dirname(fns[0])
            C.saveConfig(lastwildcard=wildcard, lastpath=self.lastpath)

            self.checkGo()
Пример #2
0
    def OnGo(self, ev=None):
        """
        run or cancel the alignment program

        The actual sequence of processes is written in threads.ThreadWithExc.run()
        """
        if self.goButton.GetValue():
            if not self.listRef.columnkeys:
                return


            fns = [os.path.join(*self.listRef.getFile(index)[:2]) for index in self.listRef.columnkeys]
            targets = [os.path.join(*self.listTgt.getFile(index)[:2]) for index in self.listTgt.columnkeys]

            # run program
            parms = [self.flat_suffix_txt.GetValue(),
                     self.flatimg_suffix_txt.GetValue(),
                     self.outextch.GetStringSelection()]

            gui = threads.GUImanager(self, __name__)
            
            self.th = threads.ThreadFlat(gui, None, fns, targets, parms)#, extrainfo)
            self.th.start()

            C.saveConfig(flat_suffix_txt=parms[0], flatimg_suffix_txt=parms[1], flatfn=fns[0], flat_format=parms[2])
            
        else:
            tid = self.th._get_my_tid()
            #stopit.async_raise(tid, threads.MyError)
            threads.async_raise(tid, threads.MyError)
Пример #3
0
    def OnChooseReferenceFile(self, evt):
        """
        set reference files
        """
        confdic = C.readConfig()
        wildcard = confdic.get('lastwildcard', FILTER)

        ll = self.listRef
        if os.name == 'posix':
            dlg = G.FileSelectorDialog(self, direc=self.lastpath, wildcard=wildcard, multiple=False)
        else:
            dlg = wx.FileDialog(self, 'Choose %sfiles'  % listtype, defaultDir=self.lastpath, wildcard=wildcard)
            
        if dlg.ShowModal() == wx.ID_OK:
            fn = dlg.GetPath()

            if not fn:
                return
            if os.name == 'posix':
                wildcard = dlg.fnPat

            ll.clearAll()
            ll.addFiles([fn])
            
            self.lastpath = os.path.dirname(fn)
            C.saveConfig(lastwildcard=wildcard, lastpath=self.lastpath)

            self.checkGo()
Пример #4
0
    def _load_func(self, fn):
        if chromformat.is_chromagnon(fn):
            h = chromformat.ChromagnonReader(fn)
        else:
            try:
                h = imgio.Reader(fn)
            except ValueError as e:
                return listbox.imgio_dialog(e, self)

            if aligner.hasSameWave(h):
                dlg = wx.MessageDialog(
                    self,
                    'The image contains multiple channels with the same wavelength. Please use a unique wavelength for each channel',
                    'Error in channel wavelengths',
                    wx.OK | wx.ICON_EXCLAMATION)
                if dlg.ShowModal() == wx.ID_OK:
                    return

            if h.nseries > 1:
                dlg = wx.MessageDialog(
                    self,
                    'Multiple series data sets are not allowed, please make a file with a single image in a file',
                    'Error in image file', wx.OK | wx.ICON_EXCLAMATION)
                if dlg.ShowModal() == wx.ID_OK:
                    return
        self.lastpath = os.path.dirname(fn)
        C.saveConfig(lastpath=self.lastpath)
        return h
Пример #5
0
 def _setFlat(self, fns):
     #ids = range(len(fns))
     #ids.reverse()
     #[self.listRef.clearRaw(i) for i in ids]
     self.listRef.clearAll()
     for i, fn in enumerate(fns):
         self.listRef.addFile(fn)
     C.saveConfig(flatfn=fns[0])
Пример #6
0
    def OnChooseImgFiles(self, evt, listtype='ref'):
        """
        set reference files
        """
        confdic = C.readConfig()
        if listtype == 'ref':
            ll = self.listRef
            wildcard = confdic.get('lastwildcardref', FILTER)
        else:
            ll = self.listTgt
            wildcard = confdic.get('lastwildcardtgt', FILTER)

        if os.name == 'posix':
            dlg = G.FileSelectorDialog(self, self.lastpath, wildcard=wildcard)
        else:
            dlg = wx.FileDialog(self,
                                'Choose %s files' % listtype,
                                defaultDir=self.lastpath,
                                style=wx.FD_MULTIPLE)

        if dlg.ShowModal() == wx.ID_OK:
            fns = dlg.GetPaths()

            if not fns:
                return
            if os.name == 'posix':
                wildcard = dlg.fnPat
            if isinstance(fns, six.string_types):  #str):
                fns = [fns]

            ll.addFiles(fns)
            if listtype != 'ref':
                if any([nw > 5 for nw in ll.nws
                        ]) and self.outextch.GetStringSelection() == (
                            os.path.extsep + aligner.WRITABLE_FORMATS[1]):
                    self.outextch.SetStringSelection(
                        os.path.extsep + aligner.WRITABLE_FORMATS[0])
                    G.openMsg(
                        parent=self,
                        msg=
                        'Since number of wavelength in some image file is more than 5,\nthe output file format was changed to tiff',
                        title="Output file format change")

            self.lastpath = os.path.dirname(fns[0])
            if listtype == 'ref':
                C.saveConfig(lastwildcardref=wildcard, lastpath=self.lastpath)
            else:
                C.saveConfig(lastwildcardtgt=wildcard, lastpath=self.lastpath)

            self.checkGo()
Пример #7
0
    def onChooseFile(self, evnt):
        """
        get image file
        call self.view()
        """
        confdic = C.readConfig()
        lastpath = confdic.get('lastpath', '')
        #parent = self.GetTopLevelParent()
        if os.name == 'posix':
            dlg = G.FileSelectorDialog(self, lastpath)
        else:
            dlg = wx.FileDialog(self, 'Choose a file', defaultDir=lastpath)

        if dlg.ShowModal() == wx.ID_OK:
            fn = dlg.GetPath()
        else:
            return

        self.view(fn)

        C.saveConfig(lastpath=os.path.dirname(fn))
Пример #8
0
    def onChooseFile(self, evnt):
        """
        get image file
        call self.view()
        """
        confdic = C.readConfig()
        lastpath = confdic.get('lastpath', '')
        #parent = self.GetTopLevelParent()
        if os.name == 'posix':
            dlg = G.FileSelectorDialog(self, lastpath)
        else:
            dlg = wx.FileDialog(self, 'Choose a file', defaultDir=lastpath)

        if dlg.ShowModal() == wx.ID_OK:
            fn = dlg.GetPath()
        else:
            return

        self.view(fn)

        C.saveConfig(lastpath=os.path.dirname(fn))
Пример #9
0
    def onChooseOriginalFile(self, ev):
        """
        get image file
        """
        confdic = C.readConfig()
        lastpath = confdic.get('lastpath', '')
        wildcard = confdic.get('localfnpat', '*')
        #parent = self.GetTopLevelParent()
        if os.name == 'posix':
            dlg = G.FileSelectorDialog(self, lastpath, wildcard)
        else:
            dlg = wx.FileDialog(self, 'Choose a file', defaultDir=lastpath)

        if dlg.ShowModal() == wx.ID_OK:
            fn = dlg.GetPath()
        else:
            return

        self.originalFileTxt.SetValue(fn)

        C.saveConfig(lastpath=os.path.dirname(fn), localfnpat=dlg.fnPat)
Пример #10
0
    def onChooseOriginalFile(self, ev):
        """
        get image file
        """
        confdic = C.readConfig()
        lastpath = confdic.get('lastpath', '')
        wildcard = confdic.get('localfnpat', '*')
        #parent = self.GetTopLevelParent()
        if os.name == 'posix':
            dlg = G.FileSelectorDialog(self, lastpath, wildcard)
        else:
            dlg = wx.FileDialog(self, 'Choose a file', defaultDir=lastpath)

        if dlg.ShowModal() == wx.ID_OK:
            fn = dlg.GetPath()
        else:
            return

        self.originalFileTxt.SetValue(fn)

        C.saveConfig(lastpath=os.path.dirname(fn), localfnpat=dlg.fnPat)
Пример #11
0
    def _load_func(self, fn):
        if chromformat.is_chromagnon(fn):
            h = chromformat.ChromagnonReader(fn)
        else:
            try:
                h = imgio.Reader(fn)
            except ValueError as e:
                return listbox.imgio_dialog(e, self)

            if aligner.hasSameWave(h):
                dlg = wx.MessageDialog(self, 'The image contains multiple channels with the same wavelength. Please use a unique wavelength for each channel', 'Error in channel wavelengths', wx.OK | wx.ICON_EXCLAMATION)
                if dlg.ShowModal() == wx.ID_OK:
                    return
                
            if h.nseries > 1:
                dlg = wx.MessageDialog(self, 'Multiple series data sets are not allowed, please make a file with a single image in a file', 'Error in image file', wx.OK | wx.ICON_EXCLAMATION)
                if dlg.ShowModal() == wx.ID_OK:
                    return
        self.lastpath = os.path.dirname(fn)
        C.saveConfig(lastpath=self.lastpath)
        return h
Пример #12
0
    def OnExtraParamButton(self, evt=None):
        confdic = C.readConfig()

        dlg = extrapanel.ExtraDialog(self, self.listRef, confdic, outdir=self.extra_parms.get('outdir'), refwave=str(self.extra_parms.get('refwave')))
        val = dlg.ShowModal()

        self.outdir = self.refwave = self.zacuur = None
        if val == wx.ID_OK:
            if not (dlg.outdir_cb.GetValue()):
                self.extra_parms['outdir'] = dlg.outdir
                C.saveConfig(outdir=dlg.outdir)
            if hasattr(dlg, 'refwave_cb') and not (dlg.refwave_cb.GetValue()):
                refwave = dlg.refwave_choice.GetStringSelection()
                try:
                    refwave = eval(refwave)
                except (TypeError, ValueError):
                    pass
                self.extra_parms['refwave'] = refwave

            if hasattr(dlg, 'tseriesListChoice'):
                self.extra_parms['tseries4wave'] = dlg.tseriesListChoice.GetStringSelection()
                
            self.extra_parms['zacuur'] = eval(dlg.accurListChoice.GetStringSelection())
            C.saveConfig(accur=self.extra_parms['zacuur'])

            self.extra_parms['max_shift'] = eval(dlg.maxshift_text.GetValue())
            C.saveConfig(max_shift=self.extra_parms['max_shift'])

        dlg.Destroy()
Пример #13
0
    def OnChooseImgFiles(self, evt, listtype='ref'):
        """
        set reference files
        """
        confdic = C.readConfig()
        if listtype == 'ref':
            ll = self.listRef
            wildcard = confdic.get('lastwildcardref', FILTER)
        else:
            ll = self.listTgt
            wildcard = confdic.get('lastwildcardtgt', FILTER)

        if os.name == 'posix':
            dlg = G.FileSelectorDialog(self, self.lastpath, wildcard=wildcard)
        else:
            dlg = wx.FileDialog(self, 'Choose %s files' % listtype, defaultDir=self.lastpath, style=wx.FD_MULTIPLE)
            
        if dlg.ShowModal() == wx.ID_OK:
            fns = dlg.GetPaths()

            if not fns:
                return
            if os.name == 'posix':
                wildcard = dlg.fnPat
            if isinstance(fns, six.string_types):
                fns = [fns]

            ll.addFiles(fns)
            if listtype != 'ref':
                if any([nw > 5 for nw in ll.nws]) and self.outextch.GetStringSelection() == (os.path.extsep + aligner.WRITABLE_FORMATS[1]):
                    self.outextch.SetStringSelection(os.path.extsep + aligner.WRITABLE_FORMATS[0])
                    G.openMsg(parent=self, msg='Since number of wavelength in some image file is more than 5,\nthe output file format was changed to tiff', title="Output file format change")
            
            self.lastpath = os.path.dirname(fns[0])
            if listtype == 'ref':
                C.saveConfig(lastwildcardref=wildcard, lastpath=self.lastpath)
            else:
                C.saveConfig(lastwildcardtgt=wildcard, lastpath=self.lastpath)

            self.checkGo()
Пример #14
0
    def OnGo(self, ev=None):
        """
        run or cancel the alignment program

        The actual sequence of processes is written in threads.ThreadWithExc.run()
        """
        if self.goButton.GetValue():
            
            if not self.listRef.columnkeys:
                return

            fns = [os.path.join(*self.listRef.getFile(index)[:2]) for index in self.listRef.columnkeys]
            targets = [os.path.join(*self.listTgt.getFile(index)[:2]) for index in self.listTgt.columnkeys]

            # other parameters
            #initguess = ''
            confdic = C.readConfig()

            form = self.outextch.GetStringSelection()
            if not form:
                self.quit('Please select the output file format next to the Suffix text box', title="The format type is missing")
                return

            # check wavelengths
            waves1 = [list(map(int, self.listRef.getFile(index)[2].split(','))) for index in self.listRef.columnkeys]
            waves2 = [list(map(int, self.listTgt.getFile(index)[2].split(','))) for index in self.listTgt.columnkeys]
            nts = all([t == 1 for t in self.listRef.nts])
            ids = af.checkWaves(waves1, waves2)
            if ids is not None and nts:
                for i, listbox in zip(ids, (self.listRef, self.listTgt)):
                    listbox.SetItemTextColour(i, 'purple')
                    #listbox.SetBackGroundColour(i, 'gray')
                msg = 'Less than two Common wavelengths were found at least in %s and %s\n\nThe program will not run.' % (self.listRef.getFile(ids[0])[1], self.listTgt.getFile(ids[1])[1])
                self.quit(msg, title='Error in input files')
                return
            
            # averaging
            if self.averageCb.GetValue() and len(fns) > 1:
                if any([waves1[0] != ws1 for ws1 in waves1[1:]]):
                    self.quit('There are inconsistency in channel composition in the reference files', title="Reference files are not appropriate for averaging")
                    return
                
                try:
                    self.label.SetLabel('averaging...')
                    self.label.SetForegroundColour('red')
                    wx.Yield()
                    ave_fn = af.averageImage(fns, ext=form)
                except Exception as e:
                    self.quit(e.args[0], title="Reference files are not appropriate for averaging")
                    return         
                self.listRef.clearAll()
                self.listRef.addFile(ave_fn)
                fns = [ave_fn]
            elif self.averageCb.GetValue() and len(fns) == 1:
                self.averageCb.SetValue(0)


            accur = self.extra_parms.get('zacuur', confdic.get('accur', aligner.ACCUR_CHOICE[0]))
            if accur in aligner.ACCUR_CHOICE_DIC:
                accur = aligner.ACCUR_CHOICE_DIC[accur]
            
            # parameters
            parms = [self.cutoutCb.GetValue(),
                     self.extra_parms.get('outdir'),#initguess,
                     self.localListChoice.GetStringSelection(),
                     self.extra_parms.get('refwave'), #None, #self.maxShift.GetValue(),
                     int(accur),#self.extra_parms.get('zacuur', confdic.get('accur', aligner.ACCUR_CHOICE[0]))), #self.accurListChoice.GetStringSelection(),
                    self.parm_suffix_txt.GetValue(),
                        self.img_suffix_txt.GetValue(),
                     self.extra_parms.get('tseries4wave', 'time'),#[nt for nt in self.listRef.nts], # copy
                     form,
                     int(self.min_pxls_choice.GetStringSelection()),
                         self.extra_parms.get('max_shift', af.MAX_SHIFT)] 

            #print(parms[4], confdic.get('accur', aligner.ACCUR_CHOICE[0]), type(parms[4]))
            # check the user-inputs
            old="""
            try:
                parms[3] = float(parms[3])
            except ValueError:
                G.openMsg(parent=self, msg='The default value (%.2f um) will be used' % af.MAX_SHIFT, title="The value for max shift allowed is missing")
                parms[3] = af.MAX_SHIFT
                self.maxShift.SetValue(str(parms[3]))"""
                        
            if not parms[6]:
                G.openMsg(parent=self, msg='The default suffix will be used', title="The file suffix is missing")
                parms[6] = aligner.IMG_SUFFIX
                self.img_suffix_txt.SetValue(parms[6])

            # save current settings
            C.saveConfig(cutout=parms[0], local=parms[2], accur=parms[4], parm_suffix_txt=parms[5], img_suffix_txt=parms[6], format=parms[8], min_pxls_yx=parms[9])
            #C.saveConfig(cutout=parms[0], local=parms[2], maxShift=parms[3], accur=parms[4], parm_suffix_txt=parms[5], img_suffix_txt=parms[6], format=parms[8], min_pxls_yx=parms[9])

            # run program
            gui = threads.GUImanager(self, __name__)
            
            self.th = threads.ThreadWithExc(gui, self.localChoice, fns, targets, parms)
            self.th.start()

        else:
            tid = self.th._get_my_tid()
            threads.async_raise(tid, threads.MyError)
Пример #15
0
 def _setInitGuess(self, fn):
     self.initGuess.clearAll()
     self.initGuess.addFile(fn)
     self.clearInitguessButton.Enable(1)
     C.saveConfig(initguess=fn)
Пример #16
0
    def OnGo(self, ev=None):
        """
        run or cancel the alignment program

        The actual sequence of processes is written in threads.ThreadWithExc.run()
        """
        if self.goButton.GetValue():
            if not self.listRef.columnkeys:
                return

            fns = [
                os.path.join(*self.listRef.getFile(index)[:2])
                for index in self.listRef.columnkeys
            ]
            targets = [
                os.path.join(*self.listTgt.getFile(index)[:2])
                for index in self.listTgt.columnkeys
            ]

            # other parameters
            initguess = ''

            form = self.outextch.GetStringSelection()
            if not form:
                G.openMsg(
                    parent=self,
                    msg=
                    'Please select the output file format next to the Suffix text box',
                    title="The format type is missing")
                self.goButton.SetValue(0)
                return

            parms = [
                self.cutoutCb.GetValue(),
                initguess,
                self.localListChoice.GetStringSelection(),
                self.maxShift.GetValue(),
                self.zmagch.GetStringSelection(),
                self.parm_suffix_txt.GetValue(),
                self.img_suffix_txt.GetValue(),
                [nt for nt in self.listRef.nts],  # copy
                form,
                int(self.min_pxls_choice.GetStringSelection())
            ]

            # check the user-inputs
            try:
                parms[3] = float(parms[3])
            except ValueError:
                G.openMsg(parent=self,
                          msg='The default value (%.2f um) will be used' %
                          af.MAX_SHIFT,
                          title="The value for max shift allowed is missing")
                parms[3] = af.MAX_SHIFT
                self.maxShift.SetValue(str(parms[3]))

            if not parms[6]:
                G.openMsg(parent=self,
                          msg='The default suffix will be used',
                          title="The file suffix is missing")
                parms[6] = alginer.IMG_SUFFIX
                self.img_suffix_txt.SetValue(parms[6])

            # save current settings
            C.saveConfig(cutout=parms[0],
                         local=parms[2],
                         maxShift=parms[3],
                         Zmag=parms[4],
                         parm_suffix_txt=parms[5],
                         img_suffix_txt=parms[6],
                         format=parms[8],
                         min_pxls_yx=parms[9])

            # run program
            gui = threads.GUImanager(self, __name__)

            self.th = threads.ThreadWithExc(gui, self.localChoice, fns,
                                            targets, parms)
            self.th.start()

        else:
            tid = self.th._get_my_tid()
            threads.async_raise(tid, threads.MyError)
Пример #17
0
 def _setInitGuess(self, fn):
     self.initGuess.clearAll()
     self.initGuess.addFile(fn)
     self.clearInitguessButton.Enable(1)
     C.saveConfig(initguess=fn)