def plot_average_volt(fn, gid=None, n=1):
    print 'Plotting average voltage; loading', fn
    d = np.loadtxt(fn)
    if gid == None:
        gid_range = np.unique(d[:, 0])
        gids = np.random.randint(np.min(gid_range), np.max(gid_range) + 1, n)
        print 'plotting random gids:', gids
    elif gid == 'all':
        gids = np.unique(d[:, 0])
    elif type(gid) == type([]):
        gids = gid
    else:
        gids = [gid]
    
    time_axis, volt = utils.extract_trace(d, gids[0])
    all_volt = np.zeros((time_axis.size, len(gids)))

    for i_, gid in enumerate(gids):
        time_axis, volt = utils.extract_trace(d, gid)
        print 'gid %d v_mean, std = %.2f +- %.2f; min %.2f max %.2f, diff %.2f ' % (gid, volt.mean(), volt.std(), volt.min(), volt.max(), volt.max() - volt.min())
        all_volt[:, i_] = volt

    avg_volt = np.zeros((time_axis.size, 2))
    for t in xrange(time_axis.size):
        avg_volt[t, 0] = all_volt[t, :].mean()
        avg_volt[t, 1] = all_volt[t, :].std()

    print 'Average voltage and std: %.2e +- %.2e (%.2e)' % (avg_volt[:, 0].mean(), avg_volt[:, 0].std(), avg_volt[:, 1].mean())
    pylab.errorbar(time_axis, avg_volt[:, 0], yerr=avg_volt[:, 1], lw=3, c='k') 
Ejemplo n.º 2
0
    def plot_response(self, title, connectivity=None):
        """
        Plots the cell's membrane potential and output spikes in response to the
        stimulus alone (that's why you need to simulate without connectivity before),
        and the response with connectivity.
        """
        volt_fn = self.params['exc_volt_fn_base'] + '.v'
        print 'Loading membrane potentials from:', volt_fn
        volt_data = np.loadtxt(volt_fn)
        spike_fn = self.params['exc_spiketimes_fn_merged'] + '%d.ras' % 0
        nspikes, spiketimes = utils.get_nspikes(spike_fn, self.params['n_exc'], get_spiketrains=True)

        if connectivity == False:
            self.spiketrains_without_connectivity = spiketimes
        else:
            self.spiketrains_with_connectivity = spiketimes

        ax = self.fig.add_subplot(self.n_fig_y, self.n_fig_x, self.fig_cnt)
        self.fig_cnt += 1
        ax2 = self.fig.add_subplot(self.n_fig_y, self.n_fig_x, self.fig_cnt)
        self.fig_cnt += 1
        y_min, y_max = -70, -45
        for i_, gid in enumerate(self.gids_to_plot):
            time_axis, volt = utils.extract_trace(volt_data, gid)
            ax.plot(time_axis, volt, lw=1, label='nspikes[%d]=%d' % (gid, nspikes[gid]), color=self.color_dict[gid])
#            self.plot_spikes(ax, spiketimes[gid], gid, y_min, y_max, lw=2)
            self.plot_spike_histogram(ax2, gid, i_, spiketimes[gid])

        ax.legend()
        ax.set_ylim((y_min, y_max))
        ax.set_ylabel('Membrane voltage [mV]', fontsize=14)
        ax.set_title(title, fontsize=14)
        self.plot_blank(ax, txt='Blank')
def plot_volt(fn, gid=None, n=1):
    print 'loading', fn
    d = np.loadtxt(fn)

    if gid == None:
        recorded_gids = np.unique(d[:, 0])
        gids = random.sample(recorded_gids, n)
        print 'plotting random gids:', gids
    elif gid == 'all':
        gids = np.unique(d[:, 0])
    elif type(gid) == type([]):
        gids = gid
    else:
        gids = [gid]
    
    for gid in gids:
        time_axis, volt = utils.extract_trace(d, gid)
        pylab.plot(time_axis, volt, label='%d' % gid, lw=2)

    parts = fn.rsplit('.')
    output_fn = "" 
    for i in xrange(len(parts)-1):
        output_fn += "%s" % parts[i] + '.'
    output_fn += 'png'
    pylab.legend()
    pylab.title(fn)
Ejemplo n.º 4
0
import pylab
import numpy as np
import utils
import sys

info_text = 'Please give the folder containing the voltage recordings after the script_name'
info_text += '\n USAGE:\n\t python plot_voltages.py [FOLDER_NAME]' 
assert (len(sys.argv) > 1), info_text
folder_name = sys.argv[1]

filenames = utils.find_files(folder_name, 'exc_volt_')
# since you can not decide on the final name your data files will have in NEST (it will depend on the number of processes, for example)
# you need to browse through the folder to retrieve all relevant files to be plotted
print 'Found filenames:', filenames


fig = pylab.figure()
ax = fig.add_subplot(111)

for fn in filenames:
    path = folder_name 
    d = np.loadtxt(fn)
    gids = np.unique(d[:, 0])
    for gid in gids:
        time_axis, volt_trace = utils.extract_trace(d, gid)
        ax.plot(time_axis, volt_trace)


pylab.show()
Ejemplo n.º 5
0
#rate_post_noblank *= rate_post_noblank[0] / rate_post[0] 
#rate_post /= rate_post.max()
rate_post = rate_post[::n_steps] # ::10 because dt for rate creation was 0.1 ms
ax.plot(np.arange(rate_post.size), rate_post, lw=2, c='b')
#rate_post_noblank /= rate_post_noblank.max()
ax.plot(np.arange(rate_post.size), rate_post_noblank, lw=1, ls='--', c='b')
ax.set_xlabel('Time [ms]')
ax.set_ylabel('Normalized motion energy')
ax.set_ylim((y_min, y_max))
ax.set_title('Input to post-synaptic cell')
ax.legend((input_spikes[0], pre_post_spikes[0]), ('Stimulus input spikes', 'Pre->post spikes \ndelayed by %.1f ms' % conn_delay))


# voltage traces
volt = np.loadtxt(volt_sim_fn)
t_axis, v1= utils.extract_trace(volt, 0)
t_axis, v2 = utils.extract_trace(volt, 3)
ax = fig.add_subplot(224)
ax.plot(t_axis, v1, lw=3, ls='--', c='b', label='input=only stimulus')
ax.plot(t_axis, v2, lw=2, c='g', label='input=stim + rec')
ax.set_xlabel('Time [ms]')
ax.set_ylabel('Voltage [mV]')
ax.set_title('Membrane voltages with and\nwithout pre-post connection')
ax.legend(loc='upper right')


#ax = fig.add_subplot(226)
#ax.plot(t_axis, v2 - v1, lw=2, label='diff: (stim+rec) - stim_only')
#ax.set_title('Difference between membrane potentials: \nV_mem(with conn) - V_mem(without pre-post connection)')
#ax.set_xlabel('Time [ms]')
#ax.set_ylabel('Voltage [mV]')