Skip to content

Commit 9a2abc9

Browse files
committed
ENH: Add new configuration execution input for subject/session groupings
1 parent f7a7ee8 commit 9a2abc9

File tree

2 files changed

+35
-53
lines changed

2 files changed

+35
-53
lines changed

nibabies/cli/parser.py

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -696,20 +696,6 @@ def parse_args(args=None, namespace=None):
696696
config.execution.log_level = int(max(25 - 5 * opts.verbose_count, logging.DEBUG))
697697
config.from_dict(vars(opts))
698698

699-
# Initialize --output-spaces if not defined
700-
if config.execution.output_spaces is None:
701-
from niworkflows.utils.spaces import Reference, SpatialReferences
702-
703-
from ..utils.misc import cohort_by_months
704-
705-
if config.workflow.age_months is None:
706-
parser.error("--age-months must be provided if --output-spaces is not set.")
707-
708-
cohort = cohort_by_months("MNIInfant", config.workflow.age_months)
709-
config.execution.output_spaces = SpatialReferences(
710-
[Reference("MNIInfant", {"res": "native", "cohort": cohort})]
711-
)
712-
713699
# Retrieve logging level
714700
build_log = config.loggers.cli
715701

@@ -831,8 +817,41 @@ def parse_args(args=None, namespace=None):
831817

832818
config.execution.participant_label = sorted(participant_label)
833819
config.workflow.skull_strip_template = config.workflow.skull_strip_template[0]
820+
config.execution.unique_labels = compute_subworkflows()
834821

835822
# finally, write config to file
836823
config_file = config.execution.work_dir / config.execution.run_uuid / "config.toml"
837824
config_file.parent.mkdir(exist_ok=True, parents=True)
838825
config.to_filename(config_file)
826+
827+
828+
def compute_subworkflows() -> list:
829+
"""
830+
Query all available participants and sessions, and construct the combinations of the
831+
subworkflows needed.
832+
"""
833+
from niworkflows.utils.bids import collect_participants
834+
835+
from nibabies import config
836+
837+
# consists of (subject_id, session_id) tuples
838+
subworkflows = []
839+
840+
subject_list = collect_participants(
841+
config.execution.layout,
842+
participant_label=config.execution.participant_label,
843+
strict=True,
844+
)
845+
846+
for subject in subject_list:
847+
# Due to rapidly changing morphometry of the population
848+
# Ensure each subject session is processed individually
849+
sessions = (
850+
config.execution.session_id
851+
or config.execution.layout.get_sessions(scope='raw', subject=subject)
852+
or [None]
853+
)
854+
# grab participant age per session
855+
for session in sessions:
856+
subworkflows.append((subject, session))
857+
return subworkflows

nibabies/config.py

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,8 @@ class execution(_Config):
425425
"""Select a particular task from all available in the dataset."""
426426
templateflow_home = _templateflow_home
427427
"""The root folder of the TemplateFlow client."""
428+
unique_labels = None
429+
"""Combinations of subject + session identifiers to be preprocessed."""
428430
work_dir = Path("work").absolute()
429431
"""Path to a working directory where intermediate results will be available."""
430432
write_graph = False
@@ -581,8 +583,6 @@ class workflow(_Config):
581583
instance keeping standard and nonstandard spaces."""
582584
surface_recon_method = "infantfs"
583585
"""Method to use for surface reconstruction."""
584-
topup_max_vols = 5
585-
"""Maximum number of volumes to use with TOPUP, per-series (EPI or BOLD)."""
586586
use_aroma = None
587587
"""Run ICA-:abbr:`AROMA (automatic removal of motion artifacts)`."""
588588
use_bbr = False
@@ -694,7 +694,6 @@ def load(filename, skip=None):
694694
section = getattr(sys.modules[__name__], sectionname)
695695
ignore = skip.get(sectionname)
696696
section.load(configs, ignore=ignore)
697-
init_spaces()
698697

699698

700699
def get(flat=False):
@@ -729,42 +728,6 @@ def to_filename(filename):
729728
filename.write_text(dumps())
730729

731730

732-
def init_spaces(checkpoint=True):
733-
"""Initialize the :attr:`~workflow.spaces` setting."""
734-
from niworkflows.utils.spaces import Reference, SpatialReferences
735-
736-
spaces = execution.output_spaces or SpatialReferences()
737-
if not isinstance(spaces, SpatialReferences):
738-
spaces = SpatialReferences(
739-
[ref for s in spaces.split(" ") for ref in Reference.from_string(s)]
740-
)
741-
742-
if checkpoint and not spaces.is_cached():
743-
spaces.checkpoint()
744-
745-
# Ensure user-defined spatial references for outputs are correctly parsed.
746-
# Certain options require normalization to a space not explicitly defined by users.
747-
# These spaces will not be included in the final outputs.
748-
if workflow.use_aroma:
749-
# Make sure there's a normalization to FSL for AROMA to use.
750-
spaces.add(Reference("MNI152NLin6Asym", {"res": "2"}))
751-
752-
if workflow.cifti_output:
753-
# CIFTI grayordinates to corresponding FSL-MNI resolutions.
754-
vol_res = "2" if workflow.cifti_output == "91k" else "1"
755-
spaces.add(Reference("fsaverage", {"den": "164k"}))
756-
spaces.add(Reference("MNI152NLin6Asym", {"res": vol_res}))
757-
# Ensure a non-native version of MNIInfant is added as a target
758-
if workflow.age_months is not None:
759-
from .utils.misc import cohort_by_months
760-
761-
cohort = cohort_by_months("MNIInfant", workflow.age_months)
762-
spaces.add(Reference("MNIInfant", {"cohort": cohort}))
763-
764-
# Make the SpatialReferences object available
765-
workflow.spaces = spaces
766-
767-
768731
def _process_initializer(cwd, omp_nthreads):
769732
"""Initialize the environment of the child process."""
770733
os.chdir(cwd)

0 commit comments

Comments
 (0)