if np.mod(i+1, 10) == 0: print('Processing data of subject %d of %d' % (i+1, len(behav['subject_nickname'].unique()))) # Get lab and timezone lab = behav.loc[behav['subject_nickname'] == nickname, 'institution_code'].unique()[0] time_zone = behav.loc[behav['subject_nickname'] == nickname, 'time_zone'].unique()[0] if (time_zone == 'Europe/Lisbon') or (time_zone == 'Europe/London'): time_zone_number = 0 elif time_zone == 'America/New_York': time_zone_number = -5 elif time_zone == 'America/Los_Angeles': time_zone_number = -7 # Fit psychometric curve left_fit = fit_psychfunc(behav[(behav['subject_nickname'] == nickname) & (behav['probabilityLeft'] == 80)]) right_fit = fit_psychfunc(behav[(behav['subject_nickname'] == nickname) & (behav['probabilityLeft'] == 20)]) neutral_fit = fit_psychfunc(behav[(behav['subject_nickname'] == nickname) & (behav['probabilityLeft'] == 50)]) perf_easy = (behav.loc[behav['subject_nickname'] == nickname, 'correct_easy'].mean()) * 100 fits = pd.DataFrame(data={'perf_easy': perf_easy, 'threshold_l': left_fit['threshold'], 'threshold_r': right_fit['threshold'], 'threshold_n': neutral_fit['threshold'], 'bias_l': left_fit['bias'], 'bias_r': right_fit['bias'], 'bias_n': neutral_fit['bias'], 'time_zone': time_zone_number, 'nickname': nickname, 'lab_number': lab})
for i, nickname in enumerate(behav['subject_nickname'].unique()): if np.mod(i + 1, 10) == 0: print('Processing data of subject %d of %d' % (i + 1, len(behav['subject_nickname'].unique()))) # Get the trials of the sessions around criterion for this subject (first # 90% + next session) trials = behav[behav['subject_nickname'] == nickname].reset_index() # Exclude sessions with less than 4 contrasts trials['contrast_set'] = trials.session_start_time.map( trials.groupby(['session_start_time'])['signed_contrast'].unique()) trials = trials.loc[trials['contrast_set'].str.len() > 4] if len(trials['session_start_time'].unique()) < 3: continue # Fit a psychometric function to these trials and get fit results fit_result = fit_psychfunc(trials) # Get RT, performance and number of trials reaction_time = trials['rt'].median() * 1000 perf_easy = trials['correct_easy'].mean() * 100 ntrials_perday = trials.groupby('session_uuid').count()['trial_id'].mean() # average trials/minute to normalise by session length trials['session_length'] = ( trials.session_end_time - trials.session_start_time).astype('timedelta64[m]') total_session_length = trials.groupby( 'session_uuid')['session_length'].mean().sum() total_n_trials = trials['trial_id'].count() # Add results to dataframe