Пример #1
0
    def load_nspikes(self):

        fn = self.params['exc_spiketimes_fn_merged'] + '.ras'
        try:
            self.nspikes_exc = utils.get_nspikes(fn, n_cells=self.params['n_exc'])
        except:
            self.nspikes_exc = np.zeros(self.params['n_exc'])
            print 'No spikes found in ', fn
            self.no_spikes = True
            return

        try:
            self.nspikes_inh = utils.get_nspikes(fn, n_cells=self.params['n_inh'])
        except:
            self.nspikes_inh = np.zeros(self.params['n_inh'])
Пример #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')
Пример #3
0
def plot_output_spikes_sorted_in_space(ax, cell_type, shift=0., m='o', c='g', sort_idx=0, ms=2):
    n_cells = params['n_%s' % cell_type]
    fn = params['%s_spiketimes_fn_merged' % cell_type] + '.ras'
    nspikes, spiketimes = utils.get_nspikes(fn, n_cells, get_spiketrains=True)
    sorted_idx = tp[:, sort_idx].argsort()

    if sort_idx == 0:
        ylim = (0, 1)
    else:
        crop = .8
        ylim = (crop * tp[:, sort_idx].min(), crop * tp[:, sort_idx].max())
    ylen = (abs(ylim[0] - ylim[1]))
    print '\n', 'sort_idx', sort_idx, ylim, 
    for i in xrange(n_cells):
        cell = sorted_idx[i]
        if sort_idx == 0:
            y_pos = (tp[cell, sort_idx] % 1.) / ylen * (abs(ylim[0] - ylim[1]))
        else:
            y_pos = (tp[cell, sort_idx]) / ylen * (abs(ylim[0] - ylim[1]))
        ax.plot(spiketimes[cell], y_pos * np.ones(nspikes[cell]), 'o', color='k', markersize=ms)
Пример #4
0
    def plot_rasterplot(self, cell_type, fig_cnt=1):
        if cell_type == 'inh':
            fn = self.params['inh_spiketimes_fn_merged'] + '.ras'
            n_cells = self.params['n_inh']
        elif cell_type == 'exc':
            fn = self.params['exc_spiketimes_fn_merged'] + '.ras'
            n_cells = self.params['n_exc']

        try:
            nspikes, spiketimes = utils.get_nspikes(fn, n_cells, get_spiketrains=True)
        except:
            print 'Problem loading spiketimes from', fn
            spiketimes = []

        ax = self.fig.add_subplot(self.n_fig_y, self.n_fig_x, fig_cnt)
        print 'debug', n_cells
        for cell in xrange(n_cells):
            ax.plot(spiketimes[cell], cell * np.ones(nspikes[cell]), 'o', color='k', markersize=1)
            
        ax.set_xlim(0, self.params['t_sim'])
        ax.set_title('Rasterplot of %s neurons' % cell_type)
        ax.set_xlabel('Time [ms]')
        ax.set_ylabel('Neuron GID')
Пример #5
0
def plot_spikes(ax, fn, n_cells):
    nspikes, spiketimes = utils.get_nspikes(fn, n_cells, get_spiketrains=True)
    for cell in xrange(int(len(spiketimes))):
        ax.plot(spiketimes[cell], cell * np.ones(nspikes[cell]), 'o', color='k', markersize=2)
Пример #6
0
import utils
import pylab
import matplotlib 
import sys
from matplotlib import cm


# load simulation parameters
PS = simulation_parameters.parameter_storage()
params = PS.load_params()                       # params stores cell numbers, etc as a dictionary

n_cells = params['n_gids_to_record']

d = np.loadtxt(params['exc_spiketimes_fn_merged'] + '.ras')
if d.size > 0:
    nspikes = utils.get_nspikes(params['exc_spiketimes_fn_merged'] + '.ras', n_cells=params['n_exc'])
    spiking_cells = np.nonzero(nspikes)[0]
    fired_spikes = nspikes[spiking_cells]
   
    print 'Number of spikes (sum, max, mean, std):\t%d\t%d\t%.2f\t%.2f' % (nspikes.sum(), nspikes.max(), nspikes.mean(), nspikes.std())
    print '\nspiking cells', len(spiking_cells), spiking_cells, '\n fraction of spiking cells', float(len(spiking_cells))  / params['n_exc']
    print 'fired_spikes mean %.2f +- %.2f' % (fired_spikes.mean(), fired_spikes.std()), fired_spikes
else:
    print 'NO SPIKES'
    exit(1)



def calculate_input_cond():
    input_cond = np.zeros(params['n_exc'])
    for cell in xrange(params['n_exc']):
Пример #7
0
else:
    print "\nPlotting the default parameters given in simulation_parameters.py\n"
    import simulation_parameters

    network_params = (
        simulation_parameters.parameter_storage()
    )  # network_params class containing the simulation parameters
    params = network_params.load_params()  # params stores cell numbers, etc as a dictionary

tp = np.loadtxt(params["tuning_prop_means_fn"])
n_cells = params["n_gids_to_record"]
idx, dist = utils.sort_cells_by_distance_to_stimulus(n_cells, verbose=False)

d = np.loadtxt(params["exc_spiketimes_fn_merged"] + ".ras")
if d.size > 0:
    nspikes = utils.get_nspikes(params["exc_spiketimes_fn_merged"] + ".ras", n_cells=params["n_exc"])
    spiking_cells = np.nonzero(nspikes)[0]
    fired_spikes = nspikes[spiking_cells]

    print "tnspikes\tGID\tmin_dist_to_stim\ttp"
    for i in xrange(n_cells):
        gid = idx[i]
        print nspikes[gid], "\t", gid, "\t", dist[i], tp[gid, :]

    print "Number of spikes (sum, max, mean, std):\t%d\t%d\t%.2f\t%.2f" % (
        nspikes.sum(),
        nspikes.max(),
        nspikes.mean(),
        nspikes.std(),
    )
    print "\nspiking cells", len(spiking_cells), spiking_cells, "\n fraction of spiking cells", float(
            param_fn += '/Parameters/simulation_parameters.json'
        print 'Loading parameters from', param_fn
        f = file(param_fn, 'r')
        params = json.load(f)
    else:
        import simulation_parameters
        ps = simulation_parameters.parameter_storage()
        params = ps.params

    tp = np.loadtxt(params['tuning_prop_means_fn'])

    AQP = ActivityQuiverPlot(params)
    sim_cnt = 0


    # you can also plot the input but do this before:
    # os.system('python merge_input_spikefiles.py')
#    spikes_fn = params['input_folder'] + 'merged_input.dat'
#    if not os.path.exists(spikes_fn):
#        os.system('python merge_input_spikefiles.py %s' % (params['folder_name']))

    spikes_fn = 'InputSpikeTrains_bX1.50e-01_bV1.50e-01_fstim5.0e+03_tsim3000_tblank200_tbeforeblank600_15520nrns/merged_input_800-1200.dat'
#    spikes_fn = params['exc_spiketimes_fn_merged'] + '.ras'
    print 'Loading ', spikes_fn
    # the spikes_fn should store the raw spike trains with spike times in column 0, and gids in column 1
    nspikes = utils.get_nspikes(spikes_fn, n_cells = params['n_exc'])
    print 'nspikes', nspikes.shape
    AQP.set_network_activity(nspikes)
    AQP.plot_activity_as_quiver(tuning_prop=tp)

 def get_nspikes(self):
     spiketimes_fn_merged = self.params['exc_spiketimes_fn_merged'] + str(self.sim_cnt) + '.ras'
     print "Loading nspikes", spiketimes_fn_merged
     self.nspikes = utils.get_nspikes(spiketimes_fn_merged, self.params['n_exc'])
Пример #10
0
params = network_params.load_params()                       # params stores cell numbers, etc as a dictionary
output_fn_base = params['spatial_readout_fn_base'] + 'sim%d_' % sim_cnt
output_fn_movie = params['spatial_readout_movie']
bg_color = 'k'

# parameters
n_frames = 50    # number of output figures
n_bins_x, n_bins_y = 20, 20
output_arrays = [np.zeros((n_bins_x, n_bins_y)) for i in xrange(n_frames)]
time_grid = np.linspace(0, params['t_sim'], n_frames+1, endpoint=True)

# load tuning properties and activity
tuning_prop = np.loadtxt(params['tuning_prop_means_fn'])
n_cells = tuning_prop[:,0].size # = params['n_exc']
fn = params['exc_spiketimes_fn_merged'] + '%d.ras' % (sim_cnt)
nspikes, spiketrains = utils.get_nspikes(fn, n_cells, get_spiketrains=True)
nspikes_normalized = nspikes / nspikes.sum()

print "nspikes", nspikes
print "N_RF_X: %d\tN_RF_Y:%d\tn_exc: %d\tn_inh: %d\tn_cells:%d" % (params['N_RF_X'], params['N_RF_Y'], params['n_exc'], params['n_inh'], params['n_cells'])
#particles = np.vstack((tuning_prop.transpose(), nspikes_normalized))

# parametrize the spatial layout
H, x_edges, y_edges = np.histogram2d(tuning_prop[:,0], tuning_prop[:, 1], bins=(n_bins_x, n_bins_y))
print "x_edges", x_edges, x_edges.size
print "y_edges", y_edges, y_edges.size


z_max = 0
for gid in xrange(n_cells):
    binned_spikes, time_bins = np.histogram(spiketrains[gid], time_grid)
Пример #11
0
import utils
import sys

import simulation_parameters
PS = simulation_parameters.parameter_storage()
params = PS.load_params()                       # params stores cell numbers, etc as a dictionary

try:
    cell_type = sys.argv[1]
except:
    cell_type = 'exc'
spike_fn = params['%s_spiketimes_fn_merged' % cell_type] + '.ras'
print 'Loading ', spike_fn
#np.loadtxt(spike_fn)

nspikes = utils.get_nspikes(spike_fn, params['n_%s' % cell_type])

n_cells = nspikes.nonzero()[0].size

idx = np.argsort(nspikes)
print 'GID\tnspikes'
print '----------------'
#for i in xrange(1, int(round(.2 *(n_cells + 1)))):
for i in xrange(1, n_cells + 1):
    print '%d\t%d' % (idx[-i], nspikes[idx[-i]])

fig = pylab.figure(figsize=(16, 10))
ax = fig.add_subplot(111)
x_axis = range(params['n_%s' % cell_type])
ax.bar(x_axis, nspikes)
ax.set_xlabel('Cell idx %s' % cell_type)
Пример #12
0
rate_post = np.load(params['input_rate_fn_base'] + str(gid_post) + '.npy')
input_spikes_post = np.load(params['input_st_fn_base'] + '%d.npy' % gid_post)
# compute input without blank
rate_post_noblank = np.zeros(params['t_sim'] / params['dt_rate'])
time = np.arange(0, params['t_sim'], params['dt_rate'])
tp_ = np.zeros((1, 4))
tp_[0, :] = tp_exc[gid_post, :]
for i_, t in enumerate(time):
    rate_post_noblank[i_] = utils.get_input(tp_, params, t / params['t_stimulus'])
rate_post_noblank *= params['f_max_stim']

np.save('debug_rate_post_noblank.npy', rate_post_noblank)

# load output spikes from the network simulation (only response to stimulus)
spikes_fn = params['exc_spiketimes_fn_merged'] + '.ras'
nspikes, spiketrains = utils.get_nspikes(spikes_fn, params['n_exc'], get_spiketrains=True)

# only response to stimulus
output_st_pre = spiketrains[gid_pre]
output_st_post = spiketrains[gid_post] 
t_max_input_pre = utils.get_time_of_max_stim(tp_exc[gid_pre, :], mp) * params['t_stimulus']
t_max_input_post = utils.get_time_of_max_stim(tp_exc[gid_post, :], mp) * params['t_stimulus']
t_diff_max = params['t_stimulus'] * (mp[2] * (tp_exc[gid_post, 0] - tp_exc[gid_pre, 0]) + mp[3] * (tp_exc[gid_post, 1] - tp_exc[gid_pre, 1])) / (mp[2]**2 + mp[3]**2)

print 't_max_input_pre (x=%.2f y=%.2f) = %.2f' % (tp_exc[gid_pre, 0], tp_exc[gid_pre, 1], t_max_input_pre)
print 't_max_input_post (x=%.2f y=%.2f) = %.2f' % (tp_exc[gid_post, 0], tp_exc[gid_post, 1], t_max_input_post)
print 'diff = ', t_max_input_post - t_max_input_pre, 't_diff_max = ', t_diff_max


t_max_response_pre, t_max_response_pre_std = utils.get_time_of_max_response(output_st_pre, range=(0, params['t_sim']), n_binsizes=20)
t_max_response_post, t_max_response_post_std = utils.get_time_of_max_response(output_st_post, range=(0, params['t_sim']), n_binsizes=20)