-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathcheck.m
160 lines (131 loc) · 5.19 KB
/
check.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
function [this, ok] = check(this, option)
% Method that performs integrity checks of the meeg object
% and its readiness for particular purposes.
% FORMAT this = check(this, option)
% IN
% option - 'basic' (default) - just check the essential fields
% '3d' - check if suitable for source reconstruction
% 'dcm' - check if suitable for DCM
%
% OUT
% ok - 1 - OK, 0- failed
% _______________________________________________________________________
% Copyright (C) 2008-2012 Wellcome Trust Centre for Neuroimaging
% Vladimir Litvak
% $Id: check.m 6542 2015-09-09 11:48:34Z karl $
if nargin == 1
option = 'basic';
end
ok = 1;
this = meeg(struct(this));
if isequal(option, 'basic')
return;
end
if ~isequal(transformtype(this), 'time')
ok = 0;
disp('Source reconstruction and DCM only work for time domain data');
return;
end
if this.montage.Mind~=0
disp('Virtual montage is applied. Make sure this is what you want.')
end
eegind = indchantype(this, 'EEG');
megind = indchantype(this, {'MEG'});
planarind = indchantype(this, {'MEGPLANAR'});
lfpind = indchantype(this, 'LFP');
if ~isempty([eegind(:); megind(:); planarind(:)])
if ~isempty(eegind)
if ~isfield(this.sensors, 'eeg') || isempty(this.sensors.eeg)
ok = 0;
disp('EEG sensor locations are not specified');
else
if ~isempty(setdiff(chanlabels(this, eegind), this.sensors.eeg.label))
ok = 0;
disp('Not all EEG channel locations are specified');
end
end
if ~isempty(strmatch('unknown', units(this, eegind)))
this = units(this, eegind, 'uV');
warning_flexible('EEG channel units are missing. Assuming uV, source scaling might be wrong');
end
end
if ~isempty([megind(:); planarind(:)])
if ~isfield(this.sensors, 'meg') || isempty(this.sensors.meg)
ok = 0;
disp('MEG sensor locations are not specified');
else
if ~isempty(setdiff({this.channels(megind).label}, this.sensors.meg.label))
disp('Not all MEG sensor locations are specified');
end
end
if ~isempty(strmatch('unknown', units(this, megind)))
this = units(this, megind, 'fT');
warning_flexible('MEG channel units are missing. Assuming fT, source scaling might be wrong');
end
if ~isempty(strmatch('unknown', units(this, planarind)))
this = units(this, planarind, 'fT/mm');
warning_flexible('MEGPLANAR channel units are missing. Assuming fT/mm, source scaling might be wrong');
end
end
if isempty(this.fiducials)
ok = 0;
disp('No fiducials are defined');
end
if ~isfield(this.fiducials, 'pnt') || isempty(this.fiducials.pnt)
if ~isempty(eegind)
% Copy EEG sensors to fiducials.
this.fiducials.pnt = this.sensors.eeg.elecpos;
else
this.fiducials.pnt = sparse(0, 3);
end
end
if ~isfield(this.fiducials, 'fid') || ...
~all(isfield(this.fiducials.fid, {'pnt', 'label'})) ||...
(length(this.fiducials.fid.label) ~= size(this.fiducials.fid.pnt, 1)) || ...
length(this.fiducials.fid.label) < 3
ok = 0;
disp('At least 3 fiducials with labels are required');
end
nzlbl = {'fidnz', 'nz', 'nas', 'nasion', 'spmnas'};
lelbl = {'fidle', 'fidt9', 'lpa', 'lear', 'earl', 'le', 'l', 't9', 'spmlpa'};
relbl = {'fidre', 'fidt10', 'rpa', 'rear', 'earr', 're', 'r', 't10', 'spmrpa'};
[sel1, nzind] = match_str(nzlbl, lower(this.fiducials.fid.label));
if isempty(nzind)
disp('Could not find the nasion fiducial');
else
nzind = nzind(1);
end
[sel1, leind] = match_str(lelbl, lower(this.fiducials.fid.label));
if isempty(leind)
disp('Could not find the left fiducial');
else
leind = leind(1);
end
[sel1, reind] = match_str(relbl, lower(this.fiducials.fid.label));
if isempty(reind)
disp('Could not find the right fiducial');
else
reind = reind(1);
end
restind = setdiff(1:length(this.fiducials.fid.label), [nzind(:)', leind(:)', reind(:)']);
this.fiducials.fid.label = this.fiducials.fid.label([nzind(:)', leind(:)', reind(:)', restind(:)']);
this.fiducials.fid.pnt = this.fiducials.fid.pnt([nzind(:)', leind(:)', reind(:)', restind(:)'], :);
end
if isequal(option, '3d')
if ~ismember(modality(this), {'EEG', 'MEG', 'Multimodal'})
ok = 0;
disp('Unsupported modality for 3D source reconstruction');
end
end
if isequal(option, 'dcm')
if strcmp(option, 'dcm')
if ~ismember(modality(this, 0), {'EEG', 'MEG', 'MEGPLANAR', 'Multimodal', 'LFP','ILAM'})
ok = 0;
disp('Unsupported modality for DCM');
end
end
if ~isempty(lfpind) && ~isempty([eegind, megind])
ok = 0;
disp('DCM does not allow mixing scalp and LFP channels in the same dataset');
end
end