21
21
'''
22
22
from __future__ import division , print_function , absolute_import
23
23
import re
24
- import collections
25
-
24
+ try :
25
+ from collections .abc import MutableSequence , MutableMapping , Iterable
26
+ except ImportError :
27
+ # PY2 compatibility
28
+ from collections import MutableSequence , MutableMapping , Iterable
29
+ from collections import OrderedDict
26
30
from .. import xmlutils as xml
27
31
from ..filebasedimages import FileBasedHeader
28
32
from ..dataobj_images import DataobjImage
@@ -104,7 +108,7 @@ def _underscore(string):
104
108
return re .sub (r'([a-z0-9])([A-Z])' , r'\1_\2' , string ).lower ()
105
109
106
110
107
- class Cifti2MetaData (xml .XmlSerializable , collections . MutableMapping ):
111
+ class Cifti2MetaData (xml .XmlSerializable , MutableMapping ):
108
112
""" A list of name-value pairs
109
113
110
114
* Description - Provides a simple method for user-supplied metadata that
@@ -124,7 +128,7 @@ class Cifti2MetaData(xml.XmlSerializable, collections.MutableMapping):
124
128
data : list of (name, value) tuples
125
129
"""
126
130
def __init__ (self , metadata = None ):
127
- self .data = collections . OrderedDict ()
131
+ self .data = OrderedDict ()
128
132
if metadata is not None :
129
133
self .update (metadata )
130
134
@@ -173,7 +177,7 @@ def _to_xml_element(self):
173
177
return metadata
174
178
175
179
176
- class Cifti2LabelTable (xml .XmlSerializable , collections . MutableMapping ):
180
+ class Cifti2LabelTable (xml .XmlSerializable , MutableMapping ):
177
181
""" CIFTI2 label table: a sequence of ``Cifti2Label``s
178
182
179
183
* Description - Used by NamedMap when IndicesMapToDataType is
@@ -191,7 +195,7 @@ class Cifti2LabelTable(xml.XmlSerializable, collections.MutableMapping):
191
195
"""
192
196
193
197
def __init__ (self ):
194
- self ._labels = collections . OrderedDict ()
198
+ self ._labels = OrderedDict ()
195
199
196
200
def __len__ (self ):
197
201
return len (self ._labels )
@@ -427,7 +431,7 @@ def _to_xml_element(self):
427
431
return surf
428
432
429
433
430
- class Cifti2VoxelIndicesIJK (xml .XmlSerializable , collections . MutableSequence ):
434
+ class Cifti2VoxelIndicesIJK (xml .XmlSerializable , MutableSequence ):
431
435
"""CIFTI2 VoxelIndicesIJK: Set of voxel indices contained in a structure
432
436
433
437
* Description - Identifies the voxels that model a brain structure, or
@@ -509,7 +513,7 @@ def _to_xml_element(self):
509
513
return vox_ind
510
514
511
515
512
- class Cifti2Vertices (xml .XmlSerializable , collections . MutableSequence ):
516
+ class Cifti2Vertices (xml .XmlSerializable , MutableSequence ):
513
517
"""CIFTI2 vertices - association of brain structure and a list of vertices
514
518
515
519
* Description - Contains a BrainStructure type and a list of vertex indices
@@ -733,7 +737,7 @@ def _to_xml_element(self):
733
737
return volume
734
738
735
739
736
- class Cifti2VertexIndices (xml .XmlSerializable , collections . MutableSequence ):
740
+ class Cifti2VertexIndices (xml .XmlSerializable , MutableSequence ):
737
741
"""CIFTI2 vertex indices: vertex indices for an associated brain model
738
742
739
743
The vertex indices (which are independent for each surface, and
@@ -889,7 +893,7 @@ def _to_xml_element(self):
889
893
return brain_model
890
894
891
895
892
- class Cifti2MatrixIndicesMap (xml .XmlSerializable , collections . MutableSequence ):
896
+ class Cifti2MatrixIndicesMap (xml .XmlSerializable , MutableSequence ):
893
897
"""Class for Matrix Indices Map
894
898
895
899
* Description - Provides a mapping between matrix indices and their
@@ -1076,7 +1080,7 @@ def _to_xml_element(self):
1076
1080
return mat_ind_map
1077
1081
1078
1082
1079
- class Cifti2Matrix (xml .XmlSerializable , collections . MutableSequence ):
1083
+ class Cifti2Matrix (xml .XmlSerializable , MutableSequence ):
1080
1084
""" CIFTI2 Matrix object
1081
1085
1082
1086
This is a list-like container where the elements are instances of
@@ -1122,7 +1126,7 @@ def _get_indices_from_mim(self, mim):
1122
1126
applies_to_matrix_dimension = mim .applies_to_matrix_dimension
1123
1127
if not isinstance (
1124
1128
applies_to_matrix_dimension ,
1125
- collections . Iterable
1129
+ Iterable
1126
1130
):
1127
1131
applies_to_matrix_dimension = (int (applies_to_matrix_dimension ),)
1128
1132
return applies_to_matrix_dimension
0 commit comments