Skip to content

Commit

Permalink
Merge 47233d3 into 829cdf3
Browse files Browse the repository at this point in the history
  • Loading branch information
espenhgn committed Oct 9, 2020
2 parents 829cdf3 + 47233d3 commit 6c8078d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 24 deletions.
3 changes: 2 additions & 1 deletion LFPy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
from .version import version as __version__
from .pointprocess import Synapse, PointProcess, StimIntElectrode
from lfpykit import RecExtElectrode, RecMEAElectrode, CurrentDipoleMoment, \
PointSourcePotential, LineSourcePotential, OneSphereVolumeConductor
PointSourcePotential, LineSourcePotential, OneSphereVolumeConductor, \
LaminarCurrentSourceDensity
from .cell import Cell
from .templatecell import TemplateCell
from .network import NetworkCell, NetworkPopulation, Network
Expand Down
8 changes: 4 additions & 4 deletions LFPy/eegmegcalc.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class FourSphereVolumeConductor(lfpykit.eegmegcalc.FourSphereVolumeConductor):
>>> # current dipole moment
>>> p = np.array([[10., 10., 10.]]*10) # 10 timesteps [nA µm]
>>> # compute potential
>>> sphere_model.calc_potential(p, rz) # [mV]
>>> sphere_model.get_dipole_potential(p, rz) # [mV]
array([[1.06247669e-08, 1.06247669e-08, 1.06247669e-08, 1.06247669e-08,
1.06247669e-08, 1.06247669e-08, 1.06247669e-08, 1.06247669e-08,
1.06247669e-08, 1.06247669e-08],
Expand All @@ -96,7 +96,7 @@ def __init__(self,
sigmas=sigmas,
iter_factor=iter_factor)

def calc_potential_from_multi_dipoles(self, cell, timepoints=None):
def get_dipole_potential_from_multi_dipoles(self, cell, timepoints=None):
"""
Return electric potential from multiple current dipoles from cell.
Expand Down Expand Up @@ -141,7 +141,7 @@ def calc_potential_from_multi_dipoles(self, cell, timepoints=None):
>>> MD_4s = FourSphereVolumeConductor(radii,
>>> sigmas,
>>> electrode_locs)
>>> phi = MD_4s.calc_potential_from_multi_dipoles(cell,
>>> phi = MD_4s.get_dipole_potential_from_multi_dipoles(cell,
>>> timepoints)
"""
multi_p, multi_p_locs = cell.get_multi_current_dipole_moments(
Expand All @@ -150,7 +150,7 @@ def calc_potential_from_multi_dipoles(self, cell, timepoints=None):
Ni, Nd, Nt = multi_p.shape
potential = np.zeros((N_elec, Nt))
for i in range(Ni):
pot = self.calc_potential(multi_p[i], multi_p_locs[i])
pot = self.get_dipole_potential(multi_p[i], multi_p_locs[i])
potential += pot
return potential

Expand Down
26 changes: 13 additions & 13 deletions LFPy/test/test_eegmegcalc.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ def test_calc_zn(self):
z1 = fs._calc_zn(n)
np.testing.assert_almost_equal(z1, -2.16574585635359)

def test_calc_potential(self):
def test_get_dipole_potential(self):
'''test comparison between four-sphere model and model for
infinite homogeneous space
when sigma is constant and r4 goes to infinity'''
Expand All @@ -384,13 +384,13 @@ def test_calc_potential(self):
[0., 40., 0.]])
four_s = LFPy.FourSphereVolumeConductor(
r_elec, radii, sigmas)
pots_4s = four_s.calc_potential(p, rz)
pots_4s = four_s.get_dipole_potential(p, rz)
inf_s = LFPy.InfiniteVolumeConductor(0.3)
pots_inf = inf_s.get_dipole_potential(p, r_elec - rz)

np.testing.assert_allclose(pots_4s, pots_inf, rtol=1e-6)

def test_calc_potential01(self):
def test_get_dipole_potential01(self):
'''test comparison between analytical 4S-model and FEM simulation'''
# load data
fem_sim = np.load(
Expand All @@ -408,15 +408,15 @@ def test_calc_potential01(self):
fs = LFPy.FourSphereVolumeConductor(
ele_coords, radii, sigmas)
k_mV_to_muV = 1e3
pot_analytical = fs.calc_potential(
pot_analytical = fs.get_dipole_potential(
p, rz).reshape(
(len(ele_coords),)).reshape(
pot_fem.shape) * k_mV_to_muV
global_error = np.abs(pot_analytical - pot_fem) / \
(np.max(np.abs(pot_fem)))
np.testing.assert_array_less(global_error, 0.01)

def test_calc_potential02(self):
def test_get_dipole_potential02(self):
'''Test radial and tangential parts of dipole sums to dipole'''
radii = [88000, 90000, 95000, 100000]
sigmas = [0.3, 1.5, 0.015, 0.3]
Expand Down Expand Up @@ -445,7 +445,7 @@ def test_calc_potential02(self):
for i in range(len(p_locs)):
fs = LFPy.FourSphereVolumeConductor(
el_locs[i], radii, sigmas)
phi = fs.calc_potential(dips[i].T, p_locs[i])
phi = fs.get_dipole_potential(dips[i].T, p_locs[i])
if i == 0:
phi0 = phi[0][0]
else:
Expand Down Expand Up @@ -480,12 +480,12 @@ def test_get_transformation_matrix_00(self):
for i in range(len(p_locs)):
fs = LFPy.FourSphereVolumeConductor(
el_locs[i], radii, sigmas)
phi = fs.calc_potential(dips[i].T, p_locs[i])
phi = fs.get_dipole_potential(dips[i].T, p_locs[i])

M = fs.get_transformation_matrix(p_locs[i])
np.testing.assert_allclose(M @ dips[i].T, phi)

def test_calc_potential_from_multi_dipoles00(self):
def test_get_dipole_potential_from_multi_dipoles00(self):
"""test comparison between multi-dipoles and single dipole approach"""
neuron.h('forall delete_section()')
soma = neuron.h.Section(name='soma')
Expand All @@ -511,7 +511,7 @@ def test_calc_potential_from_multi_dipoles00(self):
p, dipole_locs = cell.get_multi_current_dipole_moments(t_point)
Np, Nt, Nd = p.shape
Ne = electrode_locs.shape[0]
pot_MD = MD_4s.calc_potential_from_multi_dipoles(cell, t_point)
pot_MD = MD_4s.get_dipole_potential_from_multi_dipoles(cell, t_point)

cell.__del__()

Expand All @@ -521,13 +521,13 @@ def test_calc_potential_from_multi_dipoles00(self):
dip_loc = dipole_locs[i]
fs = LFPy.FourSphereVolumeConductor(
electrode_locs, radii, sigmas)
pot = fs.calc_potential(dip, dip_loc)
pot = fs.get_dipole_potential(dip, dip_loc)
pot_sum += pot

np.testing.assert_almost_equal(pot_MD, pot_sum)
np.testing.assert_allclose(pot_MD, pot_sum, rtol=1E-4)

def test_calc_potential_from_multi_dipoles01(self):
def test_get_dipole_potential_from_multi_dipoles01(self):
"""test comparison between multi-dipoles and single dipole approach"""
neuron.h('forall delete_section()')
soma = neuron.h.Section(name='soma')
Expand Down Expand Up @@ -555,7 +555,7 @@ def test_calc_potential_from_multi_dipoles01(self):
p, dipole_locs = cell.get_multi_current_dipole_moments(t_point)
Np, Nt, Nd = p.shape
Ne = electrode_locs.shape[0]
pot_MD = MD_4s.calc_potential_from_multi_dipoles(cell, t_point)
pot_MD = MD_4s.get_dipole_potential_from_multi_dipoles(cell, t_point)

cell.__del__()

Expand All @@ -565,7 +565,7 @@ def test_calc_potential_from_multi_dipoles01(self):
dip_loc = dipole_locs[i]
fs = LFPy.FourSphereVolumeConductor(
electrode_locs, radii, sigmas)
pot = fs.calc_potential(dip, dip_loc)
pot = fs.get_dipole_potential(dip, dip_loc)
pot_sum += pot

np.testing.assert_almost_equal(pot_MD, pot_sum)
Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ but a simpler point-source method is also available. The calculations assume tha
independent conductivity, and compartments are assumed to be at least at a minimal distance from the electrode (which can be specified by the user). For more information on
the biophysics underlying the numerical framework used see this coming book chapter:

- K.H. Pettersen, H. Linden, A.M. Dale and G.T. Einevoll: Extracellular spikes and current-source density, in *Handbook of Neural Activity Measurement*, edited by R. Brette and A. Destexhe, Cambridge, to appear (preprint PDF, 5.7MB http://arken.umb.no/~gautei/forskning/PettersenLindenDaleEinevoll-BookChapter-revised.pdf
- K.H. Pettersen, H. Linden, A.M. Dale and G.T. Einevoll: Extracellular spikes and current-source density, in *Handbook of Neural Activity Measurement*, edited by R. Brette and A. Destexhe, Cambridge, to appear (preprint PDF, 5.7MB http://www.csc.kth.se/~helinden/PettersenLindenDaleEinevoll-BookChapter-revised.pdf

The first release of LFPy (v1.x) was mainly designed for simulation extracellular potentials of single neurons, described in our paper on the package in Frontiers in Neuroinformatics entitled "LFPy: A tool for biophysical simulation of extracellular potentials generated by detailed model neurons".
The article can be found at http://dx.doi.org/10.3389%2Ffninf.2013.00041.
The article can be found at https://dx.doi.org/10.3389/fninf.2013.00041.
Since version 2 (LFPy v2.x), the tool also facilitates simulations of extracellular potentials and current dipole moment from ongoing activity in recurrently connected networks of multicompartment neurons, prediction of EEG scalp surface potentials,
MEG scalp surface magnetic fields, as described in the bioRXiv preprint "Multimodal modeling of neural network activity: computing LFP, ECoG, EEG and MEG signals with LFPy2.0" by Espen Hagen, Solveig Naess, Torbjoern V Ness, Gaute T Einevoll, found at https://doi.org/10.1101/281717.
MEG scalp surface magnetic fields, as described in the publication "Multimodal modeling of neural network activity: computing LFP, ECoG, EEG and MEG signals with LFPy2.0" by Espen Hagen, Solveig Naess, Torbjoern V Ness, Gaute T Einevoll, found at https://dx.doi.org/10.3389/fninf.2018.00092.

Citing LFPy
-----------
Expand All @@ -117,8 +117,8 @@ For updated information on LFPy and online documentation, see the LFPy homepage
Tutorial slides on LFPy
-----------------------

- Slides for OCNS 2019 meeting tutorial `T8: Biophysical modeling of extracellular potentials (using LFPy).` <https://www.cnsorg.org/cns-2019-tutorials#T8>_ hosted in Barcelona, Spain on LFPy: `CNS2019_LFPy_tutorial` <https://LFPy.github.io/downloads/CNS2019_LFPy_tutorial.pdf>_
- Older tutorial slides can be found at `https://LFPy.github.io/downloads` <https://github.com/LFPy/LFPy.github.io/tree/master/downloads>_
- Slides for OCNS 2019 meeting tutorial [T8: Biophysical modeling of extracellular potentials (using LFPy)](https://www.cnsorg.org/cns-2019-tutorials#T8) hosted in Barcelona, Spain on LFPy: [CNS2019 LFPy tutorial slides](https://LFPy.github.io/downloads/CNS2019_LFPy_tutorial.pdf "slides")
- Older tutorial slides can be found at [https://github.com/LFPy/LFPy.github.io/tree/master/downloads](https://github.com/LFPy/LFPy.github.io/tree/master/downloads)


Related projects
Expand Down Expand Up @@ -269,7 +269,7 @@ m2r2, Numpydoc and the Sphinx ReadTheDocs theme may be needed:
Physical units in LFPy
----------------------

Units follow the NEURON conventions found `here <https://www.neuron.yale.edu/neuron/static/docs/units/unitchart.html>`_.
Physical units follow the NEURON conventions found [here](https://www.neuron.yale.edu/neuron/static/docs/units/unitchart.html).
The units in LFPy for given quantities are:

| Quantity | Symbol | Unit |
Expand All @@ -285,6 +285,7 @@ The units in LFPy for given quantities are:
| Current dipole moment | P | [nA µm] |
| Magnetic field | H | [nA/µm] |
| Magnetic permeability | µ, mu | [T m/A] |
| Current Source Density | CSD | [nA/µm3] |

Note: resistance, conductance and capacitance are usually specific values, i.e per membrane area (lowercase r_m, g, c_m)
Depending on the mechanism files, some may use different units altogether, but this should be taken care of internally by NEURON.
10 changes: 10 additions & 0 deletions doc/classes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@ class :class:`MEG`
:undoc-members:


Current Source Density (CSD)
============================

class :class:`LaminarCurrentSourceDensity`
------------------------------------------
.. autoclass:: LaminarCurrentSourceDensity
:members:
:show-inheritance:
:undoc-members:

Misc.
=====

Expand Down

0 comments on commit 6c8078d

Please sign in to comment.