@@ -179,17 +179,20 @@ def write_morph_data(file_like, values, fnum=0):
179
179
in binary write (`'wb'` mode, implementing the `write` method)
180
180
values : array-like
181
181
Surface morphometry values
182
+
183
+ Shape must be (N,), (N, 1), (1, N) or (N, 1, 1)
182
184
fnum : int, optional
183
185
Number of faces in the associated surface
184
186
"""
185
187
magic_bytes = np .array ([255 , 255 , 255 ], dtype = np .uint8 )
186
188
187
- array = np .asarray (values ).astype ('>f4' ).squeeze ()
188
- if len (array .shape ) > 1 :
189
- raise ValueError ("Multi-dimensional values not supported" )
189
+ vector = np .asarray (values )
190
+ vnum = np .prod (vector .shape )
191
+ if vector .shape not in ((vnum ,), (vnum , 1 ), (1 , vnum ), (vnum , 1 , 1 )):
192
+ raise ValueError ("Invalid shape: argument values must be a vector" )
190
193
191
194
i4info = np .iinfo ('i4' )
192
- if len ( array ) > i4info .max :
195
+ if vnum > i4info .max :
193
196
raise ValueError ("Too many values for morphometry file" )
194
197
if not i4info .min <= fnum <= i4info .max :
195
198
raise ValueError ("Argument fnum must be between {0} and {1}" .format (
@@ -199,9 +202,9 @@ def write_morph_data(file_like, values, fnum=0):
199
202
fobj .write (magic_bytes )
200
203
201
204
# vertex count, face count (unused), vals per vertex (only 1 supported)
202
- fobj .write (np .array ([len ( array ) , fnum , 1 ], dtype = '>i4' ))
205
+ fobj .write (np .array ([vnum , fnum , 1 ], dtype = '>i4' ))
203
206
204
- fobj .write (array )
207
+ fobj .write (vector . astype ( '>f4' ) )
205
208
206
209
207
210
def read_annot (filepath , orig_ids = False ):
0 commit comments