Skip to content

Commit 9883468

Browse files
Julien Marabottooesteban
authored andcommitted
X5.py created
(cherry picked from commit 0e213cb)
1 parent d092ea1 commit 9883468

File tree

1 file changed

+25
-27
lines changed

1 file changed

+25
-27
lines changed

nitransforms/io/x5.py

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,43 +13,41 @@
1313
TransformFileError,
1414
)
1515

16-
class X5Transform:
16+
LPS = np.diag([-1, -1, 1, 1])
17+
18+
class X5LinearTransform(LinearParameters):
1719
"""A string-based structure for X5 linear transforms."""
1820

19-
_transform = None
21+
template_dtype = np.dtype(
22+
[
23+
("type", "i4"),
24+
("index", "i4"),
25+
("parameters", "f8", (4, 4)),
26+
("offset", "f4", 3), # Center of rotation
27+
]
28+
)
29+
dtype = template_dtype
2030

2131
def __init__(self, parameters=None, offset=None):
2232
return
2333

2434
def __str__(self):
2535
return
2636

37+
def to_filename(self, filename):
38+
"""Store this transform to a file with the appropriate format."""
39+
sa = self.structarr
40+
affine = np.array(
41+
np.hstack(
42+
(sa["parameters"][:3, :3].reshape(-1), sa["parameters"][:3, 3])
43+
)[..., np.newaxis],
44+
dtype="f8",
45+
)
46+
return
47+
2748
@classmethod
2849
def from_filename(cls, filename):
2950
"""Read the struct from a X5 file given its path."""
3051
if str(filename).endswith(".h5"):
31-
with H5File(str(filename), 'r') as hdf:
32-
return cls.from_h5obj(hdf)
33-
34-
@classmethod
35-
def from_h5obj(cls, h5obj):
36-
"""Read the transformations in an X5 file."""
37-
xfm_list = list(h5obj.keys())
38-
39-
xfm = xfm_list["Transform"]
40-
inv = xfm_list["Inverse"]
41-
coords = xfm_list["Size"]
42-
map = xfm_list["Mapping"]
43-
44-
return xfm, inv, coords, map
45-
46-
47-
class X5LinearTransformArray(BaseLinearTransformList):
48-
"""A string-based structure for series of X5 linear transforms."""
49-
50-
_inner_type = X5Transform
51-
52-
@property
53-
def xforms(self):
54-
"""Get the list of internal X5LinearTransforms."""
55-
return self._xforms
52+
with H5File(str(filename)) as f:
53+
return cls.from_h5obj(f)

0 commit comments

Comments
 (0)