Initialization of LFPy, a module for simulating extracellular potentials.
Group of Computational Neuroscience (compneuro.umb.no), Department of Mathematical Sciences and Technology, Norwegian University of Life Sciences.
Copyright (C) 2012 Computational Neuroscience Group, UMB.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
Classes: |
|
---|---|
Modules: |
|
Bases: object
The main cell class used in LFPy.
Arguments:
morphology : path to morphology file;
v_init: initial potential;
passive: passive mechs are initialized if True;
Ra: axial resistance;
rm: membrane resistivity;
cm: membrane capacitance;
e_pas: passive mechanism reversal potential;
timeres_NEURON: internal dt for NEURON simulation;
timeres_python: overall dt for python simulation;
tstartms: initialization time for simulation <= 0 ms
tstopms: stop time for simulation > 0 ms
nsegs_method: method for setting the number of segments;
max_nsegs_length: max segment length for method 'fixed_length';
lambda_f: AC frequency for method 'lambda_f';
custom_code: list of model-specific code files ([.py/.hoc]);
custom_fun: list of model-specific functions to be called with args:
custom_fun_args: list of arguments passed to custom_fun functions
verbose: switching verbose output on/off
Usage of cell class:
import LFPy
cellParameters = {
'morphology' : 'path/to/morphology',
'rm' : 30000,
'cm' : 1.0,
'Ra' : 150,
'timeres_NEURON' : 0.1,
'timeres_python' : 0.1,
'tstartms' : -50,
'tstopms' : 50,
}
cell = LFPy.Cell(**cellParameters)
cell.simulate()
Save data in cell to filename, using cPickle. It will however destroy any neuron.h objects upon saving, as they cannot be pickled
Usage:
cell.cellpickler('cell.cpickle')
To load this cell again in another session:
import cPickle
f = file('cell.cpickle', 'rb')
cell = cPickle.load(f)
f.close()
import LFPy cell = LFPy.tools.load(‘cell.cpickle’)
Mirror the morphology around given axis, (default x-axis), useful to introduce more heterogeneouties in morphology shapes
Get the index number of a segment in specified section which midpoint is closest to the coordinates defined by the user
Returns neuron idx of segments on interval [z_min, z_max]
Get the idx of parent’s children sections, i.e. compartments ids of sections connected to parent-argument
Get all idx of segments of parent and children sections, i.e. segment idx of sections connected to parent-argument, and also of the parent segments
Get the idx of segments in any section-argument, uses hoc naming instead of general terms as in self.get_idx().
For example:
cell.get_idx_section(section='soma[0]')
will output something like
array([0])
To list all sections in the cell object, type
for sec in cell.allseclist:
print sec.name()
Return the Euclidean distance between midpoints of two segments with indices idx0 and idx1. Will return a float in unit of micrometers.
Return the distance between midpoints of two segments with index idx0 and idx1. The argument returned is a vector [x, y, z], where x = self.xmid[idx1] - self.xmid[idx0] etc.
Return nidx segment indices in section with random probability normalized to the membrane area of segment on interval [z_min, z_max]
Return the probability (0-1) for synaptic coupling on segments in section sum(prob)=1 over all segments in section. Prob. determined by area.
Return the normalized probability (0-1) for synaptic coupling on segments in idx-array. Normalised probability determined by area of segments.
Initialize spiketimes from netcon if they exist
Insert pptype-electrode type pointprocess on segment numbered idx on cell object, with keyword arguments according to types: SEClamp, VClamp, IClamp, SinIClamp, ChirpIClamp. idx, pptype, **kwargs is passed on from PointProcessElectrode class.
Move the cell geometry so that midpoint of soma section is in (xpos, ypos, zpos). If no soma pos, use the first segment
Rotate geometry of cell object around the x-, y-, z-axis in that order. Input should be angles in radians.
using rotation matrices, takes dict with rot. angles, where x, y, z are the rotation angles around respective axes. All rotation angles are optional.
Usage:
cell = LFPy.Cell(**kwargs)
rotation = {'x' : 1.233, 'y' : 0.236, 'z' : np.pi}
cell.set_rotation(**rotation)
Insert syntype (e.g. ExpSyn) synapse on segment with index idx, **kwargs passed on from class PointProcessSynapse.
This is the main function running the simulation of the NEURON model. Start NEURON simulation and record variables specified by arguments.
Arguments:
electrode: Either an LFPy.RecExtElectrode object or a list of such.
If supplied, LFPs will be calculated at every time step
and accessible as electrode.LFP. If a list of objects
is given, accessible as electrode[0].LFP etc.
rec_imem: If true, segment membrane currents will be recorded
If no electrode argument is given, it is necessary to
set rec_imem=True in order to calculate LFP later on.
rec_vmem: record segment membrane voltages
rec_ipas: record passive segment membrane currents
rec_icap: record capacitive segment membrane currents
rec_isyn: record synaptic currents of from Synapse class instances
rec_vmemsyn: record membrane voltage of segments with Synapse
rec_istim: record currents of StimIntraElectrode
rec_variables: list of variables to record, i.e arg=['cai', ]
Destroy any NEURON hoc objects in the cell object
Superclass on top of Synapse, StimIntElectrode, just to import and set some shared variables.
Arguments:
cell : LFPy.Cell object
idx : index of segment
color : color in plot (optional)
marker : marker in plot (optional)
record_current : Must be set True for recording of pointprocess currents
kwargs : pointprocess specific variables passed on to cell/neuron
Extract coordinates of point-process
Bases: LFPy.pointprocess.PointProcess
The synapse class, pointprocesses that spawn membrane currents. See http://www.neuron.yale.edu/neuron/static/docs/help/neuron/neuron/mech.html#pointprocesses for details, or corresponding mod-files.
This class is meant to be used with synaptic mechanisms, giving rise to currents that will be part of the membrane currents.
Usage:
#!/usr/bin/env python
import LFPy
import pylab as pl
pl.interactive(1)
cellParameters = {
'morphology' : 'morphologies/L5_Mainen96_LFPy.hoc',
'tstopms' : 50,
}
cell = LFPy.Cell(**cellParameters)
synapseParameters = {
'idx' : cell.get_closest_idx(x=0, y=0, z=800),
'e' : 0, # reversal potential
'syntype' : 'ExpSyn', # synapse type
'tau' : 2, # syn. time constant
'weight' : 0.01, # syn. weight
'record_current' : True # syn. current record
}
synapse = LFPy.Synapse(cell, **synapseParameters)
synapse.set_spike_times(pl.array([10, 15, 20, 25]))
cell.simulate(rec_isyn=True)
pl.subplot(211)
pl.plot(cell.tvec, synapse.i)
pl.title('Synapse current (nA)')
pl.subplot(212)
pl.plot(cell.tvec, cell.somav)
pl.title('Somatic potential (mV)')
Collect synapse current
Collect membrane potential of segment with synapse
Set the spike times
Bases: LFPy.pointprocess.PointProcess
Class for NEURON point processes, ie VClamp, SEClamp and ICLamp, SinIClamp, ChirpIClamp with arguments. Electrode currents go here. Membrane currents will no longer sum to zero if these mechanisms are used.
Refer to NEURON documentation @ neuron.yale.edu for kwargs
Usage example:
#/usr/bin/python
import LFPy
import pylab as pl
pl.interactive(1)
#define a list of different electrode implementations from NEURON
pointprocesses = [
{
'idx' : 0,
'record_current' : True,
'pptype' : 'IClamp',
'amp' : 1,
'dur' : 20,
'delay' : 10,
},
{
'idx' : 0,
'record_current' : True,
'pptype' : 'VClamp',
'amp[0]' : -65,
'dur[0]' : 10,
'amp[1]' : 0,
'dur[1]' : 20,
'amp[2]' : -65,
'dur[2]' : 10,
},
{
'idx' : 0,
'record_current' : True,
'pptype' : 'SEClamp',
'dur1' : 10,
'amp1' : -65,
'dur2' : 20,
'amp2' : 0,
'dur3' : 10,
'amp3' : -65,
},
]
#create a cell instance for each electrode
for pointprocess in pointprocesses:
cell = LFPy.Cell(morphology='morphologies/L5_Mainen96_LFPy.hoc')
stimulus = LFPy.StimIntElectrode(cell, **pointprocess)
cell.simulate(rec_istim=True)
pl.subplot(211)
pl.plot(cell.tvec, stimulus.i, label=pointprocess['pptype'])
pl.legend(loc='best')
pl.title('Stimulus currents (nA)')
pl.subplot(212)
pl.plot(cell.tvec, cell.somav, label=pointprocess['pptype'])
pl.legend(loc='best')
pl.title('Somatic potential (mV)')
Fetch electrode current from recorder list
Collect membrane potential of segment with PointProcess
RecExtElectrode superclass. If (optional) cell argument is given then the it is imported, otherwise the cell argument has to be passed later on to calc_lfp. The argument cell can be an LFPy.cell.Cell object or either a list or a dictionary containing such Cell objects. Keyword arguments determine properties of later LFP-calculations
Arguments:
sigma : extracellular conductivity
x, y, z : coordinates or arrays of coordinates. Must be same length
N : Normal vector [x, y, z] of contact surface, default None
r : radius of contact surface, default None
n : if N != None and r > 0, the number of points to use for each
contact point in order to calculate average
color : color of electrode contact points in plots
marker : marker of electrode contact points in plots
from_file : if True, load cell object from file
cellfile : path to cell pickle
verbose : Flag for verbose output
seedvalue : fixed seed when finding random position on contact with r >0
Empty object that cell-specific variables are stored in
Bases: LFPy.recextelectrode.RecExtElectrodeSetup
RecExtElectrode class with inheritance from LFPy.RecExtElectrodeSetup able to actually calculate local field potentials from LFPy.Cell objects. **kwargs are passed on to LFPy.RecExtElectrodeSetup
Usage:
import LFPy
import pylab as pl
N = pl.empty((16, 3))
for i in xrange(N.shape[0]): N[i,] = [1, 0, 0] #normal unit vec. to contacts
electrodeParameters = { #parameters for RecExtElectrode class
'sigma' : 0.3, #Extracellular potential
'x' : pl.zeros(16)+25, #Coordinates of electrode contacts
'y' : pl.zeros(16),
'z' : pl.linspace(-500,1000,16),
'n' : 20,
'r' : 10,
'N' : N,
}
cellParameters = {
'morphology' : 'L5_Mainen96_LFPy.hoc', # morphology file
'rm' : 30000, # membrane resistivity
'cm' : 1.0, # membrane capacitance
'Ra' : 150, # axial resistivity
'timeres_NEURON' : 2**-4, # dt for NEURON sim.
'timeres_python' : 2**-4, # dt for python output
'tstartms' : -50, # start t of simulation
'tstopms' : 50, # end t of simulation
}
cell = LFPy.Cell(**cellParameters)
synapseParameters = {
'idx' : cell.get_closest_idx(x=0, y=0, z=800), # compartment
'e' : 0, # reversal potential
'syntype' : 'ExpSyn', # synapse type
'tau' : 2, # syn. time constant
'weight' : 0.01, # syn. weight
'record_current' : True # syn. current record
}
synapse = LFPy.PointProcessSynapse(cell, **synapseParameters)
synapse.set_spike_times(cell, pl.array([10, 15, 20, 25]))
cell.simulate()
electrode = LFPy.RecExtElectrode(cell, **electrodeParameters)
electrode.calc_lfp()
pl.matshow(electrode.LFP)
Calculate LFP on electrode geometry from all cell instances. Will chose distributed calculated if electrode contain ‘n’, ‘N’, and ‘r’
Copyright (C) 2012 Computational Neuroscience Group, UMB.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
Determine which method to use, line-source for soma default
Calculate electric field potential using the line-source method, all compartments treated as line sources, even soma.
Calculate local field potentials using the point-source equation on all compartments
Calculate electric field potential using the line-source method, soma is treated as point/sphere source
Copyright (C) 2012 Computational Neuroscience Group, UMB.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
Return 1/f^2 noise of shape(nrows, ncols obtained by taking the cumulative sum of gaussian white noise, with rms weight.
If filter != None, this function will apply the filter coefficients obtained by:
>>> b, a = filter(**filterargs)
>>> signal = scipy.signal.lfilter(b, a, signal)
Copyright (C) 2012 Computational Neuroscience Group, UMB.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
Generates n normal-distributed prosesses with mean mu and deviation sigma
Generate nsyn normal-distributed processes with mean mu and deviation sigma
Return synpos times nspikes random spike times on the interval [tstart, tstop]
Generate spiketimes with interspike interval statistics according to gamma-distribution with ‘shape’ k and ‘scale’ theta between tstart and tstop. Spiketimes from tmin up to tmax is calculated, times between 0 and tstop are returned
Copyright (C) 2012 Computational Neuroscience Group, UMB.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.