2015/nlp15: space_test.py

File space_test.py, 1.8 KB (added by sergiodavies, 4 years ago)

Example of topological description of a network, presented during the PyNN introduction

Line 
1#!/usr/bin/python
2import pyNN.spiNNaker as p
3import numpy, pylab
4
5p.setup(timestep=1.0, min_delay = 1.0, max_delay = 16.0)
6
7
8cell_params_lif = {'cm'        : 0.25, # nF
9                     'i_offset'  : 0.0,
10                     'tau_m'     : 20.0,
11                     'tau_refrac': 2.0,
12                     'tau_syn_E' : 5.0,
13                     'tau_syn_I' : 5.0,
14                     'v_reset'   : -70.0,
15                     'v_rest'    : -65.0,
16                     'v_thresh'  : -50.0,
17                     'v_init'    : -65.0
18                     }
19
20populations = list()
21projections = list()
22
23weight_to_spike = 3.0
24end_time = 200
25
26space1 = p.Line()
27spikeArray = {'spike_times': [range(0,end_time,50), range(0,end_time,50), range(0,end_time,50), range(0,end_time,50)]}
28populations.append(p.Population(4, p.SpikeSourceArray, spikeArray, label='inputSpikes_1', structure=space1))
29
30populations.append(p.Population(1, p.IF_curr_exp, cell_params_lif, label='pop_1'))
31
32delay_set = list(5*(1+populations[0].positions[0,:]))
33print delay_set
34projections.append(p.Projection(populations[0], populations[1], p.AllToAllConnector(weights=weight_to_spike, delays=delay_set)))
35
36populations[0].record()
37populations[1].record()
38
39p.run(end_time)
40
41spikes_1 = populations[0].getSpikes(compatible_output=True)
42spikes_2 = populations[1].getSpikes(compatible_output=True)
43spikes_2[:,0] += 4
44spikes=numpy.ndarray([len(spikes_1)+len(spikes_2),2])
45spikes[0:len(spikes_1)]=spikes_1
46spikes[len(spikes_1):]=spikes_2
47
48
49if spikes is not None:
50    # print spikes
51    pylab.figure()
52    pylab.plot([i[1] for i in spikes], [i[0] for i in spikes], ".")
53    pylab.ylabel('neuron id')
54    pylab.ylim( -1, 5 )
55    pylab.xlabel('Time/ms')
56    pylab.title('spikes')
57    pylab.show()
58else:
59    print "No spikes received"
60
61p.end()