Skip to content

Instantly share code, notes, and snippets.

View llandsmeer's full-sized avatar
💡

Lennart Landsmeer llandsmeer

💡
View GitHub Profile
@llandsmeer
llandsmeer / heat_equation_delta_sources.py
Created January 14, 2022 16:46
Poisson problem with dirichlet b.c. as grad=0 at the unit square edges and a list of source nodes (useful for heat sensor data interpolation)
# Dirichlet bc eliminated
import numpy as np
import matplotlib.pyplot as plt
import scipy.sparse as sp
import scipy.sparse.linalg as spla
N = 64
sources = [
(0.3, 0.3, 15),
(0.7, 0.7, 25)
@llandsmeer
llandsmeer / master_recipe.py
Created January 19, 2022 23:58
Arbor master recipe v1
import arbor
class master_recipe(arbor.recipe):
def __init__(self, *recipes):
arbor.recipe.__init__(self)
self.recipes = list(recipes)
self.setup_master_recipe()
### :::THIS IS THE ONLY PROBLEM:::
### global_properties() can not be specified up to subrecipe level
### which means catalogue mechanism names can not collide
import json
import random
import time
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
import numba
@numba.jit(fastmath=True, cache=True, nopython=True)
def simulate(transient=10, seconds=1, delta=0.015, record_every=10):
<!doctype html>
<meta charset="utf-8">
<div id=live style='overflow-wrap: break-word; font-family: monospace'></div>
<script>
class Controller {
constructor(ip) {
this.ip = ip
this.connect()
@llandsmeer
llandsmeer / hh.py
Created April 9, 2022 16:46
Hogkin-Huxley minimal sim
# Adapted from https://hodgkin-huxley-tutorial.readthedocs.io/en/latest/_static/Hodgkin%20Huxley.html
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import solve_ivp
C_m = 1.0
g_Na = 120.0
@llandsmeer
llandsmeer / iocell.py
Created April 14, 2022 16:46
interactive io in qt
import matplotlib.pyplot as plt
import numba
import numpy as np
@numba.jit(fastmath=True, cache=True, nopython=True)
def simulate(skip_initial_transient_seconds=0, sim_seconds=10, delta=0.005, record_every=20,
# Parameters
g_int = 0.13, # Cell internal conductance -- now a parameter (0.13)
p1 = 0.25, # Cell surface ratio soma/dendrite
p2 = 0.15, # Cell surface ratio axon(hillock)/soma
@llandsmeer
llandsmeer / pyqt5_numpy.py
Created May 28, 2022 11:25
pyqt5 show numpy arrays in a loop
import sys
import numpy as np
from PyQt5 import QtGui, QtWidgets, QtCore
class MainWindow(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
self.imshow = Grayscale()
self.setCentralWidget(self.imshow)
self.update_timer = QtCore.QTimer()
import sys
import pyte
import struct
import select
import time
import fcntl
import os
import pty
import subprocess
import termios
@llandsmeer
llandsmeer / ledfxmidi.py
Created September 23, 2022 22:37
Control LedFX using midi controller
import os
import time
import json
import requests
import rtmidi
# pip install python-rtmidi
midi = rtmidi.MidiIn()
ports = midi.get_ports()
import sympy as sm
import lark
parser = lark.Lark(r'''
%import common.SIGNED_NUMBER -> NUMBER
%import common.WS
%ignore WS
%ignore /\?.*\n/
%ignore /:.*\n/