Skip to content

Commit 0a0e306

Browse files
committed
only calculate delta_ratio for EchoTime if phasediff type fmap
1 parent 930022b commit 0a0e306

File tree

1 file changed

+41
-38
lines changed

1 file changed

+41
-38
lines changed

CPAC/utils/datasource.py

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ def calc_delta_te_and_asym_ratio(
449449
return deltaTE, ees_asym_ratio
450450

451451

452-
def gather_echo_times(echotime_1, echotime_2=None, echotime_3=None, echotime_4=None):
452+
def gather_echo_times(echotime_1, echotime_2, echotime_3=None, echotime_4=None):
453453
"""Gather the echo times from the field map data."""
454454
echotime_list = [echotime_1, echotime_2, echotime_3, echotime_4]
455455
echotime_list = list(filter(lambda item: item is not None, echotime_list))
@@ -693,23 +693,16 @@ def ingress_func_metadata(
693693
"fmap_readout_ingress",
694694
)
695695

696-
if "phase" in key or "mag" in key:
696+
# Only consider it "diff" if it's not a spin-echo or EPI-based fmap
697+
if (
698+
("phase" in key or "phasediff" in key)
699+
and not any(style in key.lower() for style in ["spin", "se", "epi"])
700+
):
697701
diff = True
698-
699702
if re.match("epi_[AP]{2}", orig_key):
700703
blip = True
701704

702705
if diff:
703-
calc_delta_ratio = pe.Node(
704-
Function(
705-
input_names=["effective_echo_spacing", "echo_times"],
706-
output_names=["deltaTE", "ees_asym_ratio"],
707-
function=calc_delta_te_and_asym_ratio,
708-
imports=["from typing import Optional"],
709-
),
710-
name=f"diff_distcor_calc_delta{name_suffix}",
711-
)
712-
713706
gather_echoes = pe.Node(
714707
Function(
715708
input_names=[
@@ -733,7 +726,42 @@ def ingress_func_metadata(
733726
except KeyError:
734727
pass
735728

729+
calc_delta_ratio = pe.Node(
730+
Function(
731+
input_names=["effective_echo_spacing", "echo_times"],
732+
output_names=["deltaTE", "ees_asym_ratio"],
733+
function=calc_delta_te_and_asym_ratio,
734+
imports=["from typing import Optional"],
735+
),
736+
name=f"diff_distcor_calc_delta{name_suffix}",
737+
)
738+
736739
wf.connect(gather_echoes, "echotime_list", calc_delta_ratio, "echo_times")
740+
741+
# Connect EffectiveEchoSpacing from functional metadata
742+
rpool.set_data(
743+
"effectiveEchoSpacing",
744+
scan_params,
745+
"effective_echo_spacing",
746+
{},
747+
"",
748+
"func_metadata_ingress",
749+
)
750+
node, out_file = rpool.get("effectiveEchoSpacing")[
751+
"['effectiveEchoSpacing:func_metadata_ingress']"
752+
]["data"]
753+
wf.connect(node, out_file, calc_delta_ratio, "effective_echo_spacing")
754+
rpool.set_data(
755+
"deltaTE", calc_delta_ratio, "deltaTE", {}, "", "deltaTE_ingress"
756+
)
757+
rpool.set_data(
758+
"ees-asym-ratio",
759+
calc_delta_ratio,
760+
"ees_asym_ratio",
761+
{},
762+
"",
763+
"ees_asym_ratio_ingress",
764+
)
737765

738766
# Add in nodes to get parameters from configuration file
739767
# a node which checks if scan_parameters are present for each scan
@@ -805,31 +833,6 @@ def ingress_func_metadata(
805833
"pe-direction", scan_params, "pe_direction", {}, "", "func_metadata_ingress"
806834
)
807835

808-
if diff:
809-
# Connect EffectiveEchoSpacing from functional metadata
810-
rpool.set_data(
811-
"effectiveEchoSpacing",
812-
scan_params,
813-
"effective_echo_spacing",
814-
{},
815-
"",
816-
"func_metadata_ingress",
817-
)
818-
node, out_file = rpool.get("effectiveEchoSpacing")[
819-
"['effectiveEchoSpacing:func_metadata_ingress']"
820-
]["data"]
821-
wf.connect(node, out_file, calc_delta_ratio, "effective_echo_spacing")
822-
rpool.set_data(
823-
"deltaTE", calc_delta_ratio, "deltaTE", {}, "", "deltaTE_ingress"
824-
)
825-
rpool.set_data(
826-
"ees-asym-ratio",
827-
calc_delta_ratio,
828-
"ees_asym_ratio",
829-
{},
830-
"",
831-
"ees_asym_ratio_ingress",
832-
)
833836

834837
return wf, rpool, diff, blip, fmap_rp_list
835838

0 commit comments

Comments
 (0)