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 __init__(self, dsviewer): self.dsviewer = dsviewer self.image = dsviewer.image self.view = dsviewer.view self.do = dsviewer.do if not _check_complete_mdh(self.image.mdh): logger.warning( 'Series does not seem to have metadata needed for localization analysis' ) self.analysisController = AnalysisController(self.image.mdh) self.analysisSettingsView = AnalysisSettingsView( self.dsviewer, self.analysisController, self) self._fitdefaults = FitDefaults(self.dsviewer, self.analysisController) self.analysisController.onImagesPushed.connect(self.OnImagesPushed) self.queueName = None if 'fitResults' in dir(self.image): self.fitResults = self.image.fitResults else: self.fitResults = [] if 'resultsMdh' in dir(self.image): self.resultsMdh = self.image.resultsMdh #a timer object to update for us self.timer = mytimer() self.timer.Start(5000) self.numAnalysed = 0 self.numEvents = 0 if self.image.filename.upper().startswith('PYME-CLUSTER:'): self.newStyleTaskDistribution = True else: self.newStyleTaskDistribution = NEW_STYLE_DISTRIBUTION dsviewer.pipeline = pipeline.Pipeline() self.ds = None dsviewer.paneHooks.append(self.GenFitStatusPanel) dsviewer.updateHooks.append(self.update) dsviewer.statusHooks.append(self.GetStatusText) if 'bgRange' in dir(self.image.data): self.dsviewer.AddMenuItem('View', "SubtractBackground", self.OnToggleBackground)
def main(): import sys from PYME.LMVis import pipeline from PYME.IO.image import ImageStack resultFile, imageFile, speckles = sys.argv[1:] pipe = pipeline.Pipeline() pipe.OpenFile(resultFile) prepPipeline(pipe) img = image.ImageStack(filename=imageFile, mdh='/Users/david/Downloads/JN150629c3_4_MMStack_Pos0.ome.md') selectAndPlotEvents(pipe, speckleFile = speckles)
def test_hdf_import(): import os import numpy as np from PYME import resources from PYME.LMVis import pipeline p = pipeline.Pipeline( filename=os.path.join(resources.get_test_data_dir(), 'test_hdf.hdf')) # did we load the correct number of localisations? assert (len(p['x']) == 4281) # did we correctly estimate the image bounds? assert np.allclose( p.imageBounds.bounds, (-686.9195, -597.1356, 80.27731, 47.10489, -265.4904, 232.2955))
def __init__(self, dsviewer): self.dsviewer = dsviewer self.image = dsviewer.image self.view = dsviewer.view self.do = dsviewer.do if 'fitResults' in dir(self.image): self.fitResults = self.image.fitResults else: self.fitResults = [] if 'resultsMdh' in dir(self.image): self.resultsMdh = self.image.resultsMdh dsviewer.paneHooks.append(self.GenPanels) dsviewer.updateHooks.append(self.update) if (len(self.fitResults) > 0) and not 'PYME_BUGGYOPENGL' in os.environ.keys(): self.GenResultsView() if not 'pipeline' in dir(dsviewer): dsviewer.pipeline = pipeline.Pipeline(visFr=self) self.pipeline = dsviewer.pipeline self.pipeline.visFr = self self.view.filter = self.pipeline #self.Quads = None #dsviewer.menubar.Insert(dsviewer.menubar.GetMenuCount()-1, self.CreateMenuBar(subMenu=True), 'Points') # initialize the common parts visCore.VisGUICore.__init__(self) self.CreateMenuBar(subMenu=True) #self.Bind(wx.EVT_IDLE, self.OnIdle) self._sf = False
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
def __init__(self, parent, filename=None, id=wx.ID_ANY, title="PYME Visualise", pos=wx.DefaultPosition, size=(900,750), style=wx.DEFAULT_FRAME_STYLE, use_shaders=True, cmd_args=None, pipeline_vars = {}): # populate about box info self._component_name = 'PYMEVisualise' self._long_desc = "Visualisation of localisation microscopy data." AUIFrame.__init__(self, parent, id, title, pos, size, style) self.cmd_args = cmd_args self._flags = 0 self.pipeline = pipeline.Pipeline(visFr=self) self.pipeline.dataSources.update(pipeline_vars) visCore.VisGUICore.__init__(self, use_shaders=use_shaders) #self.Quads = None #self.SetMenuBar(self.CreateMenuBar()) self.CreateMenuBar(use_shaders=use_shaders) self.statusbar = self.CreateStatusBar(1, wx.STB_SIZEGRIP) self.statusbar.SetStatusText("", 0) #self._leftWindow1 = wx.Panel(self, -1, size = wx.Size(220, 1000)) #self._pnl = 0 #initialize the common parts ############################### #NB: this has to come after the shell has been generated, but before the fold panel ################################ self.MainWindow = self #so we can access from shell self.sh = wx.py.shell.Shell(id=-1, parent=self, size=wx.Size(-1, -1), style=0, locals=self.__dict__, startupScript=config.get('VisGUI-console-startup-file', None), introText='PYMEVisualize - note that help, license, etc. below is for Python, not PYME\n\n') #self._mgr.AddPane(self.sh, aui.AuiPaneInfo(). # Name("Shell").Caption("Console").Centre().CloseButton(False).CaptionVisible(False)) self.AddPage(self.sh, caption='Shell') self.elv = None self.colp = None self.mdp = None self.rav = None self.generatedImages = [] self.sh.Execute('from pylab import *') self.sh.Execute('from PYME.DSView.dsviewer import View3D') import os if os.getenv('PYMEGRAPHICSFIX'): # fix issue with graphics freezing on some machines (apparently matplotlib related) self.sh.Execute('plot()') self.sh.Execute('close()') #self.workspace = workspaceTree.WorkWrap(self.__dict__) ##### Make certain things visible in the workspace tree #components of the pipeline #col = self.workspace.newColour() #self.workspace.addKey('pipeline', col) #Generated stuff #col = self.workspace.newColour() #self.workspace.addKey('GeneratedMeasures', col) #self.workspace.addKey('generatedImages', col) #self.workspace.addKey('objects', col) #main window, so we can get everything else if needed #col = self.workspace.newColour() #self.workspace.addKey('MainWindow', col) ###### #self.workspaceView = workspaceTree.WorkspaceTree(self, workspace=self.workspace, shell=self.sh) #self.AddPage(page=wx.StaticText(self, -1, 'foo'), select=False, caption='Workspace') # self.glCanvas = gl_render.LMGLCanvas(self) # self.AddPage(page=self.glCanvas, select=True, caption='View') # self.glCanvas.cmap = pylab.cm.gist_rainbow #pylab.cm.hot #self.Bind(wx.EVT_SIZE, self.OnSize) self.Bind(wx.EVT_MOVE, self.OnMove) self.Bind(wx.EVT_CLOSE, self.OnClose) #self.Bind(wx.EVT_IDLE, self.OnIdle) #self.refv = False statusLog.SetStatusDispFcn(self.SetStatus) self.paneHooks.append(self.GenPanels) self.CreateFoldPanel() #from .layer_panel import CreateLayerPane, CreateLayerPanel #CreateLayerPane(sidePanel, self) #CreateLayerPanel(self) self._recipe_manager = recipeGui.PipelineRecipeManager(self.pipeline) self._recipe_editor = recipeGui.RecipeView(self, self._recipe_manager) self.AddPage(page=self._recipe_editor, select=False, caption='Pipeline Recipe') self.AddMenuItem('Recipe', 'Reconstruct from open image', self.reconstruct_pipeline_from_open_image) self.AddMenuItem('Recipe', 'Reconstruct from image file', self.reconstruct_pipeline_from_image_file) if not filename is None: def _recipe_callback(): recipe = getattr(self.cmd_args, 'recipe', None) print('Using recipe: %s' % recipe) if recipe: from PYME.recipes import modules self.pipeline.recipe.update_from_yaml(recipe) #self.recipeView.SetRecipe(self.pipeline.recipe) self.update_datasource_panel() self._recipe_editor.update_recipe_text() wx.CallLater(50,self.OpenFile,filename, recipe_callback=_recipe_callback) #self.refv = False wx.CallAfter(self.RefreshView) nb = self._mgr.GetNotebooks()[0] nb.SetSelection(0) self.add_common_menu_items()
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_)