-
Notifications
You must be signed in to change notification settings - Fork 1
/
Figure_3AB.py
191 lines (140 loc) · 6.33 KB
/
Figure_3AB.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# -*- coding: utf-8 -*-
"""
This script generates plots and tables related to Figure 3 of the manuscript:
"Flexible auditory training, psychophysics, and enrichment
of common marmosets with an automated, touchscreen-based system"
by Calapai A.*, Cabrera-Moreno J.*, Moser T., Jeschke M.
* shared contribution
script author: Calapai A. ([email protected])
February 2022
list of input files:
- Animals_metaData.csv
- Figure_3AB.csv
list of output files:
- Figure_3AB.pdf , Figure_3AB.png
"""
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# =============================================
# disable chain assignment warning
pd.options.mode.chained_assignment = None # default='warn'
# =============================================
# Setting plotting parameters
sizeMult = 1
saveplot = 1 # 1 or 0; 1 saves plots in the folder "./analysis_output" without showing them; 0 shows without plotting
savetable = 1 # 1 or 0; 1 saves tables in "./analysis_output" without showing them
labelFontSize = 6
sns.set(style="whitegrid")
sns.set_context("paper")
# =============================================
# Parameters for the analysis
CRT_minimumTrials = 100
CRT_minimumTrials_2AC = 500
CRT_minimumTrials_TS = 3000
CTRL_lastNsessions = 10
CTRL_RT_min = 0.4 # in milliseconds
CTRL_RT_max = 5 # in milliseconds
sliding_window_size = 100 # in trials
bin_size = 5
pd.options.mode.chained_assignment = None
# =============================================
# Load color palette from animals metadata file
# Assign unique identifier to animals based on the AnimalDictionary.csv
csv_file = './data/Animals_metaData.csv'
AnimalDictionary = pd.read_csv(csv_file, low_memory=False, sep=';')
palette = pd.DataFrame()
for m in AnimalDictionary.monkey.unique():
palette = palette.append({
'animal': AnimalDictionary[AnimalDictionary.monkey == m].ID.to_list()[0],
'color': [AnimalDictionary[AnimalDictionary.monkey == m]['palette_r'].values[0],
AnimalDictionary[AnimalDictionary.monkey == m]['palette_g'].values[0],
AnimalDictionary[AnimalDictionary.monkey == m]['palette_b'].values[0]]},
ignore_index=True)
# Create unique palette for each animal
sns.set_palette(sns.color_palette("deep", n_colors=14))
palette = dict(zip(palette.animal, palette.color))
# =============================================
# Load the data for Figure 3A
def dataload():
performance_df = pd.read_csv('./data/Figure_3AB.csv', low_memory=False, decimal=',')
# Format the columns of the imported curated data file
performance_df['p_trials'] = performance_df['p_trials'].astype(int)
performance_df['HitRate'] = performance_df['HitRate'].astype(float)
performance_df['Trials'] = performance_df['Trials'].astype(int)
return performance_df
# ========================================================
# FIGURE 3AB
figure3A_height = (60 / 25.4) * sizeMult
figure3A_width = (120 / 25.4) * sizeMult
# load the data
performance_df = dataload()
plot_df = performance_df.groupby(['sessionType', 'monkey', 'p_trials', 'Trials'])['HitRate'].mean().reset_index()
# initialize the figure
f, (ax1, ax2) = plt.subplots(1, 2, sharey=False, gridspec_kw={'width_ratios': [1, 1, ]},
constrained_layout=False, figsize=(figure3A_width, figure3A_height))
# Plot the Natural Discrimination, 3 Visual Stimuli condition
sizes = (min(performance_df[performance_df['sessionType'] == '2 Visual Stimuli'].Trials.values),
max(performance_df[performance_df['sessionType'] == '2 Visual Stimuli'].Trials.values))
size_thick = (2, 4)
g = sns.lineplot(x="p_trials", y="HitRate", size='Trials', sizes=size_thick, hue="monkey", legend='brief',
data=plot_df[plot_df['sessionType'] == '2 Visual Stimuli'], ax=ax1, palette=palette)
ax1.set(xlim=[0, 100], ylim=[0, 1])
ax1.set_ylabel(ylabel='Hit Rate', fontsize=labelFontSize)
ax1.set_xlabel(xlabel='Percentage of Trials', fontsize=labelFontSize)
ax1.set_title('2 Visual Stimuli', fontsize=labelFontSize)
ax1.tick_params(labelsize=labelFontSize)
# Manually create a legend for the total trial
handles, labels = [(a + b) for a, b, in zip(ax1.get_legend_handles_labels(), ax2.get_legend_handles_labels())]
idx = [10, 11, 12, 13, 14, 15]
l = []
h = []
for i in idx:
l.append(labels[i])
h.append(handles[i])
l[0] = 'Trials'
g.legend(h, l, loc='lower center', ncol=2, frameon=False, title=None, fontsize=labelFontSize)
ax1.set_yticks([0.25, 0.5, 0.75, 1])
ax1.axhline(0.50, color='grey', linestyle='--')
ax1.tick_params(axis=u'both', which=u'both', length=0)
# Plot the Natural Discrimination, 3 Visual Stimuli condition
sizes = (min(plot_df[plot_df['sessionType'] == '3 Visual Stimuli'].Trials.values),
max(plot_df[plot_df['sessionType'] == '3 Visual Stimuli'].Trials.values))
size_thick = (2, 3.5)
g = sns.lineplot(x="p_trials", y="HitRate", size='Trials', sizes=size_thick, hue="monkey", legend='brief',
data=plot_df[plot_df['sessionType'] == '3 Visual Stimuli'], ax=ax2, palette=palette)
ax2.set(xlim=[0, 100], ylim=[0, 1])
ax2.set_ylabel(ylabel=None)
ax2.set_xlabel(xlabel='Percentage of Trials', fontsize=labelFontSize)
ax2.tick_params(labelsize=labelFontSize)
ax2.set_title('3 Visual Stimuli', fontsize=labelFontSize)
ax2.set_yticks([0.16, 0.33, 0.5, 0.66, 0.82, 1])
ax2.axhline(0.33, color='grey', linestyle='--')
handles, labels = [(a + b) for a, b, in zip(ax1.get_legend_handles_labels(), ax2.get_legend_handles_labels())]
idx = [21, 22, 23, 24, 25]
l = []
h = []
for i in idx:
l.append(labels[i])
h.append(handles[i])
l[0] = 'Trials'
g.legend(h, l, loc='lower center', ncol=2, frameon=False, title=None, fontsize=labelFontSize)
# Add figure level legend for the animal names
ax3 = ax2.twinx()
ax3.get_yaxis().set_visible(False)
ax3.set_yticklabels([])
ax2.tick_params(axis=u'both', which=u'both', length=0)
handles, labels = [(a + b) for a, b, in zip(ax1.get_legend_handles_labels(), ax2.get_legend_handles_labels())]
idx = [0, 1, 2, 3, 4, 5, 6, 17, 18, 7, 8, 9]
l = []
h = []
for i in idx:
l.append(labels[i])
h.append(handles[i])
l[0] = 'Animals'
ax3.legend(h, l, loc='center right', bbox_to_anchor=(1.45, 0.5), ncol=1, frameon=False, title=None, fontsize=labelFontSize)
# Save the figure
if saveplot:
plt.savefig('./analysis_output/Figure_3AB.pdf', format='pdf')
plt.savefig('./analysis_output/Figure_3AB.png', format='png')
plt.close()