DCAN-Labs / abcd-hcp-pipeline

bids application for processing functional MRI data, robust to scanner, acquisition and age variability.
https://hub.docker.com/r/dcanumn/abcd-hcp-pipeline
BSD 3-Clause "New" or "Revised" License
48 stars 19 forks source link

Grab Readout Dir from a more intuitive JSON field #91

Open audreymhoughton opened 1 year ago

audreymhoughton commented 1 year ago
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.