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

ENH: fsLR output space, cifti output in HCP grayordinate space #1887

Merged
merged 35 commits into from
Dec 11, 2019

Conversation

mgxd
Copy link
Collaborator

@mgxd mgxd commented Nov 27, 2019

Closes #1537, #1673

Changes proposed in this pull request

  • Adds fsLR support to --output-spaces, which involves a two step resample (first to fsaverage:den-164, then to fsLR:den-<den>) [Incomplete implementation of fsLR output space #1673]
    • possible densities (32k (default), 59k, 164k)
  • CIFTI output when using --cifti-output is now compliant with HCP grayordinate space (cortex in fsLR, subcortical in MNI152NLin6Asym)
    • this is now the default variant, and will be anytime fsLR is specified in output-spaces
    • support for legacy variants (fsaverage5/6, MNI152NLin2009cAsym) has been removed
  • Reassigns the space tag to the cifti output, with the new default as space-fsLR and the old behavior as space-fMRIPrep
  • Adds option of specifying CIFTI grayordinates to flag --cifti-output [grayordinates]
    • default is set to 91k (2mm resolution), 170k is also supported (1.6mm)
    • directly affects the fsLR surface density (91k corresponds to 32k surfaces, 170k to 59k

Blocking

@auto-comment
Copy link

auto-comment bot commented Nov 27, 2019

Thank your for raising your pull request.

Some of the fMRIPRep maintainers will review your changes as soon as time permits.
I'm attaching below a Review Checklist for the reviewers, to copy and paste
it in their review comment.

## PR Review

*Please check off boxes as applicable, and elaborate in comments below.  Your review is not limited to these topics, as described in the reviewer guide*

- [ ] As the reviewer I confirm that there are no conflicts of interest for me to review this work.

Please check what applies in the following aspects of the PR:

#### Code documentation

- [ ] New functions and modules are documented following the guidelines.
- [ ] Existing code required amendments in documentation and has been updated.
- [ ] Sufficient inline comments ensure readability by other contributors in the long term.

#### Documentation site

- [ ] The modifications to *fMRIPrep* in this PR **do not require extra documentation**. This is a common situation when a bug fix that does not change the code base substantially is submitted.
- [ ] This PR requires documentation. The corresponding documentation will be submitted as an additional PR in the future.
- [ ] This PR requires extra documentation, and will be included within this PR. Please check the boxes that apply best:
  - [ ] An existing feature is substantially modified, changing the interface and/or logic of a module.
  - [ ] A new feature is being added, therefore full documentation of it will be included
  - [ ] This PR addresses an error in existing documentation.
- [ ] Yes, all expected sections of documentation were generated by the CI build, and look as expected

#### Tests

- [ ] The new functionalities in this PR are covered by the existing tests
- [ ] New test batteries have been included with this PR

#### Data

- [ ] This PR does not require any additional data to be uploaded to OSF.
- [ ] This PR requires additional data for tests.

#### Dependencies: smriprep

- [ ] This PR does not require any update on `smriprep`; or
- [ ] `smriprep` has correctly been pinned.

#### Dependencies: niworkflows

- [ ] This PR does not require any update on `niworkflows`; or
- [ ] `niworkflows` has correctly been pinned.

#### Dependencies: sdcflows

- [ ] This PR does not require any update on `sdcflows`; or
- [ ] `sdcflows` has correctly been pinned.

#### Dependencies: Nipype

- [ ] This PR does not require any update on `nipype`; or
- [ ] `nipype` has correctly been pinned.

#### Dependencies: other

- [ ] This PR does not require any update on other dependencies; or
- [ ] other dependencies have correctly been pinned.

#### Reports generated within CI tests

- [ ] Yes, I have checked the reports of ds005 and they are not modified or the changes are as expected
- [ ] Yes, I have checked the reports of ds054 and they are not modified or the changes are as expected
- [ ] Yes, I have checked the reports of ds010 and they are not modified or the changes are as expected

### Review Comments (other than those left inline with the code)

@mgxd mgxd requested review from oesteban and effigies November 27, 2019 18:20
@mgxd
Copy link
Collaborator Author

mgxd commented Nov 27, 2019

One concern I wanted to raise: because we are resampling the BOLD timeseries to high-res fsaverage before going to fsLR this can result in much larger than expected output directories.

A few ideas of how to address this (would love to hear what others think):

  • Don't and just let users remove it on their own
  • Default to internally removing them if fsaverage is omitted in the --output-spaces command line
  • Add some flag (--minimal-cifti-output?) to signal internal removal

Copy link
Member

@oesteban oesteban left a comment

Choose a reason for hiding this comment

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

Outstanding work :)

Had a quick first pass. Let's get this done!

fmriprep/cli/run.py Outdated Show resolved Hide resolved
fmriprep/workflows/bold/base.py Outdated Show resolved Hide resolved
fmriprep/workflows/bold/base.py Outdated Show resolved Hide resolved
fmriprep/workflows/bold/base.py Outdated Show resolved Hide resolved
fmriprep/workflows/bold/base.py Outdated Show resolved Hide resolved
@oesteban
Copy link
Member

  • Default to internally removing them if fsaverage is omitted in the --output-spaces command line

See #1892, this is exactly the kind of question that issue is raising. I think this is the way to go (not dumping anything to the output folder unless it is explicitly listed in --output-spaces regardless whether fMRIPrep needs it internally or not.

Copy link
Member

@oesteban oesteban left a comment

Choose a reason for hiding this comment

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

Very close!

fmriprep/sub-01/func/sub-01_task-mixedgamblestask_run-01_desc-confounds_regressors.json
fmriprep/sub-01/func/sub-01_task-mixedgamblestask_run-01_desc-confounds_regressors.tsv
fmriprep/sub-01/func/sub-01_task-mixedgamblestask_run-01_desc-MELODIC_mixing.tsv
fmriprep/sub-01/func/sub-01_task-mixedgamblestask_run-01_space-fMRIPrep_bold.dtseries.json
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't this be

Suggested change
fmriprep/sub-01/func/sub-01_task-mixedgamblestask_run-01_space-fMRIPrep_bold.dtseries.json
fmriprep/sub-01/func/sub-01_task-mixedgamblestask_run-01_space-fsaverage_den-10k_bold.dtseries.json

?

Copy link
Member

Choose a reason for hiding this comment

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

Related question: how much time would add to run this with --output-spaces fsLR <...> --cifti-outputs?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

does space-fsaverage imply subcortical structures in MNI152NLin2009cAsym?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

not sure exactly how long, the biggest addon would be resampling to fsaverage:164k (resampling to fsLR is fairly quick). Would also spike the size of outputs, as BOLD in fsaverage is fairly big.

If this sounds reasonable, I can add it in

@@ -923,10 +924,12 @@ def init_func_preproc_wf(
# SURFACES ##################################################################################
surface_spaces = [space for space in output_spaces.keys() if space.startswith('fs')]
if freesurfer and surface_spaces:
fslr_density = output_spaces.get('fsLR', {}).get('den', '32k')
Copy link
Member

Choose a reason for hiding this comment

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

We'll need to address #1895 if we want this to work.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i've opened nipreps/smriprep#145 - since that isn't exclusive to this I'll submit a fix separate from this. A quick workaround is to specify at least one parameter for fsLR/fsaverage

Copy link
Member

@oesteban oesteban left a comment

Choose a reason for hiding this comment

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

@pep8speaks
Copy link

pep8speaks commented Dec 5, 2019

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 2019-12-11 05:40:01 UTC

@oesteban
Copy link
Member

oesteban commented Dec 7, 2019

I guess nipreps/niworkflows#436 and #1906 are the blockers now - correct?

@oesteban
Copy link
Member

oesteban commented Dec 7, 2019

@mgxd please check my conflict resolution 5645707

I have added some details

@mgxd mgxd added the api-change label Dec 7, 2019
@mgxd
Copy link
Collaborator Author

mgxd commented Dec 7, 2019

yes, we'll need to get nipreps/niworkflows#436 in and cut a new release before merging this.

Copy link
Member

@oesteban oesteban left a comment

Choose a reason for hiding this comment

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

This is almost there. I left a comment about the UX, which interacts with #1892

docs/outputs.rst Outdated Show resolved Hide resolved
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.

This will require a minor version increment.

automatically added to the list of output spaces (option ``--output-space``).""", file=stderr)
if opts.cifti_output:
grayords = {'91k': '32k', '170k': '59k'} # CIFTI total grayords to surface densities
output_spaces['fsLR'] = {'den': grayords[opts.cifti_output]}
Copy link
Member

Choose a reason for hiding this comment

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

Do you really want to force GIFTI outputs if you're having CIFTI outputs? If they're not explicitly asking for it, it's a lot of duplicated output.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

that's how we are currently handling CIFTIs, i.e. fsaverage5/6 surfaces are always produced atm.

I hope to get this functionality in, and then address the inherent problem after (#1892)

Copy link
Member

Choose a reason for hiding this comment

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

Okay.

if 'fsLR' in output_spaces:
output_spaces['fsLR'] = {'den': output_spaces.get('fsLR', {}).get('den') or '32k'}
# resample to fsLR from highest density fsaverage
output_spaces['fsaverage'] = {'den': '164k'}
Copy link
Member

Choose a reason for hiding this comment

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

Similarly, now asking for CIFTIs in fsLR means that I'm also getting GIFTI outputs in fsaverage space.

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, see above

@@ -940,26 +946,37 @@ def init_func_preproc_wf(
*Grayordinates* files [@hcppipelines], which combine surface-sampled
data and volume-sampled data, were also generated.
"""
cifti_volume = "MNI152NLin6Asym" if 'fsLR' in cifti_spaces else "MNI152NLin2009cAsym"
Copy link
Member

Choose a reason for hiding this comment

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

I thought they used an FSL-packaged (and slightly weird) version of the template. Do we need to account for that?

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 are using the same labelled MNI template the HCP folks use to generate the CIFTIs, which should be in same space as the template - what do you mean by slightly weird?

Copy link
Member

Choose a reason for hiding this comment

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

I might be misremembering. During the TemplateFlow changeover we switched from using FSL's packaged template (MNI152NLin2009cAsym) to MNI's, and there were some differences. I thought using FSL's distribution was something we'd copied from HCP. @oesteban will probably know better.

Copy link
Member

@oesteban oesteban Dec 11, 2019

Choose a reason for hiding this comment

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

I thought they used an FSL-packaged (and slightly weird) version of the template. Do we need to account for that?

The "MNI" distributed with FSL is an unofficial version created by A. Janke with the same data and methodology of the official MNI152NLin6Sym atlas. We called this variant MNI152NLin6Asym in TemplateFlow, although it is not an official MNI template.

Then, the HCP folks resampled the 1mm^3 grid to different resolutions that seem useful to them. We originally placed these files under the fsLR ID in TemplateFlow. @mgxd refactored TemplateFlow and moved them to their (more proper) place in MNI152NLin6Asym.

During the TemplateFlow changeover, we did not switch from the official, latest MNI template (MNI152NLin2009cAsym) to MNI's (I guess you were referring to MNI152NLin6Asym). What really happened is that some submodules (and particularly, ICA-AROMA) stopped using the MNI152NLin2009cAsym template. After the changeover, if you set --ica-aroma then the MNI152NLin6Asym is added to the output-spaces list because ICA-AROMA was originally trained on that space.

Hopefully, this clarifies the spotty connections between TemplateFlow, the "MNI" template(s) and this PR.

@effigies
Copy link
Member

Apologies if my comments recapitulate earlier arguments. I haven't been following this PR closely.

@mgxd
Copy link
Collaborator Author

mgxd commented Dec 11, 2019

@oesteban any other concerns?

@oesteban oesteban merged commit 63a661b into nipreps:master Dec 11, 2019
@mgxd mgxd deleted the enh/cifti-hcp branch December 11, 2019 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sampling HCP-compatible CIfTIs
4 participants