Skip to content

Commit efb35e1

Browse files
committed
ENH: Implement CoordinateAxis.get_indices
1 parent ff4b511 commit efb35e1

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

nibabel/coordimage.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,19 @@ def get_indices(self, parcel, indices=None):
6464
requested parcel. If indices are provided, further subsample
6565
the requested parcel.
6666
"""
67-
raise NotImplementedError
67+
subseqs = []
68+
idx = 0
69+
for p in self.parcels:
70+
if p.name == parcel:
71+
subseqs.append(range(idx, idx + len(p)))
72+
idx += len(p)
73+
if not subseqs:
74+
return ()
75+
if indices:
76+
return np.hstack(subseqs)[indices]
77+
if len(subseqs) == 1:
78+
return subseqs[0]
79+
return np.hstack(subseqs)
6880

6981
def __len__(self):
7082
return sum(len(parcel) for parcel in self.parcels)

0 commit comments

Comments
 (0)