コード例 #1
0
"""
import seaborn as sns
import os
import matplotlib.pyplot as plt
from paper_behavior_functions import (figpath, seaborn_style, group_colors,
                                      query_sessions_around_criterion,
                                      institution_map)
# import wrappers etc
from ibl_pipeline import reference, subject, behavior
from dj_tools import plot_psychometric, dj2pandas

# INITIALIZE A FEW THINGS
seaborn_style()
figpath = figpath()
pal = group_colors()
institution_map, col_names = institution_map()
col_names = col_names[:-1]

# ================================= #
# GET DATA FROM TRAINED ANIMALS
# ================================= #

use_sessions, use_days = query_sessions_around_criterion(
    criterion='trained', days_from_criterion=[2, 0], as_dataframe=False)
# restrict by list of dicts with uuids for these sessions
b = use_sessions * subject.Subject * subject.SubjectLab * reference.Lab * \
    behavior.TrialSet.Trial
# reduce the size of the fetch
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',
コード例 #2
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
    elif time_zone == 'America/New_York':
コード例 #3
0
# Query sessions
use_subjects = query_subjects()
ses = (use_subjects * behavior_analysis.SessionTrainingStatus * behavior_analysis.PsychResults
       & 'training_status = "in_training" OR training_status = "untrainable"').proj(
               'subject_nickname', 'n_trials_stim', 'institution_short').fetch(format='frame')
ses = ses.reset_index()
ses['n_trials'] = [sum(i) for i in ses['n_trials_stim']]

# Construct dataframe
training_time = pd.DataFrame(columns=['sessions'], data=ses.groupby('subject_nickname').size())
training_time['trials'] = ses.groupby('subject_nickname').sum()
training_time['lab'] = ses.groupby('subject_nickname')['institution_short'].apply(list).str[0]

# Change lab name into lab number
training_time['lab_number'] = training_time.lab.map(institution_map()[0])
training_time = training_time.sort_values('lab_number')

#  statistics
# Test normality
_, normal = stats.normaltest(training_time['sessions'])
if normal < 0.05:
    kruskal = stats.kruskal(*[group['sessions'].values
                              for name, group in training_time.groupby('lab')])
    if kruskal[1] < 0.05:  # Proceed to posthocs
        posthoc = sp.posthoc_dunn(training_time, val_col='sessions',
                                  group_col='lab_number')
else:
    anova = stats.f_oneway(*[group['sessions'].values
                             for name, group in training_time.groupby('lab')])
    if anova[1] < 0.05:
        sessions
        & 'subject_nickname = "%s"' % nickname).fetch('institution_short')[0]
    learned.loc[i, 'perf_easy'] = perf_easy
    learned.loc[i, 'reaction_time'] = reaction_time
    learned.loc[i, 'threshold'] = fit_result.loc[0, 'threshold']
    learned.loc[i, 'bias'] = fit_result.loc[0, 'bias']
    learned.loc[i, 'lapse_low'] = fit_result.loc[0, 'lapselow']
    learned.loc[i, 'lapse_high'] = fit_result.loc[0, 'lapsehigh']
    learned.loc[i, 'n_trials'] = ntrials_perday
    learned.loc[i, 'n_sessions'] = nsessions

# Drop mice with faulty RT
learned = learned[learned['reaction_time'].notnull()]

# Change lab name into lab number
learned['lab_number'] = learned.lab.map(institution_map()[0])
learned = learned.sort_values('lab_number')

# Convert to float
learned[[
    'perf_easy', 'reaction_time', 'threshold', 'n_sessions', 'bias',
    'lapse_low', 'lapse_high'
]] = learned[[
    'perf_easy', 'reaction_time', 'threshold', 'n_sessions', 'bias',
    'lapse_low', 'lapse_high'
]].astype(float)

# Add all mice to dataframe seperately for plotting
learned_2 = learned.copy()
learned_2['lab'] = 'All'
learned_2['lab_number'] = 'All'
コード例 #5
0
                                      group_colors, figpath, query_subjects,
                                      FIGURE_WIDTH, FIGURE_HEIGHT)
from ibl_pipeline.analyses import behavior as behavior_analysis

# Settings
fig_path = figpath()
bin_centers = np.arange(3, 40, 3)
bin_size = 5
seaborn_style()

# Load in data
use_subjects = query_subjects()
behav = (use_subjects *
         behavior_analysis.BehavioralSummaryByDate).fetch(format='frame')
behav['lab'] = behav['institution_short']
behav['lab_number'] = behav.lab.map(institution_map()[0])

# Get variability over days
mean_days = pd.DataFrame(columns=bin_centers,
                         index=np.unique(behav['lab_number']))
std_days = pd.DataFrame(columns=bin_centers,
                        index=np.unique(behav['lab_number']))
for i, day in enumerate(bin_centers):
    this_behav = behav[(behav['training_day'] > day - np.floor(bin_size / 2))
                       &
                       (behav['training_day'] < day + np.floor(bin_size / 2))]
    mean_days[day] = this_behav.groupby(
        'lab_number').mean()['performance_easy']
    std_days[day] = this_behav.groupby('lab_number').std()['performance_easy']

# Plot output
                    & '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]
    time_zone = behav.loc[behav['subject_nickname'] == nickname,
                          'time_zone'].unique()[0]
コード例 #7
0
Guido Meijer
Jul 1, 2020
"""

from os import mkdir
from os.path import join, isdir
import pandas as pd
from paper_behavior_functions import (query_subjects,
                                      query_sessions_around_criterion,
                                      institution_map, CUTOFF_DATE)
from ibl_pipeline.analyses import behavior as behavioral_analyses
from ibl_pipeline import reference, subject, behavior, acquisition
from dj_tools import dj2pandas

# Get map of lab number to institute
institution_map, _ = institution_map()

# create data directory if it doesn't exist yet
if not isdir('data'):
    mkdir('data')

# Create list of subjects used
subjects = query_subjects(as_dataframe=True)
subjects.to_csv(join('data', 'subjects.csv'))

# %%=============================== #
# FIGURE 2
# ================================= #
print('Starting figure 2..')

# Query list of subjects to use
コード例 #8
0
def decoding(data, labels, clf):
    kf = LeaveOneOut()
    y_pred = np.empty(len(labels), dtype='<U5')
    for train_index, test_index in kf.split(data):
        clf.fit(data[train_index], labels[train_index])
        y_pred[test_index] = clf.predict(data[test_index])
    f1 = f1_score(labels, y_pred, average='micro')
    cm = confusion_matrix(labels, y_pred)
    return f1, cm


# %% Query sessions

if QUERY is True:
    behav = query_session_around_performance()
    behav['institution_code'] = behav.institution_short.map(institution_map()[0])
else:
    behav = load_csv('Fig3.csv')

# Create dataframe with behavioral metrics of all mice
learned = pd.DataFrame(columns=['mouse', 'lab', 'perf_easy', 'n_trials',
                                'threshold', 'bias', 'reaction_time',
                                'lapse_low', 'lapse_high', 'time_zone', 'UTC'])

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
    trials = behav[behav['subject_nickname'] == nickname]