def viscLifetimes(viscs):
    from PYME.Analysis._fithelpers import *

    plt.figure()

    constants = {'q': 1e-6, 'O2': 0.1 * air_sat_O2_conc}
    I = Stimulus(I0, [1e6], [0])

    tXs = []
    tRs = []

    for i in range(len(viscs)):
        visc = viscs[i]
        visc2 = visc

        if visc <= 10:
            t = np.linspace(1, 10e6, 10000)
        else:
            t = np.linspace(1, 10e6, 1000)

        r = genReactionScheme(visc, visc2)

        s = System(r,
                   constants=constants,
                   ties={'S1': ('I', 'S0')},
                   stimulae={'I': I})  #
        s.GenerateGradAndJacCode()
        s.initialConditions[
            'S0'] = 1e-3  #conc of fluorophores on an antibody ~ 100M

        res = s.solve(t)

        r1 = FitModel(emod, [1e-3, 3], res['X'][t > 1e6], t[t > 1e6] / 1e6 - 1)
        tXs.append(r1[0][1])

        r1 = FitModel(emod, [1e-3, 3], res['R'][t > 1e6], t[t > 1e6] / 1e6 - 1)
        tRs.append(r1[0][1])

    plt.loglog(viscs, tXs, label='X', lw=2)
    plt.loglog(viscs, tRs, label='R', lw=2)

    plt.ylabel('Time constant [$s^{-1}$]')

    plt.legend()
def stateLifetimes(spec, concs):
    from PYME.Analysis._fithelpers import FitModel

    figure()

    constants={'q':10e-3, 'O2':0.1*air_sat_O2_conc}
    I = Stimulus(0, [], [])

    t = linspace(1, 10e6, 1000)

    tXs = []
    tRs = []

    nConc = constants[spec]

    for i in range(len(concs)):
        constants[spec] = concs[i]

        s = System(r,constants=constants, ties={'S1':('I', 'S0')},stimulae={'I':I})#
        s.GenerateGradAndJacCode()
        #s.initialConditions['S0'] = 1e-3 #conc of fluorophores on an antibody ~ 100M
        s.initialConditions['X'] = 1e-3
        s.initialConditions['R'] = 1e-3

        res = s.solve(t)

        r1 = FitModel(emod, [1e-3, 3], res['X'], t/1e6)
        tXs.append(r1[0][1])

        r1 = FitModel(emod, [1e-3, 3], res['R'], t/1e6)
        tRs.append(r1[0][1])

        print(max(tXs[-1], tRs[-1]))
        #t = linspace(1, 5e6*max(max(tXs[-1], tRs[-1]), 1e-3), 1000)

    loglog(concs, tXs, label='X', lw=2)
    loglog(concs, tRs, label='R', lw=2)

    plot([nConc, nConc], ylim(), 'k--')

    ylabel('Time constant [s]')
    xlabel('[%s]' % spec)

    legend()
def dyeConc(concs):
    from PYME.Analysis._fithelpers import FitModel

    plt.figure()

    constants = {'q': 0, 'O2': 0}
    I = Stimulus(I0, [], [])

    t = np.linspace(1, 1e6, 1000)

    tXs = []
    tRs = []

    s = System(r,
               constants=constants,
               ties={'S1': ('I', 'S0')},
               stimulae={'I': I})  #
    s.GenerateGradAndJacCode()

    for i in range(len(concs)):
        s.initialConditions['S0'] = concs[
            i]  #conc of fluorophores on an antibody ~ 100M

        res = s.solve(t)

        r1 = FitModel(emod, [1e-3, 3], res['X'][t > 1e6], t[t > 1e6] / 1e6 - 1)
        tXs.append(r1[0][1])

        r1 = FitModel(emod, [1e-3, 3], res['R'][t > 1e6], t[t > 1e6] / 1e6 - 1)
        tRs.append(r1[0][1])

    plt.loglog(concs, tXs, label='X', lw=2)
    plt.loglog(concs, tRs, label='R', lw=2)

    plt.ylabel('Time constant [$s^{-1}$]')

    plt.legend()
Beispiel #4
0
def FitJumpSizeDist(velocities, startParams, dT):
    from PYME.Analysis._fithelpers import FitModel

    N = len(velocities)

    plt.figure()

    h, b, _ = plt.hist(velocities, 200)

    x = b[1:]
    dx = x[1] - x[0]

    r = FitModel(jumpDistModel, startParams, h, x, N, dT, dx)

    plt.plot(x, jumpDistModel(r[0], x, N, dT, dx), lw=2)

    fT = 0

    for i in range(len(startParams) / 2):
        D, f = r[0][(2 * i):(2 * i + 2)]

        plt.plot(x,
                 N * f * jumpDistProb(x, D, dT) * dx,
                 '--',
                 lw=2,
                 label='D = %3.2g, f=%3.2f' % (D, f))
        fT += f

    D = r[0][-1]
    plt.plot(x,
             N * (1 - fT) * jumpDistProb(x, D, dT) * dx,
             '--',
             lw=2,
             label='D = %3.2g, f=%3.2f' % (D, (1 - fT)))

    plt.xlabel('Jump Size [nm]')
    plt.ylabel('Frequency')
    plt.legend()

    return r
Beispiel #5
0
    def msdinfo(self):
        if not '_msdinfo' in dir(self):
            from PYME.Analysis.points.DistHist import msdHistogram
            from PYME.Analysis._fithelpers import FitModel

            x = self['x']
            y = self['y']
            t = self['t']

            dt = self.pipeline.mdh.getOrDefault('Camera.CycleTime', 1.0)

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

            h = msdHistogram(x, y, t, nT)
            t_ = dt * np.arange(len(h))

            res = FitModel(powerMod2D, [h[-1] / t_[-1], 1.], h[1:], t_[1:])
            D, alpha = res[0]

            #calculate the diffusion coefficient for normal (not anomolous diffusion)
            #restrict to the first 100 bins to try and minimise effects of drift
            #fit an offset to take localization precision into account
            D_ = float(
                np.linalg.lstsq(
                    np.vstack([t_[1:100], np.ones_like(t_[1:100])]).T,
                    h[1:100])[0][0] / 4)

            self._msdinfo = {
                't': t_,
                'msd': h,
                'D': D,
                'alpha': alpha,
                'Dnormal': D_
            }

        return self._msdinfo
Beispiel #6
0
def FitTrace(tr, mdh):
    # from pylab import *
    import matplotlib.pyplot as plt
    #tr = (ds - mdh.getEntry('Camera.ADOffset')).sum(1).sum(0)

    cycTime = mdh.getEntry('Camera.CycleTime')
    t = cycTime * np.arange(len(tr))

    plt.figure()
    plt.plot(t, tr)

    yp = -.1 * tr.max()

    y1 = tr[61:80]

    r1 = FitModel(kinModels.e3mod, [y1[0], 1.0, 0], y1,
                  cycTime * np.arange(len(y1)))

    plt.plot(t[61:80],
             kinModels.e3mod(r1[0], cycTime * np.arange(len(y1))),
             lw=2)
    plt.text(t[65], yp, '%3.2fs' % r1[0][1])

    y2 = tr[81:1500]
    r2 = FitModel(intensProf.eMod5, [y2[-1], -50, 50], y2,
                  cycTime * np.arange(len(y2)))

    plt.plot(t[81:1500],
             intensProf.eMod5(r2[0], cycTime * np.arange(len(y2))),
             lw=2)
    plt.text(t[700], yp, '%3.2fs' % r2[0][2])

    y3 = tr[1501:1600]

    r3 = FitModel(kinModels.e3mod, [y3[0], 1.0, 0], y3,
                  cycTime * np.arange(len(y3)))

    plt.plot(t[1501:1600],
             kinModels.e3mod(r3[0], cycTime * np.arange(len(y3))),
             lw=2)
    plt.text(t[1520], yp, '%3.2fs' % r3[0][1])

    #    y4 = tr[1601:2500]
    #    r4 = FitModel(intensProf.eMod5, [y4[-1], -50, 50], y4, cycTime*arange(len(y4)))
    #
    #    plot(t[1601:2500], intensProf.eMod5(r4[0], cycTime*arange(len(y4))), lw=2)
    #    text(t[1900], yp, '$\\tau = %3.2fs$'%r4[0][2])

    y5 = tr[2502:2600]
    r5 = FitModel(kinModels.e3mod, [y5[0], 1.0, 0], y5,
                  cycTime * np.arange(len(y5)))

    plt.plot(t[2502:2600],
             kinModels.e3mod(r5[0], cycTime * np.arange(len(y5))),
             lw=2)
    plt.text(t[2520], yp, '%3.2fs' % r5[0][1])

    y6 = tr[3502:3600]
    r6 = FitModel(kinModels.e3mod, [y6[0], 1.0, 0], y6,
                  cycTime * np.arange(len(y6)))

    plt.plot(t[3502:3600],
             kinModels.e3mod(r6[0], cycTime * np.arange(len(y6))),
             lw=2)
    plt.text(t[3520], yp, '%3.2fs' % r6[0][1])