Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] display error when impossible slice timing values are given #969

Merged
merged 7 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,10 @@ repos:
types: [dockerfile]
entry: ghcr.io/hadolint/hadolint hadolint

- repo: https://github.com/codespell-project/codespell
rev: v2.2.4
hooks:
- id: codespell

ci:
skip: [hadolint-docker]
6 changes: 5 additions & 1 deletion bidspm.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@
opt.dir.output = args.Results.output_dir;
opt.dryRun = false;
opt.verbosity = 3;
bugReport(opt, ME);
if isempty(which('bugReport'))
rethrow(ME);
else
bugReport(opt, ME);
end
returnCode = 1;
end
end
Expand Down
2 changes: 1 addition & 1 deletion docs/source/examples/preprocess.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using statistical parametric mapping
(SPM12 - 7771; Wellcome Center for Neuroimaging, London, UK;
https://www.fil.ion.ucl.ac.uk/spm; RRID:SCR_007037)
using MATLAB 9.4.0.813654 (R2018a)
on a unix computer (Linux version 5.15.0-53-generic (buildd@lcy02-amd64-047) (gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0, GNU ld (GNU Binutils for Ubuntu) 2.38) #59-Ubuntu SMP Mon Oct 17 18:53:30 UTC 2022
on a unix computer (Linux version 5.15.0-53-generic (build@lcy02-amd64-047) (gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0, GNU ld (GNU Binutils for Ubuntu) 2.38) #59-Ubuntu SMP Mon Oct 17 18:53:30 UTC 2022
).
.

Expand Down
2 changes: 1 addition & 1 deletion docs/source/examples/stats.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using statistical parametric mapping
(SPM12 - 7771; Wellcome Center for Neuroimaging, London, UK;
https://www.fil.ion.ucl.ac.uk/spm; RRID:SCR_007037)
using MATLAB 9.4.0.813654 (R2018a)
on a unix computer (Linux version 5.15.0-53-generic (buildd@lcy02-amd64-047) (gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0, GNU ld (GNU Binutils for Ubuntu) 2.38) #59-Ubuntu SMP Mon Oct 17 18:53:30 UTC 2022
on a unix computer (Linux version 5.15.0-53-generic (build@lcy02-amd64-047) (gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0, GNU ld (GNU Binutils for Ubuntu) 2.38) #59-Ubuntu SMP Mon Oct 17 18:53:30 UTC 2022
).

The input data were the preprocessed BOLD images in IXI549Space space for the task " facerepetition ".
Expand Down
2 changes: 1 addition & 1 deletion lib/mancoreg/mancoreg.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function mancoreg(varargin)
% and "reset transformation" button (12.1.2004, JH)
%
% Version 1.0.3
% Added: Made compatible with SPM5 and corrected "Yawn" (altho I like it)
% Added: Made compatible with SPM5 and corrected "Yawn" (although I like it)

global st mancoregvar

Expand Down
2 changes: 1 addition & 1 deletion lib/panel-2.14/demo/demopanelA.m
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
% mitigate this is to export at a higher DPI, but that makes
% for a very large figure file. an alternative is to ask
% panel to render at a higher DPI but then to smooth back
% down to the specfied resolution. you'll have to wait a few
% down to the specified resolution. you'll have to wait a few
% seconds for the result, since rendering at these sizes
% takes time. here, we'll smooth by factor 2. since this
% takes a little while, i don't usually do this until i'm
Expand Down
6 changes: 3 additions & 3 deletions lib/panel-2.14/panel.m
Original file line number Diff line number Diff line change
Expand Up @@ -2382,7 +2382,7 @@ function pack(p, varargin)
p.m_children(end + 1) = child;
end

% recurse (further argumens are passed on)
% recurse (further arguments are passed on)
if ~isempty(args)
child_packdim = flippackdim(p.packdim);
edges = 'hv';
Expand Down Expand Up @@ -5027,10 +5027,10 @@ function restoreAxisState(h, store)

end

function b = isofsize(value, siz)
function b = isofsize(value, size_)

sz = size(value);
b = length(sz) == length(siz) && all(sz == siz);
b = length(sz) == length(size_) && all(sz == size_);

end

Expand Down
2 changes: 1 addition & 1 deletion lib/utils/cprintf.m
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@
style = style(~debugIdx);
end

% Check if the remaining style sting is a numeric vector
% Check if the remaining style string is a numeric vector
%styleNum = str2num(style); %#ok<ST2NM> % not good because style='text' is evaled!
%if ~isempty(styleNum)
if any(style==' ' | style==',' | style==';')
Expand Down
6 changes: 3 additions & 3 deletions lib/utils/resize_img.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function resize_img(imnames, Voxdim, BB, ismask)
% This version doesn't check spm_flip_analyze_images -- the handedness of
% the output image and matrix should match those of the input.

% DONWLOADED FROM ON THE 2021 02 17
% DOWNLOADED FROM ON THE 2021 02 17
% https://blogs.warwick.ac.uk/nichols/entry/spm5_gem_3/

% Check spm version:
Expand Down Expand Up @@ -99,8 +99,8 @@ function resize_img(imnames, Voxdim, BB, ismask)

% output image
VO = V;
[pth, nam, ext] = fileparts(V.fname);
VO.fname = fullfile(pth, ['r' nam ext]);
[pth, name, ext] = fileparts(V.fname);
VO.fname = fullfile(pth, ['r' name ext]);
VO.dim(1:3) = imgdim(1:3);
VO.mat = mat;
VO = spm_create_vol(VO);
Expand Down
36 changes: 18 additions & 18 deletions lib/utils/unfold.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function unfold(input, varargin)
% unfold(SC, name, show, file_id)
%
%
% :param SC: vairable to show the content of.
% :param SC: variable to show the content of.
% :type SC: structure or cell
%
% If SC is a structure it recursively shows the name of SC and
Expand All @@ -17,10 +17,10 @@ function unfold(input, varargin)
%
% It uses the caller's workspace variable name as the name of SC.
%
% :param name: can be used isntead of the name of SC.
% :param name: can be used instead of the name of SC.
% :type name: string
%
% :param show: if ``false`` only the fieldnames and their sizes are shown,
% :param show: if ``false`` only the fieldnames and their size_es are shown,
% if ``true`` the contents are shown also.
% :type show: boolean
%
Expand Down Expand Up @@ -97,11 +97,11 @@ function unfold(input, varargin)
for i = 1:NF

if NS > 1
siz = size(input);
size_ = size_e(input);
if show
name_i = [name '(' indToStr(siz, h) ').' F{i}];
name_i = [name '(' indToStr(size_, h) ').' F{i}];
else
name_i = [name '(' indToStr(siz, NS) ').' F{i}];
name_i = [name '(' indToStr(size_, NS) ').' F{i}];
end
else
name_i = [name '.' F{i}];
Expand All @@ -116,7 +116,7 @@ function unfold(input, varargin)
printKeyToScreen(name_i, file_id);
fprintf(file_id, ' =\t{};');
else
siz = size(input(h).(F{i}));
size_ = size_e(input(h).(F{i}));
NC = numel(input(h).(F{i}));
if show
jmax = NC;
Expand All @@ -125,9 +125,9 @@ function unfold(input, varargin)
end
for j = 1:jmax
if show
name_j = [name_i '{' indToStr(siz, j) '}'];
name_j = [name_i '{' indToStr(size_, j) '}'];
else
name_j = [name_i '{' indToStr(siz, NC) '}'];
name_j = [name_i '{' indToStr(size_, NC) '}'];
end
printKeyToScreen(name_j, file_id);
if show
Expand All @@ -153,9 +153,9 @@ function unfold(input, varargin)
fprintf(file_id, ' =\t{};');
else
% recursively display cell
siz = size(input);
size_ = size_e(input);
for i = 1:numel(input)
name_i = [name '{' indToStr(siz, i) '}'];
name_i = [name '{' indToStr(size_, i) '}'];
unfold(input{i}, name_i, show, file_id);
end
end
Expand Down Expand Up @@ -209,20 +209,20 @@ function printValueToScreen(input, file_id)

% local functions
% --------------------------------------------------------------------------
function str = indToStr(siz, ndx)
function str = indToStr(size_, ndx)

n = length(siz);
n = length(size_);
% treat vectors and scalars correctly
if n == 2
if siz(1) == 1
siz = siz(2);
if size_(1) == 1
size_ = size_(2);
n = 1;
elseif siz(2) == 1
siz = siz(1);
elseif size_(2) == 1
size_ = size_(1);
n = 1;
end
end
k = [1 cumprod(siz(1:end - 1))];
k = [1 cumprod(size_(1:end - 1))];
ndx = ndx - 1;
str = '';
for i = n:-1:1
Expand Down
14 changes: 9 additions & 5 deletions src/preproc/utils/getAcquisitionTime.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,24 @@
% SPM accepts slice time acquisition as inputs for slice order
% (simplifies things when dealing with multiecho data)

sliceOrder = unique(sliceOrder);

acquisitionTime = repetitionTime - (repetitionTime / numel(sliceOrder));
acquisitionTime = computeAcquisitionTime(sliceOrder, repetitionTime);

% ceil to avoid making this too brittle
if any(sliceOrder >= ceil(acquisitionTime * 1000) / 1000)
if any(sliceOrder > ceil(acquisitionTime * 100) / 100)
sliceOrder = bids.internal.create_unordered_list(num2str(sliceOrder));
msg = sprintf(['Acquisition time cannot be < to any slice timing value:\n\n', ...
'Current values:', ...
'\n- acquisition time: %f', ...
'\n- slice timing: ' pattern], ...
'\n- slice timing %s'], ...
acquisitionTime, ...
sliceOrder);
id = 'sliceTimingSuperiorToAcqTime';
logger('ERROR', msg, 'id', id, 'filename', mfilename());
end

end

function acquisitionTime = computeAcquisitionTime(sliceOrder, repetitionTime)
sliceOrder = unique(sliceOrder);
acquisitionTime = repetitionTime - (repetitionTime / numel(sliceOrder));
end
79 changes: 79 additions & 0 deletions tests/tests_preproc/utils/test_getAcquisitionTime.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
function test_suite = test_getAcquisitionTime %#ok<*STOUT>
% (C) Copyright 2023 bidspm developers
try % assignment of 'localfunctions' is necessary in Matlab >= 2016
test_functions = localfunctions(); %#ok<*NASGU>
catch % no problem; early Matlab versions can use initTestSuite fine
end
initTestSuite;
end

function test_getAcquisitionTime_basic()

repetitionTime = 1.5;
sliceOrder = repmat([0.5475, 0, 0.3825, 0.055, 0.4375, 0.11, ...
0.4925, 0.22, 0.6025, 0.275, 0.6575, 0.3275, ...
0.71, 0.165], ...
1, 3)';

acquisitionTime = getAcquisitionTime(sliceOrder, repetitionTime);

assertElementsAlmostEqual(acquisitionTime, 1.3929, 'absolute', 1e-4);

end

function test_getAcquisitionTime_error()

repetitionTime = 1.5;
sliceOrder = repmat([0.5475, 0, 0.3825, 0.055, 0.4375, 0.11, ...
0.4925, 0.22, 0.6025, 0.275, 0.6575, 0.3275, ...
0.71, 1.49], ...
1, 3)';

assertExceptionThrown(@() getAcquisitionTime(sliceOrder, repetitionTime), ...
'getAcquisitionTime:sliceTimingSuperiorToAcqTime');

end

function test_getAcquisitionTime_bug_967()
% https://github.com/cpp-lln-lab/bidspm/issues/967

repetitionTime = 2;
sliceOrder = [0
0.0575
0.115
0.1725
0.23
0.2875
0.345
0.4025
0.46
0.5175
0.575
0.6325
0.69
0.745
0.8025
0.86
0.9175
0.975
1.0325
1.09
1.1475
1.205
1.2625
1.32
1.3775
1.435
1.4925
1.55
1.6075
1.665
1.7225
1.7775
1.835
1.8925
1.95];

getAcquisitionTime(sliceOrder, repetitionTime);

end