LFPykernels
Forward-model based calculations of causal spike-signal impulse response functions for finite-sized neuronal network models
Install / Use
/learn @LFPy/LFPykernelsREADME
LFPykernels
The LFPykernels package incorporates forward-model based calculations of causal spike-signal
impulse response functions for finite-sized neuronal network models.
Build Status
Citation
These codes correspond to results shown in the peer-reviewed manuscript:
Hagen E, Magnusson SH, Ness TV, Halnes G, Babu PN, et al. (2022) Brain signal predictions from multi-scale networks using a linearized framework. PLOS Computational Biology 18(8): e1010353. https://doi.org/10.1371/journal.pcbi.1010353
Bibtex format:
@article{10.1371/journal.pcbi.1010353,
doi = {10.1371/journal.pcbi.1010353},
author = {Hagen, Espen AND Magnusson, Steinn H. AND Ness, Torbjørn V. AND Halnes, Geir AND Babu, Pooja N. AND Linssen, Charl AND Morrison, Abigail AND Einevoll, Gaute T.},
journal = {PLOS Computational Biology},
publisher = {Public Library of Science},
title = {Brain signal predictions from multi-scale networks using a linearized framework},
year = {2022},
month = {08},
volume = {18},
url = {https://doi.org/10.1371/journal.pcbi.1010353},
pages = {1-51},
number = {8},
}
If you use this software, please cite it as (change <version>/<git-SHA>/<git-tag> accordingly):
Hagen, Espen. (2021). LFPykernels (<version>/<git-SHA>/<git-tag>). Zenodo. https://doi.org/10.5281/zenodo.5720619
BibTex format:
@software{hagen_espen_2021_5720619,
author = {Hagen, Espen},
title = {LFPykernels},
month = nov,
year = 2021,
note = {If you use this software, please cite it as below.},
publisher = {Zenodo},
version = {<version>/<git-SHA>/<git-tag>},
doi = {10.5281/zenodo.5720619},
url = {https://doi.org/10.5281/zenodo.5720619}
}
If you use or refer to this work, please cite it as above.
Adaptations or modifications of this work should comply with the provided LICENSE file provided with this repository.
Features
The LFPykernels package incorporates forward-model based calculations of causal spike-signal
impulse response functions for finite-sized neuronal network models.
The signals considered are low-frequency extracellular potentials ("local field potential" - LFP)
or current dipole moments (and by extension EEG and MEG like signals) that are
thought to mainly stem from synaptic currents and associated return currents.
The basic idea is that the effect of any spike event in each presynaptic
population on each signal type can be captured by single linearised multicompartment neuron
models representative of each population and simultaneously accounting for known distributions of
cells and synapses in space, distributions of delays, synaptic currents and associated return currents.
The present methodology is described in detail by Hagen E et al., 2022.
The intended use for filter kernels predicted using LFPykernels is forward-model based signal predictions
from neuronal network simulation frameworks using simplified neuron representations like leaky integrate-and-fire
point neurons or rate-based neurons, but can also be used with biophysically detailed network models.
Let $\nu_X(t)$ describe presynaptic population spike rates in units of spikes/dt
and $H_{YX}(\mathbf{R}, \tau)$ predicted spike-signal kernels for the connections between presynaptic populations $X$ and
postsynaptic populations $Y$ the full signal may then be computed via the sum over linear convolutions:
V(\mathbf{R}, t) = \sum_X \sum_Y (\nu_X \ast H_{YX})(\mathbf{R}, t)
A more elaborate example combining kernel predictions with a spiking point-neuron network simulation is provided in the example notebook https://github.com/LFPy/LFPykernels/blob/main/examples/LIF_net_forward_model_predictions.ipynb
For questions, please raise an issue at https://github.com/LFPy/LFPykernels/issues.
Usage
Example prediction of kernel function $H(\mathbf{R},\tau)$ mapping spike events of a
presynaptic inhibitory population $X==\mathrm{I}$ to extracellular potential contributions by a
postsynaptic excitatory population $Y==\mathrm{E}$ (see https://github.com/LFPy/LFPykernels/blob/main/examples/README_example.ipynb):
import os
import matplotlib.pyplot as plt
import scipy.stats as st
import numpy as np
from lfpykernels import GaussCylinderPotential, KernelApprox
import neuron
# recompile mod files if needed
mech_loaded = neuron.load_mechanisms('mod')
if not mech_loaded:
os.system('cd mod && nrnivmodl && cd -')
mech_loaded = neuron.load_mechanisms('mod')
print(f'mechanisms loaded: {mech_loaded}')
# misc parameters
dt = 2**-4 # time resolution (ms)
t_X = 500 # time of synaptic activations (ms)
tau = 50 # duration of impulse response function after onset (ms)
Vrest = -65 # assumed average postsynaptic potential (mV)
X=['E', 'I'] # presynaptic population names
N_X = np.array([8192, 1024]) # presynpatic population sizes
Y = 'E' # postsynaptic population
N_Y = 8192 # postsynaptic population size
C_YX = np.array([0.05, 0.05]) # pairwise connection probability between populations X and Y
nu_X = {'E': 2.5, 'I': 5.0} # assumed spike rates of each population (spikes/s)
g_eff = True # account for changes in passive leak due to persistent synaptic activations
def set_passive(cell, Vrest):
"""Insert passive leak channel across all sections
Parameters
----------
cell: object
LFPy.NetworkCell like object
Vrest: float
Steady state potential
"""
for sec in cell.template.all:
sec.insert('pas')
sec.g_pas = 0.0003 # (S/cm2)
sec.e_pas = Vrest # (mV)
# parameters for LFPy.NetworkCell representative of postsynaptic population
cellParameters={
'templatefile': 'BallAndSticksTemplate.hoc',
'templatename': 'BallAndSticksTemplate',
'custom_fun': [set_passive],
'custom_fun_args': [{'Vrest': Vrest}],
'templateargs': None,
'delete_sections': False,
'morphology': 'BallAndSticks_E.hoc'}
populationParameters={
'radius': 150.0, # population radius (µm)
'loc': 0.0, # average depth of cell bodies (µm)
'scale': 75.0} # standard deviation (µm)
# Predictor for extracellular potentials across depth assuming planar disk source
# elements convolved with Gaussian along z-axis.
# See https://lfpykernels.readthedocs.io/en/latest/#class-gausscylinderpotential for details
probe = GaussCylinderPotential(
cell=None,
z=np.linspace(1000., -200., 13), # depth of contacts (µm)
sigma=0.3, # tissue conductivity (S/m)
R=populationParameters['radius'], #
sigma_z=populationParameters['scale'],
)
# Create KernelApprox object. See https://lfpykernels.readthedocs.io/en/latest/#class-kernelapprox for details
kernel = KernelApprox(
X=X,
Y=Y,
N_X=N_X,
N_Y=N_Y,
C_YX=C_YX,
cellParameters=cellParameters,
populationParameters=populationParameters,
# function and parameters used to estimate average multapse count:
multapseFunction=st.truncnorm,
multapseParameters=[
{'a': (1 - 2.) / .6, 'b': (10 - 2.) / .6, 'loc': 2.0, 'scale': 0.6},
{'a': (1 - 5.) / 1.1, 'b': (10 - 5.) / 1.1, 'loc': 5.0, 'scale': 1.1}],
# function and parameters for delay distribution from connections between a
# population in X onto population Y:
delayFunction=st.truncnorm,
delayParameters=[{'a': -2.2, 'b': np.inf, 'loc': 1.3, 'scale': 0.5},
{'a': -1.5, 'b': np.inf, 'loc': 1.2, 'scale': 0.6}],
# parameters for synapses from connections by populations X onto Y
synapseParameters=[
{'weight': 0.00012, 'syntype': 'Exp2Syn', 'tau1': 0.2, 'tau2': 1.8, 'e': 0.0},
{'weight': 0.002, 'syntype': 'Exp2Syn', 'tau1': 0.1, 'tau2': 9.0, 'e': -80.0}],
# parameters for spatial synaptic connectivity by populations X onto Y
synapsePositionArguments=[
{'section': ['apic', 'dend'],
'fun': [st.norm],
'funargs': [{'loc': 50.0, 'scale': 100.0}],
'funweights': [1.0]},
{'section': ['soma', 'apic', 'dend'],
'fun': [st.norm],
'funargs': [{'loc': -100.0, 'scale': 100.0}],
'funweights': [1.0]}],
# parameters for extrinsic synaptic input
extSynapseParameters={'syntype': 'Exp2Syn', 'weight': 0.0002, 'tau1': 0.2, 'tau2': 1.8, 'e': 0.0},
nu_ext=40., # external activation rate (spikes/s)
n_ext=450, # number of extrinsic synapses
nu_X=nu_
Related Skills
node-connect
351.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
claude-opus-4-5-migration
110.6kMigrate prompts and code from Claude Sonnet 4.0, Sonnet 4.5, or Opus 4.1 to Opus 4.5
frontend-design
110.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
model-usage
351.2kUse CodexBar CLI local cost usage to summarize per-model usage for Codex or Claude, including the current (most recent) model or a full model breakdown. Trigger when asked for model-level usage/cost data from codexbar, or when you need a scriptable per-model summary from codexbar cost JSON.
