diff --git a/docs/notebooks/Reading and Writing transforms.ipynb b/docs/notebooks/Reading and Writing transforms.ipynb
index 61ea269f..c0e85de2 100644
--- a/docs/notebooks/Reading and Writing transforms.ipynb
+++ b/docs/notebooks/Reading and Writing transforms.ipynb
@@ -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",
@@ -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')"
]
},
@@ -741,7 +742,7 @@
"outputs": [],
"source": [
"xfm.reference = oblique\n",
- "moved_oblique = xfm.apply(las_anatomy)"
+ "moved_oblique = apply(xfm, las_anatomy)"
]
},
{
@@ -895,7 +896,7 @@
],
"metadata": {
"kernelspec": {
- "display_name": "Python 3",
+ "display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
@@ -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
}
diff --git a/docs/notebooks/isbi2020.ipynb b/docs/notebooks/isbi2020.ipynb
index 80442dbe..903d86e7 100644
--- a/docs/notebooks/isbi2020.ipynb
+++ b/docs/notebooks/isbi2020.ipynb
@@ -34,7 +34,8 @@
"from pathlib import Path\n",
"import nibabel as nb\n",
"from niworkflows.viz.notebook import display\n",
- "import nitransforms as nt"
+ "import nitransforms as not\n",
+ "from nitransforms.resampling import apply"
]
},
{
@@ -161,7 +162,7 @@
}
],
"source": [
- "resampled_in_t1 = identity_xfm.apply(bold_nii)\n",
+ "resampled_in_t1 = apply(identity_xfm, bold_nii)\n",
"print(resampled_in_t1.affine)\n",
"print(resampled_in_t1.shape)"
]
@@ -180,7 +181,1695 @@
"outputs": [
{
"data": {
- "image/svg+xml": "",
+ "image/svg+xml": [
+ ""
+ ],
"text/plain": [
""
]
@@ -231,7 +1920,7 @@
}
],
"source": [
- "moved_to_t1 = t1w_to_bold_xfm.apply(bold_nii)\n",
+ "moved_to_t1 = apply(t1w_to_bold_xfm, bold_nii)\n",
"print(moved_to_t1.affine)\n",
"print(moved_to_t1.shape)"
]
@@ -243,7 +1932,1695 @@
"outputs": [
{
"data": {
- "image/svg+xml": "",
+ "image/svg+xml": [
+ ""
+ ],
"text/plain": [
""
]
@@ -280,7 +3657,1683 @@
"outputs": [
{
"data": {
- "image/svg+xml": "",
+ "image/svg+xml": [
+ ""
+ ],
"text/plain": [
""
]
@@ -290,7 +5343,7 @@
}
],
"source": [
- "display(bold_nii, bold_to_t1w_xfm.apply(t1w_nii))"
+ "display(bold_nii, apply(bold_to_t1w_xfm, t1w_nii))"
]
},
{
@@ -315,7 +5368,7 @@
],
"metadata": {
"kernelspec": {
- "display_name": "Python 3",
+ "display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
@@ -329,9 +5382,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.7.3"
+ "version": "3.11.8"
}
},
"nbformat": 4,
"nbformat_minor": 4
-}
\ No newline at end of file
+}
diff --git a/nitransforms/manip.py b/nitransforms/manip.py
index 233f5adf..b30fd646 100644
--- a/nitransforms/manip.py
+++ b/nitransforms/manip.py
@@ -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."""
diff --git a/nitransforms/nonlinear.py b/nitransforms/nonlinear.py
index 17befc8a..9c29c53c 100644
--- a/nitransforms/nonlinear.py
+++ b/nitransforms/nonlinear.py
@@ -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(
diff --git a/nitransforms/tests/test_nonlinear.py b/nitransforms/tests/test_nonlinear.py
index cfaa12c2..24d1f83e 100644
--- a/nitransforms/tests/test_nonlinear.py
+++ b/nitransforms/tests/test_nonlinear.py
@@ -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)
@@ -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())
@@ -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(