-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathplotratemaps.m
5322 lines (5086 loc) · 307 KB
/
plotratemaps.m
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
function [selcell_orig] = plotratemaps(objtype,criteria,save,maptype,varargin)
% Function to plot rate maps for place, view and heading direction
% Without additional inputs, it will work from and save in current
% directory
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% INPUT VARIABLES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% objtype: 'place', 'view', or 'direction'
%
% criteria: 'sic' or 'ise'
%
% save: 1 (save figures) or 0.
% NOTE: if using save, figure folder location must be hard-coded below.
%
% maptype: Type of smoothing, 'raw' (unsmoothed), 'boxcar'
% (boxcar-smoothed) or 'adaptive' (adaptive-smooted) NOTE: Currently only
% raw and adaptive smoothing have been tested.
%
% Varargin: If only need to plot 1 cell's maps
% 1st: cell directory
%
% Note: replace 'criteria' with 'sortsic' if need to sort cells by SIC/ISE
% sortsic: 1 (sort the plotting by descending SIC) or 0 (sort the plotting
% by date)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
sortcrit = 0;
video = 0;
filttype = 'FiltVel';
pix = 1;
cwd = '/Volumes/Hippocampus/Data/picasso-misc/AnalysisHM/Current Analysis';
% Saving figure directory
if strcmp(objtype,'mixsel0') || strcmp(objtype,'mixsel1')
figdir = [cwd '/Figures/' filttype '/' num2str(pix) 'px' '/RateMaps/mixsel/UseCorr' objtype(end) '_test'];
else
figdir = [cwd '/Figures/' filttype '/' num2str(pix) 'px' '/RateMaps/' objtype '_' criteria '_' num2str(maptype) '_' 'test'];
% figdir = [cwd '/Figures/' filttype '/' num2str(pix) 'px' '/RateMaps/' objtype '_' criteria '_' num2str(maptype) '_' 'yy1px'];
end
if nargin > 4 % If plotting a single cell and map is already given as input (only used in placebyview.m)
% Load cell list
cellList = varargin(1);
cd([cellList{1} '/' filttype '/' num2str(pix) 'px/']);
% Load object
switch objtype
case 'place'
objMain = load('vmpc.mat');
objMain = objMain.vmp;
case 'view'
objMain = load('vmsv.mat');
objMain = objMain.vms;
case 'direction'
objMain = load('vmhd.mat');
objMain = objMain.vmd;
end
% Load object corrected for independent influences of place/view
objCorr = load('vmcorr.mat');
objCorr = objCorr.vmcorr;
if save
%%% FILL IN
end
else % If plotting a batch of cells
if save
if exist(figdir,'dir') ~= 7
mkdir(figdir);
else
rmdir(figdir,'s');
mkdir(figdir);
end
end
% Load cell list
cd(cwd);
fid = fopen([cwd '/cell_list.txt'],'rt');
cellList = textscan(fid,'%s','Delimiter','\n');
cellList = cellList{1};
% Make sure no empty cells
notempty = ~cellfun(@isempty,cellList);
cellList = cellList(notempty,:);
% Make sure no duplicates
cellList = unique(cellList);
% Load object
c_objdir = [cwd '/Combined Objects/' filttype '/' num2str(pix) 'px/'];
if exist(c_objdir,'dir') ~= 7
disp('Missing combined object');
else
cd(c_objdir);
end
switch objtype
case 'place'
objMain = load('c_vmpc.mat');
objMain = objMain.vmp;
case 'view'
objMain = load('c_vmsv.mat');
objMain = objMain.vms;
case 'headdirection'
objMain = load('c_vmhd.mat');
objMain = objMain.vmd;
case 'all'
objPlace = load('c_vmpc.mat');
objPlace = objPlace.vmp;
objView = load('c_vmsv.mat');
objView = objView.vms;
objHeaddirection = load('c_vmhd.mat');
objHeaddirection = objHeaddirection.vmd;
objMain = objPlace; % Placeholder
objMS0 = load('c_vmms0.mat');
objMS0 = objMS0.vmms;
case 'mixsel0'
tic;
objMain = load('c_vmms0.mat');
objMain = objMain.vmms;
disp(['Loading c_vmms0 obj took ' num2str(toc) 's']); tic;
objPlace = load('c_vmpc.mat');
objPlace = objPlace.vmp;
disp(['Loading c_vmpc obj took ' num2str(toc) 's']); tic;
objView = load('c_vmsv.mat');
objView = objView.vms;
disp(['Loading c_vmsv obj took ' num2str(toc) 's']); tic;
objHeaddirection = load('c_vmhd.mat');
objHeaddirection = objHeaddirection.vmd;
disp(['Loading c_vmhd obj took ' num2str(toc) 's']);
case 'mixsel1'
objMain = load('c_vmms1.mat');
objMain = objMain.vmms;
objPlace = load('c_vmpc.mat');
objPlace = objPlace.vmp;
objView = load('c_vmsv.mat');
objView = objView.vms;
objHeaddirection = load('c_vmhd.mat');
objHeaddirection = objHeaddirection.vmd;
case 'allprop'
objMain0 = load('c_vmms0.mat');
objMain0 = objMain0.vmms;
objMain = load('c_vmms1.mat'); % Treat this as the main obj
objMain = objMain.vmms;
objPlace = load('c_vmpc.mat');
objPlace = objPlace.vmp;
objView = load('c_vmsv.mat');
objView = objView.vms;
objHeaddirection = load('c_vmhd.mat');
objHeaddirection = objHeaddirection.vmd;
case 'trajectory'
objMain = load('c_vmpc.mat');
objMain = objMain.vmp;
end
% Load object corrected for independent influences of place/view
objCorr = load('c_vmcorr.mat');
objCorr = objCorr.vmcorr;
cd(cwd);
% Check that combined object is the same size as cell list
if size(cellList,1) ~= size(objMain.data.origin,1)
disp('Object has different number of cells than CellList');
end
end
% Generate unique identifier for each cell
s = regexp(cellList{1},'session');
identifiers = zeros(size(cellList,1),5);
cellid = cell(size(cellList,1),1);
missing = [];
for ii = 1:size(cellList,1)
if exist(cellList{ii},'dir') == 7
% Collect date, session, array, channel, cell
identifiers(ii,:) = [str2double(cellList{ii}(s-9:s-2)) str2double(cellList{ii}(s+7:s+8)) ...
str2double(cellList{ii}(s+15:s+16)) str2double(cellList{ii}(s+25:s+27)) str2double(cellList{ii}(s+33:s+34))];
% Cell identifier
cellid{ii} = horzcat(num2str(identifiers(ii,4)),'-',num2str(identifiers(ii,5)));
else
missing = [missing ii];
end
end
% Remove missing cells
identifiers(missing,:) = [];
cellid(missing) = [];
cellList(missing) = [];
setsessions = unique(identifiers(:,1));
setcells = unique(cellid);
%%%% PATCH - c_vmcorr may have fewer cells than c_vmpc or c_vmv.
%%%% Match the cells in c_vmcorr to cells in other objects
if size(objCorr.data.origin,1) ~= size(objMain.data.origin,1)
disp('Corrected object is not the same size as main object');
% for ii = 1:size(objCorr.data.origin,1)
% [~,matchcorr] = ismember(objCorr.data.origin{1},objMain.data.origin);
% end
% else
% matchcorr = (1:size(objCorr.data.origin,1))';
end
% Load firing rate maps depending on smoothing type
switch maptype
case 'raw'
mapname = 'maps_raw';
critname = [upper(criteria) '_adsm'];
critshname = [upper(criteria) 'sh_adsm'];
case 'smooth'
mapname = 'maps_sm';
critname = ['crit_sm'];
critshname = ['critsh_sm'];
secmapname = 'secsmoothmap_adsm';
case 'dur'
mapname = 'dur_raw';
critname = [upper(criteria) '_adsm'];
critshname = [upper(criteria) 'sh_adsm'];
case 'boxcar'
mapname = 'maps_bcsm';
critname = [upper(criteria) '_bcsm'];
critshname = [upper(criteria) 'sh_bcsm'];
secmapname = 'secsmoothmap_bcsm';
case 'disk'
mapname = 'maps_dksm';
critname = [upper(criteria) '_dksm'];
critshname = [upper(criteria) 'sh_dksm'];
secmapname = 'secsmoothmap_dksm';
case 'adaptive'
mapname = 'maps_adsm';
critname = [upper(criteria) '_adsm'];
critshname = [upper(criteria) 'sh_adsm'];
secmapname = 'secsmoothmap_adsm';
end
if strcmp(objtype,'place')
maps = objMain.data.(mapname);
objtype_short = 'p';
elseif strcmp(objtype,'view')
maps = objMain.data.(mapname);
objtype_short = 'v';
elseif strcmp(objtype,'headdirection')
maps = objMain.data.(mapname);
objtype_short = 'h';
elseif strcmp(objtype,'mixsel0') || strcmp(objtype,'mixsel1')
maps_p = objPlace.data.(mapname);
maps_v = objView.data.(mapname);
elseif strcmp(objtype,'allprop')
maps_p = objPlace.data.(mapname);
maps_v = objView.data.(mapname);
end
% Load nptdata objMain
nCells = objMain.data.numSets;
% Plot params
plotgridh = 5; % cols
plotgridv = 3; % rows
fig = 1;
subpnum = 1;
% Set up cell counts
crossallthresh = 0;
crosscellthresh = 0;
crosspopthresh = 0;
crosseitherthresh = 0;
selcell_orig = [];
selcell_corr = [];
if ismember(objtype,{'place','view','headdirection'}) % One row per cell
%%% Pick (up to 5) things to plot
% 'full','half1','half2','corr_pv','covar_pv', 'pred_hv_raw', 'pred_hv_sm'
panels = {'full','half1','half2','corr_pv','pred_pv'}; % 'pred','corr_hv',
% Get shuffled SIC threshold for all cells
% thr_sh = [objMain.data.(critname); objMain.data.(critshname)]; % all shuffles of population
% thr_pop = prctile(thr_sh,95); % thr_place = 0.057; thr_view = ?
% z_pop = zscore(thr_sh);
% Get population threshold for selectivity
cell_indsP = ismember(objMain.data.origin,cellList);
leaveout_P = find(objMain.data.discard | ~cell_indsP); % cells with <100 spikes are discarded
leaveout_P = repmat(1:objMain.data.Args.NumShuffles,size(leaveout_P)) + (leaveout_P*objMain.data.Args.NumShuffles-objMain.data.Args.NumShuffles);
thr_sh = objMain.data.critsh_sm(setdiff(1:size(objMain.data.critsh_sm,1),leaveout_P));
thr_pop = prctile(thr_sh,95);
z_pop = zscore(thr_sh);
% Plot data summaries
plotdatasummary = 1;
if plotdatasummary
h=figure(fig);
hold on;
figname = horzcat(objtype,' Data Summaries');
set(h,'Name',figname,'Units','Normalized','Position',[0 1 1 1]);
% Get relevant spatial variables
sic = objMain.data.crit_sm(cell_indsP);
sparsity = objMain.data.sparsity(cell_indsP);
coherence = objMain.data.coherence(cell_indsP);
sig2noise = objMain.data.sig2noise(cell_indsP);
tbl = table(sic,sparsity,coherence,sig2noise);
% Plot all cells but reduce size of cells with <100 spikes and max rate < 0.7Hz
pointsize = repmat(100,sum(cell_indsP),1);
pointsize(objMain.data.discard(cell_indsP) | ~objMain.data.rateok(cell_indsP)) = 30;
% Plot
s = scatter3(tbl,'sig2noise','sparsity','coherence','filled','ColorVariable','sic');
s.SizeData = pointsize;
hold on;
% Mask non-selective cells with black
nonsel = objMain.data.crit_sm(cell_indsP)<=thr_pop;
s = scatter3(objMain.data.sig2noise(nonsel),objMain.data.sparsity(nonsel),objMain.data.coherence(nonsel),pointsize(nonsel),'filled','k');
pointcolor = repmat([0 0 0],sum(cell_indsP),1); % non-selective cells in black
% Format colors
colorbar;
view(-60,70);
colormap cool;
% Format axes
xlabel('sig2noise');
ylabel('sparsity')
zlabel('coherence');
ax = gca;
ax.XGrid = 'on';
ax.YGrid = 'on';
ax.Title.String = figname;
% Save figure
figtitle = [figname];
savefigure(save,s,figtitle,figdir);
fig = fig + 1;
end
for ii = 1:size(setsessions,1) % For each session
cells_indList = find(identifiers(:,1) == setsessions(ii));
for jj = 1:length(cells_indList) % For each cell
cell_indList = cells_indList(jj);
cell_ind = find(strcmp(objMain.data.origin,cellList(cells_indList(jj))));
% okminspk = objMain.data.filtspknum(cell_ind) >= 100;
% if ~okminspk
% disp(['Fewer than 100 spikes: ' cellList(cell_ind)]);
% end
% Save previous figure
if jj*5 > plotgridh * plotgridv && mod((jj*5), (plotgridh * plotgridv)) == 5
% Save previous figure
figtitle = [num2str(setsessions(ii)) '-' num2str(floor(jj/(plotgridh * plotgridv))),' FigNum ',num2str(h.Number)];
savefigure(save,h,figtitle,figdir);
fig = fig + 1;
subpnum = 1;
end
% Get shuffled SI cutoff for this cell - 95th percentile
crit = objMain.data.(critname)(cell_ind,1);
thr_cell = prctile(objMain.data.(critshname)( (cell_ind-1)*objMain.data.Args.NumShuffles+1:cell_ind*objMain.data.Args.NumShuffles ,1 ) ,95);
z_cell = z_pop(cell_ind,1);
% Get map
if nargin <= 5 % If mapGrid is not already specified (i.e. if plotting for a batch of cells
mapLin = maps(cell_ind,:);
% if corrected map exists, get it
if any(ismember(objMain.data.origin{cell_ind},objCorr.data.origin))
[~,corr_ind] = ismember(objMain.data.origin{cell_ind},objCorr.data.origin);
if strcmp(objtype,'place') || strcmp(objtype,'view')
mapLincorr = objCorr.data.pv(corr_ind).(['maps_sm' '_corr' objtype_short]);
elseif strcmp(objtype,'headdirection')
mapLincorr = objCorr.data.ph(corr_ind).(['maps_sm' '_corr' objtype_short]);
end
else
mapLincorr = nan(size(mapLin));
corr_ind = [];
end
end
% Setup figure
h = figure(fig);
hold on;
figname = horzcat(objtype,': ',num2str(setsessions(ii)));
set(h,'Name',figname,'Units','Normalized','Position',[0 1 0.75 0.75]);
% Plot full session rate map
if ismember('full',panels)
% Find subplot number
ax = subplot(plotgridv,plotgridh,(mod(jj-1,plotgridv))*plotgridh+find(strcmp('full',panels)));
% Plot map
[mapGrid,~,maxrate]= plotmap(mapLin,objtype);
% Set up axes
if strcmp(objtype,'view') && maxrate < nanmax(mapLin)
ax.Title.String = {horzcat('Cue: ',num2str(mapLin(1),2),'Hz'),...
horzcat('Hint: ',num2str(mapLin(2),2),'Hz')};
ax.Title.Color = 'r';
else
ax.Title.String = {horzcat(num2str(setsessions(ii)), 'ch',num2str(identifiers(cell_indList,4)),...
'c',num2str(identifiers(cell_indList,5)),', ',num2str(maxrate,3),'Hz'), ...
horzcat(criteria, '=',num2str(crit,2),'/',num2str(thr_cell,2),'/',num2str(thr_pop,2)),...
horzcat('z-',criteria,'= ',num2str(z_cell))};
rate = text(ax,1,1.05,1,[num2str(maxC,2) 'Hz'],'Units','Normalized','FontSize',16,'HorizontalAlignment','right');
si = text(ax,0,1.05,1,num2str(basedata.SI,2),'Units','Normalized','FontSize',16,'HorizontalAlignment','left');
if crit >= thr_cell && crit >= thr_pop && okminspk && maxrate>=0.7
ax.Title.Color = 'r';
crossallthresh = crossallthresh + 1;
elseif crit >= thr_cell && crit < thr_pop && okminspk && maxrate>=0.7
ax.Title.Color = 'm';
crosscellthresh = crosscellthresh + 1;
crosseitherthresh = crosseitherthresh + 1;
elseif crit < thr_cell && crit >= thr_pop && okminspk && maxrate>=0.7
ax.Title.Color = 'b';
crosspopthresh = crosspopthresh + 1;
crosseitherthresh = crosseitherthresh + 1;
end
if crit >= thr_pop && okminspk && maxrate>=0.7
selcell_orig(end+1,1) = cell_ind;
end
end
% Patch standing point if placebyview
if nargin > 5 % If placebyview
fieldCoords
patch([fieldCoords(1)-2 fieldCoords(1)-2 fieldCoords(1)+1 fieldCoords(1)+1],[fieldCoords(2)-2 fieldCoords(2)+1 fieldCoords(2)+1 fieldCoords(2)-2], [0 0 0 0] ,[1 1 1 1],'FaceColor','none');
end
end
% Plot session halves
if ismember('half1',panels) || ismember('half2',panels)
% Intra-session correlation %%%%%% NOTE: Should use boxcar
% smoothed map
map1 = objMain.data.([mapname '1'])(cell_ind,:);
map2 = objMain.data.([mapname '2'])(cell_ind,:);
vis1 = ~isnan(map1);
vis2 = ~isnan(map2);
vis = vis1 & vis2; % Correlate only visited bins;
intracorr = corr2(map1(vis), map2(vis));
crit1 = objMain.data.([critname '1'])(cell_ind);
crit2 = objMain.data.([critname '2'])(cell_ind);
% Plot
for kk = 1:2
if ismember(['half' num2str(kk)],panels)
ax = subplot(plotgridv,plotgridh,(mod(jj-1,plotgridv))*plotgridh++find(strcmp(['half' num2str(kk)],panels)));
mapLin = eval(['map' num2str(kk)]);
crit = eval(['crit' num2str(kk)]);
half = num2str(kk);
% Plot map
[~,~,maxrate_half]= plotmap(mapLin,objtype);
% Set up axes
ax.Title.String = {horzcat('half',half,': ','corr=',num2str(intracorr,2),', ',...
num2str(maxrate_half,3),'Hz'),horzcat(criteria, '=',num2str(crit,2),'/',num2str(thr_cell,2),'/',num2str(thr_pop,2))};
if crit >= thr_cell && crit >= thr_pop && okminspk && maxrate>=0.7
ax.Title.Color = 'r';
elseif crit >= thr_cell && crit < thr_pop && okminspk && maxrate>=0.7
ax.Title.Color = 'm';
elseif crit < thr_cell && crit >= thr_pop && okminspk && maxrate>=0.7
ax.Title.Color = 'b';
end
end
end
end
% Plot corrected maps
if cell2mat(regexp(panels,'corr'))
howmanycorrpanels = find(~cellfun(@isempty,regexp(panels,'corr')));
for kk = 1:size(howmanycorrpanels,2)
ax = subplot(plotgridv,plotgridh,(mod(jj-1,plotgridv))*plotgridh++howmanycorrpanels(kk));
corrobj = strsplit(panels{howmanycorrpanels(kk)},'_');
if ~isempty(regexp(corrobj{2},objtype_short))
temp = objCorr.data.(corrobj{2});
if isempty(corr_ind)
critcorr = nan;
else
critcorr = temp(corr_ind).(['crit_sm' '_corr' objtype_short]);
end
% Plot map
[~,~,maxratecorr]= plotmap(mapLincorr,objtype);
% Set up axes
if ~isempty(corr_ind)
ax.Title.String = {horzcat('Corrected',corrobj{2},temp(corr_ind).llhpicklabel,'of',...
num2str(size(temp(corr_ind).llh,1)),': ',num2str(maxratecorr,3),'Hz'), ...
horzcat(criteria, '=',num2str(critcorr,2),'/',num2str(thr_cell,2),'/',num2str(thr_pop,2))};
else
ax.Title.String = 'No corrected map';
end
if critcorr >= thr_cell && critcorr >= thr_pop && okminspk && maxratecorr>=0.7
ax.Title.Color = 'r';
elseif critcorr >= thr_cell && critcorr < thr_pop && okminspk && maxratecorr>=0.7
ax.Title.Color = 'm';
elseif critcorr < thr_cell && critcorr >= thr_pop && okminspk && maxratecorr>=0.7
ax.Title.Color = 'b';
end
if critcorr >= thr_pop && okminspk && maxratecorr>=0.7
selcell_corr(end+1,1) = cell_ind;
end
else
ax.Title.String = ['Requested corr obj does not have "' objtype '"'];
end
end
end
% Plot predicted artefactual map
if cell2mat(regexp(panels,'pred'))
howmanypredpanels = find(~cellfun(@isempty,regexp(panels,'pred')));
for kk = 1:size(howmanypredpanels,2)
ax = subplot(plotgridv,plotgridh,(mod(jj-1,plotgridv))*plotgridh++howmanypredpanels(kk));
predobj = strsplit(panels{howmanypredpanels(kk)},'_');
if ~isempty(regexp(predobj{2},objtype_short))
temp = objCorr.data.(predobj{2});
% Plot map
distmap = temp(corr_ind).(['maps_dist_' objtype_short]);
[~,~,~] = plotmap(distmap,objtype);
% Set up axes
if ~isempty(corr_ind)
ax.Title.String = {['Distributed map ' predobj{2}];...
['dist ratio ' predobj{2}(1) ' = ' num2str(temp(corr_ind).(['distratio_' predobj{2}(1)]))];...
['dist ratio ' predobj{2}(2) ' = ' num2str(temp(corr_ind).(['distratio_' predobj{2}(2)]))]};
else
ax.Title.String = 'No distributed map';
end
else
ax.Title.String = ['Requested pred obj does not have "' objtype '"'];
end
end
end
% Plot covariance matrix
if ismember('covar',panels)
% Find subplot number
ax = subplot(plotgridv,plotgridh,(mod(jj-1,plotgridv))*plotgridh++find(strcmp('covar',panels)));
% Plot map
im = imagesc(objCorr.data.covmat_norm{corr_ind});
set(im,'AlphaData',~isnan(objCorr.data.covmat_norm{corr_ind}));
set(ax,'CLim',[-nanstd(nanstd(objCorr.data.covmat_norm{corr_ind})) nanstd(nanstd(objCorr.data.covmat_norm{corr_ind}))]);
colormap jet;
colorbar;
% Replace NaNs with zeros in covariance matrix for norm calculations
l1norm = objCorr.data.l1norm(corr_ind);
l2norm = objCorr.data.l2norm(corr_ind);
% Set up axes
if ~isempty(corr_ind)
ax.Title.String = {'Covariance place-view:',horzcat('l1=', num2str(l1norm,2)), horzcat('l2=', num2str(l2norm,2))};
else
ax.Title.String = 'No corrected map';
end
end
end
% Save figure
figtitle = [num2str(setsessions(ii)) '-' num2str(ceil(length(cells_indList)/(plotgridh * plotgridv))),' FigNum ',num2str(h.Number)];
savefigure(save,h,figtitle,figdir)
fig = fig + 1;
end
disp(['Cross all thresh, ', objtype, ' only = ', num2str(crossallthresh),' cells']);
disp(['Cross cell thresh only = ', num2str(crosscellthresh),' cells']);
disp(['Cross population thresh only = ', num2str(crosspopthresh),' cells']);
disp(['Cross either thresh = ', num2str(crosseitherthresh),' cells']);
disp(['Total number of cells = ',num2str(size(cellList,1)),' cells']);
elseif strcmp(objtype,'all')
spatialvars = {'Place','View','Headdirection'};
corrvars = {{'pv','ph'},{'pv','hv'},{'ph','hv'}};
secvars = {[2,3],[1 3],[1,2]};
plotgridv = 3;
plotgridh = 7;
% Get population thresholds for selectivity
thrs_pop = nan(size(spatialvars));
zs_pop = nan(size(spatialvars));
for ii = 1:size(spatialvars,2)
objMain = eval(['obj' spatialvars{ii}]);
cell_inds = ismember(objMain.data.origin,cellList);
leaveout = find(objMain.data.discard | ~cell_inds); % cells with < 100 spikes are discarded
leaveout = repmat(1:objMain.data.Args.NumShuffles,size(leaveout)) + (leaveout*objMain.data.Args.NumShuffles-objMain.data.Args.NumShuffles);
thr_sh = objMain.data.critsh_sm(setdiff(1:size(objMain.data.critsh_sm,1),leaveout));
thrs_pop(ii) = prctile(thr_sh,95);
zs_pop(ii) = zscore(objMain.data.(critname)(cell_inds));
end
for ii = 1:size(setsessions,1) % For each session
cells_indList = find(identifiers(:,1) == setsessions(ii));
for jj = 1:length(cells_indList) % For each cell
cell_indList = cells_indList(jj);
cellname = horzcat('ch',num2str(identifiers(cell_indList,4)),...
'c',num2str(identifiers(cell_indList,5)));
for kk = 1:size(spatialvars,2) % for each main spatial variable (p, v, h)
spatialvar = spatialvars{kk};
corrvar = corrvars{kk};
objMain = eval(['obj' spatialvar]);
cell_ind = find(strcmp(objMain.data.origin,cellList(cells_indList(jj))));
if isempty(cell_ind)
continue;
end
thr_pop = thrs_pop(kk);
z_pop = zs_pop(kk);
z_cell = z_pop(cell_ind);
map_raw = objMain.data.maps_raw(cell_ind,:);
map_sm = objMain.data.(mapname)(cell_ind,:);
if isfield(objMain.data,'maps_bcsm')
map_bcsm = objMain.data.maps_bcsm(cell_ind,:);
else
map_bcsm = nan(size(map_raw));
end
% Get shuffled SI cutoff for this cell - 95th percentile
crit = objMain.data.(critname)(cell_ind,1);
thr_cell = prctile(objMain.data.(critshname)( (cell_ind-1)*objMain.data.Args.NumShuffles+1:cell_ind*objMain.data.Args.NumShuffles ,1 ) ,95);
z_cell = z_pop(cell_ind,1);
% Setup figure
h = figure(fig);
hold on;
figname = horzcat(objtype,': ',num2str(setsessions(ii)),' ',cellname, ' ',spatialvar);
set(h,'Name',figname,'Units','Normalized','Position',[0 1 1 1]);
% Panels
% full_raw, full_adsm, full_bcsm, half1_adsm, half2_adsm
% pred_pv_p_raw, pred_pv_p_adsm, corr_pv_p_raw, corr_pv_p_sm, covar
% pred_ph_p_raw, pred_ph_p_adsm, corr_ph_p_raw, corr_ph_p_sm, covar_norm
% Plot full session rate map raw
ax = subplot(plotgridv,plotgridh,1);
% Plot map
[mapGrid,~,maxrate_raw]= plotmap(map_raw,lower(spatialvar));
% Set up axes
if strcmp(objtype,'view') && maxrate_raw < nanmax(map_raw)
ax.Title.String = {horzcat('Cue: ',num2str(map_raw(1),2),'Hz'),...
horzcat('Hint: ',num2str(map_raw(2),2),'Hz')};
ax.Title.Color = 'r';
else
cellinfo = {horzcat('ch',num2str(identifiers(cell_indList,4)),...
'c',num2str(identifiers(cell_indList,5))); ...
horzcat(criteria, ' pop thr=',num2str(thr_pop,2));
horzcat(criteria, ' cell thr=',num2str(thr_cell,2));...
horzcat('pop z-',criteria,'= ',num2str(z_cell,2))};
celltext = text(ax,-0.5,2,1,cellinfo,'Units','Normalized','FontSize',14,...
'VerticalAlignment','middle','HorizontalAlignment','center');
rowtext = text(ax,-0.5,0.5,1,'Raw','Units','Normalized','FontSize',14,...
'VerticalAlignment','middle','HorizontalAlignment','center');
ax.Title.String = {'Full';''};
rate = text(ax,1,1.05,1,[num2str(maxrate_raw,2) 'Hz'],'Units','Normalized','FontSize',14,'HorizontalAlignment','right');
si = text(ax,0,1.05,1,num2str(crit,2),'Units','Normalized','FontSize',14,'HorizontalAlignment','left');
if crit >= thr_cell && crit >= thr_pop && maxrate_raw>=0.7
ax.Title.Color = 'r';
crossallthresh = crossallthresh + 1;
elseif crit >= thr_cell && crit < thr_pop && maxrate_raw>=0.7
ax.Title.Color = 'm';
crosscellthresh = crosscellthresh + 1;
crosseitherthresh = crosseitherthresh + 1;
elseif crit < thr_cell && crit >= thr_pop && maxrate_raw>=0.7
ax.Title.Color = 'b';
crosspopthresh = crosspopthresh + 1;
crosseitherthresh = crosseitherthresh + 1;
end
% if crit >= thr_pop && maxrate>=0.7
% selcell_orig(end+1,1) = cell_ind;
% end
end
ratelim_raw = mean(map_raw,'all','omitnan') + 2*std(map_raw,'omitnan');
set(ax,'CLim',[0 ratelim_raw]);
% Plot full session rate map adsm
ax = subplot(plotgridv,plotgridh,plotgridh+1);
% Plot map
[mapGrid,~,maxrate]= plotmap(map_sm,lower(spatialvar));
% Set up axes
if strcmp(objtype,'view') && maxrate < nanmax(map_sm)
ax.Title.String = {horzcat('Cue: ',num2str(map_sm(1),2),'Hz'),...
horzcat('Hint: ',num2str(map_sm(2),2),'Hz')};
ax.Title.Color = 'r';
else
ax.Title.String = {'Full';...
['sparsity=' num2str(objMain.data.sparsity(cell_ind,1),2)];...
['coherence=' num2str(objMain.data.coherence(cell_ind,1),2)];...
['sig2noise=' num2str(objMain.data.sig2noise(cell_ind,1),2)];''};
rate = text(ax,1,1.05,1,[num2str(maxrate,2) 'Hz'],'Units','Normalized','FontSize',14,'HorizontalAlignment','right');
si = text(ax,0,1.05,1,num2str(crit,2),'Units','Normalized','FontSize',14,'HorizontalAlignment','left');
if crit >= thr_cell && crit >= thr_pop && maxrate>=0.7
ax.Title.Color = 'r';
crossallthresh = crossallthresh + 1;
elseif crit >= thr_cell && crit < thr_pop && maxrate>=0.7
ax.Title.Color = 'm';
crosscellthresh = crosscellthresh + 1;
crosseitherthresh = crosseitherthresh + 1;
elseif crit < thr_cell && crit >= thr_pop && maxrate>=0.7
ax.Title.Color = 'b';
crosspopthresh = crosspopthresh + 1;
crosseitherthresh = crosseitherthresh + 1;
end
end
rowtext = text(ax,-0.5,0.5,1,'Adsm','Units','Normalized','FontSize',14,...
'VerticalAlignment','middle','HorizontalAlignment','center');
% Plot full session rate map bcsm
ax = subplot(plotgridv,plotgridh,2*plotgridh+1);
if any(~isnan(map_bcsm))
% Plot map
[mapGrid,~,maxrate_bcsm]= plotmap(map_bcsm,lower(spatialvar));
% Set up axes
if strcmp(objtype,'view') && maxrate_bcsm < nanmax(map_bcsm)
ax.Title.String = {horzcat('Cue: ',num2str(map_bcsm(1),2),'Hz'),...
horzcat('Hint: ',num2str(map_bcsm(2),2),'Hz')};
ax.Title.Color = 'r';
else
ax.Title.String = {'Full bcsm';''};
rate = text(ax,1,1.05,1,[num2str(maxrate_bcsm,2) 'Hz'],'Units','Normalized','FontSize',14,'HorizontalAlignment','right');
si = text(ax,0,1.05,1,num2str(crit,2),'Units','Normalized','FontSize',14,'HorizontalAlignment','left');
if crit >= thr_cell && crit >= thr_pop && maxrate_bcsm>=0.7
ax.Title.Color = 'r';
crossallthresh = crossallthresh + 1;
elseif crit >= thr_cell && crit < thr_pop && maxrate_bcsm>=0.7
ax.Title.Color = 'm';
crosscellthresh = crosscellthresh + 1;
crosseitherthresh = crosseitherthresh + 1;
elseif crit < thr_cell && crit >= thr_pop && maxrate_bcsm>=0.7
ax.Title.Color = 'b';
crosspopthresh = crosspopthresh + 1;
crosseitherthresh = crosseitherthresh + 1;
end
% if crit >= thr_pop && maxrate>=0.7
% selcell_orig(end+1,1) = cell_ind;
% end
end
else
ax.Title.String = {'No bcsm';''};
end
% Patch fields of base var
ax = subplot(plotgridv,plotgridh,2*plotgridh+2);
hold on;
% if mixsel obj exists, get it
if any(ismember(objMain.data.origin{cell_ind},objMS0.data.origin))
[~,mixsel_ind] = ismember(objMain.data.origin{cell_ind},objCorr.data.origin);
% maps_raw_corr_varMain = objCorr.data.(corrvar{pp})(mixsel_ind).(['maps_raw' '_corr' mainvar]);
% maps_raw_pred_varMain = objCorr.data.(corrvar{pp})(mixsel_ind).(['maps_dist_' mainvar]);
% % maps_raw_corr_varSec = objCorr.data.(corrvar{pp})(corr_ind).(['maps_raw' '_corr' secvar]);
%
% maps_sm_corr_varMain = objCorr.data.(corrvar{pp})(mixsel_ind).(['maps_sm' '_corr' mainvar]);
% maps_sm_pred_varMain = objCorr.data.(corrvar{pp})(mixsel_ind).(['maps_dist_' mainvar '_adsm']);
% % maps_sm_corr_varSec = objCorr.data.(corrvar{pp})(corr_ind).(['maps_sm' '_corr' secvar]);
else
mixsel_ind = [];
% maps_raw_corr_varMain = nan(size(maps_raw));
% % maps_raw_corr_varSec = nan(size(eval(['obj' spatialvars{secvars{kk}(1)}]).data.maps_raw(1,:)));
% maps_sm_corr_varMain = maps_raw_corr_varMain;
% % maps_sm_corr_varSec = maps_raw_corr_varSec;
end
tempmap = nan(size(map_raw));
if ~strcmp(lower(spatialvar),'headdirection')
basedata = objMS0.data.pv(mixsel_ind).(lower(spatialvar));
plotmap(tempmap,lower(spatialvar));
else
basedata = objMS0.data.ph(mixsel_ind).(lower(spatialvar));
plotmap(tempmap,lower(spatialvar),lower(spatialvar),'y');
end
colormap(ax,'jet');
% Patch env bounds
patchenvbounds(lower(spatialvar));
% Patch basemap field % Actually nothing to
% plot but use this to make size of map
% equal across subplots
for ff = 1:basedata.sigfields
if ~strcmp(lower(spatialvar),'headdirection')
if strcmp(lower(spatialvar),'place')
color = [254 132 132]/255;
else
color = [157 194 9]/255; % pistachio
end
for pp = 1:size(basedata.fieldcoord{ff},1)
% PATCH
if strcmp(lower(spatialvar),'place')
plotgrid = 3;
else
plotgrid = basedata.gridnum(ff);
end
[x,y,z] = converttosurf(plotgrid,basedata.fieldcoord{ff}(pp,1),basedata.fieldcoord{ff}(pp,2));
if strcmp(lower(spatialvar),'place')
patch(x,y,z,[1 1 1 1],'EdgeColor',color,'FaceColor','none','LineWidth',1);
elseif strcmp(lower(spatialvar),'view')
patch(x,y,z,'r','EdgeColor',color,'FaceColor','none','LineWidth',1); % Lime green. Olive drab:[107/256 142/256 35/256], Medium sea green: [60/256 179/256 113/256]
end
end
else
section = nan(size(map_raw));
section(basedata.fieldlinbin{ff}) = 1; % *nanmax(tempsecmap);
plotmap(section,lower(spatialvar),lower(spatialvar),'r');
end
end
% % Strech axis back to normal if hv and h as base
% if strcmp(msvar_short,'hv') && strcmp(msvar{oo},'headdirection')
% axis equal;
% end
% set(ax,'CLim',[0 1],'Units','Normalized',...
% 'Position',[axmargin+(subcol-1)*axwidth axmargin+(numrow-subrow)*axheight plotwidth plotheight],...
% 'DataAspectRatioMode','manual','DataAspectRatio',[1 1 1],...
% 'XColor','none','YColor','none','ZColor','none',...
% 'FontSize',14,'GridLineStyle','none','Color',axcolor);
% % Outline in red the field-only plot
% dim = [ax.Position(1) ax.Position(2) plotwidth plotheight];
% annotation('rectangle',dim,'Color',fieldcolor,'LineWidth',1);
% Plot half session rate maps (raw and adsm)
% Intra-session correlation %%%%%% NOTE: Should use boxcar
% smoothed map
if ~strcmp(lower(spatialvar),'headdirection')
map1 = objMain.data.(['maps_bcsm' '1'])(cell_ind,:);
map2 = objMain.data.(['maps_bcsm' '2'])(cell_ind,:);
else
map1 = objMain.data.([mapname '1'])(cell_ind,:);
map2 = objMain.data.([mapname '2'])(cell_ind,:);
end
vis1 = ~isnan(map1);
vis2 = ~isnan(map2);
vis = vis1 & vis2; % Correlate only visited bins;
intracorr = corr2(map1(vis), map2(vis));
crit1 = objMain.data.([critname '1'])(cell_ind);
crit2 = objMain.data.([critname '2'])(cell_ind);
% Plot
for kk = 1:2
% Raw
ax = subplot(plotgridv,plotgridh,1+kk);
% mapLin = eval(['map' num2str(kk)]);
mapLin = objMain.data.(['maps_raw' '1'])(cell_ind,:);
crit = eval(['crit' num2str(kk)]);
half = num2str(kk);
% Plot map
[~,~,maxrate_half]= plotmap(mapLin,lower(spatialvar));
% Set up axes
ax.Title.String = {['Half ' num2str(kk)];''};
rate = text(ax,1,1.05,1,[num2str(maxrate_half,2) 'Hz'],...
'Units','Normalized','FontSize',14,'HorizontalAlignment','right');
si = text(ax,0,1.05,1,num2str(crit,2),'Units','Normalized','FontSize',14,'HorizontalAlignment','left');
if crit >= thr_cell && crit >= thr_pop && maxrate_half>=0.7
ax.Title.Color = 'r';
elseif crit >= thr_cell && crit < thr_pop && maxrate_half>=0.7
ax.Title.Color = 'm';
elseif crit < thr_cell && crit >= thr_pop && maxrate_half>=0.7
ax.Title.Color = 'b';
end
set(ax,'CLim',[0 maxrate]);
% Adsm
ax = subplot(plotgridv,plotgridh,plotgridh+1+kk);
% mapLin = eval(['map' num2str(kk)]);
mapLin = objMain.data.([mapname '1'])(cell_ind,:);
crit = eval(['crit' num2str(kk)]);
half = num2str(kk);
% Plot map
[~,~,maxrate_half]= plotmap(mapLin,lower(spatialvar));
% Set up axes
ax.Title.String = {['Half ' num2str(kk)];['corr=' num2str(intracorr,2)];''};
rate = text(ax,1,1.05,1,[num2str(maxrate_half,2) 'Hz'],...
'Units','Normalized','FontSize',14,'HorizontalAlignment','right');
si = text(ax,0,1.05,1,num2str(crit,2),'Units','Normalized','FontSize',14,'HorizontalAlignment','left');
if crit >= thr_cell && crit >= thr_pop && maxrate_half>=0.7
ax.Title.Color = 'r';
elseif crit >= thr_cell && crit < thr_pop && maxrate_half>=0.7
ax.Title.Color = 'm';
elseif crit < thr_cell && crit >= thr_pop && maxrate_half>=0.7
ax.Title.Color = 'b';
end
set(ax,'CLim',[0 maxrate]);
end
% For each pair of spatial variables
% e.g. If main var = p, pairs = pv, ph
for pp = 1:2
mainvar = lower(spatialvar(1));
secvar = strtok(corrvar{pp},lower(spatialvar(1)));
% if corrected map exists, get it
if any(ismember(objMain.data.origin{cell_ind},objCorr.data.origin))
[~,corr_ind] = ismember(objMain.data.origin{cell_ind},objCorr.data.origin);
maps_raw_corr_varMain = objCorr.data.(corrvar{pp})(corr_ind).(['maps_raw' '_corr' mainvar]);
maps_raw_pred_varMain = objCorr.data.(corrvar{pp})(corr_ind).(['maps_dist_' mainvar]);
% maps_raw_corr_varSec = objCorr.data.(corrvar{pp})(corr_ind).(['maps_raw' '_corr' secvar]);
maps_sm_corr_varMain = objCorr.data.(corrvar{pp})(corr_ind).(['maps_sm' '_corr' mainvar]);
maps_sm_pred_varMain = objCorr.data.(corrvar{pp})(corr_ind).(['maps_dist_' mainvar '_adsm']);
% maps_sm_corr_varSec = objCorr.data.(corrvar{pp})(corr_ind).(['maps_sm' '_corr' secvar]);
else
corr_ind = [];
maps_raw_corr_varMain = nan(size(maps_raw));
% maps_raw_corr_varSec = nan(size(eval(['obj' spatialvars{secvars{kk}(1)}]).data.maps_raw(1,:)));
maps_sm_corr_varMain = maps_raw_corr_varMain;
% maps_sm_corr_varSec = maps_raw_corr_varSec;
end
% Plot predicted map main raw
ax = subplot(plotgridv,plotgridh,3+pp);
% Plot map
[mapGrid,~,maxrate_pred_raw]= plotmap(maps_raw_pred_varMain,lower(spatialvar));
% Set up axes
if strcmp(objtype,'view') && maxrate_pred_raw < nanmax(maps_raw_pred_varMain)
ax.Title.String = {horzcat('Cue: ',num2str(maps_raw_pred_varMain(1),2),'Hz'),...
horzcat('Hint: ',num2str(maps_raw_pred_varMain(2),2),'Hz')};
ax.Title.Color = 'r';
else
% celltext = text(ax,-0.3,0.5,1,[corrvar{pp}],'Units','Normalized','FontSize',14,...
% 'HorizontalAlignment','center','VerticalAlignment','middle','Rotation',90);
ax.Title.String = {['Pred ' corrvar{pp}];''};
set(ax,'CLim',[0 maxrate]);
rate = text(ax,1,1.05,1,[num2str(maxrate_pred_raw,2) 'Hz'],'Units','Normalized','FontSize',14,'HorizontalAlignment','right');
end
% Plot predicted map main smooth
ax = subplot(plotgridv,plotgridh,plotgridh+3+pp);
% Plot map
[mapGrid,~,maxrate_pred_sm]= plotmap(maps_sm_pred_varMain,lower(spatialvar));
% Set up axes
if strcmp(objtype,'view') && maxrate_pred_sm < nanmax(maps_sm_pred_varMain)
ax.Title.String = {horzcat('Cue: ',num2str(maps_sm_pred_varMain(1),2),'Hz'),...
horzcat('Hint: ',num2str(maps_sm_pred_varMain(2),2),'Hz')};
ax.Title.Color = 'r';
else
ax.Title.String = {['Pred ' corrvar{pp}];...
['dr ' mainvar ' on ' secvar '=' num2str(objCorr.data.(corrvar{pp})(corr_ind).(['distratio_' mainvar]),2)];...
['dr ' secvar ' on ' mainvar '=' num2str(objCorr.data.(corrvar{pp})(corr_ind).(['distratio_' secvar]),2)];''};
rate = text(ax,1,1.05,1,[num2str(maxrate_pred_sm,2) 'Hz'],'Units','Normalized','FontSize',14,'HorizontalAlignment','right');
end
set(ax,'CLim',[0 maxrate]);
% Plot corrected map main raw
ax = subplot(plotgridv,plotgridh,5+pp);
% Plot map
[mapGrid,~,maxrate_corr_raw]= plotmap(maps_raw_corr_varMain,lower(spatialvar));
% Set up axes
if strcmp(objtype,'view') && maxrate_corr_raw < nanmax(maps_raw_corr_varMain)
ax.Title.String = {horzcat('Cue: ',num2str(maps_raw_corr_varMain(1),2),'Hz'),...
horzcat('Hint: ',num2str(maps_raw_corr_varMain(2),2),'Hz')};
ax.Title.Color = 'r';
else
ax.Title.String = {['Corr ' corrvar{pp}];...
['llh ' num2str(objCorr.data.(corrvar{pp})(corr_ind).llhpick) ' of ' num2str(objCorr.data.(corrvar{pp})(corr_ind).NumIterLlh)];''};
rate = text(ax,1,1.05,1,[num2str(maxrate_corr_raw,2) 'Hz'],'Units','Normalized','FontSize',14,'HorizontalAlignment','right');
% critcorr = objCorr.data.(corrvar{pp})(corr_ind).(['crit_sm_corr' mainvar]);
% si = text(ax,0,1.05,1,num2str(critcorr,2),'Units','Normalized','FontSize',14,'HorizontalAlignment','left');
% if critcorr >= thr_cell && critcorr >= thr_pop && maxrate>=0.7
% ax.Title.Color = 'r';
% elseif critcorr >= thr_cell && critcorr < thr_pop && maxrate>=0.7
% ax.Title.Color = 'm';
% elseif critcorr < thr_cell && critcorr >= thr_pop && maxrate>=0.7
% ax.Title.Color = 'b';
% end
end
set(ax,'CLim',[0 maxrate]);
% Plot corrected map main adsm
ax = subplot(plotgridv,plotgridh,plotgridh+5+pp);
% Plot map
[mapGrid,~,maxrate_corr_sm]= plotmap(maps_sm_corr_varMain,lower(spatialvar));
% Set up axes
if strcmp(objtype,'view') && maxrate_corr_sm < nanmax(maps_sm_corr_varMain)
ax.Title.String = {horzcat('Cue: ',num2str(maps_sm_corr_varMain(1),2),'Hz'),...
horzcat('Hint: ',num2str(maps_sm_corr_varMain(2),2),'Hz')};
ax.Title.Color = 'r';
else
ax.Title.String = {['Corr ' corrvar{pp}];...
['llh ' num2str(objCorr.data.(corrvar{pp})(corr_ind).llhpick) ' of ' num2str(objCorr.data.(corrvar{pp})(corr_ind).NumIterLlh)];''};
rate = text(ax,1,1.05,1,[num2str(maxrate_corr_sm,2) 'Hz'],'Units','Normalized','FontSize',14,'HorizontalAlignment','right');
critcorr = objCorr.data.(corrvar{pp})(corr_ind).(['crit_sm_corr' mainvar]);
si = text(ax,0,1.05,1,num2str(critcorr,2),'Units','Normalized','FontSize',14,'HorizontalAlignment','left');
if critcorr >= thr_cell && critcorr >= thr_pop && maxrate_corr_sm>=0.7
ax.Title.Color = 'r';
elseif critcorr >= thr_cell && critcorr < thr_pop && maxrate_corr_sm>=0.7
ax.Title.Color = 'm';
elseif critcorr < thr_cell && critcorr >= thr_pop && maxrate_corr_sm>=0.7
ax.Title.Color = 'b';
end
end
set(ax,'CLim',[0 maxrate]);
% % Plot covariance matrix
% % if pp == 1
% ax = subplot(plotgridv,plotgridh,3+pp);
% covmat = objCorr.data.(corrvar{pp})(corr_ind).covmat_norm;
% im = imagesc(covmat);
% ax.Position(1) = ax.Position(1)+ax.Position(3)/5;
% set(im,'AlphaData',~isnan(covmat));
% set(ax,'CLim',[-nanstd(nanstd(covmat)) nanstd(nanstd(covmat))]);
% colormap jet;
% colorbar;
% % Replace NaNs with zeros in covariance matrix for norm calculations
% l1norm = objCorr.data.(corrvar{pp})(corr_ind).l1norm;
% l2norm = objCorr.data.(corrvar{pp})(corr_ind).l2norm;
% % Set up axes
% if ~isempty(corr_ind)
% ax.Title.String = {'Covariance';horzcat('l1=', num2str(l1norm,2)); horzcat('l2=', num2str(l2norm,2))};
% ax.Title.FontSize = 14;
% else
% ax.Title.String = 'No corrected map';
% end
% axis(ax,'square');
% % end
end
% Save figure
% if jj*5 > plotgridh * plotgridv && mod((jj*5), (plotgridh * plotgridv)) == 5
figtitle = [num2str(setsessions(ii)) cellname ' Fig ',num2str(h.Number) '-' spatialvar,];