Skip to content

Commit

Permalink
Merge ebd261e into 9cbe65f
Browse files Browse the repository at this point in the history
  • Loading branch information
alejoe91 committed Apr 1, 2020
2 parents 9cbe65f + ebd261e commit 98069cf
Show file tree
Hide file tree
Showing 36 changed files with 931 additions and 282 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
language: python
python:
- "2.7"
- "3.4"
- "3.5"
- "3.6"
- "3.7"
- "3.8"
Expand Down
2 changes: 1 addition & 1 deletion LFPy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* run_simulations - Functions to run NEURON simulations
"""

__version__ = "2.0.7"
from .version import version as __version__

from .pointprocess import Synapse, PointProcess, StimIntElectrode
from .recextelectrode import RecExtElectrode, RecMEAElectrode
Expand Down
1 change: 0 additions & 1 deletion LFPy/alias_method.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import division
import numpy as np


Expand Down
2 changes: 1 addition & 1 deletion LFPy/alias_method.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
# cython: language_level=2

from __future__ import division

import numpy as np
cimport numpy as np
cimport cython
Expand Down
95 changes: 89 additions & 6 deletions LFPy/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
GNU General Public License for more details.
"""

from __future__ import division

import os
import neuron
import numpy as np
Expand Down Expand Up @@ -463,8 +463,6 @@ def _create_sectionlists_from_morphology_value(self):
self.somalist.append(sec=sec)
self.nsomasec += 1



def _get_idx(self, seclist):
"""Return boolean vector which indexes where segments in seclist
matches segments in neuron.h.allsec(), rewritten from
Expand Down Expand Up @@ -543,6 +541,7 @@ def _set_extracellular(self):

for sec in self.allseclist:
sec.insert('extracellular')
self.extracellular = True

def set_synapse(self, idx, syntype,
record_current=False,
Expand Down Expand Up @@ -888,8 +887,8 @@ def get_rand_idx_area_and_distribution_norm(self, section='allsec', nidx=1,
>>> cell = LFPy.Cell(morphology=join('cells', 'cells', 'j4a.hoc'))
>>> cell.set_rotation(x=4.99, y=-4.33, z=3.14)
>>> idx = cell.get_rand_idx_area_and_distribution_norm(nidx=10000,
fun=ss.norm,
funargs=dict(loc=0, scale=200))
fun=ss.norm,
funargs=dict(loc=0, scale=200))
>>> bins = np.arange(-30, 120)*10
>>> plt.hist(cell.zmid[idx], bins=bins, alpha=0.5)
>>> plt.show()
Expand Down Expand Up @@ -924,6 +923,90 @@ def get_rand_idx_area_and_distribution_norm(self, section='allsec', nidx=1,
p /= p.sum()
return alias_method(poss_idx, p, nidx)

def enable_extracellular_stimulation(self, electrode, t_ext=None, n=1, model='inf'):
r"""
Enable extracellular stimulation with 'extracellular' mechanism.
Extracellular potentials are computed from the electrode currents
using the pointsource approximation.
If 'model' is 'inf' (default), potentials are computed as
(:math:`r_i` is the position of a comparment i,
:math:`r_e` is the position of an elextrode e, :math:`\sigma` is the
conductivity of the medium):
.. math::
V_e(r_i) = \sum_n \frac{I_n}{4 \pi \sigma |r_i - r_n|}
If model is 'semi', the method of images is used:
.. math::
V_e(r_i) = \sum_n \frac{I_n}{2 \pi \sigma |r_i - r_n|}
Parameters
----------
electrode: RecExtElectrode
Electrode object with stimulating currents
t_ext: np.ndarray or list
Time im ms corrisponding to step changes in the provided currents.
If None, currents are assumed to have
the same time steps as NEURON simulation.
n: int
Points per electrode to compute spatial averaging
model: str
'inf' or 'semi'. If 'inf' the medium is assumed to be infinite and
homogeneous. If 'semi', the method of
images is used.
Returns
-------
v_ext: np.ndarray
Computed extracellular potentials at cell mid points
"""
# access electrode object and append mapping
if electrode is not None:
# put electrode argument in list if needed
if type(electrode) == list:
electrodes = electrode
else:
electrodes = [electrode]
else:
print("'electrode' is None")
return

assert model in ['inf', 'semi'], "'model' can be 'inf' or 'semi'"

# extracellular stimulation
if np.any([np.any(el.probe.currents != 0) for el in electrodes]):
cell_mid_points = np.array([self.xmid, self.ymid, self.zmid]).T
n_tsteps = int(self.tstop / self.dt + 1)
t_cell = np.arange(n_tsteps) * self.dt

if t_ext is None:
print("Assuming t_ext is the same as simulation time")
t_ext = t_cell
for electrode in electrodes:
assert electrode.probe.currents.shape[1] == len(t_cell), \
"Discrepancy between t_ext and cell simulation time steps. Provide the 't_ext' argument"
else:
assert len(t_ext) < len(t_cell), "Stimulation time steps are greater than cell simulation steps"

v_ext = np.zeros((self.totnsegs, len(t_ext)))
for electrode in electrodes:
if np.any(np.any(electrode.probe.currents != 0)):
electrode.probe.points_per_electrode = int(n)
electrode.probe.model = model
ve = electrode.probe.compute_field(cell_mid_points)
if len(electrode.probe.currents.shape) == 1:
ve = ve[:, np.newaxis]
v_ext += ve

self._set_extracellular()
self.insert_v_ext(v_ext, np.array(t_ext))
else:
v_ext = None

return v_ext

def simulate(self, electrode=None, rec_imem=False, rec_vmem=False,
rec_ipas=False, rec_icap=False,
Expand Down Expand Up @@ -1995,7 +2078,7 @@ def insert_v_ext(self, v_ext, t_ext):
v_ext : ndarray
Numpy array of size cell.totnsegs x t_ext.size, unit mV
t_ext : ndarray
Time vector of v_ext
Time vector of v_ext in ms
Examples
--------
>>> import LFPy
Expand Down
18 changes: 9 additions & 9 deletions LFPy/eegmegcalc.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
GNU General Public License for more details.
"""

from __future__ import division

from scipy.special import eval_legendre, lpmv, legendre
import numpy as np
from warnings import warn
Expand Down Expand Up @@ -1244,16 +1244,16 @@ class MEG(object):
under the assumption of negligible magnetic induction effects (Nunez and
Srinivasan, Oxford University Press, 2006):
.. math:: \mathbf{H} = \\frac{\\mathbf{p} \\times \\mathbf{R}}{4 \pi R^3}
.. math:: \\mathbf{H} = \\frac{\\mathbf{p} \\times \\mathbf{R}}{4 \\pi R^3}
where :math:`\mathbf{p}` is the current dipole moment, :math:`\mathbf{R}`
where :math:`\mathbf{p}` is the current dipole moment, :math:`\\mathbf{R}`
the vector between dipole source location and measurement location, and
:math:`R=|\mathbf{R}|`
:math:`R=|\\mathbf{R}|`
Note that the magnetic field :math:`\mathbf{H}` is related to the magnetic
field :math:`\mathbf{B}` as :math:`\mu_0 \mathbf{H} = \mathbf{B}-\mathbf{M}`
where :math:`\mu_0` is the permeability of free space (very close to
permebility of biological tissues). :math:`\mathbf{M}` denotes material
Note that the magnetic field :math:`\\mathbf{H}` is related to the magnetic
field :math:`\\mathbf{B}` as :math:`\\mu_0 \\mathbf{H} = \\mathbf{B}-\\mathbf{M}`
where :math:`\\mu_0` is the permeability of free space (very close to
permebility of biological tissues). :math:`\\mathbf{M}` denotes material
magnetization (also ignored)
Expand All @@ -1264,7 +1264,7 @@ class MEG(object):
devices where magnetic field of current dipole moments is calculated.
In unit of (µm)
mu : float
Permeability. Default is permeability of vacuum (mu_0 = 4*pi*1E-7 T*m/A)
Permeability. Default is permeability of vacuum (:math:`\\mu_0 = 4*\\pi*10^{-7}` T*m/A)
Examples
Expand Down
2 changes: 1 addition & 1 deletion LFPy/inputgenerators.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"""

from __future__ import division

import numpy as np
import scipy.stats
import warnings
Expand Down
2 changes: 1 addition & 1 deletion LFPy/lfpcalc.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"""

from __future__ import division

import numpy as np


Expand Down
10 changes: 6 additions & 4 deletions LFPy/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
GNU General Public License for more details.
"""
from __future__ import division

import numpy as np
import os
import scipy.stats as stats
Expand Down Expand Up @@ -113,9 +113,9 @@ class NetworkCell
>>> import LFPy
>>> cellParameters = {
>>> 'morphology' : '<path to morphology.hoc>',
>>> 'templatefile' : '<path to template_file.hoc>'
>>> 'templatename' : 'templatename'
>>> 'templateargs' : None
>>> 'templatefile' : '<path to template_file.hoc>',
>>> 'templatename' : 'templatename',
>>> 'templateargs' : None,
>>> 'v_init' : -65,
>>> 'cm' : 1.0,
>>> 'Ra' : 150,
Expand Down Expand Up @@ -853,6 +853,8 @@ def connect(self, pre, post, connectivity,

return COMM.bcast([conncount, syncount])

def enable_extracellular_stimulation(self, electrode, t_ext=None, n=1, seed=None):
raise NotImplementedError()

def simulate(self, electrode=None, rec_imem=False, rec_vmem=False,
rec_ipas=False, rec_icap=False,
Expand Down
2 changes: 1 addition & 1 deletion LFPy/pointprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"""

from __future__ import division

import numpy as np
import neuron

Expand Down

0 comments on commit 98069cf

Please sign in to comment.