예제 #1
0
        return (f_gauss2d(params, X, Y), X[0], Y[0], 0)


#so that fit tasks know which class to use
FitFactory = GaussianFitFactory
#FitResult = GaussianFitResultR
FitResultsDType = fresultdtype  #only defined if returning data as numarray

#this means that factory is reponsible for it's own object finding and implements
#a GetAllResults method that returns a list of localisations
MULTIFIT = True

import PYME.localization.MetaDataEdit as mde
#from PYME.localization.FitFactories import Interpolators
#from PYME.localization.FitFactories import zEstimators

PARAMETERS = [  #mde.ChoiceParam('Analysis.InterpModule','Interp:','LinearInterpolator', choices=Interpolators.interpolatorList, choiceNames=Interpolators.interpolatorDisplayList),
    #mde.FilenameParam('PSFFilename', 'PSF:', prompt='Please select PSF to use ...', wildcard='PSF Files|*.psf'),
    #mde.ShiftFieldParam('chroma.ShiftFilename', 'Shifts:', prompt='Please select shiftfield to use', wildcard='Shiftfields|*.sf'),
    #mde.IntParam('Analysis.DebounceRadius', 'Debounce r:', 4),
    mde.FloatParam('Analysis.PSFSigma', u'PSF \u03c3  [nm]:', 130.),
    mde.FloatParam('Analysis.ResidualMax', 'Max residual:', 0.25),
    #mde.ChoiceParam('Analysis.EstimatorModule', 'Z Start Est:', 'astigEstimator', choices=zEstimators.estimatorList),
    #mde.ChoiceParam('PRI.Axis', 'PRI Axis:', 'y', choices=['x', 'y'])
]

DESCRIPTION = '2D Gaussian multi-emitter fitting'
LONG_DESCRIPTION = '2D Gaussian multi-emitter fitting: Fits x, y and I, assuming background is already subtracted. Uses it\'s own object detection routine'
USE_FOR = '2D multi-emitter'
예제 #2
0
class AnalysisSettingsView(object):
    FINDING_PARAMS = [
        mde.FloatParam('Analysis.DetectionThreshold', 'Thresh:', 1.0),
        mde.IntParam('Analysis.DebounceRadius', 'Debounce rad:', 4),
    ]

    DEFAULT_PARAMS = [
        mde.IntParam('Analysis.StartAt', 'Start at:', default=30),
        mde.ParamGroup('Background Subtraction', [
            mde.RangeParam('Analysis.BGRange', 'Background:',
                           default=(-30, 0)),
            mde.BoolParam('Analysis.subtractBackground',
                          'Subtract background in fit',
                          default=True),
            mde.BoolFloatParam('Analysis.PCTBackground',
                               'Use percentile for background',
                               default=False,
                               helpText='',
                               ondefault=0.25,
                               offvalue=0),
        ],
                       folded=False),
        mde.ParamGroup('sCMOS camera noise maps', [
            mde.FilenameParam('Camera.VarianceMapID',
                              'Variance Map:',
                              prompt='Please select variance map to use ...',
                              wildcard=MAP_WILDCARDS,
                              filename=''),
            mde.FilenameParam('Camera.DarkMapID',
                              'Dark Map:',
                              prompt='Please select dark map to use ...',
                              wildcard=MAP_WILDCARDS,
                              filename=''),
            mde.FilenameParam('Camera.FlatfieldMapID',
                              'Flatfield Map:',
                              prompt='Please select flatfield map to use ...',
                              wildcard=MAP_WILDCARDS,
                              filename=''),
        ]),
        mde.ParamGroup('Fiducial based drift tracking', [
            mde.BoolParam(
                'Analysis.TrackFiducials', 'Track Fiducials', default=False),
            mde.FloatParam('Analysis.FiducialThreshold',
                           'Fiducial Threshold',
                           default=1.8),
            mde.IntParam(
                'Analysis.FiducialROISize', 'Fiducial ROI', default=11),
            mde.FloatParam('Analysis.FiducialSize',
                           'Fiducial Diameter [nm]',
                           default=1000.),
        ]),
    ]

    def __init__(self, dsviewer, analysisController, lmanal=None):
        self.foldAnalPanes = False

        self.analysisController = analysisController
        self.analysisMDH = analysisController.analysisMDH
        self.lmanal = lmanal

        dsviewer.paneHooks.append(self.GenPointFindingPanel)
        dsviewer.paneHooks.append(self.GenAnalysisPanel)

        self.analysisController.onMetaDataChange.connect(
            self.on_metadata_change)

    def _populateStdOptionsPanel(self, pan, vsizer):
        for param in self.DEFAULT_PARAMS:
            pg = param.createGUI(
                pan,
                self.analysisMDH,
                syncMdh=True,
                mdhChangedSignal=self.analysisController.onMetaDataChange)
            vsizer.Add(pg, 0, wx.BOTTOM | wx.EXPAND, 5)
        vsizer.Fit(pan)

    def _populateFindOptionsPanel(self, pan, vsizer):
        for param in self.FINDING_PARAMS:
            pg = param.createGUI(
                pan,
                self.analysisMDH,
                syncMdh=True,
                mdhChangedSignal=self.analysisController.onMetaDataChange)
            vsizer.Add(pg, 0, wx.BOTTOM | wx.EXPAND, 5)

    def _populateCustomAnalysisPanel(self, pan, vsizer):
        try:
            fitMod = self.fitFactories[self.cFitType.GetSelection()]
            fm = __import__('PYME.localization.FitFactories.' + fitMod,
                            fromlist=['PYME', 'localization', 'FitFactories'])

            #vsizer = wx.BoxSizer(wx.VERTICAL)
            for param in fm.PARAMETERS:
                pg = param.createGUI(
                    pan,
                    self.analysisMDH,
                    syncMdh=True,
                    mdhChangedSignal=self.analysisController.onMetaDataChange)
                vsizer.Add(pg, 0, wx.BOTTOM | wx.EXPAND, 5)
            vsizer.Fit(pan)

        except AttributeError:
            pass

    def on_metadata_change(self, *args, **kwargs):
        fit_module = self.analysisMDH.getOrDefault('Analysis.FitModule',
                                                   'LatGaussFitFR')
        if not fit_module == self.fitFactories[self.cFitType.GetSelection()]:
            self.cFitType.SetSelection(self.fitFactories.index(fit_module))

        self.OnFitModuleChanged(None)

    def OnFitModuleChanged(self, event):
        self.customOptionsSizer.Clear(True)
        self._populateCustomAnalysisPanel(self.customOptionsPan,
                                          self.customOptionsSizer)
        self.customOptionsPan.GetTopLevelParent().OnSize(None)
        self.analysisMDH['Analysis.FitModule'] = self.fitFactories[
            self.cFitType.GetSelection()]

    def GenAnalysisPanel(self, _pnl):
        item = afp.foldingPane(_pnl,
                               -1,
                               caption="Analysis",
                               pinned=not (self.foldAnalPanes))

        #############################
        #std options
        pan = wx.Panel(item, -1)
        vsizer = wx.BoxSizer(wx.VERTICAL)
        pan.SetSizer(vsizer)

        self._populateStdOptionsPanel(pan, vsizer)

        item.AddNewElement(pan)

        #######################
        #Fit factory selection
        pan = wx.Panel(item, -1)

        #find out what fit factories we have
        self.fitFactories = PYME.localization.FitFactories.resFitFactories
        print((self.fitFactories))

        vsizer = wx.BoxSizer(wx.VERTICAL)
        hsizer = wx.BoxSizer(wx.HORIZONTAL)

        hsizer.Add(wx.StaticText(pan, -1, 'Type:'), 0,
                   wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, 5)
        self.cFitType = wx.Choice(
            pan,
            -1,
            choices=[
                '{:<35} \t- {:} '.format(
                    f, PYME.localization.FitFactories.useFor[f])
                for f in self.fitFactories
            ],
            size=(110, -1))

        if 'Analysis.FitModule' in self.analysisMDH.getEntryNames():
            #has already been analysed - most likely to want the same method again
            try:
                self.cFitType.SetSelection(
                    self.fitFactories.index(
                        self.analysisMDH['Analysis.FitModule']))
                #self.tThreshold.SetValue('%s' % self.image.mdh.getOrDefault('Analysis.DetectionThreshold', 1))
            except ValueError:
                self.cFitType.SetSelection(
                    self.fitFactories.index('LatGaussFitFR'))

        #elif 'Camera.ROIPosY' in self.image.mdh.getEntryNames() and (self.image.mdh.getEntry('Camera.ROIHeight') + 1 + 2*(self.image.mdh.getEntry('Camera.ROIPosY')-1)) == 512:
        #    #we have a symetrical ROI about the centre - most likely want to analyse using splitter
        #    self.cFitType.SetSelection(self.fitFactories.index('SplitterFitQR'))
        #    self.tThreshold.SetValue('0.5')
        else:
            self.cFitType.SetSelection(
                self.fitFactories.index('LatGaussFitFR'))
            self.analysisMDH['Analysis.FitModule'] = 'LatGaussFitFR'

        self.cFitType.Bind(wx.EVT_CHOICE, self.OnFitModuleChanged)

        hsizer.Add(self.cFitType, 1, wx.ALIGN_CENTER_VERTICAL, 0)
        vsizer.Add(hsizer, 0, wx.BOTTOM | wx.EXPAND, 2)

        pan.SetSizer(vsizer)
        vsizer.Fit(pan)

        item.AddNewElement(pan)

        ########################################
        #custom  (fit factory dependant) options
        self.customOptionsPan = wx.Panel(item, -1)
        self.customOptionsSizer = wx.BoxSizer(wx.VERTICAL)
        self.customOptionsPan.SetSizer(self.customOptionsSizer)

        self._populateCustomAnalysisPanel(self.customOptionsPan,
                                          self.customOptionsSizer)

        item.AddNewElement(self.customOptionsPan)

        ######################
        #Go
        if self.lmanal:
            self.bGo = wx.Button(item, -1, 'Go')

            self.bGo.Bind(wx.EVT_BUTTON, lambda e: self.lmanal.OnGo(e))
            item.AddNewElement(self.bGo)
        _pnl.AddPane(item)

        self.analysisPanel = item

    def GenPointFindingPanel(self, _pnl):
        item = afp.foldingPane(_pnl,
                               -1,
                               caption="Point Finding",
                               pinned=not (self.foldAnalPanes))

        pan = wx.Panel(item, -1)
        vsizer = wx.BoxSizer(wx.VERTICAL)

        #load point finding settings
        self._populateFindOptionsPanel(pan, vsizer)

        if not self.lmanal is None:
            hsizer = wx.BoxSizer(wx.HORIZONTAL)
            #bTest = wx.Button(pan, -1, 'Test', style=wx.BU_EXACTFIT)
            #bTest.Bind(wx.EVT_BUTTON, lambda e : self.lmanal.Test())
            #hsizer.Add(bTest, 0,wx.LEFT|wx.ALIGN_CENTER_VERTICAL, 5)

            bTestF = wx.Button(pan,
                               -1,
                               'Test This Frame',
                               style=wx.BU_EXACTFIT)
            bTestF.Bind(wx.EVT_BUTTON, lambda e: self.lmanal.OnTestFrame(e))
            hsizer.Add(bTestF, 0, wx.LEFT | wx.ALIGN_CENTER_VERTICAL, 5)

            vsizer.Add(hsizer, 0, wx.BOTTOM | wx.EXPAND, 2)

        pan.SetSizerAndFit(vsizer)

        item.AddNewElement(pan)
        _pnl.AddPane(item)
import PYME.localization.MetaDataEdit as mde
from PYME.localization.FitFactories import Interpolators
from PYME.localization.FitFactories import zEstimators

PARAMETERS = [  #mde.ChoiceParam('Analysis.InterpModule','Interp:','CSInterpolator', choices=Interpolators.interpolatorList, choiceNames=Interpolators.interpolatorDisplayList),
    mde.FilenameParam('PSFFile',
                      'PSF:',
                      prompt='Please select PSF to use ...',
                      wildcard='PSF Files|*.psf|TIFF files|*.tif'),
    mde.ShiftFieldParam('chroma.ShiftFilename',
                        'Shifts:',
                        prompt='Please select shiftfield to use',
                        wildcard='Shiftfields|*.sf'),
    #mde.IntParam('Analysis.DebounceRadius', 'Debounce r:', 4),
    mde.FloatParam('Analysis.AxialShift', 'Z Shift [nm]:', -270),
    mde.ChoiceParam('Analysis.EstimatorModule',
                    'Z Start Est:',
                    'biplaneEstimator',
                    choices=zEstimators.estimatorList),
    mde.ChoiceParam('PRI.Axis',
                    'PRI Axis:',
                    'none',
                    choices=['x', 'y', 'none']),
    mde.BoolParam('Analysis.FitBackground', 'Fit Background', True),
    mde.FloatListParam('chroma.ChannelRatios', 'Channel Ratios', [0.7]),
]

DESCRIPTION = 'Ratiometric multi-colour 3D PSF fit (large shifts).'
LONG_DESCRIPTION = 'Ratiometric multi-colour 3D PSF fit (large shifts). The 3D version of SplitterFitFNR'
예제 #4
0
        X = 1e3 * md.voxelsize.x * np.mgrid[(x - roiHalfSize):
                                            (x + roiHalfSize + 1)]
        Y = 1e3 * md.voxelsize.y * np.mgrid[(y - roiHalfSize):
                                            (y + roiHalfSize + 1)]

        return (astigmatic_gaussian(params, X, Y), X[0], Y[0], 0)


# so that fit tasks know which class to use
FitFactory = GaussianFitFactory
#FitResult = GaussianFitResultR
FitResultsDType = fresultdtype  #only defined if returning data as numarray

GPU_PREFIT = True  # fit factory does its own prefit steps on the GPU

import PYME.localization.MetaDataEdit as mde

PARAMETERS = [
    mde.FloatParam('Analysis.ROISize', u'ROI half size', 7.5),
    mde.BoolParam('Analysis.GPUPCTBackground',
                  'Calculate percentile background on GPU', True),
    mde.IntParam(
        'Analysis.DetectionFilterSize', 'Detection Filter Size:', 4,
        'Filter size used for point detection; units of pixels. Should be slightly less than the PSF FWHM'
    ),
]

DESCRIPTION = 'Astigmatic Gaussian fitting performed at warp-speed on the GPU'
LONG_DESCRIPTION = 'Astigmatic Gaussian fitting on the GPU: Fits astigmatic gaussian with sCMOS noise model. Uses it\'s own object detection routine'
USE_FOR = '3D via Astigmatism, with sCMOS noise model'
예제 #5
0
class AnalysisDetailsPanel(wx.Panel):    
    DEFAULT_PARAMS = [mde.FloatParam('Analysis.DetectionThreshold', 'Thresh:', 1.0),
                      mde.IntParam('Analysis.DebounceRadius', 'Debounce rad:', 4),
                      mde.IntParam('Analysis.StartAt', 'Start at:', default=30),
                      mde.RangeParam('Analysis.BGRange', 'Background:', default=(-30,0)),
                      mde.BoolParam('Analysis.subtractBackground', 'Subtract background in fit', default=True),
                      mde.BoolFloatParam('Analysis.PCTBackground' , 'Use percentile for background', default=False, helpText='', ondefault=0.25, offvalue=0),
                      #mde.FilenameParam('Camera.VarianceMapID', 'Variance Map:', prompt='Please select variance map to use ...', wildcard='TIFF Files|*.tif', filename=''),
                      #mde.FilenameParam('Camera.DarkMapID', 'Dark Map:', prompt='Please select dark map to use ...', wildcard='TIFF Files|*.tif', filename=''),
                      #mde.FilenameParam('Camera.FlatfieldMapID', 'Flatfield Map:', prompt='Please select flatfield map to use ...', wildcard='TIFF Files|*.tif', filename=''),
                      mde.BoolParam('Analysis.TrackFiducials', 'Track Fiducials', default=False),
                      mde.FloatParam('Analysis.FiducialThreshold', 'Fiducial Threshold', default=1.8),
    ]
    
    def __init__(self, parent, analysisSettings, mdhChangedSignal=None):
        wx.Panel.__init__(self, parent, -1)

        self.analysisSettings = analysisSettings
        self.analysisMDH = analysisSettings.analysisMDH
        self.mdhChangedSignal = mdhChangedSignal
        
        mdhChangedSignal.connect(self.OnMDChanged)
        
        self._analysisModule = ''
        
        vsizer = wx.BoxSizer(wx.VERTICAL)
        
        vsizer_std = wx.BoxSizer(wx.VERTICAL)
        self._populateStdOptionsPanel(self, vsizer_std)
        vsizer.Add(vsizer_std, 0, wx.EXPAND, 0)
        
        self.customOptionsSizer = wx.BoxSizer(wx.VERTICAL)
        self._populateCustomAnalysisPanel(self, self.customOptionsSizer)
        vsizer.Add(self.customOptionsSizer, 0, wx.EXPAND, 0)
        
        self.SetSizerAndFit(vsizer)
    

    def _populateStdOptionsPanel(self, pan, vsizer):
        for param in self.DEFAULT_PARAMS:
            pg = param.createGUI(pan, self.analysisMDH, syncMdh=True, 
                                 mdhChangedSignal = self.mdhChangedSignal)
            vsizer.Add(pg, 0,wx.BOTTOM|wx.EXPAND, 5)
        vsizer.Fit(pan)
               
        
    def _populateCustomAnalysisPanel(self, pan, vsizer):
        try:
            #fitMod = self.fitFactories[self.cFitType.GetSelection()]
            self._analysisModule = self.analysisMDH['Analysis.FitModule']
            fm = __import__('PYME.localization.FitFactories.' + self._analysisModule, fromlist=['PYME', 'localization', 'FitFactories'])
            
            #vsizer = wx.BoxSizer(wx.VERTICAL)
            for param in fm.PARAMETERS:
                pg = param.createGUI(pan, self.analysisMDH, syncMdh=True, 
                                 mdhChangedSignal = self.mdhChangedSignal)
                vsizer.Add(pg, 0,wx.BOTTOM|wx.EXPAND, 5)
            vsizer.Fit(pan)
            self.Layout()
            self.SetMinSize([200, self.GetBestSize()[1]])
            self.GetParent().Layout()
            print('custom analysis settings populated')
                
        except (KeyError, AttributeError):
            pass
        
    def OnMDChanged(self, event=None, sender=None, signal=None, mdh=None):
        if not self._analysisModule == self.analysisMDH['Analysis.FitModule']:
            self.customOptionsSizer.Clear(True)
            self._populateCustomAnalysisPanel(self, self.customOptionsSizer)
            # FIXME - can't figure out a better way to redo the vertical sizer for longer menus
            self.GetParent().fold1(self)
            self.GetParent().fold1(self)
예제 #6
0
파일: views.py 프로젝트: carandraug/PyME
import logging

import django.forms
from django.http import HttpResponseRedirect
from django.shortcuts import render

logger = logging.getLogger(__name__)

import collections
from PYME.localization import MetaDataEdit as mde
#from PYME.cluster import HTTPTaskPusher
from PYME.cluster import HTTPRulePusher, HTTPTaskPusher

FINDING_PARAMS = [  #mde.ChoiceParam('Analysis.FitModule', 'Fit module:', default='LatGaussFitFR', choices=PYME.localization.FitFactories.resFitFactories),
    mde.FloatParam('Analysis.DetectionThreshold', 'Detection threshold:', 1.0),
    mde.IntParam('Analysis.DebounceRadius', 'Debounce radius:', 4),
    mde.IntParam('Analysis.StartAt', 'Start at:', default=30),
]

BACKGROUND_PARAMS = [  #mde.IntParam('Analysis.StartAt', 'Start at:', default=30),
    mde.RangeParam('Analysis.BGRange', 'Background range:', default=[-30, 0]),
    mde.BoolParam('Analysis.subtractBackground',
                  'Subtract background in fit',
                  default=True),
    mde.BoolFloatParam('Analysis.PCTBackground',
                       'Use percentile for background',
                       default=False,
                       helpText='',
                       ondefault=0.25,
                       offvalue=0),
]