Skip to content

Commit 352b044

Browse files
committed
👔 Reorient mri_robust_template outputs
1 parent 1604b4f commit 352b044

File tree

3 files changed

+40
-14
lines changed

3 files changed

+40
-14
lines changed

CPAC/longitudinal/robust_template.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# Copyright (C) 2024 C-PAC Developers
2+
# Copyright (C) 2024-2025 C-PAC Developers
33

44
# This file is part of C-PAC.
55

@@ -146,7 +146,11 @@ def mri_robust_template(
146146
MRIConvert(), name="NIfTI-mapmov", iterfield=["in_file", "out_file"]
147147
)
148148
wf.connect(node, "mapmov", nifti_outputs, "in_file")
149-
nifti_outputs.set_input(
149+
reorient_outputs = cfg.orientation_node(
150+
"reorient_longitudinal_template", pe.MapNode
151+
)
152+
wf.connect(nifti_outputs, "out_file", reorient_outputs, "in_file")
153+
reorient_outputs.set_input(
150154
"out_file", [f"space-longitudinal{i + 1}.nii.gz" for i in range(num_sessions)]
151155
)
152156

CPAC/utils/configuration/configuration.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818

1919
import os
2020
import re
21-
from typing import Any, cast, Literal, Optional
21+
from typing import Any, cast, Literal, Optional, overload
2222
from warnings import warn
2323

2424
from click import BadParameter
2525
import pkg_resources as p
2626
import yaml
2727

28-
from CPAC.pipeline.nipype_pipeline_engine import Node
28+
from CPAC.pipeline.nipype_pipeline_engine import MapNode, Node
2929
from .diff import dct_diff
3030

3131
CONFIG_KEY_TYPE = str | list[str]
@@ -640,15 +640,21 @@ def key_type_error(self, key):
640640
)
641641
)
642642

643-
def orientation_node(self, name: str) -> Node:
643+
@overload
644+
def orientation_node(self, name: str, node_type: type[MapNode]) -> MapNode: ...
645+
@overload
646+
def orientation_node(self, name: str, node_type: type[Node]) -> Node: ...
647+
def orientation_node(
648+
self, name: str, node_type: type[Node | MapNode]
649+
) -> Node | MapNode:
644650
"""Return a node configured to resample an input with AFNI 3dresample."""
645651
from CPAC.utils.nifti_utils import orientation_node
646652

647653
orientation = cast(
648654
Literal["RPI", "LPI", "RAI", "LAI", "RAS", "LAS", "RPS", "LPS"],
649655
self["pipeline_setup", "desired_orientation"],
650656
)
651-
return orientation_node(name=name, orientation=orientation)
657+
return orientation_node(name=name, orientation=orientation, node_type=node_type)
652658

653659

654660
def check_pname(p_name: str, pipe_config: Configuration) -> str:

CPAC/utils/nifti_utils.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"""Utlities for NIfTI images."""
1818

1919
import os
20-
from typing import Literal
20+
from typing import Literal, overload
2121

2222
import numpy as np
2323
import nibabel as nib
@@ -99,17 +99,33 @@ def inverse_nifti_values(image):
9999
return nib.nifti1.Nifti1Image(out_data, img.affine)
100100

101101

102+
@overload
102103
def orientation_node(
103104
name: str,
104105
orientation: Literal["RPI", "LPI", "RAI", "LAI", "RAS", "LAS", "RPS", "LPS"],
105-
) -> pe.Node:
106+
node_type: type[pe.MapNode],
107+
) -> pe.MapNode: ...
108+
@overload
109+
def orientation_node(
110+
name: str,
111+
orientation: Literal["RPI", "LPI", "RAI", "LAI", "RAS", "LAS", "RPS", "LPS"],
112+
node_type: type[pe.Node],
113+
) -> pe.Node: ...
114+
def orientation_node(
115+
name: str,
116+
orientation: Literal["RPI", "LPI", "RAI", "LAI", "RAS", "LAS", "RPS", "LPS"],
117+
node_type: type[pe.Node | pe.MapNode],
118+
) -> pe.Node | pe.MapNode:
106119
"""Return a node configured to resample an input with AFNI 3dresample."""
107-
return pe.Node(
108-
interface=afni_utils.Resample(
120+
kwargs = {
121+
"interface": afni_utils.Resample(
109122
orientation=orientation,
110123
outputtype="NIFTI_GZ",
111124
),
112-
name=name,
113-
mem_gb=0,
114-
mem_x=(0.0115, "in_file", "t"),
115-
)
125+
"name": name,
126+
"mem_gb": 0,
127+
"mem_x": (0.0115, "in_file", "t"),
128+
}
129+
if node_type == pe.MapNode:
130+
kwargs["iterfield"] = "in_file"
131+
return node_type(**kwargs)

0 commit comments

Comments
 (0)