def read_tracksi(self, indices): """ read tracks with specific indices """ tracks = Streamlines() for i in indices: off0, off1 = self.offsets[i:i + 2] tracks.append(self.tracks[off0:off1]) return tracks
def read_tracks(self): """ read the entire tractography """ I = self.offsets[:] TR = self.tracks[:] tracks = Streamlines() for i in range(len(I) - 1): off0, off1 = I[i:i + 2] tracks.append(TR[off0:off1]) return tracks
def get_array_sequence(self, item=None): if item is None: streamlines = _load_streamlines_from_hdf(self.hdf_group) else: streamlines = ArraySequence() if isinstance(item, int): streamline = self._get_one_streamline(item) streamlines.append(streamline) elif isinstance(item, list) or isinstance(item, np.ndarray): for i in item: streamline = self._get_one_streamline(i) streamlines.append(streamline, cache_build=True) streamlines.finalize_append() elif isinstance(item, slice): offsets = self.hdf_group['offsets'][item] lengths = self.hdf_group['lengths'][item] for offset, length in zip(offsets, lengths): streamline = self.hdf_group['data'][offset:offset + length] streamlines.append(streamline, cache_build=True) streamlines.finalize_append() else: raise ValueError( 'Item should be either a int, list, ' 'np.ndarray or slice but we received {}'.format( type(item))) return streamlines