Skip to content

Instantly share code, notes, and snippets.

@rat-h
rat-h / getderiv.py
Last active September 13, 2021 20:43
Get derivative of a series
from numpy.polynomial.polynomial import polyval, polyder, polyfit
def getderiv(x,a,order=1):
b = [a[0]] + a.tolist() + [a[-1]]
y = [x[0]] + x.tolist() + [x[-1]]
return array ([
polyval(x1, polyder( polyfit([x0,x1,x2],[a0,a1,a2], order+1), order ) )
for a2,a1,a0,x2,x1,x0 in zip(b[2:],b[1:-1],b[:-2],y[2:],y[1:-1],y[:-2])
])
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rat-h
rat-h / compute_SPC_R2_meanFR.py
Last active June 3, 2021 21:45
Code for estimation R2 in a not-so-periodic network firing rate
import numpy as np
def compute_SPC_R2_meanFR(
spbins, #STH 1ms/bin
ksigma= 3., #sigma for Gaussian to smooth FR
kwidth=25., #kernel width
peaks=False #set True if peaks are neede
):
"""
The function get network spike-time histogram as numpy array
@rat-h
rat-h / find_roots.py
Created May 17, 2021 19:43
Get roots of seqence
def find_roots(x,y):
'''
Thanks to ImportanceOfBeingErnest
https://stackoverflow.com/a/46911822/1887559
'''
s = np.abs(np.diff(np.sign(y))).astype(bool)
return x[:-1][s] + np.diff(x)[s]/(np.abs(y[1:][s]/y[:-1][s])+1)
@rat-h
rat-h / CCS811_RPi.py
Last active December 23, 2020 03:03 — forked from xxlukas42/CCS811_RPi.py
#
# CCS811_RPi
#
# Petr Lukas
# July, 11 2017
#
# Version 1.0
import struct, array, time, io, fcntl, logging