bids-validator icon indicating copy to clipboard operation
bids-validator copied to clipboard

feat: Extract image orientation from NIfTI header

Open effigies opened this issue 1 year ago • 2 comments
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.)

effigies avatar Nov 14 '24 19:11 effigies

This has bitten me pretty hard; thanks for the initiative.

oesteban avatar Jan 24 '25 11:01 oesteban

xref https://github.com/bids-standard/bids-specification/pull/2097

effigies avatar Apr 04 '25 17:04 effigies

This is necessary to fully support BIDS 1.10.1. Post-merge reviews are welcome.

effigies avatar Sep 03 '25 20:09 effigies