Skip to content

Instantly share code, notes, and snippets.

View skjerns's full-sized avatar

Simon Kern skjerns

View GitHub Profile
@skjerns
skjerns / extract_windows.py
Last active April 26, 2024 14:36
Extract 1 dimensional windows from ndarrays
import warnings
import numpy as np
from sklearn import feature_extraction
def extract_windows(arr, sfreq, win_size, step_size, axis=-1):
"""extract 1d signal windows from an ndimensional array
window_size and step_size are defined in terms of seconds
this will extract a so called 'view' to the array, so the memory footprint
@skjerns
skjerns / read_raw_edf.py
Created May 17, 2022 10:46
Read Raw EDF to MNE with different sampling frequencies
from pyedflib import highlevel
import numpy as np
import mne
def resample(data, o_sfreq, t_sfreq):
"""
resample a signal using MNE resample functions
This automatically is optimized for EEG applying filters etc
@skjerns
skjerns / save_edf.py
Last active April 25, 2024 13:54
Save a mne.io.Raw object to EDF/EDF+/BDF/BDF+
# -*- coding: utf-8 -*-
"""
Created on Wed Dec 5 12:56:31 2018
@author: skjerns
Gist to save a mne.io.Raw object to an EDF file using pyEDFlib
(https://github.com/holgern/pyedflib)
Disclaimer:
- Saving your data this way will result in slight
loss of precision (magnitude +-1e-09).
- It is assumed that the data is presented in Volt (V),
@skjerns
skjerns / transfer_performance_edfx.py
Last active January 28, 2018 13:14
Calculating Transfer Scores for the EDFx with AutoSleepScorer
# -*- coding: utf-8 -*-
import glob
import csv
import numpy as np
from sklearn.metrics import f1_score
from sleepscorer import Scorer, SleepData
edfx_dir = "D:\\sleep\\edfx\\"
##################################