Skip to content

Commit d4d42a0

Browse files
committed
ENH: Implement CoordinateAxis.get_indices
1 parent 921173b commit d4d42a0

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

nibabel/coordimage.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import numpy as np
2+
13
from nibabel.fileslice import fill_slicer
24

35

@@ -66,7 +68,19 @@ def get_indices(self, parcel, indices=None):
6668
requested parcel. If indices are provided, further subsample
6769
the requested parcel.
6870
"""
69-
raise NotImplementedError
71+
subseqs = []
72+
idx = 0
73+
for p in self.parcels:
74+
if p.name == parcel:
75+
subseqs.append(range(idx, idx + len(p)))
76+
idx += len(p)
77+
if not subseqs:
78+
return ()
79+
if indices:
80+
return np.hstack(subseqs)[indices]
81+
if len(subseqs) == 1:
82+
return subseqs[0]
83+
return np.hstack(subseqs)
7084

7185
def __len__(self):
7286
return sum(len(parcel) for parcel in self.parcels)

0 commit comments

Comments
 (0)