Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ dependencies = [
"dipy>=1.5.0",
"joblib",
"nipype>=1.5.1,<2.0",
"nitransforms>=22.0.0,<24",
"nitransforms>=25.0.0",
"nireports",
"numpy>=1.21.3",
"nest-asyncio>=1.5.1",
Expand Down
2 changes: 1 addition & 1 deletion scripts/compute_nufo.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def main() -> None:
_, brain_mask = median_otsu(dwi_data, vol_idx=[0])

dwi_data_masked = dwi_data.copy()
dwi_data_masked[~brain_mask, :] = 0
dwi_data_masked[~brain_mask.astype(bool), :] = 0

# Create a CSD model
response, ratio = auto_response_ssst(
Expand Down
2 changes: 1 addition & 1 deletion scripts/optimize_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ async def train_coro(

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

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

Expand Down
3 changes: 2 additions & 1 deletion src/nifreeze/data/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import nibabel as nb
import numpy as np
from nitransforms.linear import LinearTransformsMapping
from nitransforms.resampling import apply
from typing_extensions import Self, TypeVarTuple, Unpack

Ts = TypeVarTuple("Ts")
Expand Down Expand Up @@ -265,7 +266,7 @@ def to_nifti(
datamoving = nb.Nifti1Image(frame[0], self.affine, self.datahdr)
# resample at index
resampled[..., i] = np.asanyarray(
xform.apply(datamoving, order=order).dataobj,
apply(xform, datamoving, order=order).dataobj,
dtype=self.dataobj.dtype,
)

Expand Down
3 changes: 2 additions & 1 deletion src/nifreeze/data/pet.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import numpy as np
from nibabel.spatialimages import SpatialImage
from nitransforms.linear import Affine
from nitransforms.resampling import apply
from typing_extensions import Self

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

# resample and update orientation at index
self.dataobj[..., index] = np.asanyarray(
xform.apply(dmoving, order=order).dataobj,
apply(xform, dmoving, order=order).dataobj,
dtype=self.dataobj.dtype,
)

Expand Down
4 changes: 3 additions & 1 deletion src/nifreeze/data/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ def apply_affines(nii, em_affines, output_filename=None):

for ii, bvecnii in enumerate(nb.four_to_three(nii)):
xfms = nt.linear.Affine(em_affines[ii])
transformed_nii[..., ii] = np.asanyarray((~xfms).apply(bvecnii, reference=nii).dataobj)
transformed_nii[..., ii] = np.asanyarray(
nt.resampling.apply(~xfms, bvecnii, reference=nii).dataobj
)

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

Expand Down
2 changes: 1 addition & 1 deletion src/nifreeze/model/_dipy.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def fit(
self,
data: np.ndarray,
gtab: GradientTable | np.ndarray,
mask: np.ndarray[bool, Any] | None = None,
mask: np.ndarray | None = None,
random_state: int = 0,
) -> GPFit:
"""Fit method of the DTI model class
Expand Down
3 changes: 2 additions & 1 deletion src/nifreeze/registration/ants.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import numpy as np
from nipype.interfaces.ants.registration import Registration
from nitransforms.linear import Affine
from nitransforms.resampling import apply

PARAMETERS_SINGLE_VALUE = {
"collapse_output_transforms",
Expand Down Expand Up @@ -494,7 +495,7 @@ def _run_registration(
),
)
# debugging: generate aligned file for testing
xform.apply(moving_path, reference=fixed_path).to_filename(
apply(xform, moving_path, reference=fixed_path).to_filename(
dirname / f"dbg_{vol_idx:05d}.nii.gz"
)

Expand Down
4 changes: 2 additions & 2 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ def motion_data(tmp_path_factory, datadir):
)

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

# Save the moved dataset for debugging or further processing
moved_path = tmp_path / "test.nii.gz"
ground_truth_path = tmp_path / "ground_truth.nii.gz"
moved_nii.to_filename(moved_path)
xfms.apply(moved_nii).to_filename(ground_truth_path)
nt.resampling.apply(xfms, moved_nii).to_filename(ground_truth_path)

# Wrap into dataset object
dwi_motion = DWI(
Expand Down
5 changes: 3 additions & 2 deletions test/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ def test_proximity_estimator_trivial_model(motion_data, tmp_path):
)

# Uncomment to see the realigned dataset
nt.linear.LinearTransformsMapping(
xfm = nt.linear.LinearTransformsMapping(
dwi_motion.motion_affines,
reference=b0nii,
).apply(moved_nii).to_filename(tmp_path / "realigned.nii.gz")
)
nt.resampling.apply(xfm, moved_nii).to_filename(tmp_path / "realigned.nii.gz")

# For each moved b0 volume
for i, est in enumerate(dwi_motion.motion_affines):
Expand Down
2 changes: 1 addition & 1 deletion test/test_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
T = from_matvec(euler2mat(x=r_x, y=r_y, z=r_z), (t_x, t_y, t_z))
xfm = nt.linear.Affine(T, reference=b0nii)

(~xfm).apply(b0nii, reference=b0nii).to_filename(moving)
nt.resampling.apply(~xfm, b0nii, reference=b0nii).to_filename(moving)

registration = Registration(
terminal_output="file",
Expand Down
Loading