@@ -1268,6 +1268,40 @@ def get_index_map(self, index):
1268
1268
'''
1269
1269
return self .matrix .get_index_map (index )
1270
1270
1271
+ def get_axis (self , index ):
1272
+ '''
1273
+ Generates the Cifti2 axis for a given dimension
1274
+
1275
+ Parameters
1276
+ ----------
1277
+ index : int
1278
+ Dimension for which we want to obtain the mapping.
1279
+
1280
+ Returns
1281
+ -------
1282
+ axis : cifti2_axes.Axis
1283
+ '''
1284
+ from . import cifti2_axes
1285
+ return cifti2_axes .from_mapping (self .matrix .get_index_map (index ))
1286
+
1287
+ @classmethod
1288
+ def from_axes (cls , axes ):
1289
+ '''
1290
+ Creates a new Cifti2 header based on the Cifti2 axes
1291
+
1292
+ Parameters
1293
+ ----------
1294
+ axes : Tuple[cifti2_axes.Axis]
1295
+ sequence of Cifti2 axes describing each row/column of the matrix to be stored
1296
+
1297
+ Returns
1298
+ -------
1299
+ header : Cifti2Header
1300
+ new header describing the rows/columns in a format consistent with Cifti2
1301
+ '''
1302
+ from . import cifti2_axes
1303
+ return cifti2_axes .to_header (axes )
1304
+
1271
1305
1272
1306
class Cifti2Image (DataobjImage ):
1273
1307
""" Class for single file CIFTI2 format image
@@ -1297,15 +1331,19 @@ def __init__(self,
1297
1331
Object containing image data. It should be some object that
1298
1332
returns an array from ``np.asanyarray``. It should have a
1299
1333
``shape`` attribute or property.
1300
- header : Cifti2Header instance
1334
+ header : Cifti2Header instance or Sequence[cifti2_axes.Axis]
1301
1335
Header with data for / from XML part of CIFTI2 format.
1336
+ Alternatively a sequence of cifti2_axes.Axis objects can be provided
1337
+ describing each dimension of the array.
1302
1338
nifti_header : None or mapping or NIfTI2 header instance, optional
1303
1339
Metadata for NIfTI2 component of this format.
1304
1340
extra : None or mapping
1305
1341
Extra metadata not captured by `header` or `nifti_header`.
1306
1342
file_map : mapping, optional
1307
1343
Mapping giving file information for this image format.
1308
1344
'''
1345
+ if not isinstance (header , Cifti2Header ) and header :
1346
+ header = Cifti2Header .from_axes (header )
1309
1347
super (Cifti2Image , self ).__init__ (dataobj , header = header ,
1310
1348
extra = extra , file_map = file_map )
1311
1349
self ._nifti_header = Nifti2Header .from_header (nifti_header )
0 commit comments