Skip to content

Commit 4b18c65

Browse files
committed
fix: patch warp struct
1 parent d0a0576 commit 4b18c65

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

nitransforms/io.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import numpy as np
2-
from nibabel.wrapstruct import LabeledWrapStruct
32
from nibabel.volumeutils import Recoder
43
from nibabel.affines import voxel_sizes
54

5+
from .patched import LabeledWrapStruct
6+
67
transform_codes = Recoder((
78
(0, 'LINEAR_VOX_TO_VOX'),
89
(1, 'LINEAR_RAS_TO_RAS'),
@@ -150,7 +151,7 @@ def from_string(klass, string):
150151
val = np.genfromtxt([valstring.encode()],
151152
dtype=klass.dtype[key])
152153
sa[key] = val.reshape(sa[key].shape)
153-
assert lines.pop(0) == '1 4 4'
154+
assert lines.pop(0) == '1 4 4' # xforms, shape + 1, shape + 1
154155
val = np.genfromtxt([valstring.encode() for valstring in lines[:4]],
155156
dtype='f4')
156157
sa['m_L'] = val

nitransforms/patched.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import numpy as np
2+
from nibabel.wrapstruct import LabeledWrapStruct as LWS
23

34

45
def shape_zoom_affine(shape, zooms, x_flip=True, y_flip=False):
@@ -63,3 +64,16 @@ def shape_zoom_affine(shape, zooms, x_flip=True, y_flip=False):
6364
aff[:3, :3] = np.diag(zooms)
6465
aff[:3, -1] = -origin * zooms
6566
return aff
67+
68+
69+
class LabeledWrapStruct(LWS):
70+
def __setitem__(self, item, value):
71+
''' Set values in structured data
72+
Examples
73+
--------
74+
>>> wstr = WrapStruct()
75+
>>> wstr['integer'] = 3
76+
>>> wstr['integer']
77+
array(3, dtype=int16)
78+
'''
79+
self._structarr[item] = np.asanyarray(value)

0 commit comments

Comments
 (0)