Skip to content

Commit 14b0c39

Browse files
authored
Merge pull request #352 from suyashdb/checkSliceTimingArray
Validate slice timing array with RepetitionTime
2 parents c677d18 + d074350 commit 14b0c39

File tree

4 files changed

+64
-2
lines changed

4 files changed

+64
-2
lines changed

tests/json.spec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,4 @@ describe('JSON', function(){
2424
assert(issues && issues.length === 1);
2525
});
2626
});
27-
2827
});

tests/nii.spec.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,37 @@ describe('NIFTI', function(){
135135
});
136136
});
137137

138-
});
138+
it('SliceTiming should not be greater than RepetitionTime', function(){
139+
var jsonContentsDict_new = {
140+
'/sub-15/func/sub-15_task-mixedeventrelatedprobe_run-01_bold.json': {
141+
"RepetitionTime": 1.5,
142+
"TaskName": "AntiSaccade (AS) Rewarded & Neutral with varying dot position",
143+
"EchoTime": 0.025,
144+
"NumberofPhaseEncodingSteps": 64,
145+
"FlipAngle": 70,
146+
"PhaseEncodingDirection": "j",
147+
"SliceTiming": [
148+
0.0,
149+
1.3448,
150+
1.6207,
151+
1.3966,
152+
0.6724,
153+
1.4483,
154+
1.7241
155+
]
156+
}
157+
};
158+
var file_new = {
159+
name: 'sub-15_task-mixedeventrelatedprobe_run-01_bold.nii.gz',
160+
relativePath: '/sub-15/func/sub-15_task-mixedeventrelatedprobe_run-01_bold.nii.gz'
161+
};
162+
var events = [
163+
'/sub-15/func/sub-14_task-mixedeventrelatedprobe_run-01_events.tsv',
164+
'/sub-15/run-01_events.tsv'
165+
];
166+
validate.NIFTI(null, file_new, jsonContentsDict_new, {}, [], events, function (issues) {
167+
assert(issues[2].code === 66 && issues.length === 3);
168+
});
169+
});
170+
171+
});

utils/issues/list.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,5 +326,10 @@ module.exports = {
326326
key: 'SESSION_LABEL_IN_FILENAME_DOESNOT_MATCH_DIRECTORY',
327327
severity: 'error',
328328
reason: 'Session label in the filename doesn\'t match with the path of the file. File seems to be saved in incorrect session directory.'
329+
},
330+
66: {
331+
key: 'SLICETIMING_VALUES_GREATOR_THAN_REPETITION_TIME',
332+
severity: 'error',
333+
reason: '"SliceTiming" value/s contains invalid value as it is greator than RepetitionTime. SliceTiming values should be in seconds not milliseconds (common mistake).'
329334
}
330335
};

validators/nii.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,18 @@ module.exports = function NIFTI (header, file, jsonContentsDict, bContentsDict,
164164
reason: "You should define 'SliceTiming' for this file. If you don't provide this information slice time correction will not be possible. " + sidecarMessage
165165
}));
166166
}
167+
168+
if (mergedDictionary.hasOwnProperty('SliceTiming') && mergedDictionary["SliceTiming"].constructor === Array) {
169+
var SliceTimingArray = mergedDictionary["SliceTiming"];
170+
var invalid_valuesArray = checkSliceTimingArray(SliceTimingArray, mergedDictionary['RepetitionTime']);
171+
if (invalid_valuesArray.length > 0){
172+
issues.push(new Issue({
173+
file: file,
174+
code: 66,
175+
evidence: invalid_valuesArray
176+
}));
177+
}
178+
}
167179
}
168180
else if (path.includes("_phasediff.nii")){
169181
if (!mergedDictionary.hasOwnProperty('EchoTime1') || !mergedDictionary.hasOwnProperty('EchoTime2')) {
@@ -341,7 +353,20 @@ function generateMergedSidecarDict(potentialSidecars, jsonContents) {
341353
}
342354
return mergedDictionary;
343355
}
356+
/**
357+
* Function to check each SoliceTime from SliceTiming Array
358+
*
359+
*/
344360

361+
function checkSliceTimingArray(array, repetitionTime){
362+
for (var t = 0; t < array.length; t++){
363+
var invalid_timesArray = [];
364+
if (array[t] > repetitionTime){
365+
invalid_timesArray.push(array[t]);
366+
}
367+
}
368+
return invalid_timesArray;
369+
}
345370
/**
346371
* Get B-File Contents
347372
*

0 commit comments

Comments
 (0)