|
120 | 120 | """ |
121 | 121 | import numpy as np |
122 | 122 | from . import cifti2 |
123 | | -from six import string_types, add_metaclass, integer_types |
124 | 123 | from operator import xor |
125 | 124 | import abc |
126 | 125 |
|
@@ -173,8 +172,7 @@ def to_header(axes): |
173 | 172 | return cifti2.Cifti2Header(matrix) |
174 | 173 |
|
175 | 174 |
|
176 | | -@add_metaclass(abc.ABCMeta) |
177 | | -class Axis(object): |
| 175 | +class Axis(object, metaclass=abc.ABCMeta): |
178 | 176 | """ |
179 | 177 | Abstract class for any object describing the rows or columns of a CIFTI-2 vector/matrix |
180 | 178 |
|
@@ -289,7 +287,7 @@ def __init__(self, name, voxel=None, vertex=None, affine=None, |
289 | 287 | else: |
290 | 288 | self.vertex = np.asanyarray(vertex, dtype=int) |
291 | 289 |
|
292 | | - if isinstance(name, string_types): |
| 290 | + if isinstance(name, str): |
293 | 291 | name = [self.to_cifti_brain_structure_name(name)] * self.vertex.size |
294 | 292 | self.name = np.asanyarray(name, dtype='U') |
295 | 293 |
|
@@ -505,7 +503,7 @@ def to_cifti_brain_structure_name(name): |
505 | 503 | """ |
506 | 504 | if name in cifti2.CIFTI_BRAIN_STRUCTURES: |
507 | 505 | return name |
508 | | - if not isinstance(name, string_types): |
| 506 | + if not isinstance(name, str): |
509 | 507 | if len(name) == 1: |
510 | 508 | structure = name[0] |
511 | 509 | orientation = 'both' |
@@ -589,7 +587,7 @@ def volume_shape(self, value): |
589 | 587 | value = tuple(value) |
590 | 588 | if len(value) != 3: |
591 | 589 | raise ValueError("Volume shape should be a tuple of length 3") |
592 | | - if not all(isinstance(v, integer_types) for v in value): |
| 590 | + if not all(isinstance(v, int) for v in value): |
593 | 591 | raise ValueError("All elements of the volume shape should be integers") |
594 | 592 | self._volume_shape = value |
595 | 593 |
|
@@ -679,9 +677,9 @@ def __getitem__(self, item): |
679 | 677 |
|
680 | 678 | Otherwise returns a new BrainModelAxis |
681 | 679 | """ |
682 | | - if isinstance(item, integer_types): |
| 680 | + if isinstance(item, int): |
683 | 681 | return self.get_element(item) |
684 | | - if isinstance(item, string_types): |
| 682 | + if isinstance(item, str): |
685 | 683 | raise IndexError("Can not index an Axis with a string (except for ParcelsAxis)") |
686 | 684 | return self.__class__(self.name[item], self.voxel[item], self.vertex[item], |
687 | 685 | self.affine, self.volume_shape, self.nvertices) |
@@ -914,7 +912,7 @@ def volume_shape(self, value): |
914 | 912 | value = tuple(value) |
915 | 913 | if len(value) != 3: |
916 | 914 | raise ValueError("Volume shape should be a tuple of length 3") |
917 | | - if not all(isinstance(v, integer_types) for v in value): |
| 915 | + if not all(isinstance(v, int) for v in value): |
918 | 916 | raise ValueError("All elements of the volume shape should be integers") |
919 | 917 | self._volume_shape = value |
920 | 918 |
|
@@ -989,14 +987,14 @@ def __getitem__(self, item): |
989 | 987 | - `string`: 2-element tuple of (parcel voxels, parcel vertices |
990 | 988 | - other object that can index 1D arrays: new Parcel axis |
991 | 989 | """ |
992 | | - if isinstance(item, string_types): |
| 990 | + if isinstance(item, str): |
993 | 991 | idx = np.where(self.name == item)[0] |
994 | 992 | if len(idx) == 0: |
995 | 993 | raise IndexError("Parcel %s not found" % item) |
996 | 994 | if len(idx) > 1: |
997 | 995 | raise IndexError("Multiple parcels with name %s found" % item) |
998 | 996 | return self.voxels[idx[0]], self.vertices[idx[0]] |
999 | | - if isinstance(item, integer_types): |
| 997 | + if isinstance(item, int): |
1000 | 998 | return self.get_element(item) |
1001 | 999 | return self.__class__(self.name[item], self.voxels[item], self.vertices[item], |
1002 | 1000 | self.affine, self.volume_shape, self.nvertices) |
@@ -1125,7 +1123,7 @@ def __add__(self, other): |
1125 | 1123 | ) |
1126 | 1124 |
|
1127 | 1125 | def __getitem__(self, item): |
1128 | | - if isinstance(item, integer_types): |
| 1126 | + if isinstance(item, int): |
1129 | 1127 | return self.get_element(item) |
1130 | 1128 | return self.__class__(self.name[item], self.meta[item]) |
1131 | 1129 |
|
@@ -1270,7 +1268,7 @@ def __add__(self, other): |
1270 | 1268 | ) |
1271 | 1269 |
|
1272 | 1270 | def __getitem__(self, item): |
1273 | | - if isinstance(item, integer_types): |
| 1271 | + if isinstance(item, int): |
1274 | 1272 | return self.get_element(item) |
1275 | 1273 | return self.__class__(self.name[item], self.label[item], self.meta[item]) |
1276 | 1274 |
|
@@ -1437,7 +1435,7 @@ def __getitem__(self, item): |
1437 | 1435 | nelements = 0 |
1438 | 1436 | return SeriesAxis(idx_start * self.step + self.start, self.step * step, |
1439 | 1437 | nelements, self.unit) |
1440 | | - elif isinstance(item, integer_types): |
| 1438 | + elif isinstance(item, int): |
1441 | 1439 | return self.get_element(item) |
1442 | 1440 | raise IndexError('SeriesAxis can only be indexed with integers or slices ' |
1443 | 1441 | 'without breaking the regular structure') |
|
0 commit comments