-
Notifications
You must be signed in to change notification settings - Fork 3
/
sensorplot_sensordefinition.m
107 lines (86 loc) · 3.35 KB
/
sensorplot_sensordefinition.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
function sensorplot_sensordefinition
% from the cluster based permutation stats, get visual and motor sensors +
% frequency band
if ~isdeployed,
addpath(genpath('~/code/MEG'));
addpath(genpath('~/code/Tools'));
addpath('~/Documents/fieldtrip');
ft_defaults;
end
% for each session, get the occipital and motor channels
subjectdata = subjectspecifics('ga');
sj = 'GAclean';
[~, conditions] = sensorplot_defineConditions();
nrchans = 20;
spcnt = 1;
for session = 1:2,
% occipital chans, stimstrong > stimweak
load(sprintf('%s/%s-S%d_%s_%s_freqstats.mat', subjectdata.statsdir, ...
sj, session, conditions(2).name{1}, conditions(2).name{2}));
% save this channel selection
sensorDefinition(1).group = 'occipital';
sensorDefinition(1).names = selectSens(stat, nrchans, 'descend');
subplot(2,3,spcnt); plotTopo(stat, sensorDefinition(1).names); spcnt = spcnt + 1;
title(gca, 'occipital');
% motor chans, left > right
load(sprintf('%s/%s-S%d_%s_%s_freqstats.mat', subjectdata.statsdir, ...
sj, session, conditions(3).name{1}, conditions(3).name{2}));
sensorDefinition(2).group = 'motor';
sensorDefinition(2).leftchans = selectSens(stat, nrchans, 'descend');
subplot(2,3,spcnt); plotTopo(stat, sensorDefinition(2).leftchans); spcnt = spcnt + 1;
title(gca, 'left');
% motor chans, right > left
sensorDefinition(2).rightchans = selectSens(stat, nrchans, 'ascend');
subplot(2,3,spcnt); plotTopo(stat, sensorDefinition(2).rightchans); spcnt = spcnt + 1;
title(gca, 'right');
% save for this session, so it can be used on the other session
savefast(sprintf('%s/%s-S%d_sensorDefinition.mat', subjectdata.statsdir, sj, session), 'sensorDefinition');
end
print(gcf, '-dpdf', sprintf('%s/Figures/sensorDefinition.pdf', subjectdata.path));
end
function sensnames = selectSens(dat, nrSens, sortHow)
sensidx = 0;
load('ctf275_neighb.mat'); % get neighbour struct for clusters
[val, idx] = sort(dat.stat, sortHow);
cfg = [];
cfg.channel = dat.label;
cfg.neighbours = neighbours;
% only select those that have at least 1 neighbour in the cluster
cd('~/Documents/fieldtrip/private/');
[connectivity] = channelconnectivity(cfg);
keepgoing = true;
nrsens = nrSens;
for i = 1:50, % select those that are the most active
tmpsensidx = idx(1:i);
% pick the ones that are neighbouring
tmpconn = connectivity(tmpsensidx, tmpsensidx);
try
% take only those with neighbours
tmpsensidx2 = tmpsensidx(sum(tmpconn) > 1);
% check that we're not too far
assert(numel(tmpsensidx2) <= nrSens);
sensidx = tmpsensidx2;
nrsens = nrsens + 1; % get one more channel
catch
break;
end
end
assert(numel(sensidx) <= nrSens);
disp(numel(sensidx));
sensnames = dat.label(sensidx);
end
function plotTopo(dat, sensidx)
% show what this looks like
cfgtopo = [];
cfgtopo.marker = 'off';
cfgtopo.layout = 'CTF275.lay';
cfgtopo.comment = 'no';
cfgtopo.highlight = 'on';
cfgtopo.highlightsymbol = '.';
cfgtopo.highlightsize = 5;
cfgtopo.highlightchannel = sensidx;
cfgtopo.shading = 'flat';
cfgtopo.style = 'blank';
cfgtopo.parameter = 'stat';
ft_topoplotER(cfgtopo, dat);
end