Skip to content

Instantly share code, notes, and snippets.

View danielmk's full-sized avatar

Daniel Müller-Komorowska danielmk

View GitHub Profile
@danielmk
danielmk / voltage_clamp_simulator.py
Last active July 14, 2019 17:10
Uses python with NEURON to simulate voltage clamping a ball-and-stick cell
# -*- coding: utf-8 -*-
"""
Uses python with NEURON to simulate voltage clamping a ball-and-stick cell.
Tested in Python 3.7.3 and NEURON 7.6.7
Author: @scidanm
"""
from neuron import h, gui
@danielmk
danielmk / hodgkin-huxley-cortical-pyramidal-neuron.py
Last active July 14, 2019 17:10
Python implementation of a Hodgkin-Huxley model of a cortical pyramidal neuron
# -*- coding: utf-8 -*-
"""
Python implementation of a Hodgkin-Huxley model of a cortical pyramidal neuron.
Code taken in large parts from https://gist.github.com/giuseppebonaccorso/60ce3eb3a829b94abf64ab2b7a56aaef
Adapted to work with solve_ivp.
Parameters changed to a cortical pyramidal neuron as described in https://neuronaldynamics.epfl.ch/online/Ch2.S2.html
Tested in Python 3.7.3
@danielmk
danielmk / izhikevich-first-order-euler.py
Last active July 14, 2019 17:10
A Python implementation of the Izhikevich Neuron as described in Izhikevich E.M. (2003).
# -*- coding: utf-8 -*-
"""
A Python implementation of the Izhikevich Neuron as described in Izhikevich E.M. (2003)
Tested in Python 3.7.3
Author: @scidanm
"""
import numpy as np
@danielmk
danielmk / persistent-sodium-plus-potassium-odeint.py
Last active July 14, 2019 17:10
A Python implementation of a persistent sodium plus potassium model of neuronal firing
# -*- coding: utf-8 -*-
"""
A two dimensional dynamic system with leak current, persistent sodium current
and transient potassium current. Exhibits spiking behavior and some other cool
stuff. The equations and their paremeters come from "Dynamical Systems in
Neuroscience: The Geometry of Excitability and Bursting" by Izhikevich,
Eugene M. There it says: "This model is equivalent in many respects to the
well-known and widely used ICa+Ik-model proposed by Morris and Lecar (1981)
to describe voltage oscillations in the barnacle giant muscle fiber." (p.89)
@danielmk
danielmk / hodgkin_huxley_animated.py
Last active November 27, 2019 10:30
The dynamical systems view of the Hodgkin-Huxley model
# -*- coding: utf-8 -*-
"""
Voltage spikes, also known as action potentials, are considered the key unit of information flow in
the nervous system. One of the first quantitative descriptions of the action potential is the
Hodgkin-Huxley Model, named after nobel prize winning physiologists Alan Lloyd Hodgkin and Andrew
Fielding Huxley. This matplotlib animation shows the result of simulating the Hodgkin-Huxley model
in python with parameters that are set in a way, that the model resembles a cortical pyramidal cell.
At 50ms a current is injected, making the model spike. The upper panel shows the dynamical systems
view of the action potential. Before the current injection, the model stays at the resting
potential. When the current is injected a bifurcation occurs. The system finds a limit cycle.
@danielmk
danielmk / animation_demo_matplotlib.py
Created November 29, 2019 16:00
How to make animations with Matplotlib
import numpy as np
from matplotlib.animation import FuncAnimation
import matplotlib.pyplot as plt
x = np.arange(0, 10*np.pi, 0.01)
y = np.sin(x)
fig = plt.figure()
ax = plt.subplot(1, 1, 1)
@danielmk
danielmk / animation_demo2_matplotlib.py
Created November 29, 2019 16:01
How to animate two plots with Matplotlib
import numpy as np
from matplotlib.animation import FuncAnimation
import matplotlib.pyplot as plt
x = np.arange(0, 10*np.pi, 0.01)
y_sin = np.sin(x)
y_cos = np.cos(x)
fig = plt.figure()
ax1 = plt.subplot(2, 1, 1)
@danielmk
danielmk / amp_crosscorr
Created December 29, 2019 22:21
A python port of a method described by Adhikari et al. 2010 to estimate the directionality and the lag between the eeg recordings from two brain areas.
# -*- coding: utf-8 -*-
"""
@author: Daniel Müller-Komorowska
"""
import numpy as np
import scipy.signal as signal
def amp_crosscorr(eeg1, eeg2, samp_freq, low_freq, high_freq):
"""
@danielmk
danielmk / pca_reconstruction_animated.py
Created July 23, 2020 20:26
Animation showing MNIST samples reconstructed from an increasing number of principal components.
"""
The functions in this code are taken from a Neuromatch Academy Tutorial about dimensionality
reduction by Alex Cayco Gajic & John Murray:
https://github.com/NeuromatchAcademy/course-content/tree/master/tutorials/W1D5_DimensionalityReduction
Neuromatch Academy content is licensed under a Creative Commons Attribution 4.0 International
https://github.com/NeuromatchAcademy/course-content/blob/master/LICENSE.md
I use these functions to create an animation showing a subset of MNIST samples
reconstructed from an increasing number of principal components.
@danielmk
danielmk / balanced_spiking_network.py
Created May 4, 2021 17:11
Python implementation of a balanced spiking neural network.
"""
NumPy implementation of a balanced spiking neural network. Inspired by MATLAB
code from Nicola & Clopath (2017): https://doi.org/10.1038/s41467-017-01827-3
"""
import numpy as np
from numpy.random import rand, randn
import matplotlib.pyplot as plt