From 91c28a4eb12640c2e8113b596fd9bffdfd35a65a Mon Sep 17 00:00:00 2001 From: Francois Date: Thu, 2 Mar 2023 15:13:14 +0100 Subject: [PATCH] Process extract clusters: support for raw files --- doc/license.html | 2 +- doc/version.txt | 2 +- .../functions/process_extract_cluster.m | 47 ++++++++++++------- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/doc/license.html b/doc/license.html index 101ae1432..2a246cc09 100644 --- a/doc/license.html +++ b/doc/license.html @@ -5,7 +5,7 @@

THERE IS NO UNDO BUTTON!
SET UP A BACKUP OF YOUR DATABASE


-Version: 3.230301 (01-Mar-2023)
+Version: 3.230302 (02-Mar-2023)
COPYRIGHT © 2000-2023 USC & McGill University.
diff --git a/doc/version.txt b/doc/version.txt index 76827458e..65b276eb5 100644 --- a/doc/version.txt +++ b/doc/version.txt @@ -1,2 +1,2 @@ % Brainstorm -% v. 3.230301 (01-Mar-2023) \ No newline at end of file +% v. 3.230302 (02-Mar-2023) \ No newline at end of file diff --git a/toolbox/process/functions/process_extract_cluster.m b/toolbox/process/functions/process_extract_cluster.m index 7a577fb4e..9414cc6a0 100644 --- a/toolbox/process/functions/process_extract_cluster.m +++ b/toolbox/process/functions/process_extract_cluster.m @@ -26,7 +26,7 @@ %% ===== GET DESCRIPTION ===== -function sProcess = GetDescription() %#ok +function sProcess = GetDescription() % Description the process sProcess.Comment = 'Clusters time series'; sProcess.Category = 'Custom'; @@ -34,8 +34,8 @@ sProcess.Index = 351; sProcess.Description = 'https://neuroimage.usc.edu/brainstorm/Tutorials/ChannelClusters'; % Definition of the input accepted by this process - sProcess.InputTypes = {'data'}; - sProcess.OutputTypes = {'matrix'}; + sProcess.InputTypes = {'raw', 'data'}; + sProcess.OutputTypes = {'matrix', 'matrix'}; sProcess.nInputs = 1; sProcess.nMinFiles = 1; @@ -80,7 +80,7 @@ %% ===== RUN ===== -function OutputFiles = Run(sProcess, sInputs) %#ok +function OutputFiles = Run(sProcess, sInputs) % Initialize returned variable OutputFiles = {}; % REDIRECTING SCOUT CALLS TO PROCESS_EXTRACT_SCOUTS @@ -122,15 +122,7 @@ % ===== LOOP ON THE FILES ===== for iInput = 1:length(sInputs) - sResults = []; - - % === READ FILES === - % Load recordings - sMat = in_bst_data(sInputs(iInput).FileName); - matValues = sMat.F; - stdValues = sMat.Std; - % Input filename - condComment = sInputs(iInput).FileName; + % === READ CHANNEL FILE === % Check for channel file if isempty(sInputs(iInput).ChannelFile) bst_report('Error', sProcess, sInputs(iInput), 'This process requires a channel file.'); @@ -143,8 +135,31 @@ return; end + % === READ RECORDINGS === + % Load data file + sMat = in_bst_data(sInputs(iInput).FileName); + % Raw file + isRaw = strcmpi(sInputs(iInput).FileType, 'raw'); + if isRaw + % Convert time bounds into samples + sFile = sMat.F; + if ~isempty(TimeWindow) + SamplesBounds = round(sFile.prop.times(1) .* sFile.prop.sfreq) + bst_closest(TimeWindow, sMat.Time) - 1; + else + SamplesBounds = []; + end + % Read data + [matValues, sMat.Time] = in_fread(sFile, ChannelMat, 1, SamplesBounds, []); + stdValues = []; + % Remember that time selection is already applied + TimeWindow = []; + % Epoched data file + else + matValues = sMat.F; + stdValues = sMat.Std; + end % Nothing loaded - if isempty(sMat) || (isempty(matValues) && (isempty(sResults) || ~isfield(sResults, 'ImagingKernel') || isempty(sResults.ImagingKernel))) + if isempty(sMat) || isempty(matValues) bst_report('Error', sProcess, sInputs(iInput), 'Could not load anything from the input file. Check the requested time window.'); return; end @@ -272,9 +287,9 @@ scoutStds = cat(1, scoutStds, tmpStd); for iRow = 1:size(tmpScout,1) if ~isempty(RowNames) - Description = cat(1, Description, [sClusters(iClust).Label '.' RowNames{iRow} ' @ ' condComment]); + Description = cat(1, Description, [sClusters(iClust).Label '.' RowNames{iRow} ' @ ' sInputs(iInput).FileName]); else - Description = cat(1, Description, [sClusters(iClust).Label ' @ ' condComment]); + Description = cat(1, Description, [sClusters(iClust).Label ' @ ' sInputs(iInput).FileName]); end end end