def psy_by_mouse(unique_signed_contrasts): mice = pd.DataFrame.from_dict( (subject.Subject()) * (subject.SubjectLab()) * (behavior_analysis.SessionTrainingStatus() & 'training_status="trained" ')) psy_df = pd.DataFrame(columns=unique_signed_contrasts) for row, mouse in enumerate(mice.subject_nickname.unique()): key = ((subject.Subject() & 'subject_nickname = "{}"'.format(mouse)) * (behavior.TrialSet() & 'n_trials > 100') * (subject.SubjectLab()) * (behavior_analysis.SessionTrainingStatus() & 'training_status="trained" ')).fetch('KEY') choice, cont_left, cont_right = (behavior.TrialSet.Trial & key).fetch( 'trial_response_choice', 'trial_stim_contrast_left', 'trial_stim_contrast_right') signed_contrasts = cont_right - cont_left right_choices = choice == 'CCW' total_trials = [] right_trials = [] for cont in unique_signed_contrasts: matching = (signed_contrasts == cont) total_trials.append(np.sum(matching)) right_trials.append(np.sum(right_choices[matching])) prop_right_trials = np.divide(right_trials, total_trials) psy_df.loc[row, :] = prop_right_trials return psy_df
def _insert_virtual_tables(self): # insert virtual modules tables in order virtuals = Graph(behavior.TrialSet()).get_table_list(virtual_only=True) + \ Graph(ephys.DefaultCluster()).get_table_list(virtual_only=True) + \ Graph(behavior_analyses.BehavioralSummaryByDate()).get_table_list(virtual_only=True) for itable, vtable in enumerate(virtuals[::-1]): table_key = dict(full_table_name=vtable['full_table_name']) if Table & table_key: dj.Table._update(self & table_key, 'table_order', itable) else: self.insert1(dict(full_table_name=vtable['full_table_name'], table_class=vtable['table'], table_order_category='virtual', table_order=itable, table_label='virtual'), skip_duplicates=True)
#requires Alex glm module import matplotlib.pyplot as plt import pandas as pd ## CONNECT TO datajoint import datajoint as dj dj.config['database.host'] = 'datajoint.internationalbrainlab.org' from ibl_pipeline.analyses import behavior as behavior_analysis from ibl_pipeline import reference, subject, behavior from alexfigs_datajoint_functions import * # this has all plotting functions import seaborn as sns from glm import * key = ((subject.Subject() & 'sex!="U"') * (behavior.TrialSet() & 'n_trials > 100') * (subject.SubjectLab()) * (behavior_analysis.SessionTrainingStatus() & 'training_status="ready for ephys" ')).fetch('KEY') trials_ibl = pd.DataFrame.from_dict( (subject.Subject() * behavior.TrialSet.Trial & key).fetch(as_dict=True)) trials_ibl['signed_contrasts'] = trials_ibl[ 'trial_stim_contrast_right'] - trials_ibl['trial_stim_contrast_left'] ##Rename for GLM function trials_ibl = trials_ibl.rename(index=str, columns={ "session_start_time": "ses", "subject_uuid": "mouse_name", "trial_feedback_type": "feedbackType", "trial_response_choice": "choice" })
from define_paths import fig_path from behavior_plots import * from load_mouse_data_datajoint import * # this has all plotting functions import psychofit as psy # https://github.com/cortex-lab/psychofit # folder to save plots, from DataJoint path = '/Snapshot_DataJoint_shortcut/' # ============================================= # # START BIG OVERVIEW PLOT # ============================================= # subjects = pd.DataFrame.from_dict( ((subject.Subject() - subject.Death() & 'sex!="U"') & action.Weighing() & action.WaterAdministration() & behavior.TrialSet()).fetch(as_dict=True, order_by=['lab_name', 'subject_nickname'])) users = subjects['lab_name'].unique() print(users) for lidx, lab in enumerate(users): subjects = pd.DataFrame.from_dict( ((subject.Subject() - subject.Death() & 'subject_nickname="IBL_47"' & 'sex!="U"' & 'lab_name="%s"' % lab) & action.Weighing() & action.WaterAdministration() & behavior.TrialSet()).fetch(as_dict=True, order_by=['subject_nickname'])) # group by batches: mice that were born on the same day batches = subjects.subject_birth_date.unique()
from ibl_pipeline import reference, subject, action, acquisition, data, behavior # loading and plotting functions from behavior_plots import * from load_mouse_data_datajoint import * # this has all plotting functions import psychofit as psy # https://github.com/cortex-lab/psychofit # folder to save plots, from DataJoint path = '/Figures_DataJoint_shortcuts/' # ============================================= # # START BIG OVERVIEW PLOT # ============================================= # allsubjects = pd.DataFrame.from_dict(((subject.Subject() - subject.Death()) & 'sex!="U"' & action.Weighing() & action.WaterAdministration() & behavior.TrialSet() ).fetch(as_dict=True, order_by=['lab_name', 'subject_nickname'])) users = allsubjects['lab_name'].unique() print(users) # from guido: make sure max 5 mice are plotted on a single figure sub_batch_size = 5 for lidx, lab in enumerate(users): # take mice from this lab only subjects = pd.DataFrame.from_dict(((subject.Subject() - subject.Death() & 'sex!="U"' & 'lab_name="%s"'%lab) & action.Weighing() & action.WaterAdministration() & behavior.TrialSet() ).fetch(as_dict=True, order_by=['subject_nickname']))