Ejemplo n.º 1
0
    def view(self, target):
        """
        view with viewer
        """
        # prepare viewer
        if not self.aui:
            self.aui = aui.MyFrame(parent=self)
            self.aui.Show()

        if isinstance(target,
                      six.string_types) and chromformat.is_chromagnon(target):
            newpanel = chromeditor.ChromagnonEditor(self.aui, target)
        else:
            newpanel = aui.ImagePanel(self.aui, target)

        if isinstance(target, six.string_types):
            name = os.path.basename(target)
        else:
            name = target.file

        if sys.platform in ('linux2', 'win32'):
            wx.CallAfter(self.aui.imEditWindows.addPage,
                         newpanel,
                         name,
                         select=True)
        else:
            self.aui.imEditWindows.addPage(newpanel, name, select=True)
Ejemplo n.º 2
0
    def OnChooseInitGuess(self, evt=None):
        """
        set reference files
        """
        wildcard = '*.chromagnon*'

        if os.name == 'posix':
            dlg = G.FileSelectorDialog(self,
                                       direc=self.lastpath,
                                       wildcard=wildcard,
                                       multiple=False)
        else:
            dlg = wx.FileDialog(self,
                                'Choose chromagnon files',
                                defaultDir=self.lastpath,
                                wildcard=wildcard)

        if dlg.ShowModal() == wx.ID_OK:
            fn = dlg.GetPath()
            if chromformat.is_chromagnon(fn, True):
                self._setInitGuess(fn)
            else:
                G.openMsg(parent=self,
                          msg='The file is not a valid chromagnon file',
                          title="Warning")
Ejemplo n.º 3
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
Ejemplo n.º 4
0
    def view(self, target):
        """
        view with viewer
        """
        # prepare viewer
        if not self.aui:
            if self.parent and not self.parent.aui:
                self.aui = aui.MyFrame(parent=self.parent)
                self.parent.aui = self.aui
                self.aui.Show()
            elif not self.parent:
                self.aui = aui.MyFrame(parent=self)

                self.aui.Show()

            elif self.parent and self.parent.aui:
                self.aui = self.parent.aui

        # draw
        if isinstance(target, six.string_types):

            if chromformat.is_chromagnon(target):
                target_is_image = False
            else:
                target_is_image = True
                an = aligner.Chromagnon(target)
        else:
            an = target
            target_is_image = True

        if target_is_image:
            newpanel = aui.ImagePanel(self.aui, an.img)

        else:
            #an.close()
            newpanel = chromeditor.ChromagnonEditor(self.aui, target)

        if isinstance(target, six.string_types):
            name = os.path.basename(target)
        else:
            name = target.file
        if sys.platform in ('linux2', 'win32'):
            wx.CallAfter(self.aui.imEditWindows.addPage,
                         newpanel,
                         name,
                         select=True)
        else:
            self.aui.imEditWindows.addPage(newpanel, name, select=True)
Ejemplo n.º 5
0
    def _load_func(self, fn):
        if chromformat.is_chromagnon(fn):
            h = chromformat.ChromagnonReader(fn)
        else:
            try:
                h = bioformatsIO.load(fn)
            except ValueError:
                dlg = wx.MessageDialog(self,
                                       '%s is not a valid image file!' % ff,
                                       'Error reading image file',
                                       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
        return h
Ejemplo n.º 6
0
    def run(self):
        """
        This function execute the series of processes

        Since it uses GUI, this function uses several events to control GUI
        They are called by wx.PostEvent()
        """
        OLD_SCIK = fftmanager.SCIK
        OLD_REIK = fftmanager.REIK
        fftmanager.SCIK = False
        fftmanager.REIK = False

        fns = self.fns
        targets = self.targets
        parms = self.parms

        # parameters
        cutout = parms[0]
        initGuess = parms[1]
        if initGuess and not os.path.isfile(initGuess):
            raise ValueError(
                'The initial guess is not a valid Chromagnon file')
        local = parms[2]

        maxShift = parms[3]
        zmag = parms[4]
        self.parm_suffix = parms[5]
        self.img_suffix = parms[6]
        nts = parms[7]
        self.img_ext = parms[8]
        min_pxls_yx = parms[9]

        saveAlignParam = True
        alignChannels = True
        alignTimeFrames = True

        outs0 = []
        outs = []
        doneref = []
        donetgt = []
        errs = []

        kwds = {}

        self.progress(0)

        try:
            # calibration
            for index, fn in enumerate(fns):
                #clk0 = time.clock()
                # calculation
                if not chromformat.is_chromagnon(fn):
                    tstf = time.strftime('%Y %b %d %H:%M:%S', time.localtime())
                    self.log('\n**Measuring shifts in %s at %s' %
                             (os.path.basename(fn), tstf))
                    if self.notify_obj:
                        wx.PostEvent(
                            self.notify_obj,
                            MyEvent(EVT_COLOR_ID, ['ref', index, wx.RED]))

                    an = aligner.Chromagnon(fn)
                    an = self.getAligner(fn, index, what='ref')
                    an.setZmagSwitch(zmag)
                    an.setMaxShift(maxShift)

                    pgen = self.progressValues(target=False,
                                               an=an,
                                               alignChannels=alignChannels,
                                               alignTimeFrames=alignTimeFrames,
                                               local=local)
                    an.setProgressfunc(pgen)

                    if initGuess:
                        an.loadParm(initGuess)
                        # mapyx should not be inherited...
                        an.mapyx = None

                    if (an.nw > 1 and an.nt == 1):
                        an.findBestChannel()
                        self.echo('Calculating channel alignment...')

                        for t in range(an.nt):
                            try:
                                an.findAlignParamWave(t=t)
                            except alignfuncs.AlignError:  # in xcorr or else
                                self.echo('Calculation failed, skipping')
                                errs.append(index)
                                continue

                            if local in self.localChoice[1:]:
                                an.findNonLinear2D(t=t, npxls=min_pxls_yx)

                            if local in self.localChoice[2:]:
                                arr = an.findNonLinear3D(t=t,
                                                         npxls=min_pxls_yx)
                                del arr

                    elif an.nt > 1:
                        self.echo('Calculating timelapse alignment...')
                        an.findBestChannel()
                        an.findBestTimeFrame(an.refwave)

                        an.findAlignParamTime(doWave=False)

                    fn = an.saveParm()

                    currlist = None
                    #clk1 = time.clock()
                    #print('Done seconds', (clk1-clk0))

                    an.close()

                doneref.append(index)

                if self.notify_obj:
                    wx.PostEvent(
                        self.notify_obj,
                        MyEvent(EVT_COLOR_ID, ['ref', index, wx.BLUE]))

                if index < len(targets):
                    if self.notify_obj:
                        wx.PostEvent(
                            self.notify_obj,
                            MyEvent(EVT_COLOR_ID, ['tgt', index, wx.RED]))

                    target = targets[index]
                    tstf = time.strftime('%Y %b %d %H:%M:%S', time.gmtime())
                    self.log(
                        '\n**Applying to %s using %s at %s' %
                        (os.path.basename(target), os.path.basename(fn), tstf))

                    an = self.getAligner(target, index, what='target')

                    pgen = self.progressValues(target=True, an=an)
                    an.setProgressfunc(pgen)
                    self.progress(0)

                    an.loadParm(fn)
                    #if cutout:
                    an.setRegionCutOut(cutout)

                    out = an.saveAlignedImage()
                    donetgt.append(index)

                    an.close()

                    if self.notify_obj:
                        wx.PostEvent(
                            self.notify_obj,
                            MyEvent(EVT_COLOR_ID, ['tgt', index, wx.BLUE]))

                    if self.notify_obj:
                        wx.PostEvent(self.notify_obj,
                                     MyEvent(EVT_VIEW_ID, [out]))

                elif self.notify_obj:
                    wx.PostEvent(self.notify_obj, MyEvent(EVT_VIEW_ID, [fn]))

            # remaining target files use the last alignment file
            for index, target in enumerate(targets[len(fns):]):
                index += len(fns)
                if self.notify_obj:
                    wx.PostEvent(
                        self.notify_obj,
                        MyEvent(EVT_COLOR_ID, ['tgt', index, wx.BLUE]))

                target = targets[index]
                tstf = time.strftime('%Y %b %d %H:%M:%S', time.gmtime())
                if fns:
                    self.log(
                        '\n**Applying to %s using %s at %s' %
                        (os.path.basename(target), os.path.basename(fn), tstf))
                else:
                    self.log('\n**Applying to %s at %s' %
                             (os.path.basename(target), tstf))

                an = self.getAligner(target, index, what='target')
                pgen = self.progressValues(target=True, an=an)
                an.setProgressfunc(pgen)
                self.progress(0)

                if len(fns):
                    an.loadParm(fn)

                an.setRegionCutOut(cutout)

                out = an.saveAlignedImage()

                donetgt.append(index)

                an.close()

                if self.notify_obj:
                    wx.PostEvent(
                        self.notify_obj,
                        MyEvent(EVT_COLOR_ID, ['tgt', index, wx.BLUE]))
                    #wx.PostEvent(self.notify_obj, MyEvent(EVT_PROGRESS_ID, [prange.pop(0)]))
                # pgen.next()

                #out = aligner.Chromagnon(out)
                if self.notify_obj:
                    print('event view', out)
                    wx.PostEvent(self.notify_obj, MyEvent(EVT_VIEW_ID, [out]))

        except MyError:
            if self.notify_obj:
                wx.PostEvent(self.notify_obj, MyEvent(EVT_ABORT_ID, []))
                wx.PostEvent(self.notify_obj, MyEvent(EVT_PROGRESS_ID, [0]))
            else:
                pass
        except:
            #exc_type, exc_value, exc_traceback = sys.exc_info()
            #formatted = traceback.format_exception(exc_type, exc_value, exc_traceback)
            if self.notify_obj:
                import traceback, sys
                wx.PostEvent(self.notify_obj,
                             MyEvent(EVT_ERROR_ID,
                                     sys.exc_info()))  #formatted]))
                #wx.PostEvent(self.notify_obj, MyEvent(EVT_PROGRESS_ID, [0]))
                self.progress(0)
            else:
                pass
        else:
            if self.notify_obj:
                wx.PostEvent(self.notify_obj,
                             MyEvent(EVT_DONE_ID, [doneref, donetgt, errs]))
                #wx.PostEvent(self.notify_obj, MyEvent(EVT_PROGRESS_ID, [0]))
                self.progress(0)
            else:
                pass
        finally:
            self.logh.close()
        #bioformatsIO.uninit_javabridge()

        fftmanager.SCIK = OLD_SCIK
        fftmanager.REIK = OLD_REIK