Page 1 of 1

Raster Plot

Posted: Thu Feb 09, 2017 4:57 pm
by FariaVS
Hi guys,

How to create raster plot for simulation in NEURON?

It's my first participation in the forum :)

Re: Raster Plot

Posted: Fri Feb 10, 2017 12:43 pm
by ted
Here's one way to do this, illustrated in hoc. Should work fine as long as the few assumptions stipulated below are true, and that you're using serial execution to run simulations. Pythonists are invited to post their own code that satisfies the same assumptions.

1. Create a List whose elements are Vectors that capture the firing times of your model cells.
This code assumes that you have already set up a network whose cells are instances of cell classes, and that you have appended each of the model cells to a List called "cells":

Code: Select all

// Prepare to record spike trains
objref netcon, vec, spikes, nil // nil is just a handy alias for NULLobject
spikes = new List()

for i=0,cells.count()-1 {  // iterate over all cells
  vec = new Vector()
  netcon = new NetCon(cells.object(i), nil)
  netcon.record(vec)  // vec will record the firing times
  spikes.append(vec)  // add vec to the list of vectors that record firing times

objref netcon, vec  // we don't need these specific references any more
2. Create an instance of the Graph class that will be where you plot your spike rasters. This code will make a graph called graster appear near the top left of your display (screen coordinates are the 5th and 6th arguments):

Code: Select all

objref graster, spikey
graster = new Graph(0)
graster.view(0, 0, tstop, cells.count(), 300, 105, 300.48, 200.32)
3. Write a procedure that can be called to plot the recorded spikes on graster.

Code: Select all

proc showraster() {
  for i = 0,cells.count()-1 {  // iterate over all cells
    // number of elements in spikey must equal number of spikes fired by cell i
    // value of each element must equal i+1
    spikey = spikes.object(i).c
    spikey.mark(graster, spikes.object(i), "|", 6)
  objref spikey  // we don't need this specific reference any more
4. Write customized init and run procedures so that initialization clears the raster plot, and executing a simulation draws marks at appropriate locations in graster.

Code: Select all

proc init() {

proc run() {
        running_ = 1
There you have it. Put this code into a file called raster.hoc, and modify your own model program so that it loads raster.hoc BEFORE it calls run().

Re: Raster Plot

Posted: Tue Feb 21, 2017 5:45 pm
by FariaVS
Yeah, it worked on my model.

Many thanks, Ted.

Do you have any code or suggestions for plotting the F-I curve?


Re: Raster Plot

Posted: Tue Feb 21, 2017 11:44 pm
by ted
Better than that--this archive ...
presents serial and parallel implementations of a program that generates a toy model cell's F-I plot. The parallelization method uses the bulletin-board approach, which is documented in the Programmer's Reference in the section on ParallelContext. The code and how to use it are described in the files
bulletin_board_parallelization.html and walkthroughs.html

Don't feel compelled to use bulletin-board parallelization; serial execution of one simulation after another, with progressively increasing stimulus current, is sufficient. That said, bulletin-board style parallel execution is easy to do and produces a significant speedup.

Whatever you do, be sure to read the relevant entries in the Programmer's Reference if you come across anything you don't already know about.