-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathomissions_traces_peaks_plots_sumMice.py
1506 lines (1135 loc) · 76.3 KB
/
omissions_traces_peaks_plots_sumMice.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Vars needed here are set in omissions_traces_peaks_plots_setVars_ave.py
(Note: ABtransit codes right now do not make layer-pooled (per area) plots. To do so, just use svm_allMice_sessPooled same as when ABtransit is 0, except make plots for A, B separately, instead of averaged sessions)
Created on Thu Sep 12 18:37:08 2019
@author: farzaneh
"""
#%% SUMMARY ACROSS MICE
##########################################################################################
##########################################################################################
############# Plot traces averaged across mice of the same cre line ################
##########################################################################################
##########################################################################################
#%%
if all_ABtransit_AbefB_Aall_Ball_Bfirst_ABallButB1==1: # plot average across mice for A sessions, and B sessions, separately.
#%% Decide if you want to plot interpolated or original traces
#(because I am using linear interpolation it makes no difference really!)
trace_now = trace_ave_allCre_new
#trace_now = trace_ave_allCre
trace_sd_now = trace_sd_allCre_new
#trace_sd_now = trace_sd_allCre
xnow = time_trace_new
#xnow = time_trace
# use frames instead of time
#xnow = np.unique(np.concatenate((np.arange(0, -(samps_bef+1), -1), np.arange(0, samps_aft))))
#%% Plot the mouse-averaged traces for the two sessions (A, B), done separately for each cre line and each plane
# xlim = [-1.2, 2.25] # [-13, 24]
frame_dur_new = np.diff(xnow)[0]
r = np.round(np.array(xlim) / frame_dur_new).astype(int)
xlim_frs = np.arange(int(np.argwhere(xnow==0).squeeze()) + r[0], min(trace_now.shape[-1], int(np.argwhere(xnow==0).squeeze()) + r[1] + 1))
#num_depth = 4
bbox_to_anchor = (.92, .72)
jet_cm = colorOrder(nlines=num_sessions)
# set x tick marks
xmj = np.unique(np.concatenate((np.arange(0, time_trace[0], -1), np.arange(0, time_trace[-1], 1))))
xmn = np.arange(.25, time_trace[-1], .5)
xmjn = [xmj, xmn]
# set ylim: same for all plots of all cre lines
lims0 = [np.min(trace_now[:,:,xlim_frs] - trace_sd_now[:,:,xlim_frs]), np.max(trace_now[:,:,xlim_frs] + trace_sd_now[:,:,xlim_frs])]
for icre in range(len(all_cres)): # icre = 0
cre = all_cres[icre]
fa = plt.figure(figsize=(12, 15)) # (12, 5)
plt.suptitle('%s, %d mice' %(cre, num_each_cre[icre]), y=1.1, fontsize=18) # .94
##### classification accuracy plots #####
# subplots of traces, V1
gs = gridspec.GridSpec(1, num_depth) #, width_ratios=[3, 1])
gs.update(bottom=0.87, top=.98, wspace=.6)
# gs.update(bottom=0.63, top=0.95, wspace=.6) #, hspace=1)
# subplots of traces, LM
gs2 = gridspec.GridSpec(1, num_depth)
gs2.update(bottom=0.71, top=0.82, wspace=0.6)
# gs2.update(bottom=0.05, top=0.37, wspace=0.6) #, hspace=1)
##### Response measures; each depth #####
# subplots of flash responses
# 4 subplots: resp amp, V1 and LM; then resp timing, V1 and LM
gs3 = gridspec.GridSpec(1,4) #, width_ratios=[3, 1])
gs3.update(bottom=.52, top=0.63, wspace=.65, hspace=.5) #, left=0.03, right=0.65
# subplots of omission responses
# resp amp, V1 and LM; then resp timing, V1 and LM
gs4 = gridspec.GridSpec(1,4)
gs4.update(bottom=.37, top=0.48, wspace=.65, hspace=.5) #, left=0.03, right=0.65
##### Response Modulation (change) measures; each depth #####
# subplots of flash responses; 2 subplots: resp amp, resp timing (each includes both v1 and lm)
gs5 = gridspec.GridSpec(1,4) #, width_ratios=[3, 1])
gs5.update(bottom=.16, top=.28, wspace=.55, hspace=.5) # , left=0.05, right=0.55
# gs5.update(bottom=.17, top=0.3, left=0.05, right=0.43, wspace=.55, hspace=.5)
# subplots of omission responses; 2 subplots: resp amp, resp timing (each includes both v1 and lm)
gs6 = gridspec.GridSpec(1,4)
gs6.update(bottom=0, top=0.12, wspace=.55, hspace=.5) # , left=0.05, right=0.55
# gs6.update(bottom=.17, top=0.3, left=0.57, right=0.95, wspace=.55, hspace=.5)
'''
fa = plt.figure(figsize=(12, 5)) # 2* len(session_stages)
plt.suptitle('%s, %d mice' %(cre, num_each_cre[icre]), y=1.1, fontsize=18) # .94
# subplots of peak amp (neuron averaged, per trial) and omit-aligned traces
gs = gridspec.GridSpec(1, num_depth) #, width_ratios=[3, 1])
gs.update(bottom=0.63, top=0.95, wspace=.6) #, hspace=1)
# subplots of peak amp/ timing (trial-median)
gs2 = gridspec.GridSpec(1, num_depth)
gs2.update(bottom=0.05, top=0.37, wspace=0.6) #, hspace=1)
'''
############################################################
########## Plot population averages ##########
############################################################
lims0 = [np.min(trace_now[icre,:,xlim_frs] - trace_sd_now[icre,:,xlim_frs]), np.max(trace_now[icre,:,xlim_frs] + trace_sd_now[icre,:,xlim_frs])]
############ Subplot 1: area V1 ############ (planes 4:8)
for iplane in inds_v1: #np.arange(num_depth, num_planes): #num_planes): # iplane = 0
area = trace_peak_allMice.iloc[0]['area'][iplane] # take it from the 1st mouse, this info is the same for all mice
onePlane_allSess = np.arange(iplane, np.shape(trace_ave_allCre)[1], num_planes)
depth = depth_ave_allCre[icre, onePlane_allSess]
area = np.unique(area)[0]
depth = np.mean(depth)
top = trace_now[icre, onePlane_allSess] # num_sess x num_frs
top_sd = trace_sd_now[icre, onePlane_allSess] # num_sess x num_frs
ax1 = plt.subplot(gs[iplane-num_depth])
h = []
for isess in range(num_sessions):
h0 = plt.plot(xnow, top.T[:,isess], color=jet_cm[isess], label=session_labs[isess])[0]
h.append(h0)
# errorbars (standard error across mice)
plt.fill_between(xnow, top.T[:,isess] - top_sd.T[:,isess], top.T[:,isess] + top_sd.T[:,isess], alpha=alph, edgecolor=jet_cm[isess], facecolor=jet_cm[isess])
# mn = np.min(top.flatten())
# mx = np.max(top.flatten())
# lims = [mn, mx]
ylabn = ylabel if iplane==num_depth else ''
lims = np.array([np.nanmin(top[:,xlim_frs] - top_sd[:,xlim_frs]), np.nanmax(top[:,xlim_frs] + top_sd[:,xlim_frs])])
lims[0] = lims[0] - np.diff(lims) / 20.
lims[1] = lims[1] + np.diff(lims) / 20.
plot_flashLines_ticks_legend(lims0, h, flashes_win_trace_index_unq_time, grays_win_trace_index_unq_time, time_trace, bbox_to_anchor, ylab=ylabel, xmjn=xmjn)
plt.title('%s, %dum' %(area, depth), fontsize=13.5, y=1)
plt.xlim(xlim)
# plt.vlines(0, mn, mx, 'r', linestyle='-') #, cmap=colorsm)
# plt.vlines(flashes_win_trace_index_unq, mn, mx, linestyle=':')
# plt.xlabel('Frame (~10Hz)', fontsize=12)
# if iplane==num_depth:
# plt.ylabel('DF/F %s' %(ylab), fontsize=12)
## if iplane==0: #num_planes-1:
# plt.legend(h, session_labs, loc='center left', bbox_to_anchor=bbox_to_anchor, frameon=False, fontsize=12, handlelength=.4)
# ax1.tick_params(labelsize=10)
# plt.grid(False) # plt.box(on=None) # plt.axis(True)
# seaborn.despine()#left=True, bottom=True, right=False, top=False)
############ Subplot 2: area LM ############ (planes 0:3)
for iplane in inds_lm: #range(num_depth): #num_planes): # iplane = 0
area = trace_peak_allMice.iloc[0]['area'][iplane] # take it from the 1st mouse, this info is the same for all mice
onePlane_allSess = np.arange(iplane, np.shape(trace_ave_allCre)[1], num_planes)
depth = depth_ave_allCre[icre, onePlane_allSess]
area = np.unique(area)[0]
depth = np.mean(depth)
top = trace_now[icre, onePlane_allSess] # num_sess x num_frs
top_sd = trace_sd_now[icre, onePlane_allSess] # num_sess x num_frs
ax2 = plt.subplot(gs2[iplane])
h = []
for isess in range(num_sessions):
h0 = plt.plot(xnow, top.T[:,isess], color=jet_cm[isess], label=session_labs[isess])[0]
h.append(h0)
# errorbars (standard error across mice)
plt.fill_between(xnow, top.T[:,isess] - top_sd.T[:,isess], top.T[:,isess] + top_sd.T[:,isess], alpha=alph, edgecolor=jet_cm[isess], facecolor=jet_cm[isess])
# mn = np.min(top.flatten())
# mx = np.max(top.flatten())
# lims = [mn, mx]
ylabn = ylabel if iplane==0 else ''
lims = np.array([np.nanmin(top[:,xlim_frs] - top_sd[:,xlim_frs]), np.nanmax(top[:,xlim_frs] + top_sd[:,xlim_frs])])
lims[0] = lims[0] - np.diff(lims) / 20.
lims[1] = lims[1] + np.diff(lims) / 20.
plot_flashLines_ticks_legend(lims0, h, flashes_win_trace_index_unq_time, grays_win_trace_index_unq_time, time_trace, bbox_to_anchor, ylab=ylabel, xmjn=xmjn)
plt.title('%s, %dum' %(area, depth), fontsize=13.5, y=1)
plt.xlim(xlim)
# plt.vlines(0, mn, mx, 'r', linestyle='-') #, cmap=colorsm)
# plt.vlines(flashes_win_trace_index_unq, mn, mx, linestyle=':')
# plt.xlabel('Frame (~10Hz)', fontsize=12)
# plt.legend(h, session_labs, loc='center left', bbox_to_anchor=bbox_to_anchor, frameon=False, fontsize=12, handlelength=.4)
# ax2.tick_params(labelsize=10)
# plt.grid(False) # plt.box(on=None) # plt.axis(True)
# seaborn.despine()#left=True, bottom=True, right=False, top=False)
#%%
##########################################################################################
##########################################################################################
############# Plot peak amplitude for omission and flash evoked responses ################
##########################################################################################
##########################################################################################
####################################################################
############ Subplot gs3 & gs4: flash- & omission-evoked responses ###################
### 4 subplots: resp amp, V1 and LM; then resp timing, V1 and LM ###
####################################################################
xlabs = 'Depth (um)'
x = np.arange(num_depth)
xgap_areas = .2 # .3
depth = depth_ave_allCre[icre] # (8 x num_sessions)
inds_v1_lm = inds_v1, inds_lm
labvl = 'V1 ', 'LM '
########################################################################
#%% Image-evoked responses
########################################################################
###### Image: Response amplitude, V1, then LM ######
y_ave_now = peak_amp_flash_ave_allCre # num_cre x (8 x num_sessions)
y_sd_now = peak_amp_flash_sd_allCre
top = y_ave_now[icre] # (8 x num_sessions)
top_sd = y_sd_now[icre]
# same ylim for all layers and areas
mn = np.min(top - top_sd)
mx = np.max(top + top_sd)
r = mx - mn
lims0 = [mn-r/20., mx+r/20.] # set ylim: same for all plots of the same cre line
ylabs0 = 'Resp amplitude'
for ivl in range(len(labvl)):
inds_area_allSess = np.array([np.arange(inds_v1_lm[ivl][iplane], y_ave_now.shape[1], num_planes) for iplane in range(num_depth)])
# inds_area_allSess: # 4 x num_sessions ; each column is the indeces of v1 planes for a given session (along the 2nd dim of y_ave_now).
# inds_v1 + num_planes
indsA = inds_area_allSess[:,0] # depth indeces for V1, for session A
indsB = inds_area_allSess[:,1] # depth indeces for V1, for session B
depth_area_eachSess = np.array([depth[inds_area_allSess[idepth]] for idepth in range(num_depth)]) # 4 x num_sessions
depth_ave = np.mean(depth_area_eachSess, axis=1) # average across sessions, depth of each plane
xticklabs = np.round(depth_ave).astype(int)
ylabs = labvl[ivl] + ylabs0
# flash, response amplitude; V1, then LM; 4 depths, A,B sessions
ax1 = plt.subplot(gs3[ivl])
### testing data # plot testing, and shuffle data, ie indeces 1 and 2 in top # ind_ts_sh = [1,2] (train, test, shuffle, chance)
# session A
ax1.errorbar(x, top[indsA], yerr=top_sd[indsA], fmt='o', markersize=3, capsize=3, label='A', color='b')
# session B
ax1.errorbar(x+xgap_areas, top[indsB], yerr=top_sd[indsB], fmt='o', markersize=3, capsize=3, label='B', color='r')
plt.hlines(0, 0, len(x)-1, linestyle=':')
ax1.set_xticks(x)
ax1.set_xticklabels(xticklabs, rotation=45)
ax1.tick_params(labelsize=10)
plt.xlim([-.5, len(x)-.5])
# plt.xlabel('Depth', fontsize=12)
if ~np.isnan(lims0).any():
plt.ylim(lims0)
# ax1.set_ylabel('%s' %(ylabs), fontsize=12)
plt.title('%s' %(ylabs), fontsize=13) #12
# plt.title('Image', fontsize=13.5, y=1)
ylim = plt.gca().get_ylim(); text_y = ylim[1] + np.diff(ylim)/3
if ivl==0:
plt.ylabel('Image', fontsize=15, rotation=0, labelpad=35)
# plt.text(3.2, text_y, 'Image', fontsize=15)
if ivl==0:
# ax1.legend(loc=3, bbox_to_anchor=(-.1, 1.2, 1, .1), ncol=2, frameon=False, mode='expand', borderaxespad=0, fontsize=12, handletextpad=.5) # handlelength=1,
plt.legend(loc='center left', bbox_to_anchor=(.97,.8), frameon=False, handlelength=1, fontsize=12)
plt.grid(False) # plt.box(on=None) # plt.axis(True)
seaborn.despine()#left=True, bottom=True, right=False, top=False)
################## Image: Response timing, V1, then LM ##################
y_ave_now = peak_timing_flash_ave_allCre # num_cre x (8 x num_sessions)
y_sd_now = peak_timing_flash_sd_allCre
top = y_ave_now[icre] # (8 x num_sessions)
top_sd = y_sd_now[icre]
# same ylim for all layers and areas
mn = np.min(top - top_sd)
mx = np.max(top + top_sd)
r = mx - mn
lims0 = [mn-r/20., mx+r/20.] # set ylim: same for all plots of the same cre line
ylabs0 = 'Resp timing'
for ivl in range(len(labvl)):
inds_area_allSess = np.array([np.arange(inds_v1_lm[ivl][iplane], y_ave_now.shape[1], num_planes) for iplane in range(num_depth)])
# inds_area_allSess: # 4 x num_sessions ; each column is the indeces of v1 planes for a given session (along the 2nd dim of y_ave_now).
# inds_v1 + num_planes
indsA = inds_area_allSess[:,0] # depth indeces for V1, for session A
indsB = inds_area_allSess[:,1] # depth indeces for V1, for session B
depth_area_eachSess = np.array([depth[inds_area_allSess[idepth]] for idepth in range(num_depth)]) # 4 x num_sessions
depth_ave = np.mean(depth_area_eachSess, axis=1) # average across sessions, depth of each plane
xticklabs = np.round(depth_ave).astype(int)
ylabs = labvl[ivl] + ylabs0
# flash, response amplitude; V1, then LM; 4 depths, A,B sessions
ax1 = plt.subplot(gs3[2+ivl])
### testing data # plot testing, and shuffle data, ie indeces 1 and 2 in top # ind_ts_sh = [1,2] (train, test, shuffle, chance)
# session A
ax1.errorbar(x, top[indsA], yerr=top_sd[indsA], fmt='o', markersize=3, capsize=3, label='A', color='b')
# session B
ax1.errorbar(x+xgap_areas, top[indsB], yerr=top_sd[indsB], fmt='o', markersize=3, capsize=3, label='B', color='r')
plt.hlines(0, 0, len(x)-1, linestyle=':')
ax1.set_xticks(x)
ax1.set_xticklabels(xticklabs, rotation=45)
ax1.tick_params(labelsize=10)
plt.xlim([-.5, len(x)-.5])
# plt.xlabel('Depth', fontsize=12)
if ~np.isnan(lims0).any():
plt.ylim(lims0)
# ax1.set_ylabel('%s' %(ylabs), fontsize=12)
plt.title('%s' %(ylabs), fontsize=13) #12
# plt.title('Image', fontsize=13.5, y=1)
ylim = plt.gca().get_ylim(); text_y = ylim[1] + np.diff(ylim)/3
# plt.ylabel('Image', fontsize=15, rotation=0, labelpad=35)
# plt.text(3.2, text_y, 'Image', fontsize=15)
# ax1.legend(loc=3, bbox_to_anchor=(-.1, 1, 2, .1), ncol=2, frameon=False, mode='expand', borderaxespad=0, fontsize=12, handletextpad=.5) # handlelength=1,
# plt.legend(loc='center left', bbox_to_anchor=bb, frameon=False, handlelength=1, fontsize=12)
plt.grid(False) # plt.box(on=None) # plt.axis(True)
seaborn.despine()#left=True, bottom=True, right=False, top=False)
########################################################################
#%% Omission-evoked responses
########################################################################
###### Omission: Response amplitude, V1, then LM ######
y_ave_now = peak_amp_omit_ave_allCre # num_cre x (8 x num_sessions)
y_sd_now = peak_amp_omit_sd_allCre
top = y_ave_now[icre] # (8 x num_sessions)
top_sd = y_sd_now[icre]
# same ylim for all layers and areas
mn = np.min(top - top_sd)
mx = np.max(top + top_sd)
r = mx - mn
lims0 = [mn-r/20., mx+r/20.] # set ylim: same for all plots of the same cre line
ylabs0 = 'Resp amplitude'
for ivl in range(len(labvl)):
inds_area_allSess = np.array([np.arange(inds_v1_lm[ivl][iplane], y_ave_now.shape[1], num_planes) for iplane in range(num_depth)])
# inds_area_allSess: # 4 x num_sessions ; each column is the indeces of v1 planes for a given session (along the 2nd dim of y_ave_now).
# inds_v1 + num_planes
indsA = inds_area_allSess[:,0] # depth indeces for V1, for session A
indsB = inds_area_allSess[:,1] # depth indeces for V1, for session B
depth_area_eachSess = np.array([depth[inds_area_allSess[idepth]] for idepth in range(num_depth)]) # 4 x num_sessions
depth_ave = np.mean(depth_area_eachSess, axis=1) # average across sessions, depth of each plane
xticklabs = np.round(depth_ave).astype(int)
ylabs = labvl[ivl] + ylabs0
# omission, response amplitude; V1, then LM; 4 depths, A,B sessions
ax1 = plt.subplot(gs4[ivl])
### testing data # plot testing, and shuffle data, ie indeces 1 and 2 in top # ind_ts_sh = [1,2] (train, test, shuffle, chance)
# session A
ax1.errorbar(x, top[indsA], yerr=top_sd[indsA], fmt='o', markersize=3, capsize=3, label='A', color='b')
# session B
ax1.errorbar(x+xgap_areas, top[indsB], yerr=top_sd[indsB], fmt='o', markersize=3, capsize=3, label='B', color='r')
plt.hlines(0, 0, len(x)-1, linestyle=':')
ax1.set_xticks(x)
ax1.set_xticklabels(xticklabs, rotation=45)
ax1.tick_params(labelsize=10)
plt.xlim([-.5, len(x)-.5])
plt.xlabel('Depth', fontsize=12)
if ~np.isnan(lims0).any():
plt.ylim(lims0)
# ax1.set_ylabel('%s' %(ylabs), fontsize=12)
# plt.title('%s' %(ylabs), fontsize=13) #12
# plt.title('Omission', fontsize=13.5, y=1)
ylim = plt.gca().get_ylim(); text_y = ylim[1] + np.diff(ylim)/3
if ivl==0:
plt.ylabel('Omission', fontsize=15, rotation=0, labelpad=35)
# plt.text(3.2, text_y, 'Omission', fontsize=15)
# ax1.legend(loc=3, bbox_to_anchor=(-.1, 1, 2, .1), ncol=2, frameon=False, mode='expand', borderaxespad=0, fontsize=12, handletextpad=.5) # handlelength=1,
# plt.legend(loc='center left', bbox_to_anchor=bb, frameon=False, handlelength=1, fontsize=12)
plt.grid(False) # plt.box(on=None) # plt.axis(True)
seaborn.despine()#left=True, bottom=True, right=False, top=False)
################## Omission: Response timing, V1, then LM ##################
y_ave_now = peak_timing_omit_ave_allCre # num_cre x (8 x num_sessions)
y_sd_now = peak_timing_omit_sd_allCre
top = y_ave_now[icre] # (8 x num_sessions)
top_sd = y_sd_now[icre]
# same ylim for all layers and areas
mn = np.min(top - top_sd)
mx = np.max(top + top_sd)
r = mx - mn
lims0 = [mn-r/20., mx+r/20.] # set ylim: same for all plots of the same cre line
ylabs0 = 'Resp timing'
for ivl in range(len(labvl)):
inds_area_allSess = np.array([np.arange(inds_v1_lm[ivl][iplane], y_ave_now.shape[1], num_planes) for iplane in range(num_depth)])
# inds_area_allSess: # 4 x num_sessions ; each column is the indeces of v1 planes for a given session (along the 2nd dim of y_ave_now).
# inds_v1 + num_planes
indsA = inds_area_allSess[:,0] # depth indeces for V1, for session A
indsB = inds_area_allSess[:,1] # depth indeces for V1, for session B
depth_area_eachSess = np.array([depth[inds_area_allSess[idepth]] for idepth in range(num_depth)]) # 4 x num_sessions
depth_ave = np.mean(depth_area_eachSess, axis=1) # average across sessions, depth of each plane
xticklabs = np.round(depth_ave).astype(int)
ylabs = labvl[ivl] + ylabs0
# omission, response amplitude; V1, then LM; 4 depths, A,B sessions
ax1 = plt.subplot(gs4[2+ivl])
### testing data # plot testing, and shuffle data, ie indeces 1 and 2 in top # ind_ts_sh = [1,2] (train, test, shuffle, chance)
# session A
ax1.errorbar(x, top[indsA], yerr=top_sd[indsA], fmt='o', markersize=3, capsize=3, label='A', color='b')
# session B
ax1.errorbar(x+xgap_areas, top[indsB], yerr=top_sd[indsB], fmt='o', markersize=3, capsize=3, label='B', color='r')
plt.hlines(0, 0, len(x)-1, linestyle=':')
ax1.set_xticks(x)
ax1.set_xticklabels(xticklabs, rotation=45)
ax1.tick_params(labelsize=10)
plt.xlim([-.5, len(x)-.5])
plt.xlabel('Depth', fontsize=12)
if ~np.isnan(lims0).any():
plt.ylim(lims0)
# ax1.set_ylabel('%s' %(ylabs), fontsize=12)
# plt.title('%s' %(ylabs), fontsize=13) #12
# plt.title('Omission', fontsize=13.5, y=1)
ylim = plt.gca().get_ylim(); text_y = ylim[1] + np.diff(ylim)/3
# plt.ylabel('Omission', fontsize=15, rotation=0, labelpad=35)
# plt.text(3.2, text_y, 'Omission', fontsize=15)
# ax1.legend(loc=3, bbox_to_anchor=(-.1, 1, 2, .1), ncol=2, frameon=False, mode='expand', borderaxespad=0, fontsize=12, handletextpad=.5) # handlelength=1,
# plt.legend(loc='center left', bbox_to_anchor=bb, frameon=False, handlelength=1, fontsize=12)
plt.grid(False) # plt.box(on=None) # plt.axis(True)
seaborn.despine()#left=True, bottom=True, right=False, top=False)
####################################################################################
############## Plot relative change of response amplitude and timing from A to B ##############
####################################################################################
# add 4 subplots; 2 for resp amp (flash, omit), 2 for resp timing (flash, omit)
# each shows resp modulation for 4 depths.
# depth_ave_allCre[icre].shape # (8 x num_sessions)
# d = np.reshape(depth_ave_allCre[icre], (num_planes, num_sessions), order='F') # 8 x num_sessions
# depth_ave = np.mean(d, axis=1) # 8 # average across A,B sessions
depth_ave = np.mean(np.reshape(depth_ave_allCre[icre], (num_depth, 2, num_sessions), order='F'), axis=(1,2))
# same ylim for all layers and areas
mn = np.min(top - top_sd)
mx = np.max(top + top_sd)
r = mx - mn
lims0 = [mn-r/20., mx+r/20.] # set ylim: same for all plots of the same cre line
xlabs = 'Depth (um)'
x = np.arange(num_depth)
xticklabs = np.round(depth_ave).astype(int)
###########################################
#%% Image-evoked responses
###########################################
################# left plot: image, response amplitude #######################
ylabs = 'Resp amplitude'
y_ave_now = peak_amp_mod_flash_ave_allCre # num_cre x 8 x 4
y_sd_now = peak_amp_mod_flash_sd_allCre
top = y_ave_now[icre] # 8
top_sd = y_sd_now[icre]
ax1 = plt.subplot(gs5[0])
# testing data
ax1.errorbar(x, top[inds_v1], yerr=top_sd[inds_v1], fmt='o', markersize=3, capsize=3, label='V1', color=cols_area[1])
ax1.errorbar(x + xgap_areas, top[inds_lm], yerr=top_sd[inds_lm], fmt='o', markersize=3, capsize=3, label='LM', color=cols_area[0])
plt.hlines(0, 0, len(x)-1, linestyle=':')
ax1.set_xticks(x)
ax1.set_xticklabels(xticklabs, rotation=45)
ax1.tick_params(labelsize=10)
plt.xlim([-.5, len(x)-.5])
# plt.xlabel('Depth', fontsize=12)
# plt.ylim(lims0)
# ax1.set_ylabel('%s' %(ylabs), fontsize=12)
plt.title('%s' %(ylabs), fontsize=13) #12
# plt.title('Image', fontsize=13.5, y=1)
ylim = plt.gca().get_ylim(); text_y = ylim[1] + np.diff(ylim)/3
plt.ylabel('Image', fontsize=15, rotation=0, labelpad=35)
# plt.text(3.2, text_y, 'Image', fontsize=15)
# ax1.legend(loc=3, bbox_to_anchor=(-.1, 1, 2, .1), ncol=2, frameon=False, mode='expand', borderaxespad=0, fontsize=12, handletextpad=.5) # handlelength=1,
# plt.legend(loc='center left', bbox_to_anchor=bb, frameon=False, handlelength=1, fontsize=12)
plt.grid(False) # plt.box(on=None) # plt.axis(True)
seaborn.despine()#left=True, bottom=True, right=False, top=False)
################# right plot: flash, response timing #######################
ylabs = 'Peak timing (s)'
y_ave_now = peak_timing_mod_flash_ave_allCre # num_cre x 8 x 4
y_sd_now = peak_timing_mod_flash_sd_allCre
top = y_ave_now[icre] # 8
top_sd = y_sd_now[icre]
ax2 = plt.subplot(gs5[1])
# testing data
ax2.errorbar(x, top[inds_v1], yerr=top_sd[inds_v1], fmt='o', markersize=3, capsize=3, label='V1', color=cols_area[1])
ax2.errorbar(x + xgap_areas, top[inds_lm], yerr=top_sd[inds_lm], fmt='o', markersize=3, capsize=3, label='LM', color=cols_area[0])
# plt.hlines(0, 0, num_sessions-1, linestyle=':')
ax2.set_xticks(x)
ax2.set_xticklabels(xticklabs, rotation=45)
ax2.tick_params(labelsize=10)
plt.xlim([-.5, len(x)-.5])
# plt.xlabel('Depth', fontsize=12)
# plt.ylim(lims0)
# ax2.set_ylabel('%s' %(ylabs), fontsize=12)
plt.title('%s' %(ylabs), fontsize=13) #12
# plt.title('Image', fontsize=13.5, y=1)
# ylim = plt.gca().get_ylim(); text_y = ylim[1] + np.diff(ylim)/3.
# plt.text(1.2, text_y, 'Image', fontsize=15)
plt.legend(loc='center left', bbox_to_anchor=bb, frameon=False, handlelength=1, fontsize=12)
plt.grid(False) # plt.box(on=None) # plt.axis(True)
seaborn.despine()#left=True, bottom=True, right=False, top=False)
###########################################
#%% Omission-evoked responses
###########################################
################# left plot: omission, response amplitude #######################
ylabs = 'Resp amplitude'
y_ave_now = peak_amp_mod_omit_ave_allCre # num_cre x 8 x 4
y_sd_now = peak_amp_mod_omit_sd_allCre
top = y_ave_now[icre] # 8
top_sd = y_sd_now[icre]
ax1 = plt.subplot(gs6[0])
# testing data
ax1.errorbar(x, top[inds_v1], yerr=top_sd[inds_v1], fmt='o', markersize=3, capsize=3, label='V1', color=cols_area[1])
ax1.errorbar(x + xgap_areas, top[inds_lm], yerr=top_sd[inds_lm], fmt='o', markersize=3, capsize=3, label='LM', color=cols_area[0])
plt.hlines(0, 0, len(x)-1, linestyle=':')
ax1.set_xticks(x)
ax1.set_xticklabels(xticklabs, rotation=45)
ax1.tick_params(labelsize=10)
plt.xlim([-.5, len(x)-.5])
plt.xlabel(xlabs, fontsize=12)
# plt.ylim(lims0)
# ax1.set_ylabel('%s' %(ylabs), fontsize=12)
# plt.title('%s' %(ylabs), fontsize=12)
# plt.title('Image', fontsize=13.5, y=1)
ylim = plt.gca().get_ylim(); text_y = ylim[1] + np.diff(ylim)/3
plt.ylabel('Omission', fontsize=15, rotation=0, labelpad=35)
# plt.text(3.2, text_y, 'Omission', fontsize=15)
# ax1.legend(loc=3, bbox_to_anchor=(-.1, 1, 2, .1), ncol=2, frameon=False, mode='expand', borderaxespad=0, fontsize=12, handletextpad=.5) # handlelength=1,
# plt.legend(loc='center left', bbox_to_anchor=bb, frameon=False, handlelength=1, fontsize=12)
plt.grid(False) # plt.box(on=None) # plt.axis(True)
seaborn.despine()#left=True, bottom=True, right=False, top=False)
################# right plot: omission, response timing #######################
ylabs = 'Peak timing'
y_ave_now = peak_timing_mod_omit_ave_allCre # num_cre x 8 x 4
y_sd_now = peak_timing_mod_omit_sd_allCre
top = y_ave_now[icre] # 8
top_sd = y_sd_now[icre]
ax1 = plt.subplot(gs6[1])
# testing data
ax2.errorbar(x, top[inds_v1], yerr=top_sd[inds_v1], fmt='o', markersize=3, capsize=3, label='V1', color=cols_area[1])
ax2.errorbar(x + xgap_areas, top[inds_lm], yerr=top_sd[inds_lm], fmt='o', markersize=3, capsize=3, label='LM', color=cols_area[0])
# plt.hlines(0, 0, num_sessions-1, linestyle=':')
ax2.set_xticks(x)
ax2.set_xticklabels(xticklabs, rotation=45)
ax2.tick_params(labelsize=10)
plt.xlim([-.5, len(x)-.5])
plt.xlabel(xlabs, fontsize=12)
# plt.ylim(lims0)
# ax2.set_ylabel('%s' %(ylabs), fontsize=12)
# plt.title('%s' %(ylabs), fontsize=12)
# plt.title('Image', fontsize=13.5, y=1)
# ylim = plt.gca().get_ylim(); text_y = ylim[1] + np.diff(ylim)/3.
# plt.text(1.2, text_y, 'Image', fontsize=15)
plt.legend(loc='center left', bbox_to_anchor=bb, frameon=False, handlelength=1, fontsize=12)
plt.grid(False) # plt.box(on=None) # plt.axis(True)
seaborn.despine()#left=True, bottom=True, right=False, top=False)
if dosavefig:
nam = '%s_aveMice%s_%s_%s' %(cre, whatSess, fgn, now)
fign = os.path.join(dir0, dir_now, nam+fmt)
plt.savefig(fign, bbox_inches='tight') # , bbox_extra_artists=(lgd,)
### Old codes
"""
#%%
##########################################################################################
##########################################################################################
############# Plot peak amplitude for omission and flash evoked responses ################
##########################################################################################
##########################################################################################
plotPeakTiming = 0 # if 0, plot peak amp; if 1, plot peak timing
same_ylim_all_layers_areas = 1 # if 0, use the same ylim for the same depth of both areas (but different ylims for different depths)
if plotPeakTiming:
ylabs = 'Peak timing' #
amp_time = 'peakTime' # needed for figure name
else:
ylabs = 'Resp amplitude'
amp_time = 'peakAmp' # needed for figure name #
for icre in range(len(all_cres)): # icre = 0
cre = all_cres[icre]
fa = plt.figure(figsize=(8, 11)) # 2* len(session_stages)
plt.suptitle('%s, %d mice' %(cre, num_each_cre[icre]), y=.99, fontsize=18) # .94
# subplots of flash responses
gs = gridspec.GridSpec(num_depth,2) #, width_ratios=[3, 1])
gs.update(left=0.05, right=0.4, wspace=.6, hspace=.5)
# subplots of omission responses
gs2 = gridspec.GridSpec(num_depth,2)
gs2.update(left=0.6, right=0.95, wspace=.6, hspace=.5)
############################################################
############ Subplot gs2: omission-evoked responses ############
###############################################################
if plotPeakTiming:
y_ave_now = peak_timing_ave_allCre #peak_amp_ave_allCre
y_sd_now = peak_timing_sd_allCre #peak_amp_sd_allCre
else:
y_ave_now = peak_amp_ave_allCre
y_sd_now = peak_amp_sd_allCre
# same ylim for all layers and areas
# lims0 = [np.min(y_ave_now[icre] - y_sd_now[icre]), np.max(y_ave_now[icre] + y_sd_now[icre])] # set ylim: same for all plots of the same cre line
### Left column: area V1 (planes 4:8)
for iplane in inds_v1: #np.arange(num_depth, num_planes): #num_planes): # iplane = 0
area = trace_peak_allMice.iloc[0]['area'][iplane] # take it from the 1st mouse, this info is the same for all mice
onePlane_allSess = np.arange(iplane, np.shape(trace_ave_allCre)[1], num_planes)
depth = depth_ave_allCre[icre, onePlane_allSess]
area = np.unique(area)[0]
depth = np.mean(depth)
# use same ylim for the same depth of both areas
if same_ylim_all_layers_areas:
onePlane_allSess_allAreas = np.concatenate((onePlane_allSess, onePlane_allSess - num_depth)) # do +num_depth if iplane is 0:3 (ie for area LM)
lims0 = np.squeeze([np.min(y_ave_now[icre, onePlane_allSess_allAreas] - y_sd_now[icre, onePlane_allSess_allAreas]), \
np.max(y_ave_now[icre, onePlane_allSess_allAreas] + y_sd_now[icre, onePlane_allSess_allAreas])]) # set ylim: same for all plots of the same cre line
lims0[0] = lims0[0] - np.diff(lims0) / 20.
lims0[1] = lims0[1] + np.diff(lims0) / 20.
top = y_ave_now[icre, onePlane_allSess] # num_sess
top_sd = y_sd_now[icre, onePlane_allSess] # num_sess
ax1 = plt.subplot(gs2[iplane-num_depth, 0])
ax1.errorbar(range(num_sessions), top, yerr=top_sd, fmt='o', markersize=3, capsize=3)
plt.hlines(0, 0, num_sessions-1, linestyle=':')
ax1.set_xticks(range(num_sessions))
ax1.set_xticklabels(session_labs, rotation=45)
ax1.tick_params(labelsize=10)
plt.xlim([-.5, num_sessions-.5])
plt.ylim(lims0)
ax1.set_ylabel('%s\n(%d um)' %(ylabs, depth), fontsize=12)
if iplane==4:
plt.title('%s' %area, fontsize=13.5, y=1)
ylim = plt.gca().get_ylim(); text_y = ylim[1] + np.diff(ylim)/3.
plt.text(1.2, text_y, 'Omission', fontsize=15)
plt.grid(False) # plt.box(on=None) # plt.axis(True)
seaborn.despine()#left=True, bottom=True, right=False, top=False)
### Right column: area LM (planes 0:3)
for iplane in inds_lm: #range(num_depth): #num_planes): # iplane = 0
area = trace_peak_allMice.iloc[0]['area'][iplane] # take it from the 1st mouse, this info is the same for all mice
onePlane_allSess = np.arange(iplane, np.shape(trace_ave_allCre)[1], num_planes)
depth = depth_ave_allCre[icre, onePlane_allSess]
area = np.unique(area)[0]
depth = np.mean(depth)
# use same ylim for the same depth of both areas
if same_ylim_all_layers_areas:
onePlane_allSess_allAreas = np.concatenate((onePlane_allSess, onePlane_allSess - num_depth)) # do +num_depth if iplane is 0:3 (ie for area LM)
lims0 = np.squeeze([np.min(y_ave_now[icre, onePlane_allSess_allAreas] - y_sd_now[icre, onePlane_allSess_allAreas]), \
np.max(y_ave_now[icre, onePlane_allSess_allAreas] + y_sd_now[icre, onePlane_allSess_allAreas])]) # set ylim: same for all plots of the same cre line
lims0[0] = lims0[0] - np.diff(lims0) / 20.
lims0[1] = lims0[1] + np.diff(lims0) / 20.
top = y_ave_now[icre, onePlane_allSess] # num_sess
top_sd = y_sd_now[icre, onePlane_allSess] # num_sess
ax2 = plt.subplot(gs2[iplane, 1])
ax2.errorbar(range(num_sessions), top, yerr=top_sd, fmt='o', markersize=3, capsize=3)
plt.hlines(0, 0, num_sessions-1, linestyle=':')
ax2.set_xticks(range(num_sessions))
ax2.set_xticklabels(session_labs, rotation=45)
ax2.tick_params(labelsize=10)
plt.xlim([-.5, num_sessions-.5])
plt.ylim(lims0)
# ax2.set_ylabel('Resp amp\n%d um' %depth, fontsize=12)
if iplane==0:
plt.title('%s' %area, fontsize=13.5, y=1)
plt.grid(False) # plt.box(on=None) # plt.axis(True)
seaborn.despine()#left=True, bottom=True, right=False, top=False)
#%% Plot change in peak amplitude from A to B sessions (B minus A)
### This part still needs work... it will give good summary plots for the two areas (all depth on the x axis)
'''
# TO DO:
# 1. load the allsess file that gives the plots that make more sense in terms of quantifications!
# 2. edit the definition of diffAB_sd below... you have to compute sd on diff traces!
# 3. finish the plot
d = np.reshape(depth_ave_allCre, (depth_ave_allCre.shape[0], num_planes, 2), order='F') # num_cres x 8 x 2 (2: A and B sessions: 2 sessions)
d_ave = np.mean(d, axis=2) # num_cre x 8 (average of depth for each plane across the two sessions)
d_aveAreas = np.mean(np.reshape(d_ave[icre], (num_depth, 2), order='F'), axis=1).astype(int) # 4 # average of depth across the two areas
a = np.reshape(y_ave_now, (y_ave_now.shape[0], num_planes, 2), order='F') # num_cres x 8 x 2
diffAB_ave = np.diff(a, axis=2).squeeze() # difference from A to B # num_cre x 8
a = np.reshape(y_sd_now, (y_ave_now.shape[0], num_planes, 2), order='F') # num_cres x 8 x 2
diffAB_sd = np.diff(a, axis=2).squeeze() # difference from A to B # num_cre x 8
lims0 = np.squeeze([np.min(y_ave_now[icre, onePlane_allSess_allAreas] - y_sd_now[icre, onePlane_allSess_allAreas]), \
np.max(y_ave_now[icre, onePlane_allSess_allAreas] + y_sd_now[icre, onePlane_allSess_allAreas])]) # set ylim: same for all plots of the same cre line
lims0[0] = lims0[0] - np.diff(lims0) / 20.
lims0[1] = lims0[1] + np.diff(lims0) / 20.
# slc = np.reshape(aa[0], (num_depth, 2), order='F')
# sst = np.reshape(aa[1], (num_depth, 2), order='F')
# vip = np.reshape(aa[2], (num_depth, 2), order='F')
top = diffAB_ave[icre, inds_v1] # num_sess
top_sd = diffAB_sd[icre, inds_v1] # num_sess
ax1 = plt.subplot(1,1,1) #(gs2[iplane-num_depth, 0])
ax1.errorbar(range(num_depth), top, yerr=top_sd, fmt='o', markersize=3, capsize=3)
plt.hlines(0, 0, num_depth-1, linestyle=':')
ax1.set_xticks(range(num_depth))
ax1.set_xticklabels(d_aveAreas, rotation=45)
ax1.tick_params(labelsize=10)
plt.xlim([-.5, num_depth-.5])
plt.ylim(lims0)
ax1.set_ylabel('%s\n(%d um)' %(ylabs, depth), fontsize=12)
if iplane==4:
plt.title('%s' %area, fontsize=13.5, y=1)
ylim = plt.gca().get_ylim(); text_y = ylim[1] + np.diff(ylim)/3.
plt.text(1.2, text_y, 'Omission', fontsize=15)
plt.grid(False) # plt.box(on=None) # plt.axis(True)
seaborn.despine()#left=True, bottom=True, right=False, top=False)
'''
#%%
############################################################
############ Subplot gs: flash-evoked responses ############
############################################################
if plotPeakTiming:
y_ave_now = peak_timing_flash_ave_allCre #peak_amp_ave_allCre
y_sd_now = peak_timing_flash_sd_allCre #peak_amp_sd_allCre
else:
y_ave_now = peak_amp_flash_ave_allCre
y_sd_now = peak_amp_flash_sd_allCre
# same ylim for all layers and areas
# lims0 = [np.min(y_ave_now[icre] - y_sd_now[icre]), np.max(y_ave_now[icre] + y_sd_now[icre])] # set ylim: same for all plots of the same cre line
### Left column: area V1 (planes 4:8)
for iplane in np.arange(num_depth, num_planes): #num_planes): # iplane = 0
area = trace_peak_allMice.iloc[0]['area'][iplane] # take it from the 1st mouse, this info is the same for all mice
onePlane_allSess = np.arange(iplane, np.shape(trace_ave_allCre)[1], num_planes)
depth = depth_ave_allCre[icre, onePlane_allSess]
area = np.unique(area)[0]
depth = np.mean(depth)
# use same ylim for the same depth of both areas
if same_ylim_all_layers_areas:
onePlane_allSess_allAreas = np.concatenate((onePlane_allSess, onePlane_allSess - num_depth)) # do +num_depth if iplane is 0:3 (ie for area LM)
lims0 = np.squeeze([np.min(y_ave_now[icre, onePlane_allSess_allAreas] - y_sd_now[icre, onePlane_allSess_allAreas]), \
np.max(y_ave_now[icre, onePlane_allSess_allAreas] + y_sd_now[icre, onePlane_allSess_allAreas])]) # set ylim: same for all plots of the same cre line
lims0[0] = lims0[0] - np.diff(lims0) / 20.
lims0[1] = lims0[1] + np.diff(lims0) / 20.
top = y_ave_now[icre, onePlane_allSess] # num_sess
top_sd = y_sd_now[icre, onePlane_allSess] # num_sess
ax1 = plt.subplot(gs[iplane-num_depth, 0])
ax1.errorbar(range(num_sessions), top, yerr=top_sd, fmt='o', markersize=3, capsize=3)
plt.hlines(0, 0, num_sessions-1, linestyle=':')
ax1.set_xticks(range(num_sessions))
ax1.set_xticklabels(session_labs, rotation=45)
ax1.tick_params(labelsize=10)
plt.xlim([-.5, num_sessions-.5])
plt.ylim(lims0)
ax1.set_ylabel('%s\n(%d um)' %(ylabs, depth), fontsize=12)
if iplane==4:
plt.title('%s' %area, fontsize=13.5, y=1)
ylim = plt.gca().get_ylim(); text_y = ylim[1] + np.diff(ylim)/3.
plt.text(1.2, text_y, 'Image', fontsize=15)
plt.grid(False) # plt.box(on=None) # plt.axis(True)
seaborn.despine()#left=True, bottom=True, right=False, top=False)
### Right column: area LM (planes 0:3)
for iplane in range(num_depth): #num_planes): # iplane = 0
area = trace_peak_allMice.iloc[0]['area'][iplane] # take it from the 1st mouse, this info is the same for all mice
onePlane_allSess = np.arange(iplane, np.shape(trace_ave_allCre)[1], num_planes)
depth = depth_ave_allCre[icre, onePlane_allSess]
area = np.unique(area)[0]
depth = np.mean(depth)
# use same ylim for the same depth of both areas
if same_ylim_all_layers_areas:
onePlane_allSess_allAreas = np.concatenate((onePlane_allSess, onePlane_allSess - num_depth)) # do +num_depth if iplane is 0:3 (ie for area LM)
lims0 = np.squeeze([np.min(y_ave_now[icre, onePlane_allSess_allAreas] - y_sd_now[icre, onePlane_allSess_allAreas]), \
np.max(y_ave_now[icre, onePlane_allSess_allAreas] + y_sd_now[icre, onePlane_allSess_allAreas])]) # set ylim: same for all plots of the same cre line
lims0[0] = lims0[0] - np.diff(lims0) / 20.
lims0[1] = lims0[1] + np.diff(lims0) / 20.
top = y_ave_now[icre, onePlane_allSess] # num_sess
top_sd = y_sd_now[icre, onePlane_allSess] # num_sess
ax2 = plt.subplot(gs[iplane, 1])
ax2.errorbar(range(num_sessions), top, yerr=top_sd, fmt='o', markersize=3, capsize=3)
plt.hlines(0, 0, num_sessions-1, linestyle=':')
ax2.set_xticks(range(num_sessions))
ax2.set_xticklabels(session_labs, rotation=45)
ax2.tick_params(labelsize=10)
plt.xlim([-.5, num_sessions-.5])
plt.ylim(lims0)
# ax2.set_ylabel('Resp amp\n%d um' %depth, fontsize=12)
if iplane==0:
plt.title('%s' %area, fontsize=13.5, y=1)
plt.grid(False) # plt.box(on=None) # plt.axis(True)
seaborn.despine()#left=True, bottom=True, right=False, top=False)
#%%
if dosavefig:
nam = '%s_aveMice%s_%s_all_planes_%s_omit_flash_%s' %(cre, whatSess, fgn, amp_time, now)
fign = os.path.join(dir0, dir_now, nam+fmt)
plt.savefig(fign, bbox_inches='tight') # , bbox_extra_artists=(lgd,)
"""
#%%
############################################################################################################################################
############################################################################################################################################
############################################################################################################################################
############################################################################################################################################
#%% Not A-B transitions
############################################################################################################################################
############################################################################################################################################
############################################################################################################################################
############################################################################################################################################
#trace_peak_allMice_sessPooled
#trace_peak_allMice_sessAvSd
else:
#%% Plot omission-aligned traces
cre_all = trace_peak_allMice_sessPooled['cre_allPlanes']
cre_lines = np.unique(cre_all)
a_all = trace_peak_allMice_sessPooled['area_allPlanes'] # 8 x pooledSessNum
d_all = trace_peak_allMice_sessPooled['depth_allPlanes'] # 8 x pooledSessNum
session_labs_all = trace_peak_allMice_sessPooled['session_labs']
t_all = trace_peak_allMice_sessPooled['trace_allPlanes'] # 8 x pooledSessNum x 80
pa_all = trace_peak_allMice_sessPooled['peak_amp_allPlanes'] # 8 x pooledSessNum
pt_all = trace_peak_allMice_sessPooled['peak_timing_allPlanes'] # 8 x pooledSessNum
paf_all = trace_peak_allMice_sessPooled['peak_amp_flash_allPlanes'] # 8 x pooledSessNum
ptf_all = trace_peak_allMice_sessPooled['peak_timing_flash_allPlanes'] # 8 x pooledSessNum
cre_eachArea = trace_peak_allMice_sessPooled['cre_eachArea'] # 2 x (4*sum(num_sess_per_mouse))
t_eachArea = trace_peak_allMice_sessPooled['trace_eachArea'] # 2 x (4*sum(num_sess_per_mouse)) x 80
pa_eachArea = trace_peak_allMice_sessPooled['peak_amp_eachArea'] # 2 x (4*sum(num_sess_per_mouse))
pt_eachArea = trace_peak_allMice_sessPooled['peak_timing_eachArea'] # 2 x (4*sum(num_sess_per_mouse))
paf_eachArea = trace_peak_allMice_sessPooled['peak_amp_flash_eachArea'] # 2 x (4*sum(num_sess_per_mouse))
ptf_eachArea = trace_peak_allMice_sessPooled['peak_timing_flash_eachArea'] # 2 x (4*sum(num_sess_per_mouse))
cre_eachDepth = trace_peak_allMice_sessPooled['cre_eachDepth'] # 4 x (2*sum(num_sess_per_mouse))
t_eachDepth = trace_peak_allMice_sessPooled['trace_eachDepth'] # 4 x (2*sum(num_sess_per_mouse)) x 80