-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #160 from nipy/enh/autoload-linear
ENH: Guess open linear transform formats
- Loading branch information
Showing
8 changed files
with
144 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,34 @@ | ||
# 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 . import afni, fsl, itk, lta | ||
from nitransforms.io import afni, fsl, itk, lta | ||
from nitransforms.io.base import TransformIOError, TransformFileError | ||
|
||
__all__ = [ | ||
"afni", | ||
"fsl", | ||
"itk", | ||
"lta", | ||
"get_linear_factory", | ||
"TransformFileError", | ||
"TransformIOError", | ||
] | ||
|
||
_IO_TYPES = { | ||
"itk": (itk, "ITKLinearTransform"), | ||
"ants": (itk, "ITKLinearTransform"), | ||
"elastix": (itk, "ITKLinearTransform"), | ||
"lta": (lta, "FSLinearTransform"), | ||
"fs": (lta, "FSLinearTransform"), | ||
"fsl": (fsl, "FSLLinearTransform"), | ||
"afni": (afni, "AFNILinearTransform"), | ||
} | ||
|
||
|
||
def get_linear_factory(fmt, is_array=True): | ||
"""Return the type required by a given format.""" | ||
if fmt.lower() not in _IO_TYPES: | ||
raise TypeError(f"Unsupported transform format <{fmt}>.") | ||
|
||
module, classname = _IO_TYPES[fmt.lower()] | ||
return getattr(module, f"{classname}{'Array' * is_array}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.