-
Notifications
You must be signed in to change notification settings - Fork 0
/
collect_emp_vals.py
39 lines (34 loc) · 1.22 KB
/
collect_emp_vals.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
from scipy.io import loadmat
import os
import pandas as pd
import re
version = 4
root_dir = "/home/hannaj/"
#root_dir = "/home/jev/"
data_dir = os.path.join(root_dir, f"simnibs/{version}_emp")
res_dirs = next(os.walk(data_dir))[1]
failed_dirs = []
df_vars = ["Project", "Subject", "Mag", "Mag", "Foc",
"Foc", "Summary"]
df_dict = {x:[] for x in df_vars}
for rd in res_dirs:
files = os.listdir(os.path.join(data_dir, rd))
if "summary_metrics.mat" not in files:
failed_dirs.append(rd)
print(f"{rd} does not have final metrics.")
continue
re_rd = re.match("(.*)_(.*)", rd)
subj, proj = re_rd.groups()
mat = loadmat(os.path.join(data_dir, rd, "summary_metrics.mat"))
df_dict["Project"].append(proj)
df_dict["Subject"].append(subj)
df_dict["Summary"].append("ROI_Median")
df_dict["Mag"].append(mat["median"][0][0])
df_dict["Foc"].append(mat["focality_med"][0][0])
df_dict["Project"].append(proj)
df_dict["Subject"].append(subj)
df_dict["Summary"].append("ROI_Mean")
df_dict["Mag"].append(mat["mean"][0][0])
df_dict["Foc"].append(mat["focality_mean"][0][0])
df = pd.DataFrame.from_dict(df_dict)
df.to_pickle(os.path.join(data_dir, f"df_emp_{version}.pickle"))