-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX: Use nitransforms for most xfm handling
- Loading branch information
Showing
5 changed files
with
53 additions
and
121 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
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"""Utilities for loading transforms for resampling""" | ||
|
||
from pathlib import Path | ||
|
||
import nitransforms as nt | ||
|
||
|
||
def load_transforms(xfm_paths: list[Path], inverse: list[bool]) -> nt.base.TransformBase: | ||
"""Load a series of transforms as a nitransforms TransformChain | ||
An empty list will return an identity transform | ||
""" | ||
if len(inverse) == 1: | ||
inverse *= len(xfm_paths) | ||
elif len(inverse) != len(xfm_paths): | ||
raise ValueError('Mismatched number of transforms and inverses') | ||
|
||
chain = None | ||
for path, inv in zip(xfm_paths[::-1], inverse[::-1], strict=False): | ||
path = Path(path) | ||
if path.suffix == '.h5': | ||
# Load as a TransformChain | ||
xfm = nt.manip.load(path) | ||
else: | ||
xfm = nt.linear.load(path) | ||
if inv: | ||
xfm = ~xfm | ||
if chain is None: | ||
chain = xfm | ||
else: | ||
chain += xfm | ||
if chain is None: | ||
chain = nt.Affine() # Identity | ||
return chain |
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