Skip to content

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

@scott-huberty

Description

@scott-huberty

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.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions