Skip to content

Commit

Permalink
Make M0 TR optional for BASIL.
Browse files Browse the repository at this point in the history
  • Loading branch information
tsalo committed Sep 20, 2023
1 parent f4e4ebd commit 634edbb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
12 changes: 9 additions & 3 deletions aslprep/interfaces/cbf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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(),
Expand Down
8 changes: 6 additions & 2 deletions aslprep/workflows/asl/cbf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")]),
Expand All @@ -482,6 +481,9 @@ def _getfiledir(file):
])
# fmt:on

if metadata["M0Type"] != "Estimate":
workflow.connect([(extract_deltam, basilcbf, [("m0tr", "m0tr")])])

return workflow


Expand Down Expand Up @@ -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")]),
Expand All @@ -849,6 +850,9 @@ def _getfiledir(file):
])
# fmt:on

if metadata["M0Type"] != "Estimate":
workflow.connect([(extract_deltam, basilcbf, [("m0tr", "m0tr")])])

return workflow


Expand Down

0 comments on commit 634edbb

Please sign in to comment.