Skip to content

Commit

Permalink
Merge branch 'fix/remaining-apply-on-object-call-2' into fix/remainin…
Browse files Browse the repository at this point in the history
…g-apply-on-object
  • Loading branch information
oesteban committed May 20, 2024
2 parents 08dc3a3 + 5241f99 commit fcb98d5
Show file tree
Hide file tree
Showing 5 changed files with 5,081 additions and 22 deletions.
11 changes: 6 additions & 5 deletions docs/notebooks/Reading and Writing transforms.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"import numpy as np\n",
"import nibabel as nb\n",
"import nitransforms as nt\n",
"from nitransforms.resampling import apply\n",
"\n",
"cwd = TemporaryDirectory()\n",
"os.chdir(cwd.name)\n",
Expand Down Expand Up @@ -263,7 +264,7 @@
"metadata": {},
"outputs": [],
"source": [
"moved = xfm.apply(nii, order=0)\n",
"moved = apply(xfm, nii, order=0)\n",
"moved.to_filename('moved-nb.nii.gz')"
]
},
Expand Down Expand Up @@ -741,7 +742,7 @@
"outputs": [],
"source": [
"xfm.reference = oblique\n",
"moved_oblique = xfm.apply(las_anatomy)"
"moved_oblique = apply(xfm, las_anatomy)"
]
},
{
Expand Down Expand Up @@ -895,7 +896,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -909,9 +910,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
"version": "3.11.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
5,073 changes: 5,063 additions & 10 deletions docs/notebooks/isbi2020.ipynb

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions nitransforms/manip.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ def __len__(self):
"""Enable using len()."""
return len(self.transforms)

@property
def ndim(self):
"""Get the number of dimensions."""
return max(x.ndim for x in self._transforms)

@property
def transforms(self):
"""Get the internal list of transforms."""
Expand Down
8 changes: 4 additions & 4 deletions nitransforms/nonlinear.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,11 @@ def map(self, x, inverse=False):
--------
>>> xfm = BSplineFieldTransform(test_dir / "someones_bspline_coefficients.nii.gz")
>>> xfm.reference = test_dir / "someones_anatomy.nii.gz"
>>> xfm.map([-6.5, -36., -19.5]).tolist()
[[-6.5, -31.476097418406784, -19.5]]
>>> xfm.map([-6.5, -36., -19.5]).tolist() # doctest: +ELLIPSIS
[[-6.5, -31.476097418406..., -19.5]]
>>> xfm.map([[-6.5, -36., -19.5], [-1., -41.5, -11.25]]).tolist()
[[-6.5, -31.476097418406784, -19.5], [-1.0, -3.8072675377121996, -11.25]]
>>> xfm.map([[-6.5, -36., -19.5], [-1., -41.5, -11.25]]).tolist() # doctest: +ELLIPSIS
[[-6.5, -31.4760974184..., -19.5], [-1.0, -3.807267537712..., -11.25]]
"""
vfunc = partial(
Expand Down
6 changes: 3 additions & 3 deletions nitransforms/tests/test_nonlinear.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def test_displacements_field1(
exit_code = check_call([cmd], shell=True)
assert exit_code == 0
sw_moved_mask = nb.load("resampled_brainmask.nii.gz")
nt_moved_mask = xfm.apply(msk, order=0)
nt_moved_mask = apply(xfm, msk, order=0)
nt_moved_mask.set_data_dtype(msk.get_data_dtype())
diff = np.asanyarray(sw_moved_mask.dataobj) - np.asanyarray(nt_moved_mask.dataobj)

Expand All @@ -189,7 +189,7 @@ def test_displacements_field1(
assert exit_code == 0
sw_moved = nb.load("resampled.nii.gz")

nt_moved = xfm.apply(nii, order=0)
nt_moved = apply(xfm, nii, order=0)
nt_moved.set_data_dtype(nii.get_data_dtype())
nt_moved.to_filename("nt_resampled.nii.gz")
sw_moved.set_data_dtype(nt_moved.get_data_dtype())
Expand Down Expand Up @@ -229,7 +229,7 @@ def test_displacements_field2(tmp_path, testdata_path, sw_tool):
assert exit_code == 0
sw_moved = nb.load("resampled.nii.gz")

nt_moved = xfm.apply(img_fname, order=0)
nt_moved = apply(xfm, img_fname, order=0)
nt_moved.to_filename("nt_resampled.nii.gz")
sw_moved.set_data_dtype(nt_moved.get_data_dtype())
diff = np.asanyarray(
Expand Down

0 comments on commit fcb98d5

Please sign in to comment.