Skip to content

Commit

Permalink
add synapses, fixed ez_record segment locations
Browse files Browse the repository at this point in the history
  • Loading branch information
ahwillia committed Oct 29, 2014
1 parent 0ddb337 commit 95cca84
Show file tree
Hide file tree
Showing 10 changed files with 468 additions and 14 deletions.
20 changes: 15 additions & 5 deletions PyNeuronToolbox/morphology.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,19 @@ def shapeplot(h,ax,sections=None,order=None,cvals=None,\
return lines

def shapeplot_animate(v,lines,nframes,tscale='linear',\
x_min=-80,x_max=50,cmap=cm.YlOrBr_r):
clim=[-80,50],cmap=cm.YlOrBr_r):
""" Returns animate function which updates color of shapeplot """

if tscale == 'linear':
def animate(i):
i_t = int((i/nframes)*v.shape[0])
for i_seg in range(v.shape[1]):
lines[i_seg].set_color(cmap(int((v[i_t,i_seg]-x_min)*255/(x_max-x_min))))
lines[i_seg].set_color(cmap(int((v[i_t,i_seg]-clim[0])*255/(clim[1]-clim[0]))))
elif tscale == 'log':
def animate(i):
i_t = int(np.round((v.shape[0] ** (1.0/(nframes-1))) ** i - 1))
for i_seg in range(v.shape[1]):
lines[i_seg].set_color(cmap(int((v[i_t,i_seg]-x_min)*255/(x_max-x_min))))
lines[i_seg].set_color(cmap(int((v[i_t,i_seg]-clim[0])*255/(clim[1]-clim[0]))))
else:
raise ValueError("Unrecognized option '%s' for tscale" % tscale)

Expand Down Expand Up @@ -254,9 +254,19 @@ def get_all_sections(h):
def add_pre(h,sec_list,section):
"""
A helper function that traverses a neuron's morphology (or a sub-tree)
of the morphology in pre-order.
of the morphology in pre-order. This is usually not necessary for the
user to import.
"""
sec_list.append(section)
sref = h.SectionRef(sec=section)
for next_node in sref.child:
add_pre(h,sec_list,next_node)
add_pre(h,sec_list,next_node)

def dist_between(h,seg1,seg2):
"""
Calculates the distance between two segments. I stole this function from
a post by Michael Hines on the NEURON forum
(www.neuron.yale.edu/phpbb/viewtopic.php?f=2&t=2114)
"""
h.distance(0, seg1.x, sec=seg1.sec)
return h.distance(seg2.x, sec=seg2.sec)
7 changes: 4 additions & 3 deletions PyNeuronToolbox/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
def ez_record(h,var='v',sections=None,order=None,\
targ_names=None,cust_labels=None):
"""
Plots a 3D shapeplot
Records state variables across segments
Args:
h = hocObject to interface with neuron
Expand Down Expand Up @@ -37,14 +37,15 @@ def ez_record(h,var='v',sections=None,order=None,\
data, labels = [], []
for i in range(len(sections)):
sec = sections[i]
for position in np.linspace(0,1,sec.nseg):
positions = np.linspace(0,1,sec.nseg+2)
for position in positions[1:-1]:
# record data
data.append(h.Vector())
if var is 'v':
data[-1].record(sec(position)._ref_v)
elif var is 'cai':
data[-1].record(sec(position)._ref_cai)
# determine label
# determine labels
if cust_labels is None:
lab = sec.name()+'_'+str(round(position,5))
else:
Expand Down
30 changes: 30 additions & 0 deletions PyNeuronToolbox/synapses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from __future__ import division
import numpy as np

def add_exp2(h,seg,spktimes,e=0,tau1=0.5,tau2=20,weight=0.001):
"""
Adds a double-exponential synapse at seg, with spikes
specified by the list/np.array spktimes. Optional arguments
specify parameters for the synapse. Returns a list of
hocObjects that must be kept in memory (see below).
IMPORTANT: This function requires that you have the vecevent.mod
file compiled and loaded into python. This file can
be found in nrn/share/examples/nrniv/netcon/
IMPORTANT: Neuron requires that you keep the Exp2Syn, VecStim,
NetCon, and Vector objects in memory during the
simulation. You will also need these objects if
you wish to alter the weight of the synapse
or other parameters during the simulation.
"""
syn = h.Exp2Syn(seg)
syn.e = 0
syn.tau1 = 0.5
syn.tau2 = 20
vs = h.VecStim()
vec = h.Vector(np.sort(spktimes)) # Spend a bit of overhead to make sure spktimes are sorted
vs.play(vec)
nc = h.NetCon(vs,syn)
nc.weight[0] = weight
return [syn,vs,nc,vec] # All these things need to be kept in memory
20 changes: 15 additions & 5 deletions build/lib.linux-x86_64-2.7/PyNeuronToolbox/morphology.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,19 @@ def shapeplot(h,ax,sections=None,order=None,cvals=None,\
return lines

def shapeplot_animate(v,lines,nframes,tscale='linear',\
x_min=-80,x_max=50,cmap=cm.YlOrBr_r):
clim=[-80,50],cmap=cm.YlOrBr_r):
""" Returns animate function which updates color of shapeplot """

if tscale == 'linear':
def animate(i):
i_t = int((i/nframes)*v.shape[0])
for i_seg in range(v.shape[1]):
lines[i_seg].set_color(cmap(int((v[i_t,i_seg]-x_min)*255/(x_max-x_min))))
lines[i_seg].set_color(cmap(int((v[i_t,i_seg]-clim[0])*255/(clim[1]-clim[0]))))
elif tscale == 'log':
def animate(i):
i_t = int(np.round((v.shape[0] ** (1.0/(nframes-1))) ** i - 1))
for i_seg in range(v.shape[1]):
lines[i_seg].set_color(cmap(int((v[i_t,i_seg]-x_min)*255/(x_max-x_min))))
lines[i_seg].set_color(cmap(int((v[i_t,i_seg]-clim[0])*255/(clim[1]-clim[0]))))
else:
raise ValueError("Unrecognized option '%s' for tscale" % tscale)

Expand Down Expand Up @@ -254,9 +254,19 @@ def get_all_sections(h):
def add_pre(h,sec_list,section):
"""
A helper function that traverses a neuron's morphology (or a sub-tree)
of the morphology in pre-order.
of the morphology in pre-order. This is usually not necessary for the
user to import.
"""
sec_list.append(section)
sref = h.SectionRef(sec=section)
for next_node in sref.child:
add_pre(h,sec_list,next_node)
add_pre(h,sec_list,next_node)

def dist_between(h,seg1,seg2):
"""
Calculates the distance between two segments. I stole this function from
a post by Michael Hines on the NEURON forum
(www.neuron.yale.edu/phpbb/viewtopic.php?f=2&t=2114)
"""
h.distance(0, seg1.x, sec=seg1.sec)
return h.distance(seg2.x, sec=seg2.sec)
7 changes: 6 additions & 1 deletion build/lib.linux-x86_64-2.7/PyNeuronToolbox/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
def ez_record(h,var='v',sections=None,order=None,\
targ_names=None,cust_labels=None):
"""
Plots a 3D shapeplot
Records state variables across segments
Args:
h = hocObject to interface with neuron
Expand Down Expand Up @@ -38,6 +38,11 @@ def ez_record(h,var='v',sections=None,order=None,\
for i in range(len(sections)):
sec = sections[i]
for position in np.linspace(0,1,sec.nseg):
# ugly fix for single-segment compartments
if sec.nseg == 1:
print 'yeah'
position = 0.5
print position
# record data
data.append(h.Vector())
if var is 'v':
Expand Down
30 changes: 30 additions & 0 deletions build/lib.linux-x86_64-2.7/PyNeuronToolbox/synapses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from __future__ import division
import numpy as np

def add_exp2(h,seg,spktimes,e=0,tau1=0.5,tau2=20,weight=0.001):
"""
Adds a double-exponential synapse at seg, with spikes
specified by the list/np.array spktimes. Optional arguments
specify parameters for the synapse. Returns a list of
hocObjects that must be kept in memory (see below).
IMPORTANT: This function requires that you have the vecevent.mod
file compiled and loaded into python. This file can
be found in nrn/share/examples/nrniv/netcon/
IMPORTANT: Neuron requires that you keep the Exp2Syn, VecStim,
NetCon, and Vector objects in memory during the
simulation. You will also need these objects if
you wish to alter the weight of the synapse
or other parameters during the simulation.
"""
syn = h.Exp2Syn(seg)
syn.e = 0
syn.tau1 = 0.5
syn.tau2 = 20
vs = h.VecStim()
vec = h.Vector(np.sort(spktimes)) # Spend a bit of overhead to make sure spktimes are sorted
vs.play(vec)
nc = h.NetCon(vs,syn)
nc.weight[0] = weight
return [syn,vs,nc,vec] # All these things need to be kept in memory
Empty file.

0 comments on commit 95cca84

Please sign in to comment.