Skip to content

Commit 4f9132e

Browse files
committed
TST: Reflect configuration output spaces change in test
1 parent 51106b2 commit 4f9132e

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

nibabies/tests/test_config.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,8 @@ def test_config_spaces():
6666
section.load(configs, init=False)
6767
config.nipype.init()
6868
config.loggers.init()
69-
config.init_spaces()
70-
71-
spaces = config.workflow.spaces
69+
age = 8
70+
spaces = _load_spaces(age)
7271
assert "MNI152NLin6Asym:res-2" not in [str(s) for s in spaces.get_standard(full_spec=True)]
7372

7473
assert "MNI152NLin6Asym_res-2" not in [
@@ -78,8 +77,7 @@ def test_config_spaces():
7877
]
7978

8079
config.workflow.use_aroma = True
81-
config.init_spaces()
82-
spaces = config.workflow.spaces
80+
spaces = _load_spaces(age)
8381

8482
assert "MNI152NLin6Asym:res-2" in [str(s) for s in spaces.get_standard(full_spec=True)]
8583

@@ -91,25 +89,17 @@ def test_config_spaces():
9189

9290
config.execution.output_spaces = None
9391
config.workflow.use_aroma = False
94-
config.workflow.age_months = None
95-
config.init_spaces()
96-
spaces = config.workflow.spaces
9792

98-
assert [str(s) for s in spaces.get_standard(full_spec=True)] == []
99-
assert [
100-
format_reference((s.fullname, s.spec))
101-
for s in spaces.references
102-
if s.standard and s.dim == 3
103-
] == []
93+
with pytest.raises(RuntimeError):
94+
spaces = _load_spaces(None)
10495

10596
config.execution.output_spaces = None
10697
config.workflow.cifti_output = "91k"
10798
config.workflow.use_aroma = False
108-
config.workflow.age_months = 1
109-
config.init_spaces()
110-
spaces = config.workflow.spaces
99+
spaces = _load_spaces(1)
111100

112101
assert [str(s) for s in spaces.get_standard(full_spec=True)] == [
102+
'MNIInfant:cohort-1:res-native', # Default output space
113103
'fsaverage:den-164k',
114104
'MNI152NLin6Asym:res-2',
115105
]
@@ -118,7 +108,7 @@ def test_config_spaces():
118108
format_reference((s.fullname, s.spec))
119109
for s in spaces.references
120110
if s.standard and s.dim == 3
121-
] == ['MNI152NLin6Asym_res-2', 'MNIInfant_cohort-1']
111+
] == ['MNIInfant_cohort-1_res-native', 'MNI152NLin6Asym_res-2', 'MNIInfant_cohort-1']
122112
_reset_config()
123113

124114

@@ -138,3 +128,11 @@ def test_prng_seed(master_seed, ants_seed, numpy_seed):
138128
_reset_config()
139129
for seed in ('_random_seed', 'master', 'ants', 'numpy'):
140130
assert getattr(config.seeds, seed) is None
131+
132+
133+
def _load_spaces(age):
134+
from nibabies.workflows.base import init_execution_spaces, init_workflow_spaces
135+
136+
# Conditional based on workflow necessities
137+
spaces = init_workflow_spaces(init_execution_spaces(), age)
138+
return spaces

nibabies/workflows/base.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ def _prefix(subid):
554554
return subid if subid.startswith("sub-") else f"sub-{subid}"
555555

556556

557-
def init_workflow_spaces(execution_spaces, age):
557+
def init_workflow_spaces(execution_spaces, age_months):
558558
"""
559559
Create output spaces at a per-subworkflow level.
560560
@@ -566,9 +566,12 @@ def init_workflow_spaces(execution_spaces, age):
566566

567567
spaces = deepcopy(execution_spaces)
568568

569+
if age_months is None:
570+
raise RuntimeError("Participant age (in months) is required.")
571+
569572
if not spaces.references:
570573
# Ensure age specific template is added if nothing is present
571-
cohort = cohort_by_months("MNIInfant", age)
574+
cohort = cohort_by_months("MNIInfant", age_months)
572575
spaces.add(("MNIInfant", {"res": "native", "cohort": cohort}))
573576

574577
if not spaces.is_cached():
@@ -587,7 +590,7 @@ def init_workflow_spaces(execution_spaces, age):
587590
spaces.add(Reference("fsaverage", {"den": "164k"}))
588591
spaces.add(Reference("MNI152NLin6Asym", {"res": vol_res}))
589592
# Ensure a non-native version of MNIInfant is added as a target
590-
cohort = cohort_by_months("MNIInfant", age)
593+
cohort = cohort_by_months("MNIInfant", age_months)
591594
spaces.add(Reference("MNIInfant", {"cohort": cohort}))
592595

593596
return spaces

0 commit comments

Comments
 (0)