Skip to content

Commit 64f2051

Browse files
oestebanjhlegarreta
authored andcommitted
fix: update calls to nitransforms.resampling.apply()
1 parent a929f97 commit 64f2051

File tree

8 files changed

+16
-10
lines changed

8 files changed

+16
-10
lines changed

scripts/optimize_registration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ async def train_coro(
125125

126126
index = i * len(REFERENCES) + j
127127
moving_path = tmp_folder / f"test-{index:04d}.nii.gz"
128-
(~xfm).apply(refnii, reference=refnii).to_filename(moving_path)
128+
nt.resampling.apply(~xfm, refnii, reference=refnii).to_filename(moving_path)
129129

130130
_kwargs = {"output_transform_prefix": f"conversion-{index:04d}", **align_kwargs}
131131

src/nifreeze/data/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import nibabel as nb
3636
import numpy as np
3737
from nitransforms.linear import LinearTransformsMapping
38+
from nitransforms.resampling import apply
3839
from typing_extensions import Self, TypeVarTuple, Unpack
3940

4041
Ts = TypeVarTuple("Ts")
@@ -285,7 +286,7 @@ def to_nifti(
285286
datamoving = nb.Nifti1Image(frame[0], self.affine, self.datahdr)
286287
# resample at index
287288
resampled[..., i] = np.asanyarray(
288-
xform.apply(datamoving, order=order).dataobj,
289+
apply(xform, datamoving, order=order).dataobj,
289290
dtype=self.dataobj.dtype,
290291
)
291292

src/nifreeze/data/pet.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import numpy as np
3636
from nibabel.spatialimages import SpatialImage
3737
from nitransforms.linear import Affine
38+
from nitransforms.resampling import apply
3839
from typing_extensions import Self
3940

4041
from nifreeze.data.base import BaseDataset, _cmp, _data_repr
@@ -137,7 +138,7 @@ def set_transform(self, index: int, affine: np.ndarray, order: int = 3) -> None:
137138

138139
# resample and update orientation at index
139140
self.dataobj[..., index] = np.asanyarray(
140-
xform.apply(dmoving, order=order).dataobj,
141+
apply(xform, dmoving, order=order).dataobj,
141142
dtype=self.dataobj.dtype,
142143
)
143144

src/nifreeze/data/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ def apply_affines(nii, em_affines, output_filename=None):
2828

2929
for ii, bvecnii in enumerate(nb.four_to_three(nii)):
3030
xfms = nt.linear.Affine(em_affines[ii])
31-
transformed_nii[..., ii] = np.asanyarray((~xfms).apply(bvecnii, reference=nii).dataobj)
31+
transformed_nii[..., ii] = np.asanyarray(
32+
nt.resampling.apply(~xfms, bvecnii, reference=nii).dataobj
33+
)
3234

3335
nii_t_img = nii.__class__(transformed_nii, nii.affine, nii.header)
3436

src/nifreeze/registration/ants.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import numpy as np
3636
from nipype.interfaces.ants.registration import Registration
3737
from nitransforms.linear import Affine
38+
from nitransforms.resampling import apply
3839

3940
PARAMETERS_SINGLE_VALUE = {
4041
"collapse_output_transforms",
@@ -494,7 +495,7 @@ def _run_registration(
494495
),
495496
)
496497
# debugging: generate aligned file for testing
497-
xform.apply(moving_path, reference=fixed_path).to_filename(
498+
apply(xform, moving_path, reference=fixed_path).to_filename(
498499
dirname / f"dbg_{vol_idx:05d}.nii.gz"
499500
)
500501

test/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ def motion_data(tmp_path_factory, datadir):
113113
)
114114

115115
# Induce motion into dataset (i.e., apply the inverse transforms)
116-
moved_nii = (~xfms).apply(b0nii, reference=b0nii)
116+
moved_nii = nt.resampling.apply(~xfms, b0nii, reference=b0nii)
117117

118118
# Save the moved dataset for debugging or further processing
119119
moved_path = tmp_path / "test.nii.gz"
120120
ground_truth_path = tmp_path / "ground_truth.nii.gz"
121121
moved_nii.to_filename(moved_path)
122-
xfms.apply(moved_nii).to_filename(ground_truth_path)
122+
nt.resampling.apply(xfms, moved_nii).to_filename(ground_truth_path)
123123

124124
# Wrap into dataset object
125125
dwi_motion = DWI(

test/test_integration.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@ def test_proximity_estimator_trivial_model(motion_data, tmp_path):
4949
)
5050

5151
# Uncomment to see the realigned dataset
52-
nt.linear.LinearTransformsMapping(
52+
xfm = nt.linear.LinearTransformsMapping(
5353
dwi_motion.motion_affines,
5454
reference=b0nii,
55-
).apply(moved_nii).to_filename(tmp_path / "realigned.nii.gz")
55+
)
56+
nt.resampling.apply(xfm, moved_nii).to_filename(tmp_path / "realigned.nii.gz")
5657

5758
# For each moved b0 volume
5859
for i, est in enumerate(dwi_motion.motion_affines):

test/test_registration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_ANTs_config_b0(datadir, tmp_path, dataset, r_x, r_y, r_z, t_x, t_y, t_z
5858
T = from_matvec(euler2mat(x=r_x, y=r_y, z=r_z), (t_x, t_y, t_z))
5959
xfm = nt.linear.Affine(T, reference=b0nii)
6060

61-
(~xfm).apply(b0nii, reference=b0nii).to_filename(moving)
61+
nt.resampling.apply(~xfm, b0nii, reference=b0nii).to_filename(moving)
6262

6363
registration = Registration(
6464
terminal_output="file",

0 commit comments

Comments
 (0)