Esempio n. 1
0
def get_spike_properties_in_response_to_conductance_peak(
        dirname, spike_threshold, Gleak):
    """
    Calculate spike width and inter-spike intervals for all files with responses to
    excitatory conductance kick
    """
    files = os.listdir(dirname)

    Gkick = []
    spike_amplitudes = []
    spike_widths = []
    spike_peaks = []
    spike_dips = []
    interspike_intervals = []

    for f in files:
        if ("RA" in f) and (not "_dend_" in f) and (not "_soma_" in f):
            print f
            t, Vs, Vd, Gexc_d, Ginh_d, n,\
                 h, r, c, Ca = reading.read_hh2_buffer_full(os.path.join(dirname, f))

            spike_amplitude, spike_peak, spike_dip, spike_width, interspike_interval = calculate_spike_properties(
                t, Vs, spike_threshold)

            Gkick.append(np.max(Gexc_d) / Gleak)
            spike_amplitudes.append(spike_amplitude)
            spike_widths.append(spike_width)
            spike_peaks.append(spike_peak)
            spike_dips.append(spike_dip)
            interspike_intervals.append(interspike_interval)

    Gkick, spike_amplitudes, spike_peaks, spike_dips, spike_widths, interspike_intervals = zip(
        *sorted(
            zip(Gkick, spike_amplitudes, spike_peaks, spike_dips, spike_widths,
                interspike_intervals)))

    return Gkick, spike_amplitudes, spike_peaks, spike_dips, spike_widths, interspike_intervals
Esempio n. 2
0
#filename = "/home/eugene/Output/neuronTest/saturatedInhibitionResponse/Ginh_5.00.bin"
#filename = "/home/eugene/Output/neuronTest/kickResponse/Ginh_10.00_8.bin"
#filename = "/home/eugene/Output/neuronTest/response.bin"
#filename = "/home/eugene/Output/networks/chainGrowth/passiveDendrite/maturationTransition1/RA/RA570.bin"
#filename = "/home/eugene/Output/neuronTest/noise/noise_immature_4.bin"

#filename = "/mnt/hodgkin/eugene/Output/tuneHVCRA/finalModel/KLTH3.5Rest55mVExamples/age0/RA99.bin"
filename = "/mnt/hodgkin/eugene/Output/tuneHVCRA/finalModel/KLTH3.5Rest55mVExamples/age1.0/RA45.bin"

#filename = "/mnt/hodgkin/eugene/Output/tuneHVCRA/finalModel/KLTH/age100/RA7.bin"

#filename = "/mnt/hodgkin/eugene/Output/tuneHVCRA/finalModel/noKLTHtest/age100/RA40.bin"

#filename = "/mnt/hodgkin/eugene/Output/tuneHVCRA/finalModel/noKLTHCalciumSpike20msLeak0.75/age100/RA10.bin"

t, Vs, Vd, Gexc_d, Ginh_d, n, h, r, c, Ca = reading.read_hh2_buffer_full(
    filename)

#print t
#print Vs

print Vs[-1]
print Vd[-1]
print n[-1]
print h[-1]
print r[-1]
print c[-1]
print Ca[-1]

print "Average Vs = ", np.mean(Vs)
print "Std Vs = ", np.std(Vs)
Esempio n. 3
0
Gkick_tuned3, spike_amplitude_tuned3, spike_peaks_tuned3, spike_dips_tuned3, spike_width_tuned3, interspike_interval_tuned3 = \
                get_spike_properties_in_response_to_conductance_peak(dirname_tuned3, spike_threshold, Gleak_tuned3)

Gkick_tuned4, spike_amplitude_tuned4, spike_peaks_tuned4, spike_dips_tuned4, spike_width_tuned4, interspike_interval_tuned4 = \
                get_spike_properties_in_response_to_conductance_peak(dirname_tuned4, spike_threshold, Gleak_tuned4)

# compare neuron traces
file_original_trace = os.path.join(dirname_original, "RA35.bin")
file_tuned_trace = os.path.join(dirname_tuned, "RA35.bin")
file_tuned_trace2 = os.path.join(dirname_tuned2, "RA35.bin")
file_tuned_trace3 = os.path.join(dirname_tuned3, "RA35.bin")
file_tuned_trace4 = os.path.join(dirname_tuned4, "RA35.bin")


t_original, Vs_original, Vd_original, Gexc_d_original, Ginh_d_original, n_original,\
             h_original, r_original, c_original, Ca_original = reading.read_hh2_buffer_full(file_original_trace)

t_tuned, Vs_tuned, Vd_tuned, Gexc_d_tuned, Ginh_d_tuned, n_tuned,\
             h_tuned, r_tuned, c_tuned, Ca_tuned = reading.read_hh2_buffer_full(file_tuned_trace)

t_tuned2, Vs_tuned2, Vd_tuned2, Gexc_d_tuned2, Ginh_d_tuned2, n_tuned2,\
             h_tuned2, r_tuned2, c_tuned2, Ca_tuned2 = reading.read_hh2_buffer_full(file_tuned_trace2)

t_tuned3, Vs_tuned3, Vd_tuned3, Gexc_d_tuned3, Ginh_d_tuned3, n_tuned3,\
             h_tuned3, r_tuned3, c_tuned3, Ca_tuned3 = reading.read_hh2_buffer_full(file_tuned_trace3)

t_tuned4, Vs_tuned4, Vd_tuned4, Gexc_d_tuned4, Ginh_d_tuned4, n_tuned4,\
             h_tuned4, r_tuned4, c_tuned4, Ca_tuned4 = reading.read_hh2_buffer_full(file_tuned_trace4)
#print calculate_spike_properties(t_original, Vs_original, -20.0)
#print calculate_spike_properties(t_tuned, Vs_tuned, -20.0)
Esempio n. 4
0
import numpy as np

#filename = "/home/eugene/Output/neuronTest/saturatedInhibitionResponse/Ginh_5.00.bin"
#filename = "/home/eugene/Output/neuronTest/kickResponse/Ginh_10.00_8.bin"
#filename = "/home/eugene/Output/neuronTest/response.bin"
#filename = "/home/eugene/Output/networks/chainGrowth/passiveDendrite/test1/RA/RA231.bin"
#filename = "/home/eugene/Output/networks/chainGrowth/testGrowthDelays5/RA/RA5.bin"
#filename = "/home/eugene/Output/neuronTest/inhAndExcInputsResponse/RA.bin"
#filename = "/home/eugene/Output/neuronTest/modelStability/RA29.bin"
filename1 = "/mnt/hodgkin_home/eugene/Output/tuneHVCRA/Ad1000/Rc200/RA30.bin"
filename2 = "/mnt/hodgkin_home/eugene/Output/tuneHVCRA/Ad1000/Rc200/RA25.bin"
#filename2 = "/mnt/hodgkin_home/eugene/Output/tuneHVCRA/passiveDendrite/NaKchange/Na80K8/RA23.bin"

#filename = "/mnt/hodgkin_home/eugene/Output/neuronTest/inhAndExcInputsResponse/RA13.bin"

t1, Vs1, Vd1, Gexc_d1, Ginh_d1, n1, h1, r1, c1, Ca1 = reading.read_hh2_buffer_full(filename1)
t2, Vs2, Vd2, Gexc_d2, Ginh_d2, n2, h2, r2, c2, Ca2 = reading.read_hh2_buffer_full(filename2)

#print t
#print Vs

label1 = 'Rc200 30 Ge1.05'
label2 = 'Rc200 25 Ge1.5'


tmin = 40
tmax = 100

# membrane potentials
f = plt.figure()
Esempio n. 5
0
import numpy as np

dirname = "/home/eugene/Output/networks/chainGrowth/matureTest/RA"
fileMature = "/home/eugene/Output/networks/chainGrowth/testGrowthDelays3/mature_5300.bin"

files = os.listdir(dirname)

(_, _, mature_indicators) = reading.read_mature_indicators(fileMature)

mature_neurons = set(np.where(mature_indicators == 1)[0])

counter = 0
counter_mature = 0

for f in files:
    t, Vs, Vd, Gexc_d, Ginh_d, n, h, r, c, Ca = reading.read_hh2_buffer_full(
        os.path.join(dirname, f))

    if counter == 0:
        Ginh = np.copy(Ginh_d)
    else:
        Ginh += Ginh_d

    neuron_id = int(f.split(".bin")[0][2:])

    print neuron_id

    if neuron_id in mature_neurons:
        if counter_mature == 0:
            Ginh_mature = np.copy(Ginh_d)
        else:
            Ginh_mature += Ginh_d
Esempio n. 6
0
def compare_networkAndPoolConductance(dataDir, testDataDir, outFigureDir,
                                      simName, trial):
    """
    Function reads conductances for all neurons in the network, calculates average total conductances
    and conductances alinged to average bursting times
    """
    N_RA, N_I = reading.read_num_neurons(
        os.path.join(dataDir, "num_neurons.bin"))
    training_neurons = reading.read_training_neurons(
        os.path.join(dataDir, "training_neurons.bin"))
    N_TR = len(training_neurons)

    _, numTestTrials, \
        probability_soma_spike, average_num_soma_spikes_in_trial, mean_first_soma_spike_time, std_first_soma_spike_time,\
        probability_dend_spike, average_num_dend_spikes_in_trial, mean_first_dend_spike_time, std_first_dend_spike_time = reading.read_jitter(os.path.join(testDataDir, "jitter.bin"))

    neuronsWithRobustDendriticSpike = np.where(
        probability_dend_spike >= 0.75)[0]
    meanFirstSomaSpikeOfNeuronsWithRoburstDendriticSpike = mean_first_soma_spike_time[
        neuronsWithRobustDendriticSpike]

    t, Vs, Vd, Gexc_d, Ginh_d, n, h, r, c, Ca = reading.read_hh2_buffer_full(
        os.path.join(testDataDir, "RA/RA0_trial0.bin"))

    Ginh = np.zeros((N_RA, len(t)), np.float32)
    Gexc = np.zeros((N_RA, len(t)), np.float32)

    numOtherNeurons = N_RA - 1

    GinhSumAll = np.zeros(len(t), np.float32)
    GexcSumAll = np.zeros(len(t), np.float32)

    for testTrial in range(numTestTrials):
        print "Test trial: ", testTrial
        #if testTrial == 1:
        #  break
        for neuronId in range(N_RA):
            t, Vs, Vd, Gexc_d, Ginh_d, n, h, r, c, Ca = reading.read_hh2_buffer_full(
                os.path.join(
                    testDataDir, "RA/RA" + str(neuronId) + "_trial" +
                    str(testTrial) + ".bin"))

            Ginh[neuronId] += Ginh_d
            Gexc[neuronId] += Gexc_d

            # sum of conductances for all neurons excluding training
            if neuronId not in training_neurons:
                GinhSumAll += Ginh_d
                GexcSumAll += Gexc_d

    for neuronId in range(N_RA):
        Ginh[neuronId] /= float(numTestTrials)

    GinhSumAll = GinhSumAll / (float(numTestTrials) * float(N_RA - N_TR))
    GexcSumAll = GexcSumAll / (float(numTestTrials) * float(N_RA - N_TR))

    #print np.max(spike_times_d)
    #print np.max(t)

    #window = 100.0 # window size in ms
    window = 50.0

    Gbursted = None  # conductance aligned to bursting time
    Gother = None  # conductance of neurons that did npt burst

    dt = t[1] - t[0]
    window_t = [
        float(i) * dt - window / 2. for i in range(int(window / dt) - 1)
    ]

    GburstedInh_window = np.empty(
        (len(neuronsWithRobustDendriticSpike) - N_TR, int(window / dt) - 1),
        np.float32)  # conductances of all burst neurons aligned to burst time
    GburstedExc_window = np.empty(
        (len(neuronsWithRobustDendriticSpike) - N_TR, int(window / dt) - 1),
        np.float32)  # conductances of all burst neurons aligned to burst time

    # plot conductances for several random bursted neurons
    np.random.seed(1991)

    nid_toPlot = np.random.choice(neuronsWithRobustDendriticSpike,
                                  16,
                                  replace=False)

    nrows = 4
    ncols = 4

    fInh, axarrInh = plt.subplots(nrows=nrows, ncols=ncols)
    fExc, axarrExc = plt.subplots(nrows=nrows, ncols=ncols)

    neuronPlotCounter = 0
    neuronSavedCounter = 0

    for nid, meanFirstSpikeTime in zip(
            neuronsWithRobustDendriticSpike,
            meanFirstSomaSpikeOfNeuronsWithRoburstDendriticSpike):
        if nid in training_neurons:
            continue

        meanFirstSpikeTime = round(int(meanFirstSpikeTime / dt) * dt, 2)

        GburstedInh_window[neuronSavedCounter] = Ginh[nid][
            (t > meanFirstSpikeTime - window / 2.)
            & (t < meanFirstSpikeTime + window / 2.)]
        GburstedExc_window[neuronSavedCounter] = Gexc[nid][
            (t > meanFirstSpikeTime - window / 2.)
            & (t < meanFirstSpikeTime + window / 2.)]

        # normalize conductance by max value
        #Gbursted_window[neuronSavedCounter] /= np.max(Gbursted_window[neuronSavedCounter])

        # normalize to o mean and unit variance
        #Gbursted_window[neuronSavedCounter] = sklearn.preprocessing.scale(Gbursted_window[neuronSavedCounter], axis=0, with_mean=True, with_std=True, copy=True)

        if nid in nid_toPlot:
            row = neuronPlotCounter // 4
            col = neuronPlotCounter % 4
            axarrInh[row, col].plot(window_t,
                                    GburstedInh_window[neuronSavedCounter])
            axarrExc[row, col].plot(window_t,
                                    GburstedExc_window[neuronSavedCounter])
            #axarr[row, col].vlines(meanFirstSpikeTime, 0, np.max(Ginh[nid]))

            if row == 3:
                axarrInh[row, col].set_xlabel('Time (ms)')
                axarrExc[row, col].set_xlabel('Time (ms)')

            if col == 0:
                axarrInh[row, col].set_ylabel('Ginh (mS/cm^2)')
                axarrExc[row, col].set_ylabel('Gexc (mS/cm^2)')

            neuronPlotCounter += 1

        neuronSavedCounter += 1

        #if Gbursted == None:
        #  Gbursted = Ginh[nid[0]][(t > dend_spike_time[0] - window/2.)&(t < dend_spike_time[0] + window/2.)]
        #else:
        #  Gbursted += Ginh[nid[0]][(t > dend_spike_time[0] - window/2.)&(t < dend_spike_time[0] + window/2.)]

        #if Gother == None:
        #  Gother = (GsumAll-Ginh[nid[0]])[(t > dend_spike_time[0] - window/2.)&(t < dend_spike_time[0] + window/2.)]
        #else:
        #  Gother += (GsumAll-Ginh[nid[0]])[(t > dend_spike_time[0] - window/2.)&(t < dend_spike_time[0] + window/2.)]

        #plt.figure()
        #plt.plot(t, Gexc_d)
        #plt.vlines(dend_spike_time[0], 0, np.max(Gexc_d))

        #plt.figure()
        #plt.plot(t, G)
        #plt.vlines(dend_spike_time[0], 0, np.max(G))

    w, h = maximize_figure(fInh.number)
    fInh.savefig(outFigureDir + simName + "_trial" + str(trial) +
                 '_Ginh_examples.png',
                 bbox_inches='tight')
    plt.close(fInh)

    w, h = maximize_figure(fExc.number)
    fExc.savefig(outFigureDir + simName + "_trial" + str(trial) +
                 '_Gexc_examples.png',
                 bbox_inches='tight')
    plt.close(fExc)

    GburstedInh = np.sum(
        GburstedInh_window,
        axis=0) / float(len(neuronsWithRobustDendriticSpike) - N_TR)
    std_GburstedInh = np.std(GburstedInh_window, axis=0)

    GburstedExc = np.sum(
        GburstedExc_window,
        axis=0) / float(len(neuronsWithRobustDendriticSpike) - N_TR)
    std_GburstedExc = np.std(GburstedExc_window, axis=0)

    f = plt.figure()
    plt.plot(window_t, GburstedInh, label='bursted neurons')
    plt.plot(
        window_t, GburstedInh +
        std_GburstedInh / np.sqrt(len(neuronsWithRobustDendriticSpike) - N_TR))
    plt.plot(
        window_t, GburstedInh -
        std_GburstedInh / np.sqrt(len(neuronsWithRobustDendriticSpike) - N_TR))
    plt.xlabel('Time (ms)')
    plt.ylabel('average Ginh (mS/cm^2)')

    f.savefig(outFigureDir + simName + "_trial" + str(trial) +
              '_average_Ginh.png',
              bbox_inches='tight')
    plt.close(f)

    #plt.plot(window_t, Gother / float((N_RA - N_TR - 1)*numNeuronsWithDendSpike), label='other neurons')
    #plt.legend()

    f = plt.figure()
    plt.plot(t, GinhSumAll)
    plt.xlabel('Time (ms)')
    plt.ylabel('total Ginh (mS/cm^2)')
    f.savefig(outFigureDir + simName + "_trial" + str(trial) +
              '_total_Ginh.png',
              bbox_inches='tight')
    plt.close(f)

    f = plt.figure()
    plt.plot(window_t, GburstedExc, label='bursted neurons')
    plt.plot(
        window_t, GburstedExc +
        std_GburstedExc / np.sqrt(len(neuronsWithRobustDendriticSpike) - N_TR))
    plt.plot(
        window_t, GburstedExc -
        std_GburstedExc / np.sqrt(len(neuronsWithRobustDendriticSpike) - N_TR))
    plt.xlabel('Time (ms)')
    plt.ylabel('average Gexc (mS/cm^2)')
    f.savefig(outFigureDir + simName + "_trial" + str(trial) +
              '_average_Gexc.png',
              bbox_inches='tight')
    plt.close(f)

    #plt.plot(window_t, Gother / float((N_RA - N_TR - 1)*numNeuronsWithDendSpike), label='other neurons')
    #plt.legend()

    f = plt.figure()
    plt.plot(t, GexcSumAll)
    plt.xlabel('Time (ms)')
    plt.ylabel('total Gexc (mS/cm^2)')
    f.savefig(outFigureDir + simName + "_trial" + str(trial) +
              '_total_Gexc.png',
              bbox_inches='tight')
    plt.close(f)