-
Notifications
You must be signed in to change notification settings - Fork 0
/
mvrn_esi_imp_rt_dataset.py
93 lines (77 loc) · 3.11 KB
/
mvrn_esi_imp_rt_dataset.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#%%
import os
import numpy as np
import pandas as pd
from glob import glob
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats
import seaborn as sns
from scipy.stats import norm
# establishing the directory from which to retrieve esi vs. imp csv files
root_dir = "/home/data/madlab/mvrn_ESI_study/clean_pilot_subs/"
# compiling list of esi vs. imp subjects
final_esi_imp_subs = ["101","102","103","105","106","107","109","110","111","112","113",
"114","115","117","118","119","120","121","122","123","124","127",
"128","129","130","131","132","133","134","135","136","137","138",
"139","140","141","142","145","146","147","148","149","151","152",
"153","154","158","159","160","162","163","164","165","168","169",
"170","173","175","180","181","184","185","186","187","194","197",
"200","201","204","210","211","212","213","216","222", "246"]
study_cols = [
'Subject',
'Randomization',
'study_stim1',
'study_stim2',
'study_resp_rt1',
'study_resp_rt2'
]
test_cols = [
'Subject',
'Randomization',
'test_run',
'test_stim',
'test_stimtype',
'test_stimsim',
'test_resp',
'test_resp_rt'
]
# creating lists for study and test dfs for subsequent csv creation
study = []
test = []
# iterating over every subject
for sub in final_esi_imp_subs:
for file in glob(
os.path.join(
root_dir,
f"{sub}*.csv"
)):
study_df = pd.read_csv(
file,
usecols=study_cols,
nrows=86
)
test_df = pd.read_csv(
file,
usecols=test_cols,
nrows=238
)
study_df['Randomization'] = study_df['Randomization'].replace([1, 2], ['ESIthenIMP','IMPthenESI'])
# getting rid of parts of the column string for better coding
study_df['study_stim1'] = study_df['study_stim1'].map(lambda x: x.lstrip('esi_full_stims/').rstrip('jpg'))
study_df['study_stim2'] = study_df['study_stim2'].map(lambda x: x.lstrip('esi_full_stims/').rstrip('jpg'))
test_df['Randomization'] = test_df['Randomization'].replace([1, 2], ['ESIthenIMP','IMPthenESI'])
test_df['test_stim'] = test_df['test_stim'].map(lambda x: x.lstrip('esi_full_stims/').rstrip('jpg'))
test_df['test_stimtype'] = test_df['test_stimtype'].replace([1, 2], ['negative','neutral'])
test_df['test_stimsim'] = test_df['test_stimsim'].replace([1, 2, 4], ['target','lure', 'foil'])
test_df['test_resp'] = test_df['test_resp'].replace([1, 2], ['old','new'])
test_df['test_resp'] = test_df['test_resp'].replace('None', np.nan)
# Getting df outside of the for loop to then convert to csv
for index, row in study_df.iterrows():
study.append(row)
for index, row in test_df.iterrows():
test.append(row)
study_df = pd.DataFrame(study).to_csv('study_esi_imp.csv', index=False)
test_df = pd.DataFrame(test).to_csv('test_esi_imp.csv', index=False)
# %%