Skip to content

Instantly share code, notes, and snippets.

View fschwar4's full-sized avatar

FSchwarz fschwar4

View GitHub Profile
@fschwar4
fschwar4 / extrac_mcs_raw_rec.py
Last active April 10, 2024 07:49
Copy out only a small part of the original raw data from a MCS recording. Preserves all meta data.
import h5py as h5
file_path = 'data.h5'
stream_path = '/Data/Recording_0/AnalogStream/Stream_'
# set boundaries for data extraction
start_s = 0 # start second
end_s = 10 # end second
@fschwar4
fschwar4 / addLoggingLevel.py
Created January 12, 2024 08:21
Creating Custom/Unique Logger-Level for Python
def addLoggingLevel(levelName, levelNum, methodName=None):
"""Comprehensively adds a new logging level to the `logging` module and the
currently configured logging class.
`levelName` becomes an attribute of the `logging` module with the value
`levelNum`. `methodName` becomes a convenience method for both `logging`
itself and the class returned by `logging.getLoggerClass()` (usually just
`logging.Logger`). If `methodName` is not specified, `levelName.lower()` is
used.
@fschwar4
fschwar4 / git_meta.py
Created December 19, 2023 20:06
add git information for analysis metadata
from typing import Dict, Optional
from pathlib import Path
class MyClass:
@staticmethod
def get_git_infos() -> Dict[str, Optional[str]]:
"""Extract relevant git information for reproducibility.
This function should help to increase reproducibility of the results,
since it is than known which code version was used for the respective
@fschwar4
fschwar4 / sinc_interpolation.py
Last active April 15, 2024 11:22
Fast Python implementation of Whittaker–Shannon / sinc / bandlimited interpolation.
import numpy as np
from numpy.typing import NDArray
def sinc_interpolation(x: NDArray, s: NDArray, u: NDArray) -> NDArray:
"""Whittaker–Shannon or sinc or bandlimited interpolation.
Args:
x (NDArray): signal to be interpolated, can be 1D or 2D
s (NDArray): time points of x (*s* for *samples*)
u (NDArray): time points of y (*u* for *upsampled*)
@fschwar4
fschwar4 / coefficient_of_variation.py
Last active June 24, 2023 14:58
Calculate the local variation (Lv) as proposed in Shinomot et al. 2009. The Lv should be more robust than the coefficient of variation (Cv).
import numpy as np
def cv(spike_train: np.ndarray) -> float:
"""Calculate coefficient of variation (Cv) of the interspike intervals.
$$\displaystyle{Cv = \frac{\sigma_{ISI}}{\mu_{ISI}}}$$
Args:
spike_train (np.ndarray): Spike train.