Skip to content

REF/FIX: Simplify transform aggregation in resampling, pass identity transforms for multi-echo cases #2239

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 19 commits into from
Aug 14, 2020

Conversation

emdupre
Copy link
Collaborator

@emdupre emdupre commented Aug 12, 2020

Closes #2236
Closes #2238

Changes proposed in this pull request

  • Simplifies transformation aggregation (i.e., no longer passing variable number of xforms; unused transforms are passed as identity)
  • Refactor MEEPI connections for improved legibility
  • Removes redundant fieldwarp application for MEEPI data

Documentation that should be reviewed

N/A

@effigies effigies changed the base branch from master to maint/20.1.x August 12, 2020 01:54
@effigies
Copy link
Member

Could you rebase onto maint/20.1.x? As a bug-fix, this should patch smoothly. (If it does not, I can change back to master.)

@emdupre emdupre force-pushed the fix/meepi-t1-trans branch from 958c28b to e8c3ad5 Compare August 12, 2020 02:01
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.

LGTM. Thanks!

oesteban
oesteban previously approved these changes Aug 12, 2020
@oesteban oesteban changed the title [FIX] Split optimal combination input to bold_t1_trans_wf FIX: Split optimal combination input to bold_t1_trans_wf Aug 12, 2020
@oesteban
Copy link
Member

Seems like the multi-echo smoke test is smoking... Looks like the split node is hanging.

@effigies
Copy link
Member

Do we need to reset a Circle cache?

@effigies
Copy link
Member

Hmm. It looks like we're getting caught on a bold_split inside bold_t1_trans_wf:

200812-03:15:04,302 nipype.workflow INFO:
	 [MultiProc] Running 1 tasks, and 0 jobs ready. Free memory (GB): 4.09/4.10, Free processors: 1/2.
                     Currently running:
                       * fmriprep_wf.single_subject_02_wf.func_preproc_task_cuedSGT_run_01_echo_1_wf.bold_t1_trans_wf.bold_split

@emdupre emdupre force-pushed the fix/meepi-t1-trans branch from b7746a0 to 974c515 Compare August 12, 2020 14:26
@pep8speaks
Copy link

pep8speaks commented Aug 12, 2020

Hello @emdupre! 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 2020-08-14 02:46:11 UTC

@emdupre emdupre force-pushed the fix/meepi-t1-trans branch from 974c515 to e8cab50 Compare August 12, 2020 14:29
('itk_bold_to_t1', 'in1')]),
(merge_xforms, bold_to_t1w_transform, [('out', 'transforms')]),
(inputnode, bold_to_t1w_transform, [('bold_split', 'input_image')]),
('fieldwarp' if not multiecho else 'identity', 'in2')])
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@effigies is this what you meant by passing an 'identity' transform to ANTs ?

Copy link
Member

Choose a reason for hiding this comment

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

It will need to be directly entered, not through a connection.

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.

Here are suggestions to demonstrate what I was going for. We actually do want to connect things in the sub-workflow, but set the values directly in the input to the workflow.

Also, this is now a refactor, not a bug fix, so we should rebase back onto master. I will set the target branch now.

('itk_bold_to_t1', 'in1')]),
(merge_xforms, bold_to_t1w_transform, [('out', 'transforms')]),
(inputnode, bold_to_t1w_transform, [('bold_split', 'input_image')]),
])
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 what we want in general is the following

    merge_xforms = pe.Node(niu.Merge(3), name='merge_xforms',
                           run_without_submitting=True, mem_gb=DEFAULT_MEMORY_MIN_GB)
    workflow.connect([
        # merge transforms
        (inputnode, merge_xforms, [
            ('hmc_xforms' , 'in3'),
            ('fieldwarp', 'in2'),
            ('itk_bold_to_t1', 'in1')]),
        (merge_xforms, bold_to_t1w_transform, [('out', 'transforms')]),
        (inputnode, bold_to_t1w_transform, [('bold_split', 'input_image')]),
    ])

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We still want to vary the number of transforms depending on whether or not use_fieldwarp is active, no ?

Copy link
Member

Choose a reason for hiding this comment

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

Oh, sorry, I didn't see this. No, the idea is that we make that input be identity.

Copy link
Member

Choose a reason for hiding this comment

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

@effigies effigies changed the base branch from maint/20.1.x to master August 12, 2020 15:28
@emdupre emdupre force-pushed the fix/meepi-t1-trans branch from e8cab50 to d007ad3 Compare August 12, 2020 21:00
@emdupre emdupre changed the title FIX: Split optimal combination input to bold_t1_trans_wf REF: Split optimal combination input to bold_t1_trans_wf Aug 12, 2020
@effigies
Copy link
Member

Did a little cleaning up. If you haven't already pushed forward, could you fetch my remote and cherry-pick bbdb59645548f510458ee4d11ac3c34b94edf4f6?

Otherwise, I'll rebase on whatever you've done.

@emdupre
Copy link
Collaborator Author

emdupre commented Aug 13, 2020

OK, so it seems that the merge_xforms node in bold_t1_trans_wf is correctly merging the transforms for ds210:

> from nipype.utils.filemanip import loadpkl                                       

> res = loadpkl('result_merge_xforms.pklz')  
> res.outputs
out = ['/scratch/fmriprep_wf/single_subject_02_wf/func_preproc_task_cuedSGT_run_01_echo_1_wf/bold_reg_wf/fsl_bbr_wf/fsl2itk_fwd/affine.txt', 'identity', 'identity']

the problem is that the workflow can't actually apply this merged transform:

nipype.workflow CRITICAL:
    fMRIPrep failed: /scratch/fmriprep_wf/single_subject_02_wf/func_preproc_task_cuedSGT_run_01_echo_1_wf/bold_t1_trans_wf/bold_to_t1w_transform/result_bold_to_t1w_transform.pklz

Will this involve an update to MultiApplyTransforms ? That's the interface that's being called as bold_to_t1w_transform here:

https://github.com/poldracklab/fmriprep/blob/c717c6b216886be5de75627c067018700f0efd75/fmriprep/workflows/bold/registration.py#L320-L322

@effigies
Copy link
Member

Lol, yup.

@effigies effigies changed the title REF: Split optimal combination input to bold_t1_trans_wf REF/FIX: Simplify transform aggregation in resampling, pass identity transforms for multi-echo cases Aug 14, 2020
@effigies
Copy link
Member

I think this is ready to go. Since I contributed, a separate reviewer would be good.

@effigies effigies dismissed oesteban’s stale review August 14, 2020 14:03

Significant changes since

@emdupre emdupre requested review from tsalo and oesteban August 14, 2020 14:24
Copy link
Collaborator

@tsalo tsalo left a comment

Choose a reason for hiding this comment

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

Looks good to me. But just to clarify, it now appears that HMC+SDC xforms were applied to multi-echo data not twice, but three times?

@tsalo
Copy link
Collaborator

tsalo commented Aug 14, 2020

The code changes look good (as mentioned in my review), but I did notice that the reports don't seem to have improved. If I look at the ds210 report from this PR and compare it to the one from #2185, the SDC and coregistration sections look exactly the same. Does that make sense?

@effigies
Copy link
Member

It should only be once. We're now passing identity transforms if multi-echo is enabled.

What should be changing in the reports?

@tsalo
Copy link
Collaborator

tsalo commented Aug 14, 2020

Sorry, I mean that I thought the xforms were being applied three times before this fix. Once before T2* estimation, then again in the bold_to_T1w workflow, and then again in the bold_to_std workflow.

I just realized that the bold_to_T1w workflow doesn't feed into the bold_to_std workflow, but the HMC and SDC xforms should still have been applied twice before this fix (once before T2* estimation and once during either bold_to_t1w or bold_to_std, depending on the output), right? I assumed that the reports would show less distortion correction after the fix, possibly solving #2230 (see #2230 (comment)).

Comment on lines +533 to +535
# Already applied in bold_bold_trans_wf, which inputs to bold_t2s_wf
bold_t1_trans_wf.inputs.inputnode.fieldwarp = 'identity'
bold_t1_trans_wf.inputs.inputnode.hmc_xforms = 'identity'
Copy link
Member

Choose a reason for hiding this comment

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

@tsalo HMC and SDC are not being reapplied in bold_t1_trans_wf in the multi-echo case.

Comment on lines +678 to +680
# Already applied in bold_bold_trans_wf, which inputs to bold_t2s_wf
bold_std_trans_wf.inputs.inputnode.fieldwarp = 'identity'
bold_std_trans_wf.inputs.inputnode.hmc_xforms = 'identity'
Copy link
Member

Choose a reason for hiding this comment

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

@tsalo Similarly for bold_std_trans_wf

Copy link
Collaborator

Choose a reason for hiding this comment

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

Because that's the specific issue that this is fixing (i.e., #2236), right? Therefore, distortion correction on multi-echo data should have been exaggerated before the fix and should be better now.

Copy link
Member

Choose a reason for hiding this comment

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

Yes.

@emdupre
Copy link
Collaborator Author

emdupre commented Aug 14, 2020

The data in the reports don't have any fieldmaps collected. I wonder if it's more visible if we compared reports from ME data with fieldmaps ?

@tsalo
Copy link
Collaborator

tsalo commented Aug 14, 2020

@emdupre Possibly, but shouldn't the SyN warp, when applied twice, result in exaggerated distortion correction?

@effigies
Copy link
Member

effigies commented Aug 14, 2020

For the reports, it looks like we show the BOLD reference before and after. Both images are generated pre bold_bold_trans_wf, and so won't reflect any changes to the inputs of any of the *_trans_wfs.

https://github.com/poldracklab/fmriprep/blob/c2228f009af081137b375cb61a9c2d0a98793234/fmriprep/workflows/bold/base.py#L544-L549

@tsalo
Copy link
Collaborator

tsalo commented Aug 14, 2020

Oh okay. That makes sense. Instead of looking at the reports, then, we need to look at the preprocessed data to see if it's better. I downloaded the MNI-space preproc data from both runs and I think the difference is substantial (although not very easy to see without being able to toggle between them in fslview).

Before fix

before_fix

After fix

after_fix

@effigies
Copy link
Member

Agreed. I downloaded them, and I would say the new one looks noticeably less distorted. I'm going to merge, and we can ask @JulioAPeraza to rerun with :unstable once the CI completes.

@effigies effigies merged commit af7194a into nipreps:master Aug 14, 2020
@tsalo
Copy link
Collaborator

tsalo commented Aug 16, 2020

@JulioAPeraza, it looks like nipreps/niworkflows#556 is preventing the DockerHub build from passing, so you may need to wait until that's fixed before you can test this change.

HippocampusGirl added a commit to HippocampusGirl/fmriprep that referenced this pull request Sep 16, 2020
20.2.0 RC0 (September 04, 2020)

With this third minor release series of 2020,
the first *fMRIPrep LTS* (*long-term support*) is finally here!

This release contains a number of bug-fixes and enhancements mostly
related to easing the maintenance, anticipating patch-release breaking
changes to ensure a longstanding LTS, and addressing some run-to-run
repeatability problems of the CompCor implementation.

Thank you for using *fMRIPrep*!
If you encounter any issues with this release, please let us know
by posting an issue on our GitHub page!

A full list of changes can be found below.

* FIX: Revise the reproducibility of CompCor masks (nipreps#2130)
* FIX: Simplify transform aggregation in resampling, pass identity transforms for multi-echo cases (nipreps#2239)
* FIX: Skip the T1w check if ``--anat-derivatives`` is provided. (nipreps#2201)
* FIX: Storing ``--bids-filters`` within config file (nipreps#2177)
* FIX: Revise multi-echo reference generation, permitting using SBRefs too (nipreps#1803)
* FIX: FreeSurfer license manipulation & canary
* ENH: Output CompCor masks if ``--debug compcor`` is passed (nipreps#2248)
* ENH: Conform to BIDS Derivatives as of BIDS 1.4.0 (nipreps#2223)
* ENH: Reuse config (nipreps#2240)
* ENH: Save BOLD-anatomical transforms to derivatives folder (nipreps#2233)
* ENH: Leverage BIDSLayout's ``database_path`` (nipreps#2203)
* ENH: Add ``--no-tty`` option to ``fmriprep-docker.py`` (nipreps#2204)
* ENH: Report number of echoes in BOLD summary. (nipreps#2184)
* ENH: Ensure NiPype telemetry is just pinged once (nipreps#2168)
* DOC: Update reference in "Refinement of Brain Mask" description (nipreps#2215)
* DOC: List *TemplateFlow* templates that need to be prefetched (nipreps#2196)
* DOC: Update references to https://github.com/nipreps (nipreps#2191)
* DOC: Pin NiPype with new Sphinx extension syntax (nipreps#2092)
* MAINT: Track nipreps#2252 from 20.1.x series (nipreps#2253)
* MAINT: Silence PyBIDS warning by setting extension mode (nipreps#2250)
* MAINT: Drop CircleCI docs build (nipreps#2247)
* MAINT: Pin latest *NiPreps* (nipreps#2244)
* MAINT: Update ``setup.cfg`` (flake8 and pytest) (nipreps#2183)
* MAINT: Delete release-drafter (nipreps#2169)
* MAINT: Track bug-fix release on the 20.1.x series (nipreps#2165)
* MAINT: Remove auto-comment bot (nipreps#2166)
* MAINT: Improve the questions on the bug-report template (nipreps#2158)
HippocampusGirl added a commit to HippocampusGirl/fmriprep that referenced this pull request Sep 16, 2020
20.2.0rc1

With this third minor release series of 2020,
the first *fMRIPrep LTS* (*long-term support*) is finally here!

This release contains a number of bug-fixes and enhancements mostly
related to easing the maintenance, anticipating patch-release breaking
changes to ensure a longstanding LTS, and addressing some run-to-run
repeatability problems of the CompCor implementation.

.. admonition:: Long-Term Support (LTS)

    *fMRIPrep* 20.2 LTS introduces the `long-term support program
    <https://www.nipreps.org/devs/releases/#long-term-support-series>`__.
    This LTS version will be kindly steered and maintained by
    the group of Dr. Basile Pinsard and Prof. Pierre Bellec at
    `CRIUGM <http://www.criugm.qc.ca/>`__, (Université de Montréal).
    The LTS is planned for a window of 4 years of support (i.e., until
    September 2024).

.. caution::

    As with all minor version increments, working directories
    from previous versions **should not be reused**.

Thank you for using *fMRIPrep*!
If you encounter any issues with this release, please let us know
by posting an issue on our GitHub page!

A full list of changes can be found below.

* FIX: Get missing ``probseg`` file from MNI152NLin2009cAsym (nipreps#2271)
* FIX: Restore ``--ignore t2w/flair`` options (nipreps#2260)
* FIX: Revise the reproducibility of *CompCor* masks (nipreps#2130)
* FIX: Simplify transform aggregation in resampling, pass identity transforms for multi-echo cases (nipreps#2239)
* FIX: Skip the T1w check if ``--anat-derivatives`` is provided. (nipreps#2201)
* FIX: Storing ``--bids-filters`` within config file (nipreps#2177)
* FIX: Revise multi-echo reference generation, permitting using SBRefs too (nipreps#1803)
* FIX: *FreeSurfer* license manipulation & canary
* ENH: Output CompCor masks if ``--debug compcor`` is passed (nipreps#2248)
* ENH: Conform to BIDS Derivatives as of BIDS 1.4.0 (nipreps#2223)
* ENH: Reuse config (nipreps#2240)
* ENH: Save BOLD-anatomical transforms to derivatives folder (nipreps#2233)
* ENH: Leverage BIDSLayout's ``database_path`` (nipreps#2203)
* ENH: Add ``--no-tty`` option to ``fmriprep-docker.py`` (nipreps#2204)
* ENH: Report number of echoes in BOLD summary. (nipreps#2184)
* ENH: Ensure *NiPype* telemetry is just pinged once (nipreps#2168)
* DOC: Add FAQ entry for using pre-indexed layouts (nipreps#2256)
* DOC: Update reference in "Refinement of Brain Mask" description (nipreps#2215)
* DOC: List *TemplateFlow* templates that need to be prefetched (nipreps#2196)
* DOC: Update references to https://github.com/nipreps (nipreps#2191)
* DOC: Pin *NiPype* with new Sphinx extension syntax (nipreps#2092)
* MAINT: Track nipreps#2269 and nipreps#2269, bug-fixes on the 20.1.x series
* MAINT: Remove derivatives from layout index ignores (nipreps#2258)
* MAINT: Track nipreps#2252 from 20.1.x series (nipreps#2253)
* MAINT: Silence *PyBIDS* warning by setting extension mode (nipreps#2250)
* MAINT: Drop CircleCI docs build (nipreps#2247)
* MAINT: Pin latest *NiPreps* (nipreps#2244)
* MAINT: Update ``setup.cfg`` (flake8 and pytest) (nipreps#2183)
* MAINT: Delete release-drafter (nipreps#2169)
* MAINT: Track bug-fix release on the 20.1.x series (nipreps#2165)
* MAINT: Remove auto-comment bot (nipreps#2166)
* MAINT: Improve the questions on the bug-report template (nipreps#2158)

.. admonition:: Author list for papers based on *fMRIPrep* 20.2 LTS series

    As described in the `Contributor Guidelines
    <https://www.nipreps.org/community/CONTRIBUTING/#recognizing-contributions>`__,
    anyone listed as developer or contributor may write and submit manuscripts
    about *fMRIPrep*.
    To do so, please move the author(s) name(s) to the front of the following list:

    Markiewicz, Christopher J. \ :sup:`1`\ ; Goncalves, Mathias \ :sup:`1`\ ; DuPre, Elizabeth \ :sup:`2`\ ; Kent, James D. \ :sup:`3`\ ; Salo, Taylor \ :sup:`4`\ ; Ciric, Rastko \ :sup:`1`\ ; Pinsard, Basile \ :sup:`5`\ ; Finc, Karolina \ :sup:`6`\ ; de la Vega, Alejandro \ :sup:`7`\ ; Feingold, Franklin \ :sup:`1`\ ; Tooley, Ursula A. \ :sup:`8`\ ; Benson, Noah C. \ :sup:`9`\ ; Urchs, Sebastian \ :sup:`2`\ ; Blair, Ross W. \ :sup:`1`\ ; Erramuzpe, Asier \ :sup:`10`\ ; Lurie, Daniel J. \ :sup:`11`\ ; Heinsfeld, Anibal S. \ :sup:`12`\ ; Jacoby, Nir \ :sup:`13`\ ; Jamison, Keith W. \ :sup:`14`\ ; Frederick, Blaise B. \ :sup:`15, 16`\ ; Valabregue, Romain \ :sup:`17`\ ; Sneve, Markus H. \ :sup:`18`\ ; Liem, Franz \ :sup:`19`\ ; Adebimpe, Azeez \ :sup:`20`\ ; Velasco, Pablo \ :sup:`21`\ ; Wexler, Joseph B. \ :sup:`1`\ ; Groen, Iris I. A. \ :sup:`22`\ ; Ma, Feilong \ :sup:`23`\ ; Amlien, Inge K. \ :sup:`18`\ ; Bellec, Pierre \ :sup:`5`\ ; Cieslak, Matthew \ :sup:`20`\ ; Devenyi, Grabriel A. \ :sup:`24`\ ; Ghosh, Satrajit S. \ :sup:`25, 26`\ ; Gomez, Daniel E. P. \ :sup:`27`\ ; Halchenko, Yaroslav O. \ :sup:`23`\ ; Isik, Ayse Ilkay \ :sup:`28`\ ; Moodie, Craig A. \ :sup:`1`\ ; Naveau, Mikaël \ :sup:`29`\ ; Rivera-Dompenciel, Adriana \ :sup:`3`\ ; Satterthwaite, Theodore D. \ :sup:`20`\ ; Sitek, Kevin R. \ :sup:`30`\ ; Stojić, Hrvoje \ :sup:`31`\ ; Thompson, William H. \ :sup:`1`\ ; Wright, Jessey \ :sup:`1`\ ; Ye, Zhifang \ :sup:`32`\ ; Gorgolewski, Krzysztof J. \ :sup:`1`\ ; Poldrack, Russell A. \ :sup:`1`\ ; Esteban, Oscar \ :sup:`33`\ .

    Affiliations:

      1. Department of Psychology, Stanford University
      2. Montreal Neurological Institute, McGill University
      3. Neuroscience Program, University of Iowa
      4. Department of Psychology, Florida International University
      5. SIMEXP Lab, CRIUGM, University of Montréal, Montréal, Canada
      6. Centre for Modern Interdisciplinary Technologies, Nicolaus Copernicus University in Toruń
      7. University of Texas at Austin
      8. Department of Neuroscience, University of Pennsylvania, PA, USA
      9. Department of Psychology, New York University
      10. Computational Neuroimaging Lab, BioCruces Health Research Institute
      11. Department of Psychology, University of California, Berkeley
      12. Child Mind Institute
      13. Department of Psychology, Columbia University
      14. Department of Radiology, Weill Cornell Medicine
      15. McLean Hospital Brain Imaging Center, MA, USA
      16. Consolidated Department of Psychiatry, Harvard Medical School, MA, USA
      17. CENIR, INSERM U1127, CNRS UMR 7225, UPMC Univ Paris 06 UMR S 1127, Institut du Cerveau et de la Moelle épinière, ICM, F-75013, Paris, France
      18. Center for Lifespan Changes in Brain and Cognition, University of Oslo
      19. URPP Dynamics of Healthy Aging, University of Zurich
      20. Perelman School of Medicine, University of Pennsylvania, PA, USA
      21. Center for Brain Imaging, New York University
      22. Department of Psychology, New York University, NY, USA
      23. Dartmouth College: Hanover, NH, United States
      24. Department of Psychiatry, McGill University
      25. McGovern Institute for Brain Research, MIT, MA, USA
      26. Department of Otolaryngology, Harvard Medical School, MA, USA
      27. Donders Institute for Brain, Cognition and Behaviour, Radboud University Nijmegen
      28. Max Planck Institute for Empirical Aesthetics
      29. Cyceron, UMS 3408 (CNRS - UCBN), France
      30. Speech & Hearing Bioscience & Technology Program, Harvard University
      31. Max Planck UCL Centre for Computational Psychiatry and Ageing Research, University College London
      32. State Key Laboratory of Cognitive Neuroscience and Learning, Beijing Normal University
      33. Department of Radiology, CHUV, Université de Lausanne
@tsalo tsalo added the me-epi label Dec 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bold_t1_trans_wf connection for ME-EPI inputs MNI composite transformation on optimally combine multi-echo data
5 participants