From 634edbbfbbf2b5c35b6dd93962f6a8ec0c5ce586 Mon Sep 17 00:00:00 2001 From: Taylor Salo Date: Wed, 20 Sep 2023 09:22:02 -0400 Subject: [PATCH] Make M0 TR optional for BASIL. --- aslprep/interfaces/cbf.py | 12 +++++++++--- aslprep/workflows/asl/cbf.py | 8 ++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/aslprep/interfaces/cbf.py b/aslprep/interfaces/cbf.py index 2935dfd15..14cf37719 100644 --- a/aslprep/interfaces/cbf.py +++ b/aslprep/interfaces/cbf.py @@ -192,18 +192,24 @@ def _run_interface(self, runtime): control_img = smooth_image(control_img, fwhm=self.inputs.fwhm).get_fdata() m0data = mask_data * np.mean(control_img, axis=3) + # Use the control volumes' TR as the M0 TR. + if np.array(metadata["RepetitionTimePreparation"]).size > 1: + m0tr = np.array(metadata["RepetitionTimePreparation"])[control_volume_idx[0]] + else: + m0tr = metadata["RepetitionTimePreparation"] + elif cbf_volume_idx: # If we have precalculated CBF data, we don't need M0, so we'll just use the mask. m0data = mask_data + m0tr = None + else: raise RuntimeError( "m0scan is absent, " "and there are no control volumes that can be used as a substitute" ) - m0tr = None - else: raise RuntimeError("no pathway to m0scan") @@ -823,7 +829,7 @@ class _BASILCBFInputSpec(FSLCommandInputSpec): m0tr = traits.Float( desc="The repetition time for the calibration image (the M0 scan).", argstr="--tr %.2f", - mandatory=True, + mandatory=False, ) tis = traits.Either( traits.Float(), diff --git a/aslprep/workflows/asl/cbf.py b/aslprep/workflows/asl/cbf.py index 06a466c55..7a803e892 100644 --- a/aslprep/workflows/asl/cbf.py +++ b/aslprep/workflows/asl/cbf.py @@ -466,7 +466,6 @@ def _getfiledir(file): (("m0_file", _getfiledir), "out_basename"), ("out_file", "deltam"), ("m0_file", "mzero"), - ("m0tr", "m0tr"), ]), (determine_bolus_duration, basilcbf, [("bolus", "bolus")]), (determine_inflow_times, basilcbf, [("tis", "tis")]), @@ -482,6 +481,9 @@ def _getfiledir(file): ]) # fmt:on + if metadata["M0Type"] != "Estimate": + workflow.connect([(extract_deltam, basilcbf, [("m0tr", "m0tr")])]) + return workflow @@ -834,7 +836,6 @@ def _getfiledir(file): (inputnode, basilcbf, [ (("asl_mask", _getfiledir), "out_basename"), ("m0_file", "mzero"), - ("m0tr", "m0tr"), ]), (collect_cbf, basilcbf, [("deltam", "deltam")]), (gm_tfm, basilcbf, [("output_image", "gm_tpm")]), @@ -849,6 +850,9 @@ def _getfiledir(file): ]) # fmt:on + if metadata["M0Type"] != "Estimate": + workflow.connect([(extract_deltam, basilcbf, [("m0tr", "m0tr")])]) + return workflow