as_dataframe=False, force_cutoff=True) trial_fields = ('trial_stim_contrast_left', 'trial_stim_contrast_right', 'trial_response_time', 'trial_stim_prob_left', 'trial_feedback_type', 'trial_stim_on_time', 'trial_response_choice') # query trial data for sessions and subject name and lab info trials = use_sessions.proj('task_protocol') * behavior.TrialSet.Trial.proj(*trial_fields) subject_info = subject.Subject.proj('subject_nickname') * \ (subject.SubjectLab * reference.Lab).proj('institution_short') # Fetch, join and sort data as a pandas DataFrame behav = dj2pandas(trials.fetch(format='frame') .join(subject_info.fetch(format='frame')) .sort_values(by=['institution_short', 'subject_nickname', 'session_start_time', 'trial_id']) .reset_index()) behav['institution_code'] = behav.institution_short.map(institution_map) # split the two types of task protocols (remove the pybpod version number) behav.drop(behav[behav['signed_contrast'].isin([50., -50])].index, inplace=True) df_basic = behav.groupby(['institution_code', 'subject_nickname', 'signed_contrast']).agg( {'choice2': 'mean'}).reset_index().copy() # query sessions - FULL TASK use_sessions, _ = query_sessions_around_criterion(criterion='ephys', days_from_criterion=[2, 0], force_cutoff=True) use_sessions = use_sessions & 'task_protocol LIKE "%biased%"' # only get biased sessions
session_keys = (use_sessions & 'task_protocol LIKE "%biased%"').fetch('KEY') ses = ((use_sessions & 'task_protocol LIKE "%biased%"') * subject.Subject * subject.SubjectLab * reference.Lab * (behavior.TrialSet.Trial & session_keys)) ses = ses.proj( 'institution_short', 'subject_nickname', 'task_protocol', 'trial_stim_contrast_left', 'trial_stim_contrast_right', 'trial_response_choice', 'task_protocol', 'trial_stim_prob_left', 'trial_feedback_type', 'trial_response_time', 'trial_stim_on_time', 'time_zone').fetch( order_by= 'institution_short, subject_nickname,session_start_time, trial_id', format='frame').reset_index() behav = dj2pandas(ses) behav['institution_code'] = behav.institution_short.map( institution_map()[0]) else: behav = load_csv('Fig4.csv') biased_fits = pd.DataFrame() 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 lab and timezone lab = behav.loc[behav['subject_nickname'] == nickname, 'institution_code'].unique()[0]
if QUERY is True: from paper_behavior_functions import query_sessions_around_criterion from ibl_pipeline import reference, subject, behavior use_sessions, _ = query_sessions_around_criterion(criterion='biased', days_from_criterion=[1, 3]) use_sessions = use_sessions & 'task_protocol LIKE "%biased%"' # only get biased sessions b = (use_sessions * subject.Subject * subject.SubjectLab * reference.Lab * behavior.TrialSet.Trial) b2 = b.proj('institution_short', 'subject_nickname', 'task_protocol', 'trial_stim_contrast_left', 'trial_stim_contrast_right', 'trial_response_choice', 'task_protocol', 'trial_stim_prob_left', 'trial_feedback_type', 'trial_response_time', 'trial_stim_on_time', 'time_zone') bdat = b2.fetch(order_by='institution_short, subject_nickname, session_start_time, trial_id', format='frame').reset_index() behav = dj2pandas(bdat) behav['institution_code'] = behav.institution_short.map(institution_map()[0]) else: behav = load_csv('Fig4.csv') biased_fits = pd.DataFrame() 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 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
behav['training_day'] = behav.training_day - \ behav.training_day.min() + 1 # start at session 1 for didx, day in enumerate(days): # get data for today print(day) thisdate = behav[behav.training_day == day]['session_date'].dt.strftime('%Y-%m-%d').item() b = (subject.Subject & 'subject_nickname = "%s"' % EXAMPLE_MOUSE) \ * (subject.SubjectLab & 'lab_name="%s"' % lab) \ * (acquisition.Session.proj(session_date='date(session_start_time)') & 'session_date = "%s"' % thisdate) \ * behavior.TrialSet.Trial() \ * endcriteria.SessionEndCriteriaImplemented() behavtmp = dj2pandas(b.fetch(format='frame').reset_index()) behavtmp['trial_start_time'] = behavtmp.trial_start_time / 60 # in minutes # unclear how this can be empty - but if it happens, skip if behavtmp.empty: continue # PSYCHOMETRIC FUNCTIONS fig, ax = plt.subplots(1, 1, figsize=(FIGURE_WIDTH/5, FIGURE_HEIGHT*0.9)) plot_psychometric(behavtmp.signed_contrast, behavtmp.choice_right, behavtmp.trial_id, ax=ax, color='k') ax.set(xlabel="\u0394 Contrast (%)") if didx == 0: