예제 #1
0
            def _display_output_image(outp):
                if self.dsviewer.mode == 'visGUI':
                    mode = 'visGUI'
                elif 'out_tracks' in self.activeRecipe.namespace.keys():
                    mode = 'tracking'
                else:
                    mode = 'default'

                dv = ViewIm3D(outp, mode=mode, glCanvas=self.dsviewer.glCanvas)

                if 'out_meas' in self.activeRecipe.namespace.keys():
                    #have measurements as well - add to / overlay with output image
                    if not 'pipeline' in dir(dv):
                        dv.pipeline = pipeline.Pipeline()

                    from PYME.IO import tabular
                    cache = tabular.CachingResultsFilter(
                        self.activeRecipe.namespace['out_meas'])
                    dv.pipeline.OpenFile(ds=cache)
                    dv.view.filter = dv.pipeline

                #set scaling to (0,1)
                for i in range(outp.data.shape[3]):
                    dv.do.Gains[i] = 1.0

                if ('out_tracks' in self.activeRecipe.namespace.keys()
                    ) and 'tracker' in dir(dv):
                    dv.tracker.SetTracks(
                        self.activeRecipe.namespace['out_tracks'])
예제 #2
0
    def SetData(self, data):
        if isinstance(data, tabular.TabularBase):
            table = TabularTable(tabular.CachingResultsFilter(data))
        else:
            table = RecArrayTable(data)

        # The second parameter means that the grid is to take ownership of the
        # table and will destroy it when done.  Otherwise you would need to keep
        # a reference to it and call it's Destroy method later.
        self.SetTable(table, True)
예제 #3
0
    def execute(self, namespace):
        input = namespace[self.input]
        mdh = input.mdh

        if self.ratios_from_metadata:
            # turn off invalidation so we don't get a recursive loop. TODO - fix this properly as it's gross to be changing
            # our parameters here
            invalidate = self._invalidate_parent
            self._invalidate_parent = False
            self._get_dye_ratios_from_metadata(mdh)
            self._invalidate_parent = invalidate

        output = tabular.MappingFilter(input)
        output.mdh = mdh

        if 'gFrac' in output.keys():
            #ratiometric
            #raise NotImplementedError('Ratiometric processing in recipes not implemented yet')
            for structure, ratio in self.species_ratios.items():
                if not ratio is None:
                    output.setMapping(
                        'p_%s' % structure,
                        'exp(-(%f - gFrac)**2/(2*error_gFrac**2))/(error_gFrac*sqrt(2*numpy.pi))'
                        % ratio)
        else:
            if 'probe' in output.keys():
                #non-ratiometric (i.e. sequential) colour
                #color channel is given in 'probe' column
                output.setMapping('ColourNorm', '1.0 + 0*probe')

                for i in range(int(output['probe'].min()),
                               int(output['probe'].max() + 1)):
                    output.setMapping('p_chan%d' % i, '1.0*(probe == %d)' % i)

            nSeqCols = mdh.getOrDefault('Protocol.NumberSequentialColors', 1)
            if nSeqCols > 1:
                for i in range(nSeqCols):
                    output.setMapping('ColourNorm', '1.0 + 0*t')
                    cr = mdh['Protocol.ColorRange%d' % i]
                    output.setMapping('p_chan%d' % i, '(t>= %d)*(t<%d)' % cr)

        cached_output = tabular.CachingResultsFilter(output)
        #cached_output.mdh = output.mdh
        namespace[self.output] = cached_output
예제 #4
0
    def OnLoadOutputs(self, event):
        import pandas
        from PYME.IO import tabular

        filename = wx.FileSelector(
            'Save results as ...',
            wildcard=
            "CSV files (*.csv)|*.csv|Excell files (*.xlsx)|*.xlsx|HDF5 files (*.hdf)|*.hdf",
            flags=wx.FD_OPEN)

        if not filename == '':
            if filename.endswith('.csv'):
                data = pandas.read_csv(filename)
            elif filename.endswith('.xlsx'):
                data = pandas.read_excel(filename)
            elif filename.endswith('.hdf'):
                data = pandas.read_hdf(filename)

            if not 'pipeline' in dir(self.dsviewer):
                self.dsviewer.pipeline = pipeline.Pipeline()

            cache = tabular.CachingResultsFilter(data)
            self.dsviewer.pipeline.OpenFile(ds=cache)
            self.dsviewer.view.filter = self.dsviewer.pipeline
예제 #5
0
    def RunCurrentRecipe(self, event=None, testMode=False, saveResults=False):
        if self.activeRecipe:
            if testMode:
                #just run on current frame  # FIXME - this breaks SUPERTILE datasources and anything that needs to carry datasource attributes forward
                self.outp = self.activeRecipe.execute(
                    input=ImageStack([
                        np.atleast_3d(self.image.data[:, :, self.do.zp, c])
                        for c in range(self.image.data.shape[3])
                    ],
                                     mdh=self.image.mdh))
            else:
                #run normally
                self.outp = self.activeRecipe.execute(input=self.image)

                if saveResults:
                    dir_dialog = wx.DirDialog(None,
                                              'Set output directory',
                                              style=wx.FD_OPEN)
                    succ = dir_dialog.ShowModal()
                    if (succ == wx.ID_OK):
                        output_dir = dir_dialog.GetPath()
                        file_stub = os.path.splitext(
                            os.path.split(self.image.filename)[-1])[0]
                        self.activeRecipe.save({
                            'output_dir': output_dir,
                            'file_stub': file_stub
                        })

            def _display_output_image(outp):
                if self.dsviewer.mode == 'visGUI':
                    mode = 'visGUI'
                elif 'out_tracks' in self.activeRecipe.namespace.keys():
                    mode = 'tracking'
                else:
                    mode = 'default'

                dv = ViewIm3D(outp, mode=mode, glCanvas=self.dsviewer.glCanvas)

                if 'out_meas' in self.activeRecipe.namespace.keys():
                    #have measurements as well - add to / overlay with output image
                    if not 'pipeline' in dir(dv):
                        dv.pipeline = pipeline.Pipeline()

                    from PYME.IO import tabular
                    cache = tabular.CachingResultsFilter(
                        self.activeRecipe.namespace['out_meas'])
                    dv.pipeline.OpenFile(ds=cache)
                    dv.view.filter = dv.pipeline

                #set scaling to (0,1)
                for i in range(outp.data.shape[3]):
                    dv.do.Gains[i] = 1.0

                if ('out_tracks' in self.activeRecipe.namespace.keys()
                    ) and 'tracker' in dir(dv):
                    dv.tracker.SetTracks(
                        self.activeRecipe.namespace['out_tracks'])

            def _display_output_report(outp):
                import wx.html2
                html_view = wx.html2.WebView.New(self.dsviewer)
                self.dsviewer.AddPage(html_view, True, 'Recipe Report')
                html_view.SetPage(outp, 'Recipe Report')

            if ('out_tracks' in self.activeRecipe.namespace.keys()
                ) and 'tracker' in dir(self.dsviewer):
                self.dsviewer.tracker.SetTracks(
                    self.activeRecipe.namespace['out_tracks'])

            #assume we made measurements - put in pipeline
            #TODO - put an explict check in here

            if not 'pipeline' in dir(self.dsviewer):
                self.dsviewer.pipeline = pipeline.Pipeline()

            if isinstance(self.outp, ImageStack):
                _display_output_image(self.outp)
            elif not self.outp is None:
                from PYME.IO import tabular

                cache = tabular.CachingResultsFilter(self.outp)
                self.dsviewer.pipeline.OpenFile(ds=cache, clobber_recipe=False)
                self.dsviewer.pipeline.filterKeys = {}
                self.dsviewer.pipeline.Rebuild()
                self.dsviewer.view.filter = self.dsviewer.pipeline

            for out_ in self.activeRecipe.gather_outputs():
                if isinstance(out_, ImageStack):
                    _display_output_image(out_)
                elif isinstance(out_, six.string_types):
                    _display_output_report(out_)