Skip to content

Commit 8d8a32d

Browse files
authored
[FIX] check for bids-ish and non bids metadata for T1map generation (#1055)
* check for bids-ish and non bids metadata for T1map generation * skip warning test on octave
1 parent 07254b7 commit 8d8a32d

File tree

2 files changed

+58
-12
lines changed

2 files changed

+58
-12
lines changed

src/batches/preproc/setBatchGenerateT1map.m

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
% images for this to work (check the README of the toolbox for more info):
3131
%
3232
% - ``EchoSpacing``
33-
% - ``PartialFourierInSlice``: between 0 and 1 (example: 6/8)
33+
% - ``SlicePartialFourier`` or ``PartialFourierInSlice``:
34+
% between 0 and 1 (example: 6/8)
3435
% - ``FatSat``: must be "yes" or "no"
3536
%
3637
% Most of the those metadata should be available from the PDF of with yout
@@ -144,22 +145,48 @@
144145

145146
% Things that are not officially part of BIDS
146147
% but that should be added to the JSON of the inversion images
147-
try
148-
estimateT1.EchoSpacing = metadataInv1.EchoSpacing;
149-
estimateT1.PartialFourierInSlice = metadataInv1.PartialFourierInSlice;
150-
estimateT1.FatSat = metadataInv1.FatSat;
151-
catch
152-
msg = sprintf('Missing non-BIDS metadata for %s\nSee ''help setBatchGenerateT1map''', ...
153-
bids.internal.create_unordered_list(filter));
154-
id = 'missingNonBIDSMetadata';
155-
logger('WARNING', msg, 'id', id, 'options', opt, 'filename', mfilename());
156-
continue
148+
149+
requiredMetadata = {'EchoSpacing', 'FatSat'};
150+
for i = 1:numel(requiredMetadata)
151+
if ~ismember(requiredMetadata{i}, fieldnames(metadataInv1))
152+
missingMetadata(requiredMetadata{i}, filter, opt);
153+
continue
154+
end
155+
estimateT1.(requiredMetadata{i}) = metadataInv1.(requiredMetadata{i});
157156
end
158157

159-
matlabbatch{end + 1}.spm.tools.mp2rage.estimateT1 = estimateT1;
158+
if ~ismember('SlicePartialFourier', fieldnames(metadataInv1))
159+
missingMetadata('SlicePartialFourier', filter, opt, true);
160+
if ~ismember('PartialFourierInSlice', fieldnames(metadataInv1))
161+
missingMetadata('PartialFourierInSlice', filter, opt);
162+
continue
163+
else
164+
estimateT1.PartialFourierInSlice = metadataInv1.PartialFourierInSlice;
165+
end
166+
else
167+
estimateT1.PartialFourierInSlice = metadataInv1.SlicePartialFourier;
168+
end
169+
170+
matlabbatch{end + 1}.spm.tools.mp2rage.estimateT1 = estimateT1; %#ok<*AGROW>
160171

161172
end
162173

163174
end
164175

165176
end
177+
178+
function missingMetadata(metadata, filter, opt, tolerant)
179+
if nargin < 3
180+
tolerant = false;
181+
end
182+
msg = sprintf(['Missing non-BIDS metadata "%s" for %s\n', ...
183+
'See "help setBatchGenerateT1map"'], ...
184+
metadata, ...
185+
bids.internal.create_unordered_list(filter));
186+
id = 'missingNonBIDSMetadata';
187+
if tolerant
188+
logger('WARNING', msg, 'id', id, 'options', opt, 'filename', mfilename());
189+
else
190+
logger('ERROR', msg, 'id', id, 'options', opt, 'filename', mfilename());
191+
end
192+
end

tests/tests_batches/preproc/test_setBatchGenerateT1map.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,22 @@ function test_setBatchGenerateT1map_basic()
3636
assertEqual(estimateT1, expected);
3737

3838
end
39+
40+
function test_setBatchGenerateT1map_warning()
41+
42+
if bids.internal.is_octave()
43+
moxunit_throw_test_skipped_exception('Octave:mixed-string-concat warning thrown');
44+
end
45+
46+
subLabel = '^01';
47+
48+
opt = setOptions('vismotion', subLabel);
49+
50+
BIDS = getLayout(opt);
51+
52+
matlabbatch = {};
53+
opt.verbosity = 2;
54+
assertWarning(@() setBatchGenerateT1map(matlabbatch, BIDS, opt, subLabel), ...
55+
'setBatchGenerateT1map:missingNonBIDSMetadata');
56+
57+
end

0 commit comments

Comments
 (0)