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

24.0.0rc fails with 'MNIInfant not found in SpatialReferences if cifti-output flag not used #375

Closed
scott-huberty opened this issue Aug 5, 2024 · 4 comments · Fixed by #377
Assignees
Labels
bug Something isn't working

Comments

@scott-huberty
Copy link
Contributor

scott-huberty commented Aug 5, 2024

EDIT: Edited this message on Aug 6th to provide more background info.

Background

#360 by @mgxd Added this function:

def get_MNIInfant_key(spaces: SpatialReferences) -> str:
"""Parse spaces and return matching MNIInfant space, including cohort."""
key = None
for space in spaces.references:
# str formats as <reference.name>:<reference.spec>
if 'MNIInfant' in str(space) and 'res-native' not in str(space):
key = str(space)
break
if key is None:
raise KeyError(f'MNIInfant not found in SpatialReferences: {spaces}')
return key

Used here:

if 'MNIInfant' in [ref.space for ref in spaces.references]:
select_MNIInfant_xfm = pe.Node(
KeySelect(
fields=['anat2std_xfm', 'std2anat_xfm'],
key=get_MNIInfant_key(spaces),
),
name='select_MNIInfant_xfm',
run_without_submitting=True,
)


The Problem

If config.execution.output_spaces is None (which I believe is the default value), then Nibabies will add MNIInfant:cohort-1:res-native at this LOC:

if not spaces.references:
# Ensure age specific template is added if nothing is present
cohort = cohort_by_months('MNIInfant', age_months)
spaces.add(('MNIInfant', {'res': 'native', 'cohort': cohort}))

Thenget_MNIInfant_key will throw an error on that exact value that Nibabies just added on Line 830.... I.e.. for release candidate 24.0.0rc, a lot of my files that ran without issue on 23.1.0 now always hit the error:

KeyError: 'MNIInfant not found in SpatialReferences: Spatial References: MNIInfant:cohort-1:res-native'

Full Stack Trace
Traceback (most recent call last):
  File "/opt/conda/envs/nibabies/bin/nibabies", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/opt/conda/envs/nibabies/lib/python3.11/site-packages/nibabies/cli/run.py", line 62, in main
    retval = build_workflow(config_file)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/nibabies/lib/python3.11/site-packages/nibabies/cli/workflow.py", line 76, in build_workflow
    retval['workflow'] = init_nibabies_wf(config.execution.unique_labels)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/nibabies/lib/python3.11/site-packages/nibabies/workflows/base.py", line 147, in init_nibabies_wf
    single_subject_wf = init_single_subject_wf(
                        ^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/nibabies/lib/python3.11/site-packages/nibabies/workflows/base.py", line 521, in init_single_subject_wf
    key=get_MNIInfant_key(spaces),
        ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/nibabies/lib/python3.11/site-packages/nibabies/workflows/base.py", line 963, in get_MNIInfant_key
    raise KeyError(f'MNIInfant not found in SpatialReferences: {spaces}')
KeyError: 'MNIInfant not found in SpatialReferences: Spatial References: MNIInfant:cohort-1:res-native'

  • This error isn't very helpful because 1) MNIInfant is in Spatial References, and 2) there's no further info on what should be changed.

  • I checked locally, and on 23.1.0, the value of my Spatial Reference is the same: MNIInfant:cohort-1:res-native. The only difference on 24.0.0rc seems to be that this new function, get_MNIInfant_key forces an error on this value.

  • If I modify the function to accept this value, then things seems to run okay again. But I'd like to understand what get_MNIInfant_key really expects before I submit a PR for what I presume to be a bug.

@mgxd
Copy link
Collaborator

mgxd commented Aug 6, 2024

IIRC, this was to deal with the MNIInfant -> MNI152NLin6Asym transformation required for CIFTI outputs, since we are using a saved transform from a 1x1x1 isotropic version of each. My guess is you aren't using the --cifti-output flag, hence running into that. Seems like we need to add a check to ensure this is not required if not requesting CIFTI outputs.

@mgxd mgxd added the bug Something isn't working label Aug 6, 2024
@scott-huberty
Copy link
Contributor Author

IIRC, this was to deal with the MNIInfant -> MNI152NLin6Asym transformation required for CIFTI outputs, since we are using a saved transform from a 1x1x1 isotropic version of each. My guess is you aren't using the --cifti-output flag, hence running into that. Seems like we need to add a check to ensure this is not required if not requesting CIFTI outputs.

Yeah you are exactly right. I can confirm that I was not using the --cifti-output flag, and if I do use it, I don't hit the error.

@scott-huberty scott-huberty changed the title 24.0.0rc no longer accepts a space that 23.1.0 accepted,but gives no further info. 24.0.0rc fails with 'MNIInfant not found in SpatialReferences if cifti-output flag not used Aug 6, 2024
@mgxd
Copy link
Collaborator

mgxd commented Aug 6, 2024

@scott-huberty do you want to submit a PR? otherwise i can address this

@scott-huberty
Copy link
Contributor Author

@scott-huberty do you want to submit a PR? otherwise i can address this

Sure! I'll give it a shot. Feel free to assign me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants