Skip to content

Selecting on data_per_streamline #729

@arokem

Description

@arokem

I am trying to use the data_per_streamline attribute to select streamlines from within a Tractogram object. I am running into the following behavior.

I initialize a very simple tractogram object. The first streamline has the data_per_streamline foo key set to 0 and the other two streamlines have this set to 1:

import numpy as np import nibabel.streamlines as sl tgram = sl.Tractogram([np.array([[0, 0, 0], [1, 1, 1]]), np.array([[2, 2, 2], [3, 3, 3], [4, 4, 4]]), np.array([[5, 5, 5], [6, 6, 6]])], data_per_streamline={'foo': [[0],[1],[1]]}) 

I can find the right streamlines using np.where:

idx = np.where(tgram.data_per_streamline['foo'] == 1)[0] idx array([1, 2]) 

It even looks like it's doing the right thing when I use this for indexing:

tgram[idx].streamlines ArraySequence([array([[2, 2, 2], [3, 3, 3], [4, 4, 4]]), array([[5, 5, 5], [6, 6, 6]])]) 

But under the hood:

tgram[idx].streamlines._data array([[0, 0, 0], [1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5], [6, 6, 6]]) 

Why is it still holding onto all of the data? Is there some way to drop the data for the first (not selected) streamline?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions