-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdofilter.py
40 lines (34 loc) · 1.23 KB
/
dofilter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import mne
from os.path import isdir
import numpy as np
import re
from os.path import join
from os import listdir
root_dir = "/home/jev/hdd/epi/"
proc_dir = join(root_dir, "proc") # where the files are
proc_files = listdir(proc_dir)
subjs = ["1001", "1002", "1003", "1004", "1005", "2001", "3001", "3002"]
conds = ["Stim", "Sham"]
l_freq = 0.1
h_freq = 149.9
n_jobs = "cuda" # if you don't have cuda, change this 1 or something higher
overwrite = False
for subj in subjs:
for filename in proc_files:
# correctly identify subject raw files
ma = re.match(f"EPI_{subj}_(.*)-raw.fif", filename)
if not ma:
continue
infile = f"EPI_{subj}_{ma.groups(0)[0]}-raw.fif"
# check if it already exists
outfile = f"f_{infile}"
if outfile in proc_files and not overwrite:
print(f"{outfile} already exists. Skipping...")
continue
# filter and save
raw = mne.io.Raw(join(proc_dir, infile), preload=True)
raw.filter(l_freq=l_freq, h_freq=h_freq, n_jobs=n_jobs)
raw.notch_filter(np.arange(50, h_freq, 50), n_jobs=n_jobs)
# donwnsampling
raw.resample(300, n_jobs=n_jobs)
raw.save(join(proc_dir, outfile), overwrite=overwrite)