def main(argv):
    i0 = 3.0

    iPulseStrength = 1000000
    resultsFilenamePattern = 'results/integrationINapIKFig4-26PulseStrength%d.npz'
    phaseFigFilename = 'figures/fig4-26PhaseSpace.eps'
    voltageFigFilename = 'figures/fig4-26Voltage.eps'

    plt.figure()
    plotHighThresholdINapIKVectorField(i=i0)
    resultsFilename = resultsFilenamePattern % iPulseStrength
    results = np.load(resultsFilename)
    ys = results["ys"]
    plt.plot(ys[0, :], ys[1, :], label="p=%d" % iPulseStrength)
    plt.grid()
    plt.legend()
    plt.xlabel('Voltage (mv)')
    plt.ylabel('K activation variable, n')
    plt.savefig(phaseFigFilename)

    times = results["times"]
    plt.figure()
    plt.plot(times, ys[0, :], label="p=%d" % iPulseStrength)
    results.close()
    plt.grid()
    plt.legend()
    plt.xlabel('Time (secs)')
    plt.ylabel('Voltage (mv)')
    plt.savefig(voltageFigFilename)

    pdb.set_trace()
Exemplo n.º 2
0
def main(argv):
    i0 = 10
    numberOfPhaseMarks = 8
    annotationGap = 0.02
    resultsFilename = 'results/integrationINapIKFig10_1.npz'
    aFigFilename = 'figures/fig10_1b.eps'

    results = np.load(resultsFilename)
    times = results['times']
    ys = results['ys']
    spikeIndices = getPeakIndices(v=ys[0, :])
    spikeTimes = times[spikeIndices]

    times = np.delete(times, np.arange(0, spikeIndices[0]))
    times = times - times[0]
    ys = np.delete(ys, np.arange(0, spikeIndices[0]), axis=1)
    spikeIndices = spikeIndices - spikeIndices[0]
    spikeTimes = spikeTimes - spikeTimes[0]
    period = spikeTimes[1] - spikeTimes[0]
    phases = times % period
    phasesToPlot = np.arange(0, period, period / numberOfPhaseMarks)
    indicesBtwFirstAndSecondSpike = np.arange(0, spikeIndices[1])
    phasesToSearch = phases[indicesBtwFirstAndSecondSpike]

    indicesPhasesToPlot = np.empty(len(phasesToPlot), dtype=np.int64)
    for i in xrange(len(phasesToPlot)):
        phaseToPlot = phasesToPlot[i]
        indicesPhasesToPlot[i] = np.argmin(np.abs(phasesToSearch -
                                                  phaseToPlot))

    plt.figure()
    plotHighThresholdINapIKVectorField(i=i0)
    plt.plot(ys[0, :], ys[1, :], label="limit cycle attractor")
    plt.plot(ys[0, indicesPhasesToPlot], ys[1, indicesPhasesToPlot], 'ro')
    plt.annotate("0,T",
                 xy=ys[:, 0],
                 xytext=ys[:, indicesPhasesToPlot[0]] + annotationGap,
                 color="red",
                 size=14)
    for i in xrange(1, len(indicesPhasesToPlot)):
        plt.annotate("%d/%dT" % (i, numberOfPhaseMarks),
                     xy=ys[:, indicesPhasesToPlot[i]],
                     xytext=ys[:, indicesPhasesToPlot[i]] + annotationGap,
                     color="red",
                     size=14)
    plt.grid()
    plt.legend(loc="upper left")
    plt.xlabel('Voltage (mv)')
    plt.ylabel('K activation variable, n')
    plt.ylim((-0.1, 0.8))
    plt.savefig(aFigFilename)
    plt.show()

    pdb.set_trace()
Exemplo n.º 3
0
def main(argv):
    integrationFilename = "results/integrationINapIKFig10_10_matching1-1Sync.npz"
    figFilename = "figures/fig10_10b_matching1-1Sync.eps"
    nPhases = 6
    ylim = (-.1, .7)
    fontsize = 20

    integrationRes = np.load(integrationFilename)

    plt.plot(integrationRes["ysDCTrainPulses"][0, :],
             integrationRes["ysDCTrainPulses"][1, :],
             label="train pulses")
    plt.plot(integrationRes["ysDC"][0, :],
             integrationRes["ysDC"][1, :],
             label="DC")
    plotHighThresholdINapIKVectorField(i=integrationRes["i0"])
    plt.xlabel("Membrane Potential (V)")
    plt.ylabel("K activation variable, n")
    plt.ylim(ylim)

    spikeIndices = getPeakIndices(v=integrationRes["ysDCTrainPulses"][0, :])
    spikeTimes = integrationRes["timesDCTrainPulses"][spikeIndices]

    pulseTimes = np.arange(start=integrationRes["tPulse"],
                           stop=spikeTimes[-1],
                           step=integrationRes["Ts"])

    pulseIndices = np.empty(pulseTimes.shape)
    for i in range(len(pulseIndices)):
        pulseIndices[i] = np.argmin(
            np.abs(pulseTimes[i] - integrationRes["timesDCTrainPulses"]))

    for i in range(len(pulseIndices)):
        annotation = r"$\theta_{%d}$" % (i + 1)
        plt.annotate(annotation,
                     xy=(integrationRes["ysDCTrainPulses"][0, pulseIndices[i]],
                         integrationRes["ysDCTrainPulses"][1,
                                                           pulseIndices[i]]),
                     fontsize=fontsize)
    plt.savefig(figFilename)
    plt.show()
    pdb.set_trace()
Exemplo n.º 4
0
def main(argv):
    if len(argv) != 3:
        sys.exit("Usage: %s tauV i0" % argv[0])
    aTauV = float(argv[1])
    i0 = float(argv[2])
    tauV = lambda v: aTauV
    resultsFilename = 'results/integrationINapIKFig6-07TauV%.02fI%.02f.npz' % (
        aTauV, i0)
    phaseFigFilename = 'figures/fig6-07PhaseSpaceTauV%.02fI%.02f.eps' % (aTauV,
                                                                         i0)
    voltageFigFilename = 'figures/fig6-07VoltageTauV%.02fI%.02f.eps' % (aTauV,
                                                                        i0)

    results = np.load(resultsFilename)

    plt.figure()
    plotHighThresholdINapIKVectorField(i=results['i0'])

    plt.plot(results['ys'][0, :], results['ys'][1, :], label="trayectory")
    axes = plt.gca()
    ylim = axes.get_ylim()
    axes.set_ylim((-0.1, ylim[1]))
    plt.grid()
    plt.legend()
    plt.xlabel('Voltage (mv)')
    plt.ylabel('K activation variable, n')
    plt.savefig(phaseFigFilename)

    plt.figure()
    plt.plot(results['times'], results['ys'][0, :])
    results.close()
    plt.grid()
    plt.ylim((-90, -30))
    plt.xlim((0, 100))
    plt.axhline(y=-60.9325 - 11.0, color="black")
    plt.axhline(y=-60.9325 + 11.0, color="black")
    plt.xlabel('Time (msec)')
    plt.ylabel('Voltage (mv)')
    plt.savefig(voltageFigFilename)

    pdb.set_trace()
Exemplo n.º 5
0
def main(argv):
    iPulseStrength = 1000000
    resultsFilenamePattern = 'results/integrationINapIKFig4-23PulseStrength%d.npz'
    phaseFigFilename = 'figures/fig4-23PhaseSpace.eps'
    voltageFigFilename = 'figures/fig4-23Voltage.eps'

    plt.figure()
    plotHighThresholdINapIKVectorField() 
    '''
    plotINapIKVectorField(I=3.0, c=1.0, eL=-80, gL=8, gNa=20, gK=10, 
                                 mVOneHalf=-20, mK=15, 
                                 nVOneHalf=-25, nK=5, tauV=0.152, eNa=60,
                                 eK=-90, nDotScaleFactor=200, 
                                 vMin=-90.0, vMax=20.0, nVs=19, nVsDense=100,
                                 nMin=0.0, nMax=0.7, nNs=18, 
                                 vNullclineLabel="v nullcline",
                                 nNullclineLabel="n nullcline")
    '''
    resultsFilename = resultsFilenamePattern % iPulseStrength
    results = np.load(resultsFilename)
    plt.plot(results['ys'][0, :], results['ys'][1, :],
                                  label="p=%d"%iPulseStrength)
    plt.grid()
    plt.legend()
    plt.xlabel('Voltage (mv)')
    plt.ylabel('K activation variable, n')
    ylim = plt.gca().get_ylim()
    plt.ylim([-0.1, ylim[1]])
    plt.savefig(phaseFigFilename)

    plt.figure()
    plt.plot(results['times'], results['ys'][0, :],
                               label="p=%d"%iPulseStrength)
    results.close()
    plt.grid()
    plt.legend()
    plt.xlabel('Time (secs)')
    plt.ylabel('Voltage (mv)')
    plt.savefig(voltageFigFilename)

    pdb.set_trace()
def main(argv):
    results10_4Filename = 'results/integrationINapIKFig10_4LeftPanel.npz'
    results10_10Filename = 'results/integrationINapIKFig10_10.npz'
    figFilename = 'figures/fig10_10b.eps'
    nPhases = 4
    ylim = (-.1, .7)
    fontsize = 20

    results10_4 = np.load(results10_4Filename)
    results10_10 = np.load(results10_10Filename)

    plt.plot(results10_10["ys"][0, :],
             results10_10["ys"][1, :],
             label="limit cycle pulse")
    plt.plot(results10_4["ysDC"][0, :],
             results10_4["ysDC"][1, :],
             label="limit cycle DC")
    plotHighThresholdINapIKVectorField(i=results10_10["i0"])
    plt.xlabel("Membrane Potential (V)")
    plt.ylabel('K activation variable, n')
    plt.ylim(ylim)

    pulseTimes = results10_10["offset"]+\
                  np.arange(start=0, stop=nPhases, step=1)*results10_10["Ts"]

    pulseIndices = np.empty(pulseTimes.shape)
    for i in range(len(pulseIndices)):
        pulseIndices[i] = np.argmin(
            np.abs(pulseTimes[i] - results10_10["times"]))

    for i in range(len(pulseIndices)):
        annotation = r"$\theta_%d$" % (i + 1)
        plt.annotate(annotation,
                     xy=(results10_10["ys"][0, pulseIndices[i]],
                         results10_10["ys"][1, pulseIndices[i]]),
                     fontsize=fontsize)
    plt.savefig(figFilename)
    plt.show()
    pdb.set_trace()
Exemplo n.º 7
0
def main(argv):
    def integrateForwardManually(deriv, t0, y0, dt, nTSteps):
        ts = np.empty(nTSteps)
        ys = np.empty((len(y0), nTSteps))
        t = t0
        y = y0
        ts[0] = t
        ys[:, 0] = y
        for i in range(1, nTSteps):
            t = t + dt
            y = y + dt * deriv(y=y, t=t)
            print("t=%.02f, V=%.02f, n=%.02f" % (t, y[0], y[1]))
            ts[i] = t
            ys[:, i] = y
        return {"times": ts, "ys": ys}

    def integrateBackwardManually(deriv, t0, y0, dt, nTSteps):
        ts = np.empty(nTSteps)
        ys = np.empty((len(y0), nTSteps))
        t = t0
        y = y0
        ts[0] = t
        ys[:, 0] = y
        for i in range(1, nTSteps):
            t = t - dt
            y = y + dt * deriv(y=y, t=t)
            if y[1] < 0.0:
                y[1] = 0.0
            print("t=%.02f, V=%.02f, n=%.02f" % (t, y[0], y[1]))
            ts[i] = t
            ys[:, i] = y
        return {"times": ts, "ys": ys}

    epsilon = 1e-6
    # v0 = 10.00
    v0 = -61.0
    n0 = 0.48110
    t0 = 0.0
    # tf = 1*7.25
    tf = 1 * 7.25
    dt = 1e-3
    nTSteps = int(round((tf - t0) / dt))
    i0 = 10

    def i(t):
        return (i0)

    iNapIKModel = INapIKModel.getHighThresholdInstance()
    iNapIKModel.setI(i=i)
    # n0 = iNapIKModel._nInf(v=v0)

    y0 = np.array([v0, n0])
    # res = integrateForward(deriv=iNapIKModel.deriv, t0=t0, y0=y0, dt=dt, nTSteps=nTSteps)
    res = integrateBackward(deriv=iNapIKModel.deriv,
                            t0=tf,
                            y0=y0,
                            dt=dt,
                            nTSteps=nTSteps)
    # res = integrateForwardManually(deriv=iNapIKModel.deriv, t0=t0, y0=y0, dt=dt, nTSteps=nTSteps)
    # res = integrateBackwardManually(deriv=iNapIKModel.deriv, t0=tf, y0=y0, dt=dt, nTSteps=nTSteps)
    plt.plot(res["times"], res["ys"][0, :])
    plt.xlabel("Time (sec)")
    plt.ylabel("Voltage (mV)")
    plt.ylim((-100, 20))

    plt.figure()
    plotHighThresholdINapIKVectorField(i=i0)
    plt.plot(res["ys"][0, :], res["ys"][1, :], label="limit cycle attractor")
    plt.xlim((-100, 20))
    plt.xlabel('Voltage (mv)')
    plt.ylabel('K activation variable, n')

    plt.show()
    pdb.set_trace()
def main(argv):
    indexPhaseX0 = 10
    numberOfPhasesForX0 = 40
    i0 = 10
    nSPLUNew = 1000
    vMin = -90
    vMax = 15
    nMin = -0.1
    nMax = 0.8
    marginStart = "minX"
    integrationFilename = "results/integrationINapIKFig10_1.npz"
    isochronFilename = \
     "results/isochronINapIKFig10_1Phase%02dOver%d.npz"%(indexPhaseX0, 
                                                        numberOfPhasesForX0)
    figFilename = \
     "figures/isochronINapIKFig10_1Phase%02dOver%d.eps"%(indexPhaseX0, 
                                                        numberOfPhasesForX0)

    results = np.load(integrationFilename)
    times = results["times"]
    ys = results["ys"]
    spikeIndices = getPeakIndices(v=ys[0,:])
    spikeTimes = times[spikeIndices]

    times = np.delete(times, np.arange(0,spikeIndices[0]))
    times = times-times[0]
    ys = np.delete(ys, np.arange(0,spikeIndices[0]), axis=1)
    spikeIndices = spikeIndices-spikeIndices[0]
    spikeTimes = spikeTimes-spikeTimes[0]
    period = spikeTimes[1]-spikeTimes[0]
    phases = times%period
    phasesForX0 = np.arange(0, period, period/numberOfPhasesForX0)
    indicesBtwFirstAndSecondSpike = np.arange(0, spikeIndices[1])
    phasesToSearch = phases[indicesBtwFirstAndSecondSpike]

    indicesPhasesForX0 = np.empty(len(phasesForX0), dtype=np.int64)
    for i in xrange(len(phasesForX0)):
        phaseForX0 = phasesForX0[i]
        indicesPhasesForX0[i] = np.argmin(np.abs(phasesToSearch-phaseForX0))
    x0 = ys[:, indicesPhasesForX0[indexPhaseX0]]

    results = np.load(isochronFilename)
    isochron = results["isochron"]

    validIndices = np.logical_and(np.logical_and(vMin<=isochron[0,:], 
                                                  isochron[0,:]<=vMax),
                                   np.logical_and(nMin<=isochron[1,:], 
                                                   isochron[1,:]<=nMax)).nonzero()[0]
    isochron = isochron[:,validIndices]

#     sortedIsochron = sortIsochron(isochron=isochron, marginStart=marginStart)

#     splTck, splU = splprep(sortedIsochron, s=5.0)
#     splUNew = np.linspace(splU.min(), splU.max(), nSPLUNew)
#     splXInter, splYInter = splev(splUNew, splTck, der=0)

    # plt.figure()
    plotHighThresholdINapIKVectorField(i=i0)
    plt.plot(ys[0, :], ys[1, :], label="limit cycle attractor")
    # pdb.set_trace()

    plt.annotate("x0", xy=x0, color="red", size=14)

    def i(t):
        return(i0)
    model = INapIKModel.getHighThresholdInstance(i=i)
#     plotINapIKNullclines(i=i0, eL=model._eL, gL=model._gL, eNa=model._eNa, gNa=model._gNa, eK=model._eK, gK=model._gK, mVOneHalf=model._mVOneHalf, mK=model._mK, nVOneHalf=model._nVOneHalf, nK=model._nK)
    plt.plot(isochron[0,:], isochron[1,:], marker="o", color="lightgray",
                            linestyle="-")
#     plt.plot(splXInter, splYInter, color="gray", linestyle="solid")
    plt.legend(loc="upper left")
    plt.xlabel("Voltage (mv)")
    plt.ylabel("K activation variable, n")
    plt.xlim((-90, 15))
    plt.ylim((-0.1, 0.8))
    plt.savefig(figFilename)
    plt.show()
    pdb.set_trace()