4040)
4141from xcp_d .utils .doc import fill_doc
4242from xcp_d .utils .modified_data import calculate_exact_scans , flag_bad_run
43- from xcp_d .utils .utils import estimate_brain_radius , is_number
43+ from xcp_d .utils .utils import _create_mem_gb , estimate_brain_radius , is_number
4444from xcp_d .workflows .anatomical .parcellation import init_parcellate_surfaces_wf
4545from xcp_d .workflows .anatomical .surface import init_postprocess_surfaces_wf
4646from xcp_d .workflows .anatomical .volume import init_postprocess_anat_wf
@@ -116,7 +116,7 @@ def init_single_subject_wf(subject_id: str, anat_session: str, func_sessions: li
116116 from xcp_d.workflows.base import init_single_subject_wf
117117
118118 with mock_config():
119- wf = init_single_subject_wf("01", "01 ", ["01 "])
119+ wf = init_single_subject_wf("01", "", [""])
120120
121121 Parameters
122122 ----------
@@ -517,6 +517,8 @@ def init_single_subject_wf(subject_id: str, anat_session: str, func_sessions: li
517517 }
518518
519519 n_processed_task_runs = 0
520+ concat_bold_gb = 0
521+ concat_volume_gb = 0
520522 for j_run , bold_file in enumerate (task_files ):
521523 run_data = collect_run_data (
522524 layout = config .execution .layout ,
@@ -568,6 +570,14 @@ def init_single_subject_wf(subject_id: str, anat_session: str, func_sessions: li
568570 bold_file = bold_file ,
569571 )
570572
573+ # Compute memory estimates from the BOLD file header
574+ mem_gbx = _create_mem_gb (bold_file )
575+
576+ # Accumulate memory estimates for the concatenation workflow.
577+ # The concatenated file will be the sum of all runs.
578+ concat_bold_gb += mem_gbx ['bold' ]
579+ concat_volume_gb = max (concat_volume_gb , mem_gbx ['volume' ])
580+
571581 postprocess_bold_wf = init_postprocess_bold_wf (
572582 bold_file = bold_file ,
573583 head_radius = head_radius ,
@@ -577,6 +587,7 @@ def init_single_subject_wf(subject_id: str, anat_session: str, func_sessions: li
577587 n_runs = n_runs ,
578588 has_multiple_runs = multiscans ,
579589 exact_scans = exact_scans ,
590+ mem_gb = mem_gbx ,
580591 name = f'postprocess_{ run_counter } _wf' ,
581592 )
582593 run_counter += 1
@@ -621,9 +632,14 @@ def init_single_subject_wf(subject_id: str, anat_session: str, func_sessions: li
621632 ]) # fmt:skip
622633
623634 if config .workflow .combine_runs and (n_processed_task_runs > 0 ) and multiscans :
635+ concat_mem_gb = {
636+ 'bold' : concat_bold_gb ,
637+ 'volume' : concat_volume_gb ,
638+ }
624639 concatenate_data_wf = init_concatenate_data_wf (
625640 TR = TR ,
626641 head_radius = head_radius ,
642+ mem_gb = concat_mem_gb ,
627643 name = f'concatenate_entity_set_{ ent_set } _wf' ,
628644 )
629645
0 commit comments