Description
What happened?
Hi,
I am attempting to run anat-only preprocessing on a participant using NiBabies v25.1.0 in a Singularity container. The input dataset is BIDS-compliant, and both T1w and T2w images are present.
The workflow proceeds normally through the initial anatomical stages and confirms that existing segmentations and brain masks are found. However, the pipeline fails right after reaching ANAT Stage 5b: Concatenating normalization for ['MNI152NLin6Asym'], without producing any further output. The run terminates with:
--- An Error occurred when running NiBabies. ---
No traceback or additional context is provided, making it difficult to determine what exactly went wrong at this stage. I've attached the script and full log output for reference.
What command did you use?
#!/usr/bin/env python3
from pathlib import Path
from subprocess import Popen, PIPE, check_output
import argparse
import shlex
import shutil
import os
hostname = check_output("hostname", shell=True).decode().strip()
bids_dir = Path("/mnt/nfs/proj/opc/MRI/data/bibsnet_input")
derivatives_dir = Path("/mnt/nfs/proj/opc/MRI/data/bibsnet_output_nibabies")
bibsnet_dir = Path("/mnt/nfs/proj/opc/MRI/data/bibsnet_output/bibsnet")
nibabies_dir = derivatives_dir
rawdata_dir = bids_dir
nibabies_img = Path("/mnt/nfs/labs/Howell/Software/nibabies/nibabies_25.1.0.sif")
fs_license = Path("/mnt/nfs/proj/ineind/freesurfer/license.txt")
work_dir = Path("/mnt/nfs/proj/opc/MRI/data/nibabies_work")
def run_subprocess_cmd(cmd, error_msg=None):
print("--- running subprocess ---")
print(" ".join(cmd))
with Popen(cmd, stdout=PIPE, stderr=PIPE) as p:
while p.poll() is None:
for line in p.stdout:
print(line.decode(), end="")
if p.poll() != 0:
raise RuntimeError("subprocess ended in a non-zero exit code")
return
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-sub", type=str, required=True, help="The subject ID (ex. sub-5004, the subject ID is 5004)")
parser.add_argument("-ses", type=str, required=True, help="The session ID (ex. ses-022123, the session ID is 022123)")
parser.add_argument("-age_months", type=int, required=True, help="The subject's age in months (ex. 0 or 1 or 2 ...)")
parser.add_argument("-anat_only", action="store_true", help="Add this flag if you only want to run the anatomical workflow of NiBabies")
args, unknown_args = parser.parse_known_args()
sub_work_dir = work_dir / f"sub-{args.sub}_ses-{args.ses}"
fs_source_data = nibabies_dir / "sourcedata" / "freesurfer" / f"sub-{args.sub}_ses-{args.ses}"
mcrib_source_data = nibabies_dir / "sourcedata" / "mcribs" / f"sub-{args.sub}_ses-{args.ses}"
sub_nibabies_dir = nibabies_dir / f"sub-{args.sub}/ses-{args.ses}/"
sub_nibabies_html = nibabies_dir / f"sub-{args.sub}_ses-{args.ses}.html"
for old_outputs in [sub_work_dir, fs_source_data, mcrib_source_data, sub_nibabies_dir, sub_nibabies_html]:
if old_outputs.exists():
if old_outputs.is_dir():
shutil.rmtree(old_outputs)
else:
os.remove(old_outputs)
sub_work_dir.mkdir(parents=True, exist_ok=True)
mni_infant_cohort = 1
if args.age_months <= 2:
mni_infant_cohort = 1
elif args.age_months <= 5:
mni_infant_cohort = 2
elif args.age_months <= 8:
mni_infant_cohort = 3
else:
print("Please check the '-age_months' argument and try again")
exit(1)
nibabies_cmd = f"""apptainer run --cleanenv
-B {rawdata_dir.resolve()}:/data:ro
-B {nibabies_dir.resolve()}:/out
-B {fs_license.resolve()}:/opt/freesurfer/license.txt:ro
-B {bibsnet_dir.resolve()}:/seg
-B {sub_work_dir.resolve()}:/work
{nibabies_img}
/data /out participant -vv
--participant-label {args.sub} --session-id {args.ses}
-w /work
--fs-license-file /opt/freesurfer/license.txt
--derivatives /seg
{'--anat-only' if args.anat_only else ''}
--age-months {args.age_months}
--surface-recon-method mcribs
--cifti-output 91k
--debug registration
--project-goodvoxels
--multi-step-reg
--norm-csf
--output-spaces fsLR MNIInfant:cohort-{mni_infant_cohort} MNI152NLin6Asym:res-2 T2w
--omp-nthreads 8
--mem 300000
--nprocs 8
--stop-on-first-crash
{' '.join(unknown_args)}
"""
nibabies_cmd = shlex.split(nibabies_cmd)
try:
run_subprocess_cmd(nibabies_cmd)
print(f"--- NiBabies complete for sub-{args.sub} ses-{args.ses} ---")
except:
print("--- An Error occurred when running NiBabies. ---\n--- Check your inputs and try again ---")
print("--- DONE! ---")
What version of NiBabies are you using?
NiBabies 25.1.0 in Singularity Container
Relevant log output
[mgcollin19@turing-cnode19 bibsnet]$ python run_nibabies.py -sub 231109 -ses 2wk -age_months 0 --anat-only
--- running subprocess ---
apptainer run --cleanenv -B /mnt/nfs/proj/opc/MRI/data/bibsnet_input:/data:ro -B /mnt/nfs/proj/opc/MRI/data/bibsnet_output_nibabies:/out -B /mnt/nfs/proj/ineind/freesurfer/license.txt:/opt/freesurfer/license.txt:ro -B /mnt/nfs/proj/opc/MRI/data/bibsnet_output/bibsnet:/seg -B /mnt/nfs/proj/opc/MRI/data/nibabies_work/sub-231109_ses-2wk:/work /mnt/nfs/labs/Howell/Software/nibabies/nibabies_25.1.0.sif /data /out participant -vv --participant-label 231109 --session-id 2wk -w /work --fs-license-file /opt/freesurfer/license.txt --derivatives /seg --age-months 0 --surface-recon-method mcribs --cifti-output 91k --debug registration --project-goodvoxels --multi-step-reg --norm-csf --output-spaces fsLR MNIInfant:cohort-1 MNI152NLin6Asym:res-2 T2w --omp-nthreads 8 --mem 300000 --nprocs 8 --stop-on-first-crash --anat-only
250717-13:32:13,680 cli INFO:
Making sure the input data is BIDS compliant (warnings can be ignored in most cases).
[email protected]
This dataset appears to be BIDS compatible.
Summary: Available Tasks: Available Modalities:
57 Files, 315.97MB MRI
6 - Subjects
2 - Sessions
If you have any questions, please post on https://neurostars.org/tags/bids.
250717-13:32:23,965 nipype.workflow IMPORTANT:
Running nibabies version 25.1.0:
* BIDS dataset path: /data.
* Participant list: [['231109', '2wk']].
* Run identifier: 20250717-133151_2b34bfa6-7c2e-45e6-950a-a324615b4bea.
* Output spaces: fsLR MNIInfant:cohort-1:res-native MNI152NLin6Asym:res-2 T2w.
* Derivatives: {'seg': PosixPath('/seg')}.
* Pre-run FreeSurfer's SUBJECTS_DIR: /out/sourcedata/freesurfer.
250717-13:32:34,70 nipype.workflow INFO:
Collected the following data for sub-231109_ses-2wk:
Raw:
{'asl': [],
'bold': [],
'dwi': [],
'flair': [],
'fmap': [],
'pet': [],
'roi': [],
'sbref': [],
't1w': ['/data/sub-231109/ses-2wk/anat/sub-231109_ses-2wk_run-02_T1w.nii.gz'],
't2w': ['/data/sub-231109/ses-2wk/anat/sub-231109_ses-2wk_run-08_T2w.nii.gz']}
Derivatives:
{'t1w_aseg': '/seg/sub-231109/ses-2wk/anat/sub-231109_ses-2wk_space-T1w_desc-aseg_dseg.nii.gz',
't1w_mask': '/seg/sub-231109/ses-2wk/anat/sub-231109_ses-2wk_space-T1w_desc-brain_mask.nii.gz',
't2w_aseg': '/seg/sub-231109/ses-2wk/anat/sub-231109_ses-2wk_space-T2w_desc-aseg_dseg.nii.gz',
't2w_mask': '/seg/sub-231109/ses-2wk/anat/sub-231109_ses-2wk_space-T2w_desc-brain_mask.nii.gz',
'transforms': {}}
250717-13:32:34,296 nipype.workflow INFO:
ANAT: Using T2w as the reference anatomical
250717-13:32:34,441 nipype.workflow INFO:
ANAT Stage 1: Adding T1w template workflow
250717-13:32:34,445 nipype.workflow INFO:
ANAT Stage 1: Adding T2w template workflow
250717-13:32:34,448 nipype.workflow INFO:
ANAT Found T1w brain mask
250717-13:32:34,449 nipype.workflow INFO:
ANAT Skipping skull-strip, INU-correction only
250717-13:32:34,815 nipype.workflow INFO:
ANAT Found T2w brain mask
250717-13:32:34,816 nipype.workflow INFO:
ANAT Skipping skull-strip, INU-correction only
250717-13:32:34,817 nipype.workflow INFO:
ANAT Coregistering anatomicals
250717-13:32:34,824 nipype.workflow INFO:
ANAT Found precomputed anatomical segmentation
250717-13:32:34,825 nipype.workflow INFO:
ANAT Stage 4: Tissue segmentation
250717-13:32:34,826 nipype.workflow INFO:
ANAT Segmentation: Using existing segmentation
250717-13:32:34,832 nipype.workflow INFO:
ANAT Stage 5b: Concatenating normalization for ['MNI152NLin6Asym']
--- An Error occurred when running NiBabies. ---
--- Check your inputs and try again ---
--- DONE! ---
Add any additional information or context about the problem here.
No response