Skip to content

Commit ee6d93a

Browse files
committed
Average connectivity files: Allow matching rows for NxN
1 parent b3f2550 commit ee6d93a

File tree

5 files changed

+39
-17
lines changed

5 files changed

+39
-17
lines changed

doc/license.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<body alink="#fff000" link="#fff000" vlink="#fff000">
66
<h4><span style="font-family: Arial Black; color: #ffffff;"><strong>THERE IS NO UNDO BUTTON!<BR>SET UP A <FONT color=red>BACKUP</FONT> OF YOUR DATABASE</strong></span></h4>
77
<HR>
8-
<!-- LICENCE_START -->Version: 3.221118 (18-Nov-2022)<br>
8+
<!-- LICENCE_START -->Version: 3.221121 (21-Nov-2022)<br>
99
<span style="font-style: italic;">COPYRIGHT &copy; 2000-2022
1010
USC &amp; McGill University.<br>
1111
</span>

doc/version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
% Brainstorm
2-
% v. 3.221118 (18-Nov-2022)
2+
% v. 3.221121 (21-Nov-2022)

toolbox/process/bst_avg_files.m

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
end
120120
if isempty(DestRowNames)
121121
Messages = [Messages, 'AVG> Could not find a common list of rows: Trying to average directly the matrices...' 10 ...
122-
'AVG> To avoid this warning, uncheck the option "Match signals" in the process options.'];
122+
'AVG> To avoid this warning, uncheck the option "Match signals" in the process options.' 10];
123123
end
124124
else
125125
DestRowNames = [];
@@ -180,6 +180,11 @@
180180
if strcmpi(matName, 'ImageGridAmp') && (sMat.nComponents ~= 1) && ismember(Function, {'norm', 'rms', 'normdiff', 'normdiffnorm'})
181181
sMat = process_source_flat('Compute', sMat, 'rms');
182182
end
183+
% Connectivity matrix: unpack NxN matrices
184+
if strcmpi(matName, 'TF') && (length(sMat.RefRowNames) > 1) && isfield(sMat, 'Options') && isfield(sMat.Options, 'isSymmetric') && isequal(sMat.Options.isSymmetric, 1)
185+
sMat.TF = process_compress_sym('Expand', sMat.TF, length(sMat.RowNames));
186+
sMat.Options.isSymmetric = 0;
187+
end
183188

184189
% Copy additional fields
185190
if isfield(sMat, 'nComponents') && ~isempty(sMat.nComponents)
@@ -219,7 +224,7 @@
219224
% Apply default function
220225
[matValues, isError] = process_tf_measure('Compute', matValues, sMat.Measure, defMeasure);
221226
if isError
222-
Messages = [Messages, 'Error: Invalid measure conversion: ' sMat.Measure ' => ' defMeasure];
227+
Messages = [Messages, 'Error: Invalid measure conversion: ' sMat.Measure ' => ' defMeasure, 10];
223228
continue;
224229
end
225230
end
@@ -239,7 +244,11 @@
239244
RowNames = [];
240245
end
241246
if isfield(sMat, 'RefRowNames') && ~isempty(sMat.RefRowNames)
242-
RefRowNames = sMat.RefRowNames;
247+
if ~isempty(DestRowNames) && (length(sMat.RefRowNames) == length(sMat.RowNames))
248+
RefRowNames = DestRowNames;
249+
else
250+
RefRowNames = sMat.RefRowNames;
251+
end
243252
end
244253
if isfield(sMat, 'Events') && ~isempty(sMat.Events)
245254
Events = sMat.Events;
@@ -250,9 +259,21 @@
250259
% === CHANNEL ORDER ===
251260
% Re-order rows in matrix/timefreq files
252261
if ~isempty(DestRowNames) && ~isequal(AllRowNames{iFile}, DestRowNames)
253-
tmpValues = zeros(length(DestRowNames), size(matValues,2), size(matValues,3));
254-
tmpValues(iRowsDest{iFile},:,:) = matValues(iRowsSrc{iFile},:,:);
255-
matValues = tmpValues;
262+
nTime = size(matValues, 2);
263+
nFreq = size(matValues, 3);
264+
% Connectivity files
265+
if ~isempty(RefRowNames)
266+
% Reshape TF matrix: [Nrow x Ncol x Ntime x nFreq]
267+
R = reshape(matValues, [length(sMat.RefRowNames), length(sMat.RowNames), nTime, nFreq]);
268+
tmpValues = zeros(length(DestRowNames), length(DestRowNames), size(matValues,2), size(matValues,3));
269+
tmpValues(iRowsDest{iFile},iRowsDest{iFile},:,:) = R(iRowsSrc{iFile},iRowsSrc{iFile},:,:);
270+
matValues = reshape(tmpValues, [], nTime, nFreq);
271+
% Other files
272+
else
273+
tmpValues = zeros(length(DestRowNames), nTime, nFreq);
274+
tmpValues(iRowsDest{iFile},:,:) = matValues(iRowsSrc{iFile},:,:);
275+
matValues = tmpValues;
276+
end
256277
end
257278
% Remove the @filename at the end of the row names (if DestRowNames, this had been done already in process_stdrow)
258279
if ~isempty(RowNames) && iscell(RowNames) && isempty(DestRowNames)
@@ -416,13 +437,14 @@
416437
initRowNames = RowNames;
417438
% All other files
418439
else
419-
% If current matrix has not the same size than the others
440+
% If current matrix has not the same size as the others
420441
if ~isequal([size(MeanValues,1),size(MeanValues,2),size(MeanValues,3)], [size(matValues,1),size(matValues,2),size(matValues,3)])
421442
Messages = [Messages, sprintf('Error: File #%d contains a data matrix that has a different size:\n', iFile)];
422443
if ischar(FilesListA{iFile})
423444
Messages = [Messages, FilesListA{iFile}, 10];
424445
end
425-
continue;
446+
MeanValues = [];
447+
break;
426448
elseif ~strcmpi(MeanMatName, matName)
427449
Messages = [Messages, sprintf('Error: File #%d has a different type. All the result files should be of the same type (full results or kernel-only):\n', iFile)];
428450
if ischar(FilesListA{iFile})

toolbox/process/functions/process_extract_values.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,11 @@
349349
% Get the list of common rows (only the files with named signals: matrix and timefreq)
350350
if OPTIONS.isMatchRows && ismember(inFileType, {'matrix','timefreq','pmatrix','ptimefreq'})
351351
bst_progress('text', 'Reading the signal names...');
352+
% Cannot use this option in combination with connectivity files
353+
if ~isempty(strfind(sInputs(1).FileName, '_connect1')) || ~isempty(strfind(sInputs(1).FileName, '_connectn'))
354+
bst_report('Error', sProcess, [], 'EXTRACT> Cannot use the option "Match signals" on connectivity files.');
355+
return;
356+
end
352357
% Identify the list of all the rows in all the files
353358
[DestRowNames, AllRowNames, iRowsSrc, iRowsDest, Messages] = process_stdrow('GetUniformRows', {sInputs.FileName}, 'all');
354359
if ~isempty(Messages)

toolbox/process/functions/process_stdrow.m

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,6 @@
179179
msgError = [];
180180
% Check all the input files
181181
for iInput = 1:length(FileNames)
182-
% Cannot process connectivity files
183-
if ischar(FileNames{iInput}) && ~isempty(strfind(FileNames{iInput}, '_connectn'))
184-
msgError = 'STDROW> Cannot process connectivity [NxN] results.';
185-
return;
186-
end
187182
% Load row names
188183
switch (file_gettype(FileNames{iInput}))
189184
case 'timefreq'
@@ -196,8 +191,8 @@
196191
if strcmpi(fileMat.DataType, 'results') || ~iscell(fileMat.RowNames)
197192
msgError = 'STDROW> Cannot process source maps, or any file that does not have explicit row names.';
198193
return;
199-
elseif (length(fileMat.RefRowNames) > 1)
200-
msgError = 'STDROW> Cannot process connectivity [NxN] results.';
194+
elseif (length(fileMat.RefRowNames) > 1) && ~isequal(fileMat.RowNames, fileMat.RefRowNames)
195+
msgError = 'STDROW> Cannot process connectivity [AxB] results.';
201196
return;
202197
end
203198
% Add row names to the list

0 commit comments

Comments
 (0)