Skip to content

ENH: Subcortical alignment workflow #72

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

Merged
merged 39 commits into from
Jul 26, 2021
Merged

Conversation

mgxd
Copy link
Collaborator

@mgxd mgxd commented Jun 4, 2021

Closes #49.

A few missing pieces:

Once this standalone workflow is finalized (and somewhat tested), I'll open a separate PR actually using it in nibabies.

@pep8speaks
Copy link

pep8speaks commented Jun 4, 2021

Hello @mgxd! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2021-07-26 19:02:33 UTC

@mgxd mgxd force-pushed the enh/subcortical-cifti branch 6 times, most recently from ffa7eee to 8748be7 Compare June 4, 2021 20:57
@codecov-commenter
Copy link

codecov-commenter commented Jun 4, 2021

Codecov Report

Merging #72 (9fe1243) into master (1cdf9da) will increase coverage by 1.97%.
The diff coverage is 68.10%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #72      +/-   ##
==========================================
+ Coverage   31.53%   33.50%   +1.97%     
==========================================
  Files          42       44       +2     
  Lines        3257     3462     +205     
==========================================
+ Hits         1027     1160     +133     
- Misses       2230     2302      +72     
Impacted Files Coverage Δ
nibabies/config.py 57.41% <0.00%> (-0.76%) ⬇️
nibabies/utils/misc.py 52.38% <ø> (ø)
nibabies/workflows/bold/alignment.py 27.08% <27.08%> (ø)
nibabies/interfaces/workbench.py 88.40% <70.37%> (-11.60%) ⬇️
nibabies/interfaces/nibabel.py 73.77% <97.05%> (+29.32%) ⬆️
nibabies/conftest.py 100.00% <100.00%> (ø)
nibabies/interfaces/tests/test_nibabel.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1cdf9da...9fe1243. Read the comment docs.

@mgxd mgxd force-pushed the enh/subcortical-cifti branch from 92700af to 67e7684 Compare June 7, 2021 14:26
@mgxd mgxd force-pushed the enh/subcortical-cifti branch from 67e7684 to 0be8a65 Compare July 20, 2021 01:03
@mgxd
Copy link
Collaborator Author

mgxd commented Jul 22, 2021

One of the biggest improvements this Nipype-ified workflow offers is parallelization. However, depending on the number of timepoints in the subject's functional, there are a few points where virtual memory can substantially peak:

  1. Applying the transform of the ROI from the subjects functional to the template space
    applyxfm_roi = pe.MapNode(
    fsl.ApplyXFM(interp="spline"),
    iterfield=["reference", "in_matrix_file"],
    name='applyxfm_roi',
    mem_gb=2,
    )

I'm fairly sure this can be replaced by NiTransforms, though I don't know if that will help with the memory issue.

  1. Aggregating all processed 4D ROI images into a dense timeseries file
    create_dtseries_tmpl = pe.Node(
    CiftiCreateDenseFromTemplate(series=True, series_step=repetition_time, series_start=0),
    name='create_dtseries_tmpl',
    )

wb_command -cifti-create-dense-from-template loads up all volumes simultaneously, which can lead to memory crashes. This has been addressed in the DCAN script, but at the cost of having to do things sequentially. Since the final result is just a 4D NIfTI of all the combined ROIs, an alternate approach can be to:

  • split each 4D ROI NIfTI into 3D series
  • combine the ROIs within each timepoint (essentially adding the images together)
  • recombine the now aggregated timepoints into one 4D image

cc @ericfeczko @effigies @oesteban

mgxd added 4 commits July 23, 2021 11:29
Using `wb_command -cifti-create-dense-from-template` would load
all 4D ROIs into memory at once, causing a drastic bottleneck.
Instead of creating a dtseries only to separate back into a volumetric
NIfTI, we can simply add together the 4D ROIs and produce the same result,
minimizing the number of files simultaneously loaded in memory'
@mgxd mgxd requested review from effigies, ericfeczko and oesteban July 23, 2021 21:45
@mgxd
Copy link
Collaborator Author

mgxd commented Jul 23, 2021

Okay, the two concerns above have been addressed. I'd love to have another set of eyes look over this before merging it in

Copy link
Member

@effigies effigies left a comment

Choose a reason for hiding this comment

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

I haven't looked through the workflow in detail, yet, but here's some early comments. Do we have docs that will show the workflow graph?

return rois[0], rois[1:], ("-add %s " * (len(rois) - 1)).strip()


def merge_rois(in_files):
Copy link
Member

Choose a reason for hiding this comment

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

This feels like a significant enough function to write a test for. 3 (3,1,1,5) time series would exercise it plenty, and easy to modify to hit each error condition.

Comment on lines 249 to 251
def format_volume_rois(structs, rois):
"""Format volume arguments for CiftiCreateDenseFromTemplate."""
return [(struct, roi) for struct, roi in zip(structs, rois)]
Copy link
Member

Choose a reason for hiding this comment

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

I think this is unused. Also, it's just list(zip(structs, rois))...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, remnant of the previous implementation

@effigies
Copy link
Member

@mgxd Pushed a test to 9a89211, if you want to have a look then cherry-pick.

@mgxd
Copy link
Collaborator Author

mgxd commented Jul 24, 2021

@mgxd Pushed a test to 9a89211, if you want to have a look then cherry-pick.

haha, looks like we were both working on the same thing 👀

Copy link
Member

@effigies effigies left a comment

Choose a reason for hiding this comment

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

A few comments. It overall seems reasonable. A bit tough to be sure of the correctness without a comparison of subject with both workflows.

@mgxd
Copy link
Collaborator Author

mgxd commented Jul 26, 2021

Thanks for the review @effigies!

@mgxd mgxd merged commit 0e681c9 into nipreps:master Jul 26, 2021
@mgxd mgxd deleted the enh/subcortical-cifti branch July 26, 2021 19:11
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.

Piecewise subcortical alignment for CIFTI mapping
4 participants