-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinsert_auto_scores.py
executable file
·67 lines (49 loc) · 1.32 KB
/
insert_auto_scores.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
import pandas as pd
import pickle
from os import getcwd, chdir
import sys
if len(sys.argv)>1:
print(f'''This script inserts EEG auto QC scores in .scores.pkl file
Usage: {__file__}
No argument is needed.''')
exit()
def count(_props):
freq={}
for k,v in _props.items():
if k.endswith('-1'):
pass
else:
if v in freq:
freq[v]+=1
else:
freq[v]=1
print(freq)
print('Total',sum(freq.values()))
dir_bak=getcwd()
chdir('/data/predict1/data_from_nda/')
df=pd.read_csv('EEGqc_features/autoScore/combined-AMPSCZ-EEGautoQC-day1to1.csv')
props_file='.scores.pkl'
with open(props_file,'rb') as f:
props= pickle.load(f)
print('Before modification count:')
count(props)
props2=props.copy()
modified=False
for i,row in df.iterrows():
key='{}_{}'.format(row['subject'],row['session'])
if key in props:
if props[key]==-9:
if not pd.isna(row['score']):
props2[key]=row['score']
modified=True
else:
props2[key]=row['score']
props2[key+'-1']=''
modified=True
if modified:
print('\nAfter modification count:')
count(props2)
with open(props_file,'wb') as f:
pickle.dump(props2,f)
chdir(dir_bak)