bids-validator
bids-validator copied to clipboard
feat: Extract image orientation from NIfTI header
trafficstars
For #76 and #79, it would be helpful to have access to the image orientation. This PR starts with a function to determine axis codes from the the image affine.
If we add nifti_header.axis_codes to the context, we could then write #76 as:
NiftiPEDir:
issue:
code: NIFTI_PE_DIRECTION_CONSISTENCY
message: Phase encoding direction is inconsistent with entity
level: warning
selectors:
- type(nifti_header) != "null"
- intersects([entities.direction], ["AP", "PA", "RL", "LR", "IS", "SI"])
- sidecar.PhaseEncodingDirection
checks:
- |
entities.direction[2 - length(sidecar.PhaseEncodingDirection)]
== nifti_header.axis_codes[index(["i", "j", "k"], sidecar.PhaseEncodingDirection[0]]
(Would need to check that check... It's probably being too clever, but it is nice to get it in one.)
This has bitten me pretty hard; thanks for the initiative.
xref https://github.com/bids-standard/bids-specification/pull/2097
This is necessary to fully support BIDS 1.10.1. Post-merge reviews are welcome.