File: spkplot.hoc

package info (click to toggle)
neuron 7.6.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 48,268 kB
  • sloc: cpp: 192,952; ansic: 145,860; python: 42,092; sh: 10,507; makefile: 6,816; yacc: 3,259; java: 995; lex: 457; csh: 108; pascal: 37; sed: 5
file content (407 lines) | stat: -rw-r--r-- 11,777 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
// originally created by Michael Hines

// Modified      June 9, 2006   Added spikeplot styles, subset selection
//                              and new plot styles.  Ronald A.J. van Elburg
//               April, 2009    Made x-axis scaling consistent over different 
//               Marked @PR2    individual ISI distributions. R.A.J. van Elburg

begintemplate SpikePlot
public net, vecs, g, update
public map, save_data, save, b
public flush, begin, plot, size, view_count, fastflush, simgraph
external addplot, tstop
objref net, vecs[1], nc, g, this, y, ps, tobj, b, outlist, nil
strdef tstr, modestr
proc init() {
	outlist = new List()
	fwindow = 100
	binwidth = 10
	high=1000
	modestr = "Spikes   "
	mode=1
	spikeplotstyle=0
	marksize=4
	markcolor=1
	useline=1
	
	y = new Vector(1000)
	net = $o1
	subset_start=-1
	subset_end=-1
	lsubset_start=0
	lsubset_end=0
	
	
	if (numarg() == 1) {
		build()
		map()
	}
}
proc map() {
	sprint(tstr, "%s for %s staf/elburg", this, net)
	if (numarg() > 1) {
		b.map(tstr, $2,$3,$4,$5)
	}else{
		b.map(tstr)
	}
	update()
	flush()
}
proc unmap() {
	b.unmap()
	g = nil
}
proc build() {
	b = new VBox(3)
	b.priority(600)
	b.save("save()")
	b.ref(this)
	b.dismiss_action("unmap()")
	b.intercept(1)
	xpanel("")
	xmenu("Plot")
	xbutton("Update", "update() flush()")
		xmenu("Plot Style")
			xradiobutton("Spikes", "pmode(1)", mode==1)
			xradiobutton("Frequency (Gaussian Window)", "pmode(2)", mode==2)
			xradiobutton("Frequency (Binned)", "pmode(10)", mode==10)
			xradiobutton("ISI Histogram (Gaussian Window)", "pmode(3)", mode==3)
			xradiobutton("ISI Histogram (Binned)", "pmode(4)", mode==4)
			xradiobutton("Cumulative Frequency (Gaussian Window)", "pmode(5)", mode==5)
			xradiobutton("Cumulative Frequency (Binned)", "pmode(6)", mode==6)
			xradiobutton("Cumulative ISI Histogram (Gaussian Window)", "pmode(7)", mode==7)
			xradiobutton("Cumulative ISI Histogram (Binned)", "pmode(8)", mode==8)
		    xradiobutton("Powerspectrum (Gaussian Window)", "pmode(9)", mode==9)
		xmenu()	
		xmenu("Spike Plot Style")
			xradiobutton("Pipe", "pspikeplotstyle(0)", spikeplotstyle==0)
			xradiobutton("Filled Circle", "pspikeplotstyle(1)", spikeplotstyle==1)
			xradiobutton("Filled Triangle", "pspikeplotstyle(2)", spikeplotstyle==2)
			xradiobutton("Filled Square", "pspikeplotstyle(3)", spikeplotstyle==3)
			xradiobutton("Open Circle", "pspikeplotstyle(4)", spikeplotstyle==4)
			xradiobutton("Open Triangle", "pspikeplotstyle(5)", spikeplotstyle==5)
			xradiobutton("Open Square", "pspikeplotstyle(6)", spikeplotstyle==6)
			xbutton("Pick Size and Color","EditMark()")
			xstatebutton("Use Line",&useline ,"flush()")
		xmenu()
		
		xbutton("Select Subset","selectSubset()")
		
	xmenu()
	xvarlabel(modestr)
	xpvalue("Gaussian Window Size (ms)", &fwindow, 1, "flush()")
	xpvalue("Bin Size (ms)", &binwidth, 1, "flush()")
	xpvalue("Maximum ISI Size (ms)", &high, 1, "flush()")
	xpanel()
	g = new Graph()
	b.intercept(0)
	addplot(this, 1)
	begin()
	pmode(mode)
}


proc pmode() {
	mode = $1
	if (mode == 1) {
		modestr = "Spikes   "
	}else if (mode == 2) {
		modestr = "Frequency (Hz, Gaussian Window)"
	}else if (mode == 3) {
		modestr = "ISI Histogram (Gaussian Window)"
	}else if (mode == 4) {
		modestr = "ISI Histogram (Binned)"
	}else if (mode == 5) {
		modestr = "Cumulative Frequency (Hz, Gaussian Window)"
	}else if (mode == 6) {
		modestr = "Cumulative Frequency (Hz, Binned)"
	}if (mode == 7) {
		modestr = "Cumulative ISI Histogram (Gaussian Window)"
	}else if (mode == 8) {
		modestr = "Cumulative ISI Histogram (Binned)"
	}else if (mode == 9) {
		modestr = "Powerspectrum (Gaussian Window)"
	}else if (mode == 10) {
		modestr = "Frequency (Hz, Binned)"
	}
	flush()
}

proc pspikeplotstyle(){
	spikeplotstyle=$1
	flush()
}

proc EditMark(){
	xpanel("Edit Mark Size and Color")
		xpvalue("Mark size",  &marksize  , 0, "flush()")
		xpvalue("Mark color", &markcolor , 0, "flush()")
	xpanel()
}

proc selectSubset(){
	lsubset_start=subset_start
	lsubset_end=subset_end
	
	xpanel("Select Subset")
		xpvalue("Subset Start",  &lsubset_start , 0, "setSubset()")
		xpvalue("Subset End", &lsubset_end , 0, "setSubset()")
	xpanel()
	
	
}

proc setSubset(){
	//print "setSubset start: ",  lsubset_start, " end: ", lsubset_end , " n: ", n
	if(0 <= lsubset_start && lsubset_start <= lsubset_end && lsubset_end <= n){
		subset_start=lsubset_start
		subset_end=lsubset_end
		flush()
	}
	lsubset_start=subset_start
	lsubset_end=subset_end
}

proc update() {local i localobj vec
	//print "Update start: ",  lsubset_start, " end: ", lsubset_end , " n: ", n
	if (net.created_) {
		n = net.sources.count
	}else{
		n = 0
	}
	
	if(n<subset_end || subset_end==-1) {
		subset_end=n
	}
	
	if(n<subset_start|| subset_start==-1) {
		subset_start=0
	}
	
	if (n == 0) return
	objref vecs[n]
	for (i=outlist.count-1; i >= 0; i -= 1) {
		if (outlist.object(i).valid == 0) {
			outlist.remove(i)
		}
	}
	for i=0, n-1 {
		vecs[i] = new Vector(0)
		tobj = net.sources.object(i).cell
		nc = tobj.real.connect2target(nil)
		tobj.name(tstr)
		if (tobj.type.is_art == 0) {
			if (nc.precelllist.count < 2) {
				outlist.append(nc)
			}
		}
	
		vec=nc.get_recordvec()
		if(vec==nil){
			nc.record(vecs[i])
		}else{
			vecs[i]=vec
		}
		vecs[i].label(tstr)
	}
	objref nc, tobj
}

proc simgraph() {}
proc begin() {}

func view_count() {
	if (g == nil) {
		return 0
	}
	return g.view_count()
}
proc plot() {}
func size() {
	if (numarg() == 4) {
		g.size($1,$2,0,subset_end+1-subset_start)
		return 1.
	}else{
		return g.size($1)
	}
}
proc fastflush() {}


proc flush() {local i
	g.erase_all
	g.vfixed(1)
	g.label(.9,1)
	if (mode == 1) {			//"Spikes   "
		for (i=subset_end-1; i >= subset_start; i -= 1) {
			y.resize(vecs[i].size).fill(i+1-subset_start)
			y.label(vecs[i].label)
			if (spikeplotstyle==0){
				y.mark(g, vecs[i], "|", marksize, markcolor, 1)  //	Pipe"
			}else if (spikeplotstyle==1){
				y.mark(g, vecs[i], "O", marksize, markcolor, 1)  //	"Filled Circle"
			}else if (spikeplotstyle==2){
				y.mark(g, vecs[i], "T", marksize, markcolor, 1)	 // "Filled Triangle"
			}else if (spikeplotstyle==3){
				y.mark(g, vecs[i], "S", marksize, markcolor, 1)	 // "Filled Square" 
			}else if (spikeplotstyle==4){
				y.mark(g, vecs[i], "o", marksize, markcolor, 1)  //	"Open Circle"
			}else if (spikeplotstyle==5){
				y.mark(g, vecs[i], "t", marksize, markcolor, 1)	 // "Open Triangle"
			}else if (spikeplotstyle==6){
				y.mark(g, vecs[i], "s", marksize, markcolor, 1)	 // "Open Square" 
			}
			if(1==useline){	
				y.line(g, vecs[i], markcolor, 0)
			}
		}
		size(0,tstop,0,0)
	}else if (mode == 2) { //"Frequency (Gaussian Window)"
		for (i=subset_end-1; i >= subset_start; i -= 1) {
		    //print "sumgauss"
			y = vecs[i].sumgauss(0, tstop, binwidth, fwindow*fwindow)
			//print "label"
			y.label(vecs[i].label)
			//print "line"
			y.mul(1000).line(g, y.c.indgen(0, binwidth), 1,1)
			//print "resize"
			g.exec_menu("View = plot")
		}
	}else if (mode == 10) { //"Frequency (Binned)"
		for (i=subset_end-1; i >= subset_start; i -= 1) {
			y = vecs[i].histogram(0, tstop, binwidth)
			y.label(vecs[i].label)
			y.mul(1000/binwidth).line(g, y.c.indgen(0, binwidth), 1,1)
			g.exec_menu("View = plot")
		}
	}else if (mode == 3) {//"ISI Histogram (Gaussian Window)"
        for (i=subset_end-1; i >= subset_start; i -= 1) if (vecs[i].size > 1){
			y = vecs[i].c.deriv(1,1)
			//print "sumgauss"
			y = y.sumgauss(0, high, binwidth, fwindow*fwindow)
			//print "label"
			y.label(vecs[i].label)
			//print "line"
			y.line(g, y.c.indgen(0,  binwidth), 1,1)
			//print "resize"
			g.exec_menu("View = plot")
		}
	}else if (mode == 4) {//"ISI Histogram (Binned)"
        for (i=subset_end-1; i >= subset_start; i -= 1) if (vecs[i].size > 1){
			y = vecs[i].c.deriv(1,1)
			y = y.histogram(0, high, binwidth)
			y=y.c(1)
			y.label(vecs[i].label)
			y.line(g, y.c.indgen(0, binwidth), 1,1)
			g.exec_menu("View = plot")
		}
	}else if (mode == 5) {//"Cumulative Frequency (Gaussian Window)"
		y  = new Vector ()
		for (i=subset_end-1; i >= subset_start; i -= 1) {
			y = y.append(vecs[i])
		}
		y = y.sumgauss(0, tstop, binwidth, fwindow*fwindow)
		y.label(modestr)
		y.mul(1000).line(g, y.c.indgen(0, binwidth), 1,1)
		g.exec_menu("View = plot")
	}else if (mode == 6) {//"Cumulative Frequency (Binned)"

		y  = new Vector ()
		for (i=subset_end-1; i >= subset_start; i -= 1) {
			y = y.append(vecs[i])
		}
		y = y.histogram(0, tstop, binwidth)
		y=y.c(1)
		y.label(modestr)
		y.line(g, y.c.indgen(0, binwidth), 1,1)
		g.exec_menu("View = plot")
	}else if (mode == 7) {//"Cumulative ISI Histogram (Gaussian Window)"
		y  = new Vector ()
		for (i=subset_end-1; i >= subset_start; i -= 1) {
			y = y.append(vecs[i])
		}
		if (y.size > 1){
			y = y.c.deriv(1,1)
			y = y.sumgauss(0, high, binwidth, fwindow*fwindow)
			y.label(modestr)
			y.line(g, y.c.indgen(0, binwidth), 1,1)
			g.exec_menu("View = plot")
		}
	}else if (mode == 8) {//"Cumulative ISI Histogram (Binned)"
		y  = new Vector ()
		for (i=subset_end-1; i >= subset_start; i -= 1) {
			y = y.append(vecs[i])
		}
		if (y.size > 1){
			y = y.c.deriv(1,1)
			y = y.histogram(0, high, binwidth)
			y=y.c(1)
			y.label(modestr)
			y.line(g, y.c.indgen(0, binwidth), 1,1)
			g.exec_menu("View = plot")
		}	
	}else if (mode == 9) {//"Powerspectrum"
		y  = new Vector ()
		ps =new Vector()
		for (i=subset_end-1; i >= subset_start; i -= 1) {
			y = y.append(vecs[i])
		}
		if (y.size > 0){
		  y = y.sumgauss(0, tstop,binwidth, fwindow)
			ps.spctrm(y)		// spectrum
			ps.label(modestr)
			
			
			if (spikeplotstyle==0){
				ps.mark(g, ps.c.indgen(0, 1000/(2*binwidth),1000/(2*binwidth*ps.size())), "|", marksize, markcolor, 1)  //	Pipe"
			}else if (spikeplotstyle==1){
				ps.mark(g, ps.c.indgen(0, 1000/(2*binwidth),1000/(2*binwidth*ps.size())), "O", marksize, markcolor, 1)  //	"Filled Circle"
			}else if (spikeplotstyle==2){
				ps.mark(g, ps.c.indgen(0, 1000/(2*binwidth),1000/(2*binwidth*ps.size())), "T", marksize, markcolor, 1)	 // "Filled Triangle"
			}else if (spikeplotstyle==3){
				ps.mark(g, ps.c.indgen(0, 1000/(2*binwidth),1000/(2*binwidth*ps.size())), "S", marksize, markcolor, 1)	 // "Filled Square"
			}else if (spikeplotstyle==4){
				ps.mark(g,ps.c.indgen(0, 1000/(2*binwidth),1000/(2*binwidth*ps.size())), "o", marksize, markcolor, 1)  //	"Open Circle"
			}else if (spikeplotstyle==5){
				ps.mark(g, ps.c.indgen(0, 1000/(2*binwidth),1000/(2*binwidth*ps.size())), "t", marksize, markcolor, 1)	 // "Open Triangle"
			}else if (spikeplotstyle==6){
				ps.mark(g, ps.c.indgen(0, 1000/(2*binwidth),1000/(2*binwidth*ps.size())), "s", marksize, markcolor, 1)	 // "Open Square"
			}
			
			if(1==useline){	
			    ps.line(g, ps.c.indgen(0, 1000/(2*binwidth),1000/(2*binwidth*ps.size())), markcolor, 1)
			}
			
			g.exec_menu("View = plot")
		}	
	}
	g.flush()
}

proc save() {
	b.save("load_file(\"netbild.hoc\")\n}")
	save_data(b, "ocbox_")
	b.save("{")
}

proc save_data() {
	sprint(tstr, "{%s = new SpikePlot(%s,1)}", $s2, net) $o1.save(tstr)
	sprint(tstr, "{object_push(%s)}", $s2) $o1.save(tstr)
	sprint(tstr, "mode = %g", mode) $o1.save(tstr)
	sprint(tstr, "spikeplotstyle= %g", spikeplotstyle) $o1.save(tstr)
	sprint(tstr, "marksize= %g",  marksize ) $o1.save(tstr)
	sprint(tstr, "markcolor= %g", markcolor) $o1.save(tstr)
	sprint(tstr, "useline= %g",  useline) $o1.save(tstr)
	sprint(tstr, "fwindow = %g", fwindow) $o1.save(tstr)
	sprint(tstr, "binwidth = %g", binwidth) $o1.save(tstr)
	$o1.save("build()")
	sprint(tstr, "subset_start=%g",subset_start) $o1.save(tstr)
	sprint(tstr, "subset_end = %g",subset_end) $o1.save(tstr)
	sprint(tstr, "{g.size(%g,%g,%g,%g)}", \
		g.size(1), g.size(2), g.size(3), g.size(4))
	$o1.save(tstr)
	$o1.save("{object_pop()}")
}

endtemplate SpikePlot