Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Clarify phase encoding direction, rather than axis #2302

Merged
merged 7 commits into from
Oct 12, 2020

Conversation

mgxd
Copy link
Collaborator

@mgxd mgxd commented Oct 9, 2020

BOLD runs' FunctionalSummary nodes were returning PE-Axis instead of PE-Direction.

'i': 'Right-Left',
'j-': 'Anterior-Posterior',
'j': 'Posterior-Anterior'
}.get(self.inputs.pe_direction, 'MISSING - Assuming Anterior-Posterior')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only true for LAS images. We need the orientation of the original image, to be certain.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point - I've added a commit to consider LAS/RAS. How extensive do you think our support should be for different orientations?

@effigies
Copy link
Member

effigies commented Oct 9, 2020

We can get images in any orientation. Need something like:

def get_world_pedir(img, pe_direction):
    axes = (("Right", "Left"),
            ("Anterior", "Posterior"),
            ("Superior", "Inferior"))
    ax_idcs = {"i": 0, "j": 1, "k": 2}

    ornt = ''.join(nb.aff2axcodes(img.affine))
    axcode = ornt[ax_idcs[pe_direction[0]]]
    inv = pe_direction[1:] == "-"

    for ax in axes:
        for flip in (ax, ax[::-1]):
            if flip[not inv].startswith(axcode):
                return "-".join(flip)
    raise ValueError(f"Cannot determine world direction of phase encoding. Orientation: {ornt}; PE dir: {pe_direction}")

@effigies
Copy link
Member

effigies commented Oct 9, 2020

Incidentally, for testing, I've recently written this, which allows you to generate an image of any orientation:

def generate_image(params):
    dataobj = np.zeros(params["shape"], params["dtype"]) 
    affine = np.eye(4) 
    rot = ornt.inv_ornt_aff(ornt.axcodes2ornt(params["orientation"]), (1, 1, 1)) 
    affine[:3, :3] = np.diag(params["zooms"][:3]) @ np.linalg.inv(rot[:3, :3]) 
    return nb.Nifti1Image(dataobj, affine)

(It's intended for generating datasets on the fly, which is why it's so parameterized.)

@effigies effigies merged commit b923acb into nipreps:master Oct 12, 2020
@mgxd mgxd deleted the fix/bold-pe-reports branch October 13, 2020 15:31
effigies added a commit to effigies/fmriprep that referenced this pull request Jan 20, 2022
Backport of niprepsgh-2302 to 20.2.x series

Co-authored-by: Mathias Goncalves <mathiasg@stanford.edu>
Co-authored-by: Christopher J. Markiewicz <markiewicz@stanford.edu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants