Skip to content

Commit

Permalink
BUG: update stimulus folder and fill NA
Browse files Browse the repository at this point in the history
  • Loading branch information
jungheejung committed Sep 6, 2024
1 parent c07adcd commit c92730a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
4 changes: 3 additions & 1 deletion spacetop_prep/events/bidsify_alignvideos_ENH.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def add_rating_event(source_beh, t, t_run_start, rating_type, event_onset, event
response_value = np.nan
return pd.DataFrame({
"onset": onset, "duration": duration, "trial_type": rating_type,
"response_value": response_value, "stim_file": source_beh.loc[t, 'param_video_filename']
"response_value": response_value, "stim_file": "n/a"
# source_beh.loc[t, 'param_video_filename']
}, index=[0])

def alignvideo_format_to_bids(sub, ses, run, task_name, beh_inputdir, bids_dir):
Expand Down Expand Up @@ -186,6 +187,7 @@ def alignvideo_format_to_bids(sub, ses, run, task_name, beh_inputdir, bids_dir):
precision_dic = {'onset': 3, 'duration': 3, 'response_value': 2}
new_beh = new_beh.round(precision_dic)
new_beh = new_beh.replace(np.nan, 'n/a') # replace nan with "n/a" in BIDS way
new_beh.fillna('n/a', inplace=True)
new_beh.loc[new_beh['onset'] < 0, 'onset'] = 'n/a'
# Save new events file
try:
Expand Down
6 changes: 3 additions & 3 deletions spacetop_prep/events/bidsify_fractional_combine.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ def parse_args():
temp_study['subtask_type'] = task_name
temp_study['event_type'] = df_memstudy['event02_dummy_stimuli_type'].replace({0: 'dummy', 1: 'study'})
temp_study['value'] = temp_study['event_type'].replace({'dummy': 'study_dummy', 'study':'study'})
temp_study['stim_file'] = task_name + '/' + df_memstudy['event02_image_filename']
temp_study['stim_file'] = 'task-' + task_name + '/' + df_memstudy['event02_image_filename']
temp_study['response_accuracy'] = "n/a" #np.nan TODO: reverse inference and go back
temp_study['button_press'] = "n/a"
temp_study['reaction_time'] = "n/a"
Expand All @@ -657,7 +657,7 @@ def parse_args():
temp_test['subtask_type'] = task_name
temp_test['event_type'] = 'test'
temp_test['value'] = df_memtest['param_answer'].replace({0: 'test_new', 1:'test_old'})
temp_test['stim_file'] = task_name + '/' + df_memtest['event02_image_filename']
temp_test['stim_file'] = 'task-' + task_name + '/' + df_memtest['event02_image_filename']
df_memtest['event03_response_key'] = df_memtest['event03_response_key'].fillna(0)
temp_test['response_accuracy'] = (df_memtest['param_answer'] == df_memtest['event03_response_key']).astype(int).replace({0: 'incorrect', 1:'correct'})
temp_test['button_press'] = df_memtest.event03_response_keyname.replace({'right': 'new', 'left':'old', 'NaN': 'n/a', 'nan': 'n/a'})
Expand Down Expand Up @@ -887,7 +887,7 @@ def parse_args():
events = pd.concat([events, block_unique], ignore_index=True)
precision_dic = {'onset': 3, 'duration': 3}
events = events.round(precision_dic)
events = events.fillna("n/a")
events.fillna('n/a', inplace=True)
Path(beh_savedir).mkdir( parents=True, exist_ok=True )
save_fname = f"{sub_bids}_{ses_bids}_task-fractional_acq-mb8_{run_bids}_events.tsv"
events.to_csv(join(beh_savedir, save_fname), sep='\t', index=False)
Expand Down
8 changes: 4 additions & 4 deletions spacetop_prep/events/bidsify_fractional_subtask.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def parse_args():
events_sorted = events.sort_values(by='onset')
precision_dic = {'onset': 3, 'duration': 3}
events_sorted = events_sorted.round(precision_dic)
events = events.fillna("n/a")
events.fillna('n/a', inplace=True)
Path(beh_savedir).mkdir( parents=True, exist_ok=True )
events.to_csv(join(beh_savedir, f"{sub_bids}_{ses_bids}_task-fractional{task_name}_acq-mb8_{run_bids}_events.tsv"), sep='\t', index=False)

Expand Down Expand Up @@ -369,7 +369,7 @@ def parse_args():
posner_events_sorted = posner_events.sort_values(by='onset')
precision_dic = {'onset': 3, 'duration': 3}
posner_events_sorted = posner_events_sorted.round(precision_dic)
posner_events_sorted = posner_events_sorted.fillna("n/a")
posner_events_sorted.fillna('n/a', inplace=True)
Path(beh_savedir).mkdir( parents=True, exist_ok=True )
# extract bids info and save as new file
posner_events_sorted.to_csv(join(beh_savedir, f"{sub_bids}_{ses_bids}_task-fractional{task_name}_acq-mb8_{run_bids}_events.tsv"), sep='\t', index=False)
Expand Down Expand Up @@ -568,7 +568,7 @@ def parse_args():
temp_study['subtask_type'] = task_name
temp_study['event_type'] = df_memstudy['event02_dummy_stimuli_type'].replace({0: 'dummy', 1: 'study'})
temp_study['value'] = temp_study['event_type'].replace({'dummy': 'study_dummy', 'study':'study'})
temp_study['stim_file'] = task_name + '/' + df_memstudy['event02_image_filename']
temp_study['stim_file'] = 'task-' + task_name + '/' + df_memstudy['event02_image_filename']
temp_study['response_accuracy'] = "n/a" #np.nan TODO: reverse inference and go back
temp_study['button_press'] = "n/a"
temp_study['reaction_time'] = "n/a"
Expand All @@ -586,7 +586,7 @@ def parse_args():
temp_test['subtask_type'] = task_name
temp_test['event_type'] = 'test'
temp_test['value'] = df_memtest['param_answer'].replace({0: 'test_new', 1:'test_old'})
temp_test['stim_file'] = task_name + '/' + df_memtest['event02_image_filename']
temp_test['stim_file'] = 'task-' + task_name + '/' + df_memtest['event02_image_filename']
df_memtest['event03_response_key'] = df_memtest['event03_response_key'].fillna(0)
temp_test['response_accuracy'] = (df_memtest['param_answer'] == df_memtest['event03_response_key']).astype(int).replace({0: 'incorrect', 1:'correct'})
temp_test['button_press'] = df_memtest.event03_response_keyname.replace({'right': 'new', 'left':'old', 'NaN': 'n/a', 'nan': 'n/a'})
Expand Down
2 changes: 1 addition & 1 deletion spacetop_prep/events/bidsify_shortvideos.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def calc_adjusted_angle_df(df, x_col, y_col, xcenter, ycenter):
duration = oriData.loc[t, 'event02_video_stop'] - oriData.loc[t, 'event02_video_onset']
trial_type = 'video'
stim_file = oriData.loc[t, 'event02_video_filename']
stim_file = taskname + '/' + stim_file
stim_file = 'task-shortvideo/' + stim_file
newRow = pd.DataFrame({"onset": onset, "duration": duration, "trial_type": trial_type, \
"block_condition": block_condition, "mentalizing_level": mentalizing_level, "stim_file": stim_file}, index=[0])
newData = pd.concat([newData, newRow], ignore_index=True)
Expand Down

0 comments on commit c92730a

Please sign in to comment.