This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gc | |
import os | |
import subprocess | |
import time | |
import memray | |
import numpy as np | |
import numpy.lib.format | |
from datetime import datetime as dt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
## CALCIUM CORRECTION (based on Albumin) | |
# cave: check the units of Calcium and Albumin | |
# Calcium is given in mmol/l; Albumin in g/l | |
# equation following Payne 1973; https://doi.org/10.1136/bmj.4.5893.643 | |
# Adjusted calcium = calcium - albumin + 4.0 (if albumin in g/dL and calcium in mg/dL) | |
# Calcium conversions: 1 mg/dL = 0.25 mmol/L; 1 mmol/L = 4 mg/dL | |
# Calcium corrected [mmol/l] = Calcium measured [mmol/l] – (0,025 x Albumin [g/l]) + 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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*) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |