From 20098de4155321c59d1e37586812007a2b533ede Mon Sep 17 00:00:00 2001 From: Taylor Salo Date: Fri, 26 Jul 2024 14:54:32 -0400 Subject: [PATCH 1/4] Draft some stuff. --- fmriprep/config.py | 9 +++++++-- fmriprep/workflows/bold/base.py | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/fmriprep/config.py b/fmriprep/config.py index 6ba0ae1c..5bc3d35b 100644 --- a/fmriprep/config.py +++ b/fmriprep/config.py @@ -815,8 +815,13 @@ def init_spaces(checkpoint=True): # Ensure user-defined spatial references for outputs are correctly parsed. # Certain options require normalization to a space not explicitly defined by users. # These spaces will not be included in the final outputs. - cifti_output = workflow.cifti_output - if cifti_output: + if spaces.get_spaces(cifti=True): + # Figure out the surface spaces and volume spaces we need + cifti_spaces = spaces.get_spaces(cifti=True) + for cifti_space in cifti_spaces: + surface_space = cifti_space + volume_space = cifti_space + # CIFTI grayordinates to corresponding FSL-MNI resolutions. vol_res = '2' if cifti_output == '91k' else '1' spaces.add(Reference('MNI152NLin6Asym', {'res': vol_res})) diff --git a/fmriprep/workflows/bold/base.py b/fmriprep/workflows/bold/base.py index e37692f0..dbc9c740 100644 --- a/fmriprep/workflows/bold/base.py +++ b/fmriprep/workflows/bold/base.py @@ -695,7 +695,7 @@ def init_bold_wf( name='carpetplot_wf', ) - if config.workflow.cifti_output: + if spaces.get_spaces(cifti=True): workflow.connect( bold_grayords_wf, 'outputnode.cifti_bold', carpetplot_wf, 'inputnode.cifti_bold', ) # fmt:skip From 0d11df8d28e8af89a7882ae559ba6b975ad55a9b Mon Sep 17 00:00:00 2001 From: Taylor Salo Date: Tue, 6 Aug 2024 09:27:21 -0400 Subject: [PATCH 2/4] Update config.py --- fmriprep/config.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/fmriprep/config.py b/fmriprep/config.py index 5bc3d35b..31107991 100644 --- a/fmriprep/config.py +++ b/fmriprep/config.py @@ -815,9 +815,18 @@ def init_spaces(checkpoint=True): # Ensure user-defined spatial references for outputs are correctly parsed. # Certain options require normalization to a space not explicitly defined by users. # These spaces will not be included in the final outputs. - if spaces.get_spaces(cifti=True): + if cifti_output == '91k': + spaces.add( + Reference('fsLR', {'den': '32k', 'volspace': 'MNI152NLin6Asym', 'volres': '2'}) + ) + elif cifti_output == '170k': + spaces.add( + Reference('fsLR', {'den': '32k', 'volspace': 'MNI152NLin6Asym', 'volres': '1'}) + ) + + if spaces.get_spaces(cifti=(True,)): # Figure out the surface spaces and volume spaces we need - cifti_spaces = spaces.get_spaces(cifti=True) + cifti_spaces = spaces.get_standard(cifti=(True,)) for cifti_space in cifti_spaces: surface_space = cifti_space volume_space = cifti_space From b8e292de0b522bed071aad7a391fdb810133b824 Mon Sep 17 00:00:00 2001 From: Taylor Salo Date: Tue, 6 Aug 2024 09:33:55 -0400 Subject: [PATCH 3/4] Parse CIFTI space names. --- fmriprep/config.py | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/fmriprep/config.py b/fmriprep/config.py index 31107991..cc0363a0 100644 --- a/fmriprep/config.py +++ b/fmriprep/config.py @@ -815,25 +815,34 @@ def init_spaces(checkpoint=True): # Ensure user-defined spatial references for outputs are correctly parsed. # Certain options require normalization to a space not explicitly defined by users. # These spaces will not be included in the final outputs. - if cifti_output == '91k': - spaces.add( - Reference('fsLR', {'den': '32k', 'volspace': 'MNI152NLin6Asym', 'volres': '2'}) - ) - elif cifti_output == '170k': - spaces.add( - Reference('fsLR', {'den': '32k', 'volspace': 'MNI152NLin6Asym', 'volres': '1'}) - ) + cifti_output = workflow.cifti_output + if cifti_output: + # CIFTI grayordinates to corresponding FSL-MNI resolutions. + res = '2' if cifti_output == '91k' else '1' + den = '32k' if cifti_output == '91k' else '59k' + spaces.add(Reference('fsLR', {'den': den, 'volspace': 'MNI152NLin6Asym', 'volres': res})) if spaces.get_spaces(cifti=(True,)): # Figure out the surface spaces and volume spaces we need - cifti_spaces = spaces.get_standard(cifti=(True,)) + cifti_spaces = spaces.get_standard(cifti=(True,)) + spaces.get_nonstandard(cifti=(True,)) for cifti_space in cifti_spaces: - surface_space = cifti_space - volume_space = cifti_space - - # CIFTI grayordinates to corresponding FSL-MNI resolutions. - vol_res = '2' if cifti_output == '91k' else '1' - spaces.add(Reference('MNI152NLin6Asym', {'res': vol_res})) + # The surface space + spaces.add( + Reference( + cifti_space.space, + {k: v for k, v in cifti_space.spec.items() if not k.startswith('vol')}, + ), + ) + # The volume space + spaces.add( + Reference( + cifti_space.spec['volspace'], + { + k: v for k, v in cifti_space.spec.items() + if (k.startswith('vol') and k != 'volspace') + }, + ), + ) # Make the SpatialReferences object available workflow.spaces = spaces From ae23fc8db7755725692e8b50456381cb10f9b58f Mon Sep 17 00:00:00 2001 From: Taylor Salo Date: Tue, 6 Aug 2024 09:39:39 -0400 Subject: [PATCH 4/4] Update base.py --- fmriprep/workflows/bold/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fmriprep/workflows/bold/base.py b/fmriprep/workflows/bold/base.py index dbc9c740..6f7f429a 100644 --- a/fmriprep/workflows/bold/base.py +++ b/fmriprep/workflows/bold/base.py @@ -695,7 +695,7 @@ def init_bold_wf( name='carpetplot_wf', ) - if spaces.get_spaces(cifti=True): + if spaces.get_spaces(cifti=(True,)): workflow.connect( bold_grayords_wf, 'outputnode.cifti_bold', carpetplot_wf, 'inputnode.cifti_bold', ) # fmt:skip