Skip to content

MAINT: Increase coverage by testing edge cases and adding docstrings #248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 18, 2025
Merged
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
33 changes: 32 additions & 1 deletion nitransforms/io/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# emacs: -*- mode: python-mode; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
"""Read and write transforms."""

from nitransforms.io import afni, fsl, itk, lta, x5
from nitransforms.io.base import TransformIOError, TransformFileError

Expand All @@ -27,7 +28,37 @@


def get_linear_factory(fmt, is_array=True):
"""Return the type required by a given format."""
"""
Return the type required by a given format.

Parameters
----------
fmt : :obj:`str`
A format identifying string.
is_array : :obj:`bool`
Whether the array version of the class should be returned.

Returns
-------
type
The class object (not an instance) of the linear transfrom to be created
(for example, :obj:`~nitransforms.io.itk.ITKLinearTransform`).

Examples
--------
>>> get_linear_factory("itk")
<class 'nitransforms.io.itk.ITKLinearTransformArray'>
>>> get_linear_factory("itk", is_array=False)
<class 'nitransforms.io.itk.ITKLinearTransform'>
>>> get_linear_factory("fsl")
<class 'nitransforms.io.fsl.FSLLinearTransformArray'>
>>> get_linear_factory("fsl", is_array=False)
<class 'nitransforms.io.fsl.FSLLinearTransform'>
>>> get_linear_factory("fakepackage") # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
TypeError: Unsupported transform format <fakepackage>.

"""
if fmt.lower() not in _IO_TYPES:
raise TypeError(f"Unsupported transform format <{fmt}>.")

Expand Down
5 changes: 0 additions & 5 deletions nitransforms/linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,6 @@ def __init__(self, transforms, reference=None):
)
self._inverse = np.linalg.inv(self._matrix)

def __iter__(self):
"""Enable iterating over the series of transforms."""
for _m in self.matrix:
yield Affine(_m, reference=self._reference)

def __getitem__(self, i):
"""Enable indexed access to the series of matrices."""
return Affine(self.matrix[i, ...], reference=self._reference)
Expand Down
Loading