@@ -22,39 +22,24 @@ def __init__(self, binaryblock=None, endianness=None, check=True):
22
22
if binaryblock is not None and _dtype == self .dtype :
23
23
self ._structarr = binaryblock .copy ()
24
24
return
25
- super (StringBasedStruct , self ).__init__ (binaryblock , endianness , check )
25
+ super ().__init__ (binaryblock , endianness , check )
26
26
27
27
def __array__ (self ):
28
28
"""Return the internal structure array."""
29
29
return self ._structarr
30
30
31
+ def to_string (self ):
32
+ """Convert to a string directly writeable to file."""
33
+ raise NotImplementedError
31
34
32
- class LinearParameters (StringBasedStruct ):
33
- """
34
- A string-based structure for linear transforms.
35
-
36
- Examples
37
- --------
38
- >>> lp = LinearParameters()
39
- >>> np.all(lp.structarr['parameters'] == np.eye(4))
40
- True
41
-
42
- >>> p = np.diag([2., 2., 2., 1.])
43
- >>> lp = LinearParameters(p)
44
- >>> np.all(lp.structarr['parameters'] == p)
45
- True
35
+ @classmethod
36
+ def from_string (cls , string ):
37
+ """Read the struct from string."""
38
+ raise NotImplementedError
46
39
47
- """
48
40
49
- template_dtype = np .dtype ([("parameters" , "f8" , (4 , 4 ))])
50
- dtype = template_dtype
51
-
52
- def __init__ (self , parameters = None ):
53
- """Initialize with default parameters."""
54
- super ().__init__ ()
55
- self .structarr ["parameters" ] = np .eye (4 )
56
- if parameters is not None :
57
- self .structarr ["parameters" ] = parameters
41
+ class LinearTransformStruct (StringBasedStruct ):
42
+ """File data structure from linear transforms."""
58
43
59
44
def to_filename (self , filename ):
60
45
"""Store this transform to a file with the appropriate format."""
@@ -78,12 +63,44 @@ def from_fileobj(cls, fileobj, check=True):
78
63
return cls .from_string (fileobj .read ())
79
64
80
65
@classmethod
81
- def from_string (cls , string ):
82
- """Read the struct from string ."""
66
+ def from_ras (cls , ras , moving = None , reference = None ):
67
+ """Create an affine from a nitransform's RAS+ matrix ."""
83
68
raise NotImplementedError
84
69
85
70
86
- class BaseLinearTransformList (StringBasedStruct ):
71
+ class LinearParameters (LinearTransformStruct ):
72
+ """
73
+ A string-based structure for linear transforms.
74
+
75
+ Examples
76
+ --------
77
+ >>> lp = LinearParameters()
78
+ >>> np.all(lp.structarr['parameters'] == np.eye(4))
79
+ True
80
+
81
+ >>> p = np.diag([2., 2., 2., 1.])
82
+ >>> lp = LinearParameters(p)
83
+ >>> np.all(lp.structarr['parameters'] == p)
84
+ True
85
+
86
+ """
87
+
88
+ template_dtype = np .dtype ([("parameters" , "f8" , (4 , 4 ))])
89
+ dtype = template_dtype
90
+
91
+ def __init__ (self , parameters = None ):
92
+ """
93
+ Initialize with default parameters.
94
+
95
+
96
+ """
97
+ super ().__init__ ()
98
+ self .structarr ["parameters" ] = np .eye (4 )
99
+ if parameters is not None :
100
+ self .structarr ["parameters" ] = parameters
101
+
102
+
103
+ class BaseLinearTransformList (LinearTransformStruct ):
87
104
"""A string-based structure for series of linear transforms."""
88
105
89
106
template_dtype = np .dtype ([("nxforms" , "i4" )])
@@ -113,41 +130,6 @@ def __getitem__(self, idx):
113
130
return len (self ._xforms )
114
131
raise KeyError (idx )
115
132
116
- def to_filename (self , filename ):
117
- """Store this transform to a file with the appropriate format."""
118
- with open (str (filename ), "w" ) as f :
119
- f .write (self .to_string ())
120
-
121
- def to_ras (self , moving = None , reference = None ):
122
- """Return a nitransforms' internal RAS matrix."""
123
- raise NotImplementedError
124
-
125
- def to_string (self ):
126
- """Convert to a string directly writeable to file."""
127
- raise NotImplementedError
128
-
129
- @classmethod
130
- def from_filename (cls , filename ):
131
- """Read the struct from a file given its path."""
132
- with open (str (filename )) as f :
133
- string = f .read ()
134
- return cls .from_string (string )
135
-
136
- @classmethod
137
- def from_fileobj (cls , fileobj , check = True ):
138
- """Read the struct from a file object."""
139
- return cls .from_string (fileobj .read ())
140
-
141
- @classmethod
142
- def from_ras (cls , ras , moving = None , reference = None ):
143
- """Create an ITK affine from a nitransform's RAS+ matrix."""
144
- raise NotImplementedError
145
-
146
- @classmethod
147
- def from_string (cls , string ):
148
- """Read the struct from string."""
149
- raise NotImplementedError
150
-
151
133
152
134
class DisplacementsField :
153
135
"""A data structure representing displacements fields."""
0 commit comments