Beispiel #1
0
def runonce(x, P):
    # print("Round " + str(P4F["freq"][x]) + ", cond: " + str(x))
    thisdur = (P["dur"][x] - 5.0) / 1000.0
    SO = seh.create_sound(
        fs=100e3, freq=P["freq"][x], duration=thisdur, dbspl=P["dB"][x]
    )
    SP = seh.create_spk(SO, fs=100e3, N=P["Nsyn"][x], cf=P["cf"][x], seed=2121977)
    S = np.array(SP["spikes"] * 1000.0)
    R = sem.SE_BS(
        S,
        Simdur=P["dur"][x],
        dt=P["dt"][x],
        G_EoH=P["G_EoH"][x],
        StochasticEoH=P["Stochastic_EoH"][x],
        N=P["Nsyn"][x],
        G_Dend=P["gsyn"][x],
        tau_Dend=P["tau_dendsyn"][x],
        L=P["L"][x],
        D=P["D"][x],
        constR=P["constR"][x],
        gKLT_d=P["gKLT_d"][x],
        gIH_d=P["gIH_d"][x],
        gLEAK_d=P["gLEAK_d"][x],
    )
    Ev = seh.SimpleDetectAP(R["Vm"], thr=-100, dt=P["dt"][x], LM=-20, RM=10)
    SAPr = len(Ev["PeakT"]) / (P["dur"][x] / 1000.0)
    sav, sst, Smeanv, Stdv, Smodv = average_over_cyle(
        D=R["Vm"], freq=P["freq"][x], dt=P["dt"][x], dur=P["dur"][x]
    )
    #
    return [SAPr, Smeanv, Smodv]
Beispiel #2
0
def runonce(x, P):
    ####GENERATE SPIKE INPUTS (the spiketimes are always the same to improve comparability)
    thisdur = (P["dur"][x] - 5.0) / 1000.0
    N = P["Nsyn"][x]
    anf_num = (N + 1, 0, 0)
    SO = seh.create_sound(
        fs=100e3, freq=P["freq"][x], duration=thisdur, dbspl=P["dB"][x]
    )
    SP = seh.create_spk(
        SO, fs=100e3, N=P["Nsyn"][x] + 1, cf=P["cf"][x], seed=65564 + x, anf_num=anf_num
    )  # generate enough spiketrains
    S = np.array(SP["spikes"] * 1000.0)
    # somaticsynapsesonly=0,
    R0 = sem.SE_BS(
        S,
        Simdur=P["dur"][x],
        dt=P["dt"][x],
        G_EoH=P["G_EoH"][x],
        StochasticEoH=P["Stochastic_EoH"][x],
        N=P["Nsyn"][x],
        G_Dend=0.0,
        L=P["L"][x],
        D=P["D"][x],
        constR=P["constR"][x],
        gKLT_d=P["gKLT_d"][x],
        gIH_d=P["gIH_d"][x],
        gLEAK_d=P["gLEAK_d"][x],
        somaticsynapsesonly=P["synapselocationtype"][x],
    )
    RD = sem.SE_BS(
        S,
        Simdur=P["dur"][x],
        dt=P["dt"][x],
        G_EoH=P["G_EoH"][x],
        StochasticEoH=P["Stochastic_EoH"][x],
        N=P["Nsyn"][x],
        G_Dend=P["gsyn"][x],
        L=P["L"][x],
        D=P["D"][x],
        constR=P["constR"][x],
        gKLT_d=P["gKLT_d"][x],
        gIH_d=P["gIH_d"][x],
        gLEAK_d=P["gLEAK_d"][x],
        somaticsynapsesonly=P["synapselocationtype"][x],
    )
    Ev0 = seh.SimpleDetectAP(R0["Vm"], thr=-100, dt=P["dt"][x], LM=-20, RM=10)
    EvD = seh.SimpleDetectAP(RD["Vm"], thr=-100, dt=P["dt"][x], LM=-20, RM=10)
    APr0 = len(Ev0["PeakT"]) / (P["dur"][x] / 1000.0)
    APrD = len(EvD["PeakT"]) / (P["dur"][x] / 1000.0)
    VS0, phi0, R0, phases0 = seh.vectorstrength(
        Ev0["PeakT"], P["freq"][x], [0.0, P["dur"][x]]
    )
    VSD, phiD, RD, phasesD = seh.vectorstrength(
        EvD["PeakT"], P["freq"][x], [0.0, P["dur"][x]]
    )
    print((str(x)))
    return [VS0, phi0, R0, APr0, VSD, phiD, RD, APrD]
Beispiel #3
0
def runonce(x, P):
    print(x)
    ####MODEL INPUT = SOUND
    thisdur = (P["dur"][x] - 5.0) / 1000.0
    SO = seh.create_sound(fs=100e3,
                          freq=P["freq"][x],
                          duration=thisdur,
                          dbspl=P["dB"][x])
    SP = seh.create_spk(SO,
                        fs=100e3,
                        N=P["Nsyn"][x],
                        cf=P["cf"][x],
                        seed=2121977)  # generate enough spiketrains
    S = np.array(SP["spikes"] * 1000.0)
    R = sem.SE_BS(
        S,
        Simdur=P["dur"][x],
        dt=P["dt"][x],
        G_EoH=P["G_EoH"][x],
        StochasticEoH=P["Stochastic_EoH"][x],
        N=P["Nsyn"][x],
        G_Dend=P["gsyn"][x],
        tau_Dend=P["tau_dendsyn"][x],
        L=P["L"][x],
        D=P["D"][x],
        constR=P["constR"][x],
        gKLT_d=P["gKLT_d"][x],
        gIH_d=P["gIH_d"][x],
        gLEAK_d=P["gLEAK_d"][x],
    )
    Ev = seh.SimpleDetectAP(R["Vm"], thr=-100, dt=P["dt"][x], LM=-20, RM=10)
    SAPr = len(Ev["PeakT"]) / (P["dur"][x] / 1000.0)
    sav, sst, Smeanv, Stdv, Smodv = average_over_cyle(D=R["Vm"],
                                                      freq=P["freq"][x],
                                                      dt=P["dt"][x],
                                                      dur=P["dur"][x])
    #
    # save example data (if required)
    if P["save_examples"] and np.any(P["which_example_to_save"] == x):
        XT = {}
        XT["Sound"] = R["Vm"]
        XT["Av_Sound"] = sav
        XT["St_Sound"] = sst
        thisfn = P["Example_PN"] + P["Example_FN"] + str(x) + ".npy"
        np.save(thisfn, XT, allow_pickle=True)
    #
    return [SAPr, Smeanv, Smodv]
Beispiel #4
0
def runmain():
    simdur = 400.0  # 1000
    dt = 0.01
    N = 32
    freq = 1450.0
    cf = 1501.0
    db = 70  # 70?
    SO = seh.create_sound(fs=100e3,
                          freq=freq,
                          duration=(simdur * 0.6) / 1000.0,
                          dbspl=db)
    Silence = seh.create_sound(fs=100e3,
                               freq=freq,
                               duration=(simdur * 0.4) / 1000.0,
                               dbspl=-10)
    SP = seh.create_spk(
        np.concatenate((SO, Silence)),
        fs=100e3,
        N=N + 1,
        cf=cf,
        seed=65562,
        anf_num=(N, 0, 0),
    )
    S = np.array(SP["spikes"] * 1000.0)
    R32Som = sem.SE_BS(
        S,
        Simdur=simdur,
        dt=dt,
        G_EoH=0.055,
        StochasticEoH=True,
        N=N,
        G_Dend=0.016,
        EoHseed=8347236,
        somaticsynapsesonly=1,
    )
    R32 = sem.SE_BS(
        S,
        Simdur=simdur,
        dt=dt,
        G_EoH=0.055,
        StochasticEoH=True,
        N=N,
        G_Dend=0.016,
        EoHseed=8347236,
    )
    R0 = sem.SE_BS(
        S,
        Simdur=simdur,
        dt=dt,
        G_EoH=0.055,
        StochasticEoH=True,
        N=N,
        G_Dend=0.0,
        EoHseed=8347236,
    )

    R3d_32 = sem.SE_3D(
        S,
        Simdur=simdur,
        dt=dt,
        G_EoH=0.055,
        StochasticEoH=True,
        N=N,
        G_Dend=0.064,
        EoHseed=8347236,
    )
    R3d_32som = sem.SE_3D(
        S,
        Simdur=simdur,
        dt=dt,
        G_EoH=0.055,
        StochasticEoH=True,
        N=N,
        G_Dend=0.064,
        EoHseed=8347236,
        somaticsynapsesonly=1,
    )
    R3d_0 = sem.SE_3D(
        S,
        Simdur=simdur,
        dt=dt,
        G_EoH=0.055,
        StochasticEoH=True,
        N=N,
        G_Dend=0.0,
        EoHseed=8347236,
    )
    T = np.linspace(0, simdur - dt, int(round(simdur / dt)))

    fh = plt.figure()
    sp1 = fh.add_subplot(4, 1, 1)
    sp1.set_title("Stylized Dendrite")
    sp1.plot(T, R0["Vm"], "b-", linewidth=0.5, label="0nS")
    sp1.plot(T, R32["Vm"], "g-", linewidth=0.5, label="16nS")
    sp1.set_ylabel("Vm (mV)")
    sp1.set_xlabel("Time (ms)")
    sp1.plot(T, (np.concatenate((SO, Silence)) * 75) - 75.0,
             color="g",
             linewidth=0.5)
    sp1.legend()

    sp2 = fh.add_subplot(4, 1, 2)
    sp2.plot(T, R32["Vm"], "g-", linewidth=0.5, label="Dendritic")
    sp2.plot(T, R32Som["Vm"], "r-", linewidth=0.5, label="Somatic")
    sp2.plot(T, (np.concatenate((SO, Silence)) * 75) - 75.0,
             color="g",
             linewidth=0.5)
    sp2.set_ylabel("Vm (mV)")
    sp2.set_xlabel("Time (ms)")
    sp2.spines["top"].set_visible(False)
    sp2.spines["right"].set_visible(False)
    sp2.legend()

    sp3 = fh.add_subplot(4, 1, 3)
    sp3.set_title("3D Dendrite")
    sp3.plot(T, R3d_0["Vm"], "b-", linewidth=0.5, label="0nS")
    sp3.plot(T, R3d_32["Vm"], "g-", linewidth=0.5, label="32nS")
    sp3.plot(T, (np.concatenate((SO, Silence)) * 75) - 75.0,
             color="g",
             linewidth=0.5)
    sp3.set_ylabel("Vm (mV)")
    sp3.set_xlabel("Time (ms)")
    sp3.spines["top"].set_visible(False)
    sp3.spines["right"].set_visible(False)
    sp3.legend()

    sp4 = fh.add_subplot(4, 1, 4)
    sp4.plot(T, R3d_32["Vm"], "g-", linewidth=0.5, label="Dendritic")
    sp4.plot(T, R3d_32som["Vm"], "r-", linewidth=0.5, label="Somatic")
    sp4.plot(T, (np.concatenate((SO, Silence)) * 75) - 75.0,
             color="g",
             linewidth=0.5)
    sp4.set_ylabel("Vm (mV)")
    sp4.set_xlabel("Time (ms)")
    sp4.spines["top"].set_visible(False)
    sp4.spines["right"].set_visible(False)
    sp4.legend()

    plt.tight_layout()
    plt.show()
Beispiel #5
0
def runonce(x, P):
    ####hard coded settings, rarely change these:
    APdetect_thr = -75
    ####GENERATE SPIKE INPUTS (the spiketimes are always the same to improve comparability)
    thisdur = (P["dur"][x] - 5.0) / 1000.0
    N = P["Nsyn"][x] + 1
    anf_num = (N, 0, 0)
    if P["AdvZseed"]:
        thisZseed = P["Zseed"] + x
    else:
        thisZseed = P["Zseed"]
    if P["AdvEoHseed"]:
        thisEoHseed = P["EoHseed"] + x
    else:
        thisEoHseed = P["EoHseed"]
    SO = seh.create_sound(fs=100e3,
                          freq=P["freq"][x],
                          duration=thisdur,
                          dbspl=P["dB"][x])
    SP = seh.create_spk(SO,
                        fs=100e3,
                        N=N,
                        cf=P["cf"][x],
                        seed=thisZseed,
                        anf_num=anf_num)  # generate enough spiketrains
    S = np.array(SP["spikes"] * 1000.0)
    R0 = sem.SE_3D(
        S,
        Simdur=P["dur"][x],
        dt=P["dt"][x],
        G_EoH=P["G_EoH"][x],
        StochasticEoH=P["Stochastic_EoH"][x],
        N=P["Nsyn"][x],
        G_Dend=P["gsyn"][x] * 0.0,  # set dendritic synapses to zero
        tau_Dend=P["tau_dendsyn"][x],
        gKLT_d=P["gKLT_d"][x],
        gIH_d=P["gIH_d"][x],
        gLEAK_d=P["gLEAK_d"][x],
        cell=P["cell"][x],
        EoHseed=thisEoHseed,
        somaticsynapsesonly=P["synapselocationtype"][x],
    )
    #
    RD = sem.SE_3D(
        S,
        Simdur=P["dur"][x],
        dt=P["dt"][x],
        G_EoH=P["G_EoH"][x],
        StochasticEoH=P["Stochastic_EoH"][x],
        N=P["Nsyn"][x],
        G_Dend=P["gsyn"][x],
        tau_Dend=P["tau_dendsyn"][x],
        gKLT_d=P["gKLT_d"][x],
        gIH_d=P["gIH_d"][x],
        gLEAK_d=P["gLEAK_d"][x],
        cell=P["cell"][x],
        EoHseed=thisEoHseed,
        somaticsynapsesonly=P["synapselocationtype"][x],
    )
    Ev0 = seh.SimpleDetectAP(R0["Vm"],
                             thr=APdetect_thr,
                             dt=P["dt"][x],
                             LM=-20,
                             RM=10)
    EvD = seh.SimpleDetectAP(RD["Vm"],
                             thr=APdetect_thr,
                             dt=P["dt"][x],
                             LM=-20,
                             RM=10)
    APr0 = len(Ev0["PeakT"]) / (P["dur"][x] / 1000.0)
    APrD = len(EvD["PeakT"]) / (P["dur"][x] / 1000.0)
    VS0, phi0, Ray0, phases0 = seh.vectorstrength(Ev0["PeakT"], P["freq"][x],
                                                  [0.0, P["dur"][x]])
    VSD, phiD, RayD, phasesD = seh.vectorstrength(EvD["PeakT"], P["freq"][x],
                                                  [0.0, P["dur"][x]])
    print((str(x)))
    return [VS0, phi0, Ray0, APr0, VSD, phiD, RayD, APrD]
Beispiel #6
0
def runonce(x, P):
    ####GENERATE SPIKE INPUTS (the spiketimes are always the same)
    # generate dendrite spiketimes (always the same)
    thisdur = (P["dur"][x] - 5.0) / 1000.0
    SO = seh.create_sound(fs=100e3,
                          freq=P["freq"][x],
                          duration=thisdur,
                          dbspl=P["dB"][x])
    SP = seh.create_spk(SO,
                        fs=100e3,
                        N=P["Nsyn"][x],
                        cf=P["cf"][x],
                        seed=3433833)  # generate enough spiketrains
    cycledur = 1.0 / P["freq"][x]
    shift = cycledur * 100.0  # we wait 100 cycle durations to start with the EoH
    currlen = len(SP)
    # SP.loc[currlen] = [
    #    SP.loc[currlen - 1][0],
    #    SP.loc[currlen - 1][1],
    #    np.array((shift + P["EoH_Time"][x],)),
    #    SP.loc[currlen - 1][3],
    # ]
    SP.loc[currlen] = [
        np.array((shift + P["EoH_Time"][x], )),
        SP.loc[currlen - 1][1],
        SP.loc[currlen - 1][2],
        SP.loc[currlen - 1][3],
    ]
    S = np.array(SP["spikes"] * 1000.0)
    R0 = sem.SE_BS(
        S,
        Simdur=P["dur"][x],
        dt=P["dt"][x],
        G_EoH=P["G_EoH"][x],
        StochasticEoH=P["Stochastic_EoH"][x],
        N=P["Nsyn"][x],
        G_Dend=0.0,
        tau_Dend=P["tau_dendsyn"][x],
        L=P["L"][x],
        D=P["D"][x],
        constR=P["constR"][x],
        gKLT_d=P["gKLT_d"][x],
        gIH_d=P["gIH_d"][x],
        gLEAK_d=P["gLEAK_d"][x],
        EoHseed=65232,
    )
    R = sem.SE_BS(
        S,
        Simdur=P["dur"][x],
        dt=P["dt"][x],
        G_EoH=P["G_EoH"][x],
        StochasticEoH=P["Stochastic_EoH"][x],
        N=P["Nsyn"][x],
        G_Dend=P["gsyn"][x],
        tau_Dend=P["tau_dendsyn"][x],
        L=P["L"][x],
        D=P["D"][x],
        constR=P["constR"][x],
        gKLT_d=P["gKLT_d"][x],
        gIH_d=P["gIH_d"][x],
        gLEAK_d=P["gLEAK_d"][x],
        EoHseed=65232,
    )
    print((str(P["G_EoH"][x]) + " " + str(P["gsyn"][x]) + " " + str(x)))
    return [R0["Vm"], R["Vm"]]
Beispiel #7
0
def mkexampletraces():
    """
    As per reviewer request we generate example traces for two extreme conditions,
    one at N=32 and g=0.06 (negative effect on rate) and one at N=32 and g=0.03
    (positive effect on rate).
    """
    dur = 5000.0
    dur_s = dur / 1000.0
    dt = 0.01
    freq = 1389.0
    cf = 1501.0
    dB = 65.0
    zseed = 45453
    eohseed = 34823
    stocheoh = True
    geoh = 0.55
    L = 50.0
    D = 3.0
    N = 32
    anf_num = (N + 1, 0, 0)
    kltd = 0.0085
    hd = 0.001
    ld = 0.001
    SO = seh.create_sound(fs=100e3, freq=freq, duration=dur_s, dbspl=dB)
    SP = seh.create_spk(SO,
                        fs=100e3,
                        N=N + 1,
                        cf=cf,
                        seed=zseed,
                        anf_num=anf_num)
    S = np.array(SP["spikes"] * 1000.0)
    print(".")
    RX1 = sem.SE_BS(
        S,
        Simdur=dur,
        dt=dt,
        G_EoH=geoh,
        StochasticEoH=stocheoh,
        N=N,
        G_Dend=0.016,
        L=L,
        D=D,
        constR=False,
        gKLT_d=kltd,
        gIH_d=hd,
        gLEAK_d=ld,
        EoHseed=eohseed,
    )
    print(".")
    RX2 = sem.SE_BS(
        S,
        Simdur=dur,
        dt=dt,
        G_EoH=geoh,
        StochasticEoH=stocheoh,
        N=N,
        G_Dend=0.048,
        L=L,
        D=D,
        constR=False,
        gKLT_d=kltd,
        gIH_d=hd,
        gLEAK_d=ld,
        EoHseed=eohseed,
    )
    Ev1 = seh.SimpleDetectAP(RX1["Vm"], thr=-100, dt=dt, LM=-20, RM=10)
    Ev2 = seh.SimpleDetectAP(RX2["Vm"], thr=-100, dt=dt, LM=-20, RM=10)
    APr1 = len(Ev1["PeakT"]) / dur_s
    APr2 = len(Ev2["PeakT"]) / dur_s
    VS1, phi1, Ray1, phases1 = seh.vectorstrength(Ev1["PeakT"], freq,
                                                  [0.0, dur])
    VS2, phi2, Ray2, phases2 = seh.vectorstrength(Ev2["PeakT"], freq,
                                                  [0.0, dur])
    tx = np.linspace(0, dur - dt, int(dur / dt))
    fhand = plt.figure()
    ax1 = plt.subplot(211)
    ax1.set_title("Rate=" + str(APr1) + ", VS=" + str(VS1))
    ax2 = plt.subplot(212)
    ax2.set_title("Rate=" + str(APr2) + ", VS=" + str(VS2))
    ax1.plot(tx, RX1["Vm"], "k")
    ax1.set_xlim((800.0, 1000.0))
    ax2.plot(tx, RX2["Vm"], color="r", linewidth=0.5)
    ax2.set_xlim((800.0, 1000.0))
    ax1.plot(Ev1["PeakT"],
             Ev1["PeakV"],
             color="g",
             marker=".",
             linestyle="None")
    ax2.plot(Ev2["PeakT"],
             Ev2["PeakV"],
             color="r",
             marker=".",
             linestyle="None")
    plt.tight_layout()
    return fhand
Beispiel #8
0
def runonce(x, cf=450.0, freq=500.0, dbspl=65.0, dur=1000.0):
    thisdur = (dur - 5.0) / 1000.0
    N = 32
    anf_num = (N + 1, 0, 0)
    SO = seh.create_sound(
        fs=100e3,
        freq=freq,
        duration=thisdur,
        dbspl=dbspl,
    )
    SP = seh.create_spk(SO,
                        fs=100e3,
                        N=N + 1,
                        cf=cf,
                        seed=65564 + x,
                        anf_num=anf_num)
    S = np.array(SP["spikes"] * 1000.0)
    R0 = sem.SE_BS(
        S,
        Simdur=dur,
        dt=0.01,
        G_EoH=0.055,
        StochasticEoH=True,
        EoHseed=917634 + x,
        N=32,
        G_Dend=0.0,
    )
    print(".")
    RD = sem.SE_BS(
        S,
        Simdur=dur,
        dt=0.01,
        G_EoH=0.055,
        StochasticEoH=True,
        EoHseed=917634 + x,
        N=32,
        G_Dend=0.016,
    )
    print(".")
    R03 = sem.SE_3D(
        S,
        Simdur=dur,
        dt=0.01,
        G_EoH=0.055,
        StochasticEoH=True,
        EoHseed=917634 + x,
        N=32,
        G_Dend=0.0,
        cell=1,
    )
    print(".")
    RD3 = sem.SE_3D(
        S,
        Simdur=dur,
        dt=0.01,
        G_EoH=0.055,
        StochasticEoH=True,
        EoHseed=917634 + x,
        N=32,
        G_Dend=0.064,
        cell=1,
    )
    print(".")
    Ev0 = seh.SimpleDetectAP(R0["Vm"], thr=-100, dt=0.01, LM=-20, RM=10)
    EvD = seh.SimpleDetectAP(RD["Vm"], thr=-100, dt=0.01, LM=-20, RM=10)
    Ev03 = seh.SimpleDetectAP(R03["Vm"], thr=-100, dt=0.01, LM=-20, RM=10)
    EvD3 = seh.SimpleDetectAP(RD3["Vm"], thr=-100, dt=0.01, LM=-20, RM=10)
    VS0, phi0, R0, phases0 = seh.vectorstrength(Ev0["PeakT"], freq, [0.0, dur])
    VSD, phiD, RD, phasesD = seh.vectorstrength(EvD["PeakT"], freq, [0.0, dur])
    VS03, phi03, R03, phases03 = seh.vectorstrength(Ev03["PeakT"], freq,
                                                    [0.0, dur])
    VSD3, phiD3, RD3, phasesD3 = seh.vectorstrength(EvD3["PeakT"], freq,
                                                    [0.0, dur])
    nAP0 = len(Ev0["PeakT"])
    nAPD = len(EvD["PeakT"])
    nAP03 = len(Ev03["PeakT"])
    nAPD3 = len(EvD3["PeakT"])
    ISI0 = np.diff(Ev0["PeakT"])
    ISID = np.diff(EvD["PeakT"])
    ISI03 = np.diff(Ev03["PeakT"])
    ISID3 = np.diff(EvD3["PeakT"])
    cycdurms = 1000.0 / freq
    ncycles = (thisdur * 1000.0) / cycdurms
    bins = np.arange(0.0, 25.0, cycdurms)
    hist0, bin_edges0 = np.histogram(ISI0, bins)
    histD, bin_edgesD = np.histogram(ISID, bins)
    hist03, bin_edges03 = np.histogram(ISI03, bins)
    histD3, bin_edgesD3 = np.histogram(ISID3, bins)
    EI0 = hist0[0] / ncycles
    EID = histD[0] / ncycles
    EI03 = hist03[0] / ncycles
    EID3 = histD3[0] / ncycles
    return (nAP0, nAPD, VS0, VSD, EI0, EID, nAP03, nAPD3, VS03, VSD3, EI03,
            EID3)
Beispiel #9
0
def runmain():
    rep = 10
    simdur = 1000.0
    dt = 0.01
    N = 33
    freq = 1251.0  # 1251.0
    cf = 1001.0  # 1501.0
    db = 70
    SO = seh.create_sound(fs=100e3,
                          freq=freq,
                          duration=(simdur * 0.6) / 1000.0,
                          dbspl=db)
    Silence = seh.create_sound(fs=100e3,
                               freq=freq,
                               duration=(simdur * 0.4) / 1000.0,
                               dbspl=-10)
    R32 = []
    R0 = []
    Ev0 = []
    Fail0 = []
    Ev32 = []
    Fail32 = []
    APr0 = []
    APr32 = []
    allVS0 = []
    allVS32 = []
    allPhi0 = []
    allPhi32 = []
    #
    SIN = []
    DIN = []
    SR0 = []
    DR0 = []
    SF0 = []
    DF0 = []
    SR32 = []
    DR32 = []
    SF32 = []
    DF32 = []
    for thisrep in range(rep):
        SP = seh.create_spk(
            np.concatenate((SO, Silence)),
            fs=100e3,
            N=N,
            cf=cf,
            seed=65562 + thisrep,
            anf_num=(N, 0, 0),
        )
        S = np.array(SP["spikes"] * 1000.0)
        R32.append(
            sem.SE_BS(
                S,
                Simdur=simdur,
                dt=dt,
                G_EoH=0.055,
                StochasticEoH=True,
                N=N,
                G_Dend=0.016,
                EoHseed=8347236 + thisrep,
            ))
        R0.append(
            sem.SE_BS(
                S,
                Simdur=simdur,
                dt=dt,
                G_EoH=0.055,
                StochasticEoH=True,
                N=N,
                G_Dend=0.0,
                EoHseed=8347236 + thisrep,
            ))
        Ev0.append(
            seh.SimpleDetectAP(R0[-1]["Vm"], thr=-100, dt=dt, LM=-20, RM=10))
        Fail0.append(seh.SimpleGetFails(S[-1], Ev0[-1], R0[-1], simdur, dt))
        Ev32.append(
            seh.SimpleDetectAP(R32[-1]["Vm"], thr=-100, dt=dt, LM=-20, RM=10))
        Fail32.append(seh.SimpleGetFails(S[-1], Ev32[-1], R32[-1], simdur, dt))
        APr0.append(len(Ev0[-1]["PeakT"]) / (simdur / 1000.0))
        APr32.append(len(Ev32[-1]["PeakT"]) / (simdur / 1000.0))
        #
        tVS0, tphi0, tRay0, tphases0 = seh.vectorstrength(
            Ev0[-1]["PeakT"], freq, [0.0, simdur * 0.6])
        tVS32, tphi32, tRay32, tphases32 = seh.vectorstrength(
            Ev32[-1]["PeakT"], freq, [0.0, simdur * 0.6])
        allVS0.append(tVS0)
        allVS32.append(tVS32)
        allPhi0.append(tphi0)
        allPhi32.append(tphi32)
        #
        # generate more results for writing...
        stimlen = simdur * 0.6
        stimlen_s = (simdur * 0.6) / 1000.0
        spontlen_s = (simdur - stimlen) / 1000.0
        myEv0 = np.array(Ev0[-1]["PeakT"])
        myFail0 = np.array(Fail0[-1]["PeakT"])
        myEv32 = np.array(Ev32[-1]["PeakT"])
        myFail32 = np.array(Fail32[-1]["PeakT"])
        SIN.append(np.sum(S[-1] > stimlen) / spontlen_s)
        DIN.append(np.sum(S[-1] < stimlen) / stimlen_s)
        SR0.append(np.sum(myEv0 > stimlen) / spontlen_s)
        DR0.append(np.sum(myEv0 < stimlen) / stimlen_s)
        SF0.append(np.sum(myFail0 > stimlen) / spontlen_s)
        DF0.append(np.sum(myFail0 < stimlen) / stimlen_s)
        SR32.append(np.sum(myEv32 > stimlen) / spontlen_s)
        DR32.append(np.sum(myEv32 < stimlen) / stimlen_s)
        SF32.append(np.sum(myFail32 > stimlen) / spontlen_s)
        DF32.append(np.sum(myFail32 < stimlen) / stimlen_s)
    SIN = np.array(SIN)
    DIN = np.array(DIN)
    SR0 = np.array(SR0)
    DR0 = np.array(DR0)
    SF0 = np.array(SF0)
    DF0 = np.array(DF0)
    SR32 = np.array(SR32)
    DR32 = np.array(DR32)
    SF32 = np.array(SF32)
    DF32 = np.array(DF32)
    # Pool spiketimes and construct smooth cyclehist
    Spt0 = np.array(())
    for s0 in Ev0:
        Spt0 = np.append(Spt0, s0["PeakT"])
    Spt32 = np.array(())
    for s32 in Ev32:
        Spt32 = np.append(Spt32, s32["PeakT"])
    VS0, phi0, Ray0, phases0 = seh.vectorstrength(Spt0, freq,
                                                  [0.0, simdur * 0.6])
    VS32, phi32, Ray32, phases32 = seh.vectorstrength(Spt32, freq,
                                                      [0.0, simdur * 0.6])
    T = np.linspace(0, simdur - dt, int(round(simdur / dt)))
    sT = np.linspace(0, (simdur * 0.8) - dt, int(round((simdur * 0.8) / dt)))
    print("######Statistical comparison#########")
    print("Total number of AP: " + str(len(Spt0)) + " vs. " + str(len(Spt32)))
    outtext1 = str(np.mean(APr0)) + "+/-" + str(round(np.std(APr0), 2))
    outtext2 = str(np.mean(APr32)) + "+/-" + str(round(np.std(APr32), 2))
    print("Mean AP rate: " + outtext1 + " vs. " + outtext2)
    Tval, p = stats.ttest_rel(APr0, APr32)
    print("T=" + str(round(Tval, 3)) + ", p=" + str(p) + ", N=" + str(rep))
    outtext4 = str(np.mean(allVS0)) + "+/-" + str(round(np.std(allVS0), 2))
    outtext5 = str(np.mean(allVS32)) + "+/-" + str(round(np.std(allVS32), 2))
    print("Mean VS: " + outtext4 + " vs. " + outtext5)
    Tval, p = stats.ttest_rel(allVS0, allVS32)
    print("T=" + str(round(Tval, 3)) + ", p=" + str(p) + ", N=" + str(rep))
    outtext6 = str(np.mean(allPhi0)) + "+/-" + str(round(np.std(allPhi0), 2))
    outtext7 = str(np.mean(allPhi32)) + "+/-" + str(round(np.std(allPhi32), 2))
    print("Mean Phi: " + outtext6 + " vs. " + outtext7)
    Tval, p = stats.ttest_rel(allPhi0, allPhi32)
    print("T=" + str(round(Tval, 3)) + ", p=" + str(p) + ", N=" + str(rep))
    #
    print("Driven input rate: " + str(round(np.mean(DIN), 2)) + "+/-" +
          str(round(np.std(DIN), 2)))
    outtext1 = str(round(np.mean(DR0), 2)) + "+/-" + str(round(np.std(DR0), 2))
    outtext2 = str(round(np.mean(DR32), 2)) + "+/-" + str(
        round(np.std(DR32), 2))
    print("Mean driven AP rate: " + outtext1 + " vs. " + outtext2)
    Tval, p = stats.ttest_rel(DR0, DR32)
    print("T=" + str(round(Tval, 3)) + ", p=" + str(p) + ", N=" + str(rep))
    #
    print("Spont input rate: " + str(round(np.mean(SIN), 2)) + "+/-" +
          str(round(np.std(SIN), 2)))
    outtext1 = str(round(np.mean(SR0), 2)) + "+/-" + str(round(np.std(SR0), 2))
    outtext2 = str(round(np.mean(SR32), 2)) + "+/-" + str(
        round(np.std(SR32), 2))
    print("Mean spont AP rate: " + outtext1 + " vs. " + outtext2)
    Tval, p = stats.ttest_rel(SR0, SR32)
    print("T=" + str(round(Tval, 3)) + ", p=" + str(p) + ", N=" + str(rep))
    #
    outtext1 = str(round(np.mean(DF0), 2)) + "+/-" + str(round(np.std(DF0), 2))
    outtext2 = str(round(np.mean(DF32), 2)) + "+/-" + str(
        round(np.std(DF32), 2))
    print("Mean driven Fail rate: " + outtext1 + " vs. " + outtext2)
    Tval, p = stats.ttest_rel(DF0, DF32)
    print("T=" + str(round(Tval, 3)) + ", p=" + str(p) + ", N=" + str(rep))
    #
    outtext1 = str(round(np.mean(SF0), 2)) + "+/-" + str(round(np.std(SF0), 2))
    outtext2 = str(round(np.mean(SF32), 2)) + "+/-" + str(
        round(np.std(SF32), 2))
    print("Mean spont Fail rate: " + outtext1 + " vs. " + outtext2)
    Tval, p = stats.ttest_rel(SF0, SF32)
    print("T=" + str(round(Tval, 3)) + ", p=" + str(p) + ", N=" + str(rep))
    print("Exact values for traces shown:")
    print("Driven AP rate: " + str(DR0[0]) + " vs. " + str(DR32[0]))
    print("Driven Fail rate: " + str(DF0[0]) + " vs. " + str(DF32[0]))
    print("Spont AP rate: " + str(SR0[0]) + " vs. " + str(SR32[0]))
    print("Spont Fail rate: " + str(SF0[0]) + " vs. " + str(SF32[0]))
    # draw panels
    fwidth = 8.5
    fh = plt.figure(figsize=(fwidth / 2.54, fwidth / 2.54))
    fh.subplots_adjust(left=0.15,
                       bottom=0.125,
                       right=0.95,
                       top=0.95,
                       wspace=0.55,
                       hspace=0.55)
    sp1 = fh.add_subplot(2, 3, (1, 2))
    sp1.plot(T, R0[0]["Vm"], "k-", linewidth=0.5)
    sp1.plot(Ev0[0]["PeakT"], Ev0[0]["PeakV"], "g.", markersize=2)
    sp1.plot(Fail0[0]["PeakT"], Fail0[0]["PeakV"], "r.", markersize=2)
    sp1.plot(S[-1], np.zeros((len(S[-1]), )) + 20.0, "b.", markersize=2)
    sp1.set_ylabel("Vm (mV)")
    sp1.set_xlabel("Time (ms)")
    sp1.spines["top"].set_visible(False)
    sp1.spines["right"].set_visible(False)
    sp1.plot(T, (np.concatenate((SO, Silence)) * 75) - 75.0,
             color="g",
             linewidth=0.5)
    #
    sp1b = fh.add_subplot(2, 3, 3)
    H0 = np.histogram(phases0, np.linspace(0, 1, 33))
    sp1b.plot(H0[1][1:], H0[0], "k")
    sp1b.set_ylabel("AP/bin")
    sp1b.set_xlabel("Phase (cycles)")
    sp1b.set_xticks((0, 0.5, 1))
    sp1b.set_yticks((0, 60, 120))
    sp1b.plot((phi0, phi0), (0, sp1b.get_ylim()[1]), "r-")
    annotext = r"VS=" + str(round(VS0, 2)) + "\n" + r"$\phi$=" + str(
        round(phi0, 2))
    sp1b.annotate(annotext, xy=(phi0, sp1b.get_ylim()[1]), fontsize=5)
    sp1b.spines["top"].set_visible(False)
    sp1b.spines["right"].set_visible(False)
    #
    sp2 = fh.add_subplot(2, 3, (4, 5))
    sp2.plot(T, R32[0]["Vm"], "k-", linewidth=0.5)
    sp2.plot(Ev32[0]["PeakT"], Ev32[0]["PeakV"], "g.", markersize=2)
    sp2.plot(Fail32[0]["PeakT"], Fail32[0]["PeakV"], "r.", markersize=2)
    sp2.plot(S[-1], np.zeros((len(S[-1]), )) + 20.0, "b.", markersize=2)
    sp2.plot(T, (np.concatenate((SO, Silence)) * 75) - 75.0,
             color="g",
             linewidth=0.5)
    sp2.set_ylabel("Vm (mV)")
    sp2.set_xlabel("Time (ms)")
    sp2.spines["top"].set_visible(False)
    sp2.spines["right"].set_visible(False)
    #
    sp2b = fh.add_subplot(2, 3, 6)
    H32 = np.histogram(phases32, np.linspace(0, 1, 33))
    sp2b.plot(H32[1][1:], H32[0], "k")
    sp2b.set_ylabel("AP/bin")
    sp2b.set_xlabel("Phase (cycles)")
    sp2b.set_xticks((0, 0.5, 1))
    sp2b.set_yticks((0, 60, 120))
    sp2b.plot((phi32, phi32), (0, sp2b.get_ylim()[1]), "r-")
    annotext = r"VS=" + str(round(VS32, 2)) + "\n" + r"$\phi$=" + str(
        round(phi32, 2))
    sp2b.annotate(annotext, xy=(phi32, sp2b.get_ylim()[1]), fontsize=5)
    sp2b.spines["top"].set_visible(False)
    sp2b.spines["right"].set_visible(False)
    #
    pp = PdfPages("./figs/Figure6_raw.pdf")
    pp.savefig(dpi=600)
    pp.close()
Beispiel #10
0
def mkexampletraces(minL, minD, maxL, maxD):
    """
    As per reviewer request we generate example traces for extreme conditions
    """
    dur = 5000.0
    dur_s = dur / 1000.0
    dt = 0.01
    freq = 1389.0
    cf = 1501.0
    dB = 65.0
    zseed = 45453
    eohseed = 34823
    stocheoh = True
    geoh = 0.055
    N = 32
    gsyn = 0.016
    anf_num = (N + 1, 0, 0)
    SO = seh.create_sound(fs=100e3, freq=freq, duration=dur_s, dbspl=dB)
    SP = seh.create_spk(SO,
                        fs=100e3,
                        N=N + 1,
                        cf=cf,
                        seed=zseed,
                        anf_num=anf_num)
    S = np.array(SP["spikes"] * 1000.0)
    print(".")
    RX1 = sem.SE_BS(
        S,
        Simdur=dur,
        dt=dt,
        G_EoH=geoh,
        StochasticEoH=stocheoh,
        N=N,
        G_Dend=0.0,
        L=minL,
        D=minD,
        constR=False,
        EoHseed=eohseed,
    )
    print(".")
    RX2 = sem.SE_BS(
        S,
        Simdur=dur,
        dt=dt,
        G_EoH=geoh,
        StochasticEoH=stocheoh,
        N=N,
        G_Dend=gsyn,
        L=minL,
        D=minD,
        constR=False,
        EoHseed=eohseed,
    )
    print(".")
    RX3 = sem.SE_BS(
        S,
        Simdur=dur,
        dt=dt,
        G_EoH=geoh,
        StochasticEoH=stocheoh,
        N=N,
        G_Dend=0.0,
        L=maxL,
        D=maxD,
        constR=False,
        EoHseed=eohseed,
    )
    print(".")
    RX4 = sem.SE_BS(
        S,
        Simdur=dur,
        dt=dt,
        G_EoH=geoh,
        StochasticEoH=stocheoh,
        N=N,
        G_Dend=gsyn,
        L=maxL,
        D=maxD,
        constR=False,
        EoHseed=eohseed,
    )
    Ev1 = seh.SimpleDetectAP(RX1["Vm"], thr=-100, dt=dt, LM=-20, RM=10)
    Ev2 = seh.SimpleDetectAP(RX2["Vm"], thr=-100, dt=dt, LM=-20, RM=10)
    Ev3 = seh.SimpleDetectAP(RX3["Vm"], thr=-100, dt=dt, LM=-20, RM=10)
    Ev4 = seh.SimpleDetectAP(RX4["Vm"], thr=-100, dt=dt, LM=-20, RM=10)
    APr1 = np.round(len(Ev1["PeakT"]) / dur_s)
    APr2 = np.round(len(Ev2["PeakT"]) / dur_s)
    APr3 = np.round(len(Ev3["PeakT"]) / dur_s)
    APr4 = np.round(len(Ev4["PeakT"]) / dur_s)
    VS1, phi1, Ray1, phases1 = seh.vectorstrength(Ev1["PeakT"], freq,
                                                  [0.0, dur])
    VS2, phi2, Ray2, phases2 = seh.vectorstrength(Ev2["PeakT"], freq,
                                                  [0.0, dur])
    VS3, phi3, Ray3, phases3 = seh.vectorstrength(Ev3["PeakT"], freq,
                                                  [0.0, dur])
    VS4, phi4, Ray4, phases4 = seh.vectorstrength(Ev4["PeakT"], freq,
                                                  [0.0, dur])
    tx = np.linspace(0, dur - dt, int(dur / dt))
    fhand = plt.figure()
    ax1 = plt.subplot(211)
    ax1.set_title(
        str(APr1) + ", " + str(VS1) + " / " + str(APr2) + ", " + str(VS2))
    ax1.plot(tx, RX1["Vm"], "k")
    ax1.plot(Ev1["PeakT"],
             Ev1["PeakV"],
             color="g",
             marker=".",
             linestyle="None")
    ax1.plot(tx, RX2["Vm"], "r")
    ax1.plot(Ev2["PeakT"],
             Ev2["PeakV"],
             color="r",
             marker=".",
             linestyle="None")
    ax1.set_xlim((300.0, 500.0))
    ax2 = plt.subplot(212)
    ax2.set_title(
        str(APr3) + ", " + str(VS3) + " / " + str(APr4) + ", " + str(VS4))
    ax2.plot(tx, RX3["Vm"], color="k", linewidth=0.5)
    ax2.plot(Ev3["PeakT"],
             Ev3["PeakV"],
             color="g",
             marker=".",
             linestyle="None")
    ax2.plot(tx, RX4["Vm"], color="r", linewidth=0.5)
    ax2.plot(Ev4["PeakT"],
             Ev4["PeakV"],
             color="r",
             marker=".",
             linestyle="None")
    ax2.set_xlim((300.0, 500.0))
    plt.tight_layout()
    return fhand