Skip to content

Commit 9854498

Browse files
authored
Merge pull request #2097 from effigies/feat/nifti-axis-codes
[ENH] Specify that dir-<label> should correspond to PhaseEncodingDirection
2 parents fd4d520 + aacae58 commit 9854498

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

src/schema/meta/context.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ properties:
316316
- xyzt_units
317317
- qform_code
318318
- sform_code
319+
- axis_codes
319320
additionalProperties: false
320321
properties:
321322
dim_info:
@@ -404,6 +405,17 @@ properties:
404405
name: 'sform code'
405406
description: 'Use of the affine fields.'
406407
type: integer
408+
axis_codes:
409+
name: 'axis codes'
410+
description: >
411+
Orientation labels indicating primary direction of data axes defined
412+
with respect to the object of interest.
413+
type: array
414+
minItems: 3
415+
maxItems: 3
416+
items:
417+
type: string
418+
enum: ['R', 'L', 'A', 'P', 'S', 'I']
407419
mrs:
408420
name: 'NIfTI-MRS extension'
409421
description: 'NIfTI-MRS JSON fields'

src/schema/objects/entities.yaml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,23 @@ direction:
8383
This entity represents the `"PhaseEncodingDirection"` metadata field.
8484
Therefore, if the `dir-<label>` entity is present in a filename,
8585
`"PhaseEncodingDirection"` MUST be defined in the associated metadata.
86-
Please note that the `<label>` does not need to match the actual value of the field.
86+
87+
Labels need not follow any particular convention and in case of conflict,
88+
JSON metadata MUST take precedence in interpreting an image.
89+
90+
For example, `dir-j0` and `dir-j1` can indicate `"PhaseEncodingDirection": "j"` and `"j-"` (or vice versa),
91+
identifying the phase-encoding axis while avoiding indicating polarity.
92+
However, in case of a dataset indicating `dir-j0` with `"PhaseEncodingDirection": "i"`, the
93+
JSON metadata overrides the entity `dir-` setting.
94+
95+
The use of generic labels, such as `dir-reference` and `dir-reversed`, is RECOMMENDED
96+
to avoid any possible inconsistency.
97+
98+
To avoid inconsistency, if the `<label>` is `AP`, `PA`, `LR`, `RL`, `SI`, or `IS`,
99+
then the `"PhaseEncodingDirection"` SHOULD correspond to the data
100+
axis that most closely aligns with the cardinal direction and orientation.
101+
For example, `dir-PA` and `dir-AP` for an image in RAS+ orientation SHOULD have
102+
`"PhaseEncodingDirection": "j"` and `"j-"`, respectively.
87103
type: string
88104
format: label
89105
echo:

src/schema/rules/checks/nifti.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,19 @@ XformCodes0:
4949
- nifti_header != null
5050
checks:
5151
- nifti_header.qform_code != 0 || nifti_header.sform_code != 0
52+
53+
NiftiPEDir:
54+
issue:
55+
code: NIFTI_PE_DIRECTION_CONSISTENCY
56+
message: |
57+
The PhaseEncodingDirection and affine orientation indicate
58+
that the entity value (one of AP, PA, RL, LR, SI, IS) may be inaccurate.
59+
level: warning
60+
selectors:
61+
- type(nifti_header.axis_codes) != "null"
62+
- intersects([entities.direction], ["AP", "PA", "RL", "LR", "SI", "IS"])
63+
- sidecar.PhaseEncodingDirection
64+
checks:
65+
- |
66+
entities.direction[2 - length(sidecar.PhaseEncodingDirection)]
67+
== nifti_header.axis_codes[index(["i", "j", "k"], sidecar.PhaseEncodingDirection[0])]

tools/schemacode/tests/test_context_types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def test_assignability() -> None:
7575
xyzt_units=xyzt_units,
7676
qform_code=1,
7777
sform_code=1,
78+
axis_codes=("L", "P", "S"),
7879
)
7980

8081
ome: p.Ome = ctx.Ome()

0 commit comments

Comments
 (0)