Skip to content

Commit 5ea2120

Browse files
committed
_magnitude1 and _magnitude2 should not have a fourth dimension
1 parent fbc5ce7 commit 5ea2120

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

tests/headerField.spec.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
const assert = require('assert')
2+
const headerFields = require('../validators/headerFields')
3+
4+
describe('headerFields', () => {
5+
it('should throw an error if _magnitude1 or _magnitude2 files have too many dimensions.', () => {
6+
// each of these headers has one too many dimensions on the 'dim' field.
7+
// the first entry is the total count, and the following three entries are spatial.
8+
const headers = [
9+
[
10+
{
11+
name: 'sub-01_magnitude1.nii',
12+
relativePath: 'sub-01_magnitude1.nii',
13+
},
14+
{
15+
dim: [5, 1, 1, 1, 1],
16+
pixdim: [5, 1, 1, 1, 1],
17+
xyzt_units: [5, 1, 1, 1, 1],
18+
},
19+
],
20+
[
21+
{
22+
name: 'sub-01_magnitude2.nii',
23+
relativePath: 'sub-01_magnitude2.nii',
24+
},
25+
{
26+
dim: [5, 1, 1, 1, 1],
27+
pixdim: [5, 1, 1, 1, 1],
28+
xyzt_units: [5, 1, 1, 1, 1],
29+
},
30+
],
31+
]
32+
const issues = headerFields(headers)
33+
assert(
34+
issues.length == 2 && issues[0].code == '94' && issues[1].code == '94',
35+
)
36+
})
37+
38+
it('_magnitude1 or _magnitude2 files should have 3 dimensions.', () => {
39+
const headers = [
40+
[
41+
{
42+
name: 'sub-01_magnitude1.nii',
43+
relativePath: 'sub-01_magnitude1.nii',
44+
},
45+
{
46+
dim: [4, 1, 1, 1],
47+
pixdim: [4, 1, 1, 1],
48+
xyzt_units: [4, 1, 1, 1],
49+
},
50+
],
51+
[
52+
{
53+
name: 'sub-01_magnitude2.nii',
54+
relativePath: 'sub-01_magnitude2.nii',
55+
},
56+
{
57+
dim: [3, 1, 1],
58+
pixdim: [4, 1, 1, 1],
59+
xyzt_units: [4, 1, 1, 1],
60+
},
61+
],
62+
]
63+
const issues = headerFields(headers)
64+
assert.deepEqual(issues, [])
65+
})
66+
})

utils/issues/list.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,4 +509,10 @@ module.exports = {
509509
reason:
510510
'Each _phasediff.nii[.gz] file should be associated with a _magnitude1.nii[.gz] file.',
511511
},
512+
94: {
513+
key: 'MAGNITUDE_FILE_WITH_TOO_MANY_DIMENSIONS',
514+
severity: 'error',
515+
reason:
516+
'_magnitude1.nii[.gz] and _magnitude2.nii[.gz] files must not have more than three dimensions. ',
517+
},
512518
}

validators/headerFields.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ var headerField = function headerField(headers, field) {
9090
evidence: 'header field "dim" = ' + header[field],
9191
})
9292
continue
93+
} else if (
94+
(file.name.indexOf('magnitude1') > -1 ||
95+
file.name.indexOf('magnitude2') > -1) &&
96+
header[field][0] > 4
97+
) {
98+
issues[file.relativePath] = new Issue({
99+
file: file,
100+
code: 94,
101+
evidence: 'this magnitude file has more than three dimensions. ',
102+
})
93103
}
94104
field_value = header[field].slice(1, header[field][0] + 1).toString()
95105
} else if (field === 'pixdim') {

0 commit comments

Comments
 (0)