def get_readoutdir(metadata):
"""
get readout direction from bids metadata. !!Note that this method only
applies where the nifti orientation is RAS!!
:param metadata: grabbids metadata dict.
:return: unwarp dir in cartesian (world) coordinates.
"""
iopd = metadata['ImageOrientationPatientDICOM']
ped = metadata['InPlanePhaseEncodingDirectionDICOM']
# readout direction is opposite the in plane phase encoding direction
if ped == 'ROW':
readoutvec = iopd[3:]
elif ped == 'COL':
readoutvec = iopd[:3]
else:
raise ValueError('phase encoding direction not recognized: ' + ped)
# convert 3-vector to symbolic unit vector
i = max([0, 1, 2], key=lambda x: abs(readoutvec[x]))
readoutdir = ['x', 'y', 'z'][i]
# TODO: Fix readoutdir algorithm. Arbitratily switched pos to neg for ABCD.
if readoutvec[i] > 0:
readoutdir += '-'
return readoutdir
There should be a field in the sidecar JSONs that just has this information instead of determining it in this roundabout way. We need it to be grabbed from elsewhere for HCP-YA.
Comment from @ericfeczko: If you have the phase encoding direction and the in plane axis, the readout direction can be inferred from the two.
There should be a field in the sidecar JSONs that just has this information instead of determining it in this roundabout way. We need it to be grabbed from elsewhere for HCP-YA.
Comment from @ericfeczko: If you have the phase encoding direction and the in plane axis, the readout direction can be inferred from the two.