Exemple #1
0
def fit(frame_nums, model='q2'):
    t, c = get_offtime_cdf(frame_nums)

    if (model == 'q2'):
        res = fh.FitModel(qpaint2mod, np.sqrt([0.5, 3.5, 500.]), c, t)
    
    else:
        res = fh.FitModel(qpaint1mod, np.sqrt([500., ]), c, t)
    
    return res[0]**2
Exemple #2
0
 def OnGaussianFit(self, event):
     import PYME.Analysis._fithelpers as fh
     
     def gmod(p,x):
         A, x0, sig, b = p
         
         return A*pylab.exp(-(x-x0)**2/(2*sig**2)) + b
     
     pylab.figure()
     
     cols = ['b','g','r']
     xv = self.image.xvals
     
     for chan in range(self.image.data.shape[3]):    
         I = self.image.data[:,0,0, chan].squeeze().astype('f')
         
         res = fh.FitModel(gmod, [I.max()-I.min(), xv[I.argmax()], xv[1] - xv[0], I.min()], I, xv)
         
         pylab.plot(xv, I, cols[chan] + 'x', label=self.image.names[chan])
         pylab.plot(xv, gmod(res[0], self.image.xvals), cols[chan], label='%2.3g, %2.3g, \n%2.3g, %2.3g' % tuple(res[0]))
         
         print((res[0]))
         #imo = self.image.parent
     pylab.legend()
     #rawIntensity.processIntensityTrace(I, imo.mdh, dt=imo.mdh['Camera.CycleTime'])
     pylab.show()
Exemple #3
0
def plot_and_fit(frame_nums, model='q2'):
    import matplotlib.pyplot as plt
    
    plt.figure(figsize=(6, 3))
    plt.subplot(121)
    
    t, c = get_offtime_cdf(frame_nums)
    
    plt.plot(t, c, 'x')

    t_ = np.logspace(0, np.log10(t.max()))
    
    if (model == 'q2'):
        res = fh.FitModel(qpaint2mod, np.sqrt([0.5, 3.5, 500.]), c, t)
        
        f = qpaint2mod(res[0], t_)
    else:
        res = fh.FitModel(qpaint1mod, np.sqrt([500.,]), c, t)
        
        f = qpaint1mod(res[0], t_)
    
    plt.plot(t_, f)
    plt.grid()
    
    print(res[0]**2)
    
    #plt.semilogy()

    #plt.figure()
    plt.subplot(122)
    plt.plot(t, 1-c, 'x')
    plt.plot(t_, 1- f)
    
    plt.semilogy()
    
    plt.ylim((1-c).min(), 1)
    
    plt.grid()
    
    return res[0]**2
    
    
    #plt.plot()



        
    def OnCalcMSDs(self, event=None):
        #TODO - move this logic to reports - like dh5view module
        # import pylab
        import matplotlib.pyplot as plt
        from PYME.Analysis import _fithelpers as fh
        from PYME.Analysis.points.DistHist import msdHistogram

        def powerMod(p,t):
            D, alpha = p
            return 4*D*t**alpha #factor 4 for 2D (6 for 3D)
            
        pipeline = self.visFr.pipeline

        clumps = set(pipeline['clumpIndex'])

        dt = pipeline.mdh.getEntry('Camera.CycleTime')


        Ds = np.zeros(len(clumps))
        Ds_ =  np.zeros(pipeline['x'].shape)
        alphas = np.zeros(len(clumps))
        alphas_ =  np.zeros(pipeline['x'].shape)
        error_Ds = np.zeros(len(clumps))

        plt.figure()

        for i, ci in enumerate(clumps):
            I = pipeline['clumpIndex'] == ci

            x = pipeline['x'][I]
            y = pipeline['y'][I]
            t = pipeline['t'][I]

            nT = int((t.max() - t.min())/2)


            h = msdHistogram(x, y, t, nT)

            t_ = dt*np.arange(len(h))

            plt.plot(t_, h)

            res = fh.FitModel(powerMod, [h[-1]/t_[-1], 1.], h, t_)

            Ds[i] = res[0][0]
            Ds_[I] = res[0][0]
            alphas[i] = res[0][1]
            alphas_[I] = res[0][1]

            print((res[0]))#, res[1]
            if not res[1] is None:
                error_Ds[i] = np.sqrt(res[1][0,0])
            else:
                error_Ds[i] = -1e3

        plt.figure()
        plt.scatter(Ds, alphas)

        pipeline.addColumn('diffusionConst', Ds_, -1)
        pipeline.addColumn('diffusionExp', alphas_)

        pipeline.Rebuild()