Skip to content

Commit 7efc8c9

Browse files
authored
Merge pull request #409 from mgxd/tst/workflow-construction
TST: Build workflow across different conditions
2 parents 8cc8db2 + e5124cc commit 7efc8c9

File tree

7 files changed

+462
-45
lines changed

7 files changed

+462
-45
lines changed

nibabies/data/tests/config.toml

+28-39
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,67 @@
11
[environment]
22
cpu_count = 8
3-
exec_docker_version = "20.10.12"
4-
exec_env = "nibabies-docker"
5-
free_mem = 0.4
3+
exec_env = "posix"
4+
free_mem = 2.2
65
overcommit_policy = "heuristic"
76
overcommit_limit = "50%"
8-
nipype_version = "1.6.1"
9-
templateflow_version = "0.7.2"
10-
version = "21.1.0"
7+
nipype_version = "1.5.0"
8+
templateflow_version = "24.2.2"
9+
version = "24.1.0"
1110

1211
[execution]
13-
bids_dir = "/data"
14-
bids_database_dir = "/tmp/bids_db"
15-
bids_description_hash = "c47e9ebb943ca662556808b2aeac3f6c8bb2a242696c32850c64ec47aba80d9e"
12+
bids_dir = "ds000005/"
13+
bids_description_hash = "5d42e27751bbc884eca87cb4e62b9a0cca0cd86f8e578747fe89b77e6c5b21e5"
1614
boilerplate_only = false
17-
sloppy = true
18-
debug = []
19-
derivatives = [ "/opt/derivatives/precomputed",]
2015
fs_license_file = "/opt/freesurfer/license.txt"
21-
fs_subjects_dir = "/opt/subjects"
22-
layout = "BIDS Layout: .../data | Subjects: 1 | Sessions: 1 | Runs: 1"
23-
log_dir = "/tmp/logs"
24-
log_level = 20
16+
fs_subjects_dir = "/opt/freesurfer/subjects"
17+
log_dir = "/tmp/fmriprep/logs"
18+
log_level = 40
2519
low_mem = false
2620
md_only_boilerplate = false
27-
nibabies_dir = "/out"
28-
notrack = false
29-
output_dir = "/out"
30-
me_output_echos = false
31-
output_layout = "bids"
32-
output_spaces = "MNIInfant:cohort-1:res-native"
21+
notrack = true
22+
output_dir = "/tmp"
23+
output_spaces = "MNIInfant:cohort-1"
3324
reports_only = false
34-
run_uuid = "20220323-202555_01a7d80d-7ff4-4b13-a99c-ec399045e9ff"
35-
segmentation_atlases_dir = "/opt/segmentations"
25+
run_uuid = "20200306-105302_d365772b-fd60-4741-a722-372c2f558b50"
3626
participant_label = [ "01",]
37-
templateflow_home = "/home/nibabies/.cache/templateflow"
38-
work_dir = "/scratch"
27+
templateflow_home = "~/.cache/templateflow"
28+
work_dir = "work/"
3929
write_graph = false
4030

4131
[workflow]
4232
anat_only = false
43-
bold2t1w_dof = 6
44-
bold2t1w_init = "register"
45-
cifti_output = false
33+
bold2anat_dof = 6
4634
fd_radius = 45
4735
fmap_bspline = false
4836
force_syn = false
4937
hires = true
50-
ignore = [ "slicetiming",]
38+
ignore = []
5139
longitudinal = false
5240
medial_surface_nan = false
5341
project_goodvoxels = false
5442
regressors_all_comps = false
5543
regressors_dvars_th = 1.5
5644
regressors_fd_th = 0.5
57-
run_reconall = true
5845
skull_strip_fixed_seed = false
5946
skull_strip_template = "UNCInfant:cohort-1"
60-
skull_strip_t1w = "force"
61-
slice_time_ref = 0.5
62-
spaces = "MNIInfant:cohort-1:res-native MNIInfant:cohort-1"
63-
use_bbr = false
64-
use_syn_sdc = false
47+
surface_recon_method = "auto"
6548

6649
[nipype]
6750
crashfile_format = "txt"
6851
get_linked_libs = false
69-
memory_gb = 8
70-
nprocs = 4
71-
omp_nthreads = 2
52+
memory_gb = 32
53+
nprocs = 8
54+
omp_nthreads = 8
7255
plugin = "MultiProc"
7356
resource_monitor = false
7457
stop_on_first_crash = false
7558

7659
[nipype.plugin_args]
7760
maxtasksperchild = 1
7861
raise_insufficient = false
62+
63+
[execution.bids_filters.t1w]
64+
reconstruction = "<Query.NONE: 1>"
65+
66+
[execution.bids_filters.t2w]
67+
reconstruction = "<Query.NONE: 1>"

nibabies/utils/bids.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ def parse_bids_for_age_months(
236236

237237
# Play nice with sessions
238238
subject = f'sub-{subject_id}'
239-
session = f'ses-{session_id}' or ''
240-
prefix = f'{subject}' + f'_{session}' if session else ''
239+
session = f'ses-{session_id}' if session_id else ''
240+
prefix = f'{subject}' + (f'_{session}' if session else '')
241241

242242
subject_level = session_level = Path(bids_root) / subject
243243
if session_id:

nibabies/workflows/anatomical/fit.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ def init_infant_anat_fit_wf(
940940

941941
workflow.__desc__ = desc
942942

943-
if not recon_method:
943+
if recon_method is None:
944944
LOGGER.info('ANAT Skipping Stages 6+')
945945
return workflow
946946

@@ -1765,6 +1765,10 @@ def init_infant_single_anat_fit_wf(
17651765

17661766
workflow.__desc__ = desc
17671767

1768+
if recon_method is None:
1769+
LOGGER.info('ANAT Skipping Stages 5+')
1770+
return workflow
1771+
17681772
# Stage 5: Surface reconstruction
17691773
if recon_method == 'mcribs':
17701774
if reference_anat == 'T1w':

nibabies/workflows/base.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,13 @@
7070
from bids.layout import BIDSLayout
7171
from niworkflows.utils.spaces import SpatialReferences
7272

73+
SubjectSession = tuple[str, str | None]
74+
7375

7476
AUTO_T2W_MAX_AGE = 8
7577

7678

77-
def init_nibabies_wf(subworkflows_list):
79+
def init_nibabies_wf(subworkflows_list: list[SubjectSession]):
7880
"""
7981
Build *NiBabies*'s pipeline.
8082
@@ -92,7 +94,7 @@ def init_nibabies_wf(subworkflows_list):
9294
from nibabies.workflows.tests import mock_config
9395
from nibabies.workflows.base import init_nibabies_wf
9496
with mock_config():
95-
wf = init_nibabies_wf()
97+
wf = init_nibabies_wf(['01', None])
9698
9799
Parameters
98100
----------

nibabies/workflows/bold/registration.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ def init_fsl_bbr_wf(
603603
flt_bbr.inputs.schedule = data.load('flirtsch/bbr.sch')
604604
# fmt:off
605605
workflow.connect([
606-
(inputnode, wm_mask, [('t1w_dseg', 'in_seg')]),
606+
(inputnode, wm_mask, [('anat_dseg', 'in_seg')]),
607607
(inputnode, flt_bbr, [('in_file', 'in_file')]),
608608
(lta_to_fsl, flt_bbr, [('out_fsl', 'in_matrix_file')]),
609609
])

nibabies/workflows/tests/__init__.py

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
2+
# vi: set ft=python sts=4 ts=4 sw=4 et:
3+
#
4+
# Copyright The NiPreps Developers <[email protected]>
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
# We support and encourage derived works from this project, please read
19+
# about our expectations at
20+
#
21+
# https://www.nipreps.org/community/licensing/
22+
#
23+
"""Utilities and mocks for testing and documentation building."""
24+
25+
import os
26+
import shutil
27+
from contextlib import contextmanager
28+
from pathlib import Path
29+
from tempfile import mkdtemp
30+
31+
from toml import loads
32+
33+
from nibabies import data
34+
from nibabies.workflows.base import init_execution_spaces
35+
36+
37+
@contextmanager
38+
def mock_config(bids_dir=None):
39+
"""Create a mock config for documentation and testing purposes."""
40+
from ... import config
41+
42+
_old_fs = os.getenv('FREESURFER_HOME')
43+
if not _old_fs:
44+
os.environ['FREESURFER_HOME'] = mkdtemp()
45+
46+
settings = loads(data.load.readable('tests/config.toml').read_text())
47+
for sectionname, configs in settings.items():
48+
if sectionname != 'environment':
49+
section = getattr(config, sectionname)
50+
section.load(configs, init=False)
51+
config.nipype.omp_nthreads = 1
52+
config.nipype.init()
53+
config.loggers.init()
54+
init_execution_spaces()
55+
56+
bids_dir = bids_dir or data.load('tests/ds000005').absolute()
57+
58+
config.execution.work_dir = Path(mkdtemp())
59+
config.execution.bids_dir = bids_dir
60+
config.execution.nibabies_dir = Path(mkdtemp())
61+
config.execution.bids_database_dir = None
62+
config.execution._layout = None
63+
config.execution.init()
64+
65+
yield
66+
67+
shutil.rmtree(config.execution.work_dir)
68+
shutil.rmtree(config.execution.nibabies_dir)
69+
70+
if not _old_fs:
71+
del os.environ['FREESURFER_HOME']

0 commit comments

Comments
 (0)