Skip to content

Commit d34a669

Browse files
Julien Marabottooesteban
authored andcommitted
enh: x5 implementation
(cherry picked from commit e465332)
1 parent b4b5af4 commit d34a669

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

nitransforms/io/x5.py

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,46 +13,43 @@
1313
TransformFileError,
1414
)
1515

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

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
19+
_transform = None
3020

3121
def __init__(self, parameters=None, offset=None):
3222
return
3323

3424
def __str__(self):
3525
return
3626

37-
def to_filename(self, filename):
38-
'''store this transform to a file with the X5 format'''
39-
sa = self.structarr
40-
affine = '''some affine that will return a 4x4 array'''
41-
return
42-
4327
@classmethod
4428
def from_filename(cls, filename):
4529
"""Read the struct from a X5 file given its path."""
4630
if str(filename).endswith(".h5"):
47-
with H5File(str(filename)) as f:
48-
return cls.from_h5obj(f)
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+
4946

5047
class X5LinearTransformArray(BaseLinearTransformList):
5148
"""A string-based structure for series of X5 linear transforms."""
5249

53-
_inner_type = X5LinearTransform
50+
_inner_type = X5Transform
5451

5552
@property
5653
def xforms(self):
57-
"""Get the list of internal ITKLinearTransforms."""
54+
"""Get the list of internal X5LinearTransforms."""
5855
return self._xforms

0 commit comments

Comments
 (0)