Raster Plot

Using the graphical user interface to build and exercise models. Includes customizing the GUI by writing a little bit of hoc.
Post Reply
FariaVS
Posts: 9
Joined: Wed Feb 08, 2017 9:06 am

Raster Plot

Post by FariaVS » Thu Feb 09, 2017 4:57 pm

Hi guys,

How to create raster plot for simulation in NEURON?

It's my first participation in the forum :)

ted
Site Admin
Posts: 5091
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Raster Plot

Post by ted » Fri Feb 10, 2017 12:43 pm

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.size(0,tstop,0,cells.count())
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() {
  graster.erase_all()
  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.fill(i+1)
    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() {
        finitialize(v_init)
        fcurrent()
        graster.erase_all()
}

proc run() {
        running_ = 1
        stdinit()
        continuerun(tstop)
        showraster()
}
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().

FariaVS
Posts: 9
Joined: Wed Feb 08, 2017 9:06 am

Re: Raster Plot

Post by FariaVS » Tue Feb 21, 2017 5:45 pm

Yeah, it worked on my model.

Many thanks, Ted.

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

Regards

ted
Site Admin
Posts: 5091
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Raster Plot

Post by ted » Tue Feb 21, 2017 11:44 pm

Better than that--this archive
https://www.neuron.yale.edu/ftp/ted/neu ... zation.zip
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.

Post Reply