|
13 | 13 | TransformFileError,
|
14 | 14 | )
|
15 | 15 |
|
16 |
| -class X5Transform: |
| 16 | +LPS = np.diag([-1, -1, 1, 1]) |
| 17 | + |
| 18 | +class X5LinearTransform(LinearParameters): |
17 | 19 | """A string-based structure for X5 linear transforms."""
|
18 | 20 |
|
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 |
20 | 30 |
|
21 | 31 | def __init__(self, parameters=None, offset=None):
|
22 | 32 | return
|
23 | 33 |
|
24 | 34 | def __str__(self):
|
25 | 35 | return
|
26 | 36 |
|
| 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 | + |
27 | 48 | @classmethod
|
28 | 49 | def from_filename(cls, filename):
|
29 | 50 | """Read the struct from a X5 file given its path."""
|
30 | 51 | 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