def mapfig(N, R, dendtype, cellnr): M = sem.SE_3D( S=np.zeros((32, 1)), Simdur=10.0, dt=0.1, cell=cellnr, impedancetesting=1, impdendtype=dendtype, impdendid=N, debug=1, ) thishand = plt.figure() plt.semilogx(R[3], R[2], "k-") plt.plot(R[0], R[1], "ro") plt.plot(R[3][0], R[2][0], "mo") plt.text(R[0], R[1], str(R[0]) + "Hz/" + str(R[1]) + "$(M\Omega)$") plt.xlabel("Frequency (Hz)") plt.ylabel("$Z (M\Omega)$") if dendtype == 0: plt.title("Cell " + str(cellnr) + ", distal dend " + str(N)) else: plt.title("Cell " + str(cellnr) + ", proximal dend " + str(N)) plt.ylim((0, 15)) plt.tight_layout() return thishand, M["impathlen"], R[0], R[1], R[2][0]
def runonce( x, impfreq, Ra, imptesttype, impdendtype, impdendid, cell, ): time.sleep( np.random.uniform()) # testing whether this helps parallel processing # errors caused by reading the sloc files..- print(str(x)) simdur = 1000.0 # 1000 pretime = 100.0 dt = 0.01 N = 32 S = np.zeros((N, 1)) # T = np.linspace(0, simdur - dt, int(round(simdur / dt))) impamp = 0.1 impphase = 0.0 # IS = impamp * np.sin(impfreq[x]/1000.0 * 2 * np.pi * T + impphase) if imptesttype[x] == 1: thisfreq = impfreq[x] else: thisfreq = impfreq R = sem.SE_3D( S, Simdur=simdur, dt=dt, cell=cell[x], Ra=Ra[x], EoHseed=8347236, impedancetesting=imptesttype[x], impstim=(impamp, thisfreq, impphase), impdendtype=impdendtype[x], impdendid=impdendid[x], ) if imptesttype[x] == 1: A = average_over_cyle(R["Vm"], impfreq[x], dt, simdur) cytax = np.linspace(0, 1, A[0].size) vmax = np.max(A[0]) imax = np.argmax(A[0]) vmin = np.min(A[0]) imin = np.argmin(A[0]) r_megohm = (vmax - A[2]) / impamp phi = cytax[imax] return (r_megohm, phi) elif imptesttype[x] == -1: fres, zmax, Pxx, f = analyze_chirpdata(R["Vm"], dt, simdur) return (fres, zmax, Pxx, f)
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()
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]
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)
if __name__ == "__main__": addedargs = sys.argv[1:] # args are (fname, weload, nconds, ncores, cell) myargs = [1, 5, 4, 1] for iarg, thisarg in enumerate(addedargs): myargs[iarg] = int(thisarg) nconds = myargs[1] ncores = myargs[2] cell = myargs[3] if myargs[0] == 1: weload = True else: weload = False # nprox, ndist = sem.SE_3D(np.array((0, )), cell=cell, listinfo=True) allprox = np.arange(nprox) alldist = np.arange(ndist) print("cell" + str(cell) + ": NProx=" + str(nprox) + ", NDist=" + str(ndist)) if weload and os.path.isfile("./results/impedance_res_3d_R_" + str(cell) + ".npy"): resR = np.load("./results/impedance_res_3d_R_" + str(cell) + ".npy") resR = resR.tolist() datashape_R = np.shape(resR) allRa = np.linspace(25.0, 300.0, datashape_R[0]) # resD = np.load("./results/impedance_res_3d_D_" + str(cell) + ".npy") resD = resD.tolist() resP = np.load("./results/impedance_res_3d_P_" + str(cell) + ".npy") resP = resP.tolist()