15 January 2020
"""
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',
Exemplo n.º 2
0
        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:
        posthoc = sp.posthoc_tukey(training_time, val_col='sessions',
                                   group_col='lab_number')


# %% PLOT

# Set figure style and color palette
use_palette = [[0.6, 0.6, 0.6]] * len(np.unique(training_time['lab']))
use_palette = use_palette + [[1, 1, 0.2]]
lab_colors = group_colors()

# Add all mice to dataframe seperately for plotting
training_time_no_all = training_time.copy()
training_time_no_all.loc[training_time_no_all.shape[0] + 1, 'lab_number'] = 'All'
training_time_all = training_time.copy()
training_time_all['lab_number'] = 'All'
training_time_all = training_time.append(training_time_all)

f, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 5))
sns.set_palette(lab_colors)

sns.swarmplot(y='sessions', x='lab_number', hue='lab_number', data=training_time_no_all,
              palette=lab_colors, ax=ax1)
axbox = sns.boxplot(y='sessions', x='lab_number', data=training_time_all,
                    color='white', showfliers=False, ax=ax1)
import matplotlib.pyplot as plt
from paper_behavior_functions import (figpath, seaborn_style, group_colors,
                                      query_sessions_around_criterion,
                                      institution_map)
from ibl_pipeline import reference, subject, behavior
from dj_tools import fit_psychfunc, dj2pandas
import pandas as pd
from sklearn.ensemble import RandomForestClassifier
from sklearn.naive_bayes import GaussianNB
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import KFold
from sklearn.metrics import f1_score, confusion_matrix

# Initialize
fig_path = figpath()
pal = group_colors()
institution_map, col_names = institution_map()
col_names = col_names[:-1]

# Settings
DECODER = 'forest'  # forest, bayes or regression
NUM_SPLITS = 3  # n in n-fold cross validation
ITERATIONS = 2000  # how often to decode
METRICS = [
    'threshold_l', 'threshold_r', 'bias_l', 'bias_r', 'lapselow_l',
    'lapselow_r', 'lapsehigh_l', 'lapsehigh_r'
]
METRICS_CONTROL = [
    'threshold_l', 'threshold_r', 'bias_l', 'bias_r', 'lapselow_l',
    'lapselow_r', 'lapsehigh_l', 'lapsehigh_r', 'time_zone'
]
        'zscore': learned_zs_mean['Bias'],
        'metric': 'Bias',
        'lab': learned_zs_mean.index.values
    }))
learned_zs_new = learned_zs_new.append(
    pd.DataFrame({
        'zscore': learned_zs_mean['Reaction time'],
        'metric': 'Trial duration',
        'lab': learned_zs_mean.index.values
    }))

# Set color palette
use_palette = [[0.6, 0.6, 0.6]] * len(np.unique(learned['lab']))
use_palette = use_palette + [[1, 1, 0.2]]
sns.set_palette(use_palette)
lab_colors = group_colors()

# Plot behavioral metrics per lab
f, (ax1, ax2, ax3, ax4, ax5) = plt.subplots(1, 5, figsize=(16, 4))
sns.set_palette(use_palette)

sns.boxplot(y='perf_easy', x='lab_number', data=learned_2, ax=ax1)
ax1.set(ylabel='Performance at easy contrasts (%)', ylim=[70, 101], xlabel='')
[
    tick.set_color(lab_colors[i])
    for i, tick in enumerate(ax1.get_xticklabels()[:-1])
]
plt.setp(ax1.xaxis.get_majorticklabels(), rotation=40)

sns.boxplot(y='threshold', x='lab_number', data=learned_2, ax=ax2)
ax2.set(ylabel='Visual threshold (% contrast)', ylim=[-1, 40], xlabel='')
Exemplo n.º 5
0
                 'intercept']
cat = ['institution', 'weight', 'parameter']
for i in tbehav['institution_code'].unique():
    tbehav_temp = tbehav.loc[tbehav['institution_code'] == i]
    tsum_temp = pd.DataFrame(0, index=np.arange(len(tfeature_list)), columns=cat)
    tsum_temp['institution'] = i 
    tsum_temp['parameter'] = tfeature_list
    for t in tfeature_list:
        tsum_temp.loc[tsum_temp['parameter'] == t, 'weight'] = tbehav_temp[t].mean()
    tsummary_curves = pd.concat([tsummary_curves, tsum_temp])

##############################################################################
#******************************* Plotting ***********************************#
##############################################################################

pal = group_colors()

# Visualization

figpath = figpath()

# Set seed for simulation
np.random.seed(1)

# Line colors
cmap = sns.diverging_palette(20, 220, n=3, center="dark")

# Get data from example session (TODO make inot specific query)


# Data for bias session