Skip to content

Commit

Permalink
reduce warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Remi-Gau committed Aug 11, 2023
1 parent 0e2e5bb commit 9137f31
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 53 deletions.
2 changes: 1 addition & 1 deletion demos/bayes/ds000114_run.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
% set to false to not re run the model specification
FIRST_LEVEL = true;

VERBOSITY = 1;
VERBOSITY = 2;

FWHM = 8;

Expand Down
3 changes: 3 additions & 0 deletions demos/bayes/models/default_model.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
],
"space": [
"MNI152NLin2009cAsym"
],
"ses": [
"test"
]
}
},
Expand Down
15 changes: 11 additions & 4 deletions src/batches/preproc/setBatchSmoothingFunc.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [matlabbatch, allRT] = setBatchSmoothingFunc(matlabbatch, BIDS, opt, subLabel)
function [matlabbatch, allmetadata] = setBatchSmoothingFunc(matlabbatch, BIDS, opt, subLabel)
%
% Creates a batch to smooth the bold files of a subject
%
Expand Down Expand Up @@ -42,7 +42,7 @@
[sessions, nbSessions] = getInfo(BIDS, subLabel, opt, 'Sessions');

allFiles = [];
allRT = [];
allmetadata = struct('RTs', [], 'STCorrected', {{}});

for iSes = 1:nbSessions

Expand All @@ -68,11 +68,18 @@
fileName(iFile, :)); %#ok<*AGROW>

if isfield(metadata{iFile}, 'RepetitionTime')
allRT(end + 1) = metadata{iFile}.RepetitionTime;
allmetadata.RTs(end + 1) = metadata{iFile}.RepetitionTime;
else
allRT(end + 1) = nan;
allmetadata.RTs(end + 1) = nan;
end

if isfield(metadata{iFile}, 'SliceTimingCorrected')
allmetadata.STCorrected{end + 1} = metadata{iFile}.SliceTimingCorrected;
else
allmetadata.STCorrected{end + 1} = false;
end

% TODO transfer StartTime for STC
end

% add the files to list
Expand Down
29 changes: 23 additions & 6 deletions src/batches/stats/setBatchSubjectLevelGLMSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -220,18 +220,24 @@
oldVerbosity = opt.verbosity;
opt.verbosity = 0;

sliceOrder = getAndCheckSliceOrder(BIDS, opt, filter);
[sliceOrder, STCorrected] = getAndCheckSliceOrder(BIDS, opt, filter);

opt.verbosity = oldVerbosity;
end

if isempty(sliceOrder) && ~opt.dryRun
% if files were not slice time corrected
% we rely on the number of slices
if ~STCorrected && ~opt.dryRun
sliceOrder = getNbSlices(BIDS, filter);
return
end

fileName = bids.query(BIDS, 'data', filter);
hdr = spm_vol(fileName{1});
% files were slice time corrected
% but don't all have the same slice time correction information
% we throw a warning
if isempty(sliceOrder) && ~opt.dryRun

% TODO we are assuming axial acquisition here
sliceOrder = 1:hdr(1).dim(3);
sliceOrder = getNbSlices(BIDS, filter);

msg = ['\n\n', ...
'Slice timing information was missing for at least one run,\n', ...
Expand All @@ -251,6 +257,17 @@

end

function nbSlices = getNbSlices(BIDS, filter)
% ASUUMPTIONS
%
% - assuming axial acquisition
% - assumng all files have same number of slices
fileToSelect = 1;
fileName = bids.query(BIDS, 'data', filter);
hdr = spm_vol(fileName{fileToSelect});
nbSlices = 1:hdr(1).dim(3);
end

function runDuration = getRunDuration(opt, fullpathBoldFilename, TR)

nvVols = getNbVols(opt, fullpathBoldFilename);
Expand Down
32 changes: 21 additions & 11 deletions src/bids/getAndCheckSliceOrder.m
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
function sliceOrder = getAndCheckSliceOrder(BIDS, opt, filter)
function [sliceOrder, stCorrected] = getAndCheckSliceOrder(BIDS, opt, filter)
%
% Get the slice order information from the BIDS metadata.
% If inconsistent slice timing is found across files
% it throws an error.
%
% USAGE::
%
% sliceOrder = getAndCheckSliceOrder(opt)
% [sliceOrder, stCorrected] = getAndCheckSliceOrder(BIDS, opt, filter)
%
% :param BIDS: dataset layout.
% See also: bids.layout, getData.
% :type BIDS: structure
%
% :param opt: Options chosen for the analysis.
% See checkOptions.
% :type opt: structure
% :param opt: Options chosen for the analysis.
% See checkOptions.
% :type opt: structure
%
% :param filter: Defines files to include.
% See bids.query.
% :type filter: structure
%
% :returns:
% - :sliceOrder: a vector of the time when each slice was acquired in
% in a volume or indicating the order of acquisition of the slices.
% - :sliceOrder: a vector of the time when each slice was acquired in
% in a volume or indicating the order of acquisition of the slices.
%
% ``getAndCheckSliceOrder`` will try to read the ``opt`` structure
% for any relevant information about slice timing.
% If this is empty, it queries the BIDS dataset to see if there is any
% consistent slice timing information for a given ``filter``.
% - :stCorrected: true if all files have been slice time corrected,
% False otherwise.
%
% See also: bidsSTC, setBatchSTC
%
Expand All @@ -32,6 +34,14 @@

% TODO support for DelayTime and AcquisitionDuration

filter.target = 'SliceTimingCorrected';
sliceTimingCorrected = bids.query(BIDS, 'metadata', filter);
stCorrected = all(cellfun(@(x) (x), sliceTimingCorrected));
if ~stCorrected
sliceOrder = [];
return
end

filter.target = 'SliceTiming';
sliceTiming = bids.query(BIDS, 'metadata', filter);

Expand Down
2 changes: 1 addition & 1 deletion src/bids/initBids.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function initBids(varargin)
'use_schema', false, ...
'index_derivatives', false, ...
'tolerant', true, ...
'verbose', opt.verbosity > 0);
'verbose', false);

pipeline = opt.pipeline.name;
if ~strcmp(opt.pipeline.type, '')
Expand Down
4 changes: 0 additions & 4 deletions src/defaults/checkOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,6 @@
end

% deal with space
if ~strcmpi(opt.pipeline.type, 'stats')
fieldsToSet = struct('space', {{'individual', 'IXI549Space'}});
opt = setFields(opt, fieldsToSet);
end
if isfield(opt, 'space') && ~iscell(opt.space)
opt.space = {opt.space};
end
Expand Down
5 changes: 4 additions & 1 deletion src/messages/bidspmHelp.m
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ function bidspmHelp()
% 'action', 'stats', ...
% 'participant_label', {}, ...
% 'task', {}, ...
% 'space', {'individual', 'IXI549Space'}, ...
% 'space', {}, ...
% 'bids_filter_file', struct([]), ...
% 'options', struct([]), ...,
% 'verbosity', 2, ...
Expand Down Expand Up @@ -327,6 +327,9 @@ function bidspmHelp()
% :param space: Defaults to ``{}``
% :type space: cell string
%
% :param task: Defaults to ``{}``
% :type task: char or cell string
%
%
% *Optional parameters*
%
Expand Down
4 changes: 1 addition & 3 deletions src/stats/subject_level/getFFXdir.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function ffxDir = getFFXdir(subLabel, opt)
%
% Sets the name the FFX directory and creates it if it does not exist
% Sets the name the FFX directory
%
% USAGE::
%
Expand Down Expand Up @@ -39,8 +39,6 @@
ffxDir = [ffxDir '_roi'];
end

spm_mkdir(ffxDir);

end

function string = deregexify(string)
Expand Down
14 changes: 7 additions & 7 deletions src/workflows/preproc/bidsSmoothing.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function bidsSmoothing(opt)
opt.taskName = bids.query(BIDS, 'tasks');
end

allRT = {};
allmetadata = struct('RTs', [], 'STCorrected', {{}});
unRenamedFiles = {};

for iSub = 1:numel(opt.subjects)
Expand All @@ -49,10 +49,10 @@ function bidsSmoothing(opt)
switch modality
case 'func'
matlabbatch = {};
[matlabbatch, allRT{iSub}] = setBatchSmoothingFunc(matlabbatch, ...
BIDS, ...
opt, ...
subLabel);
[matlabbatch, allmetadata(iSub)] = setBatchSmoothingFunc(matlabbatch, ...
BIDS, ...
opt, ...
subLabel);
[~, unRenamedFiles{iSub}] = saveAndRunWorkflow(matlabbatch, ...
['smoothing_FWHM-', ...
num2str(opt.fwhm.func)], ...
Expand Down Expand Up @@ -95,8 +95,8 @@ function bidsSmoothing(opt)
idx = ~cellfun('isempty', ...
strfind(unRenamedFiles{iSub}{1}.files, ...
metadata.SpmFilename));
rt = allRT{iSub}(idx);
metadata.RepetitionTime = rt;
metadata.RepetitionTime = allmetadata(iSub).RTs(idx);
metadata.SliceTimingCorrected = allmetadata(iSub).STCorrected(idx);
bids.util.jsonencode(jsonFile, metadata);
end
end
Expand Down
15 changes: 0 additions & 15 deletions tests/tests_bids_model/test_getFFXdir.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ function test_getFFXdir_ignored_desc()
'task-vislocalizer_space-IXI549Space_FWHM-0');

assertEqual(ffxDir, expectedOutput);
assertEqual(exist(expectedOutput, 'dir'), 7);

rmdir(ffxDir, 's');
end

end
Expand All @@ -55,10 +52,6 @@ function test_getFFXdir_basic()
ffxDir = getFFXdir(subLabel, opt);

assertEqual(ffxDir, expectedOutput);
assertEqual(exist(expectedOutput, 'dir'), 7);

rmdir(ffxDir, 's');

end

function test_getFFXdir_extra_entity()
Expand All @@ -78,10 +71,6 @@ function test_getFFXdir_extra_entity()
'task-vismotion_acq-1p60mm_space-IXI549Space_FWHM-6');

assertEqual(ffxDir, expectedOutput);
assertEqual(exist(expectedOutput, 'dir'), 7);

rmdir(ffxDir, 's');

end

function test_getFFXdir_user_specified()
Expand All @@ -97,8 +86,4 @@ function test_getFFXdir_user_specified()
'task-vismotion_space-individual_FWHM-6_node-globalSignal');

assertEqual(ffxDir, expectedOutput);
assertEqual(exist(expectedOutput, 'dir'), 7);

rmdir(ffxDir, 's');

end

0 comments on commit 9137f31

Please sign in to comment.