-
Notifications
You must be signed in to change notification settings - Fork 262
First point of LazyTractogram
is not saved
#586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@MarcCote Do you have time to look into this? |
I fixed it, but I really don't like what I did.
If @MarcCote or anyone have a better solution, go for it! |
@nilgoyette the streamlines you provided to LazyTractogram is not a generator function, i.e. calling it should provide new generators every time. For instance, In [3]: gen = (s for s in range(5))
In [4]: lmb = lambda: gen
In [5]: print(list(lmb()))
[0, 1, 2, 3, 4]
In [6]: print(list(lmb()))
[] |
As @nilgoyette told me offline, this particular scenario happens when you do tracking and you want to dump streamlines into a file as you generate them. This is obviously a valid reason. We definitively want to support writing in "lazy" mode. One thing we could do is to add a flag to LazyTractogram that tells us whether the streamlines (and other scalar infos) is a generator function or simply an instanciated generator (that can be consumed only once). |
MRG: fix #596 First point of `LazyTractogram` is not saved With this PR, we now assume tractogram objects can be iterated over only once at saving time. This PR fixes issue #586. Thanks to @nilgoyette for providing the missing unit test and part of the solution
This test should pass
The problem comes from
When
self.tractogram
is a generator,first_item
is not in the generator anymore.I took 10 minutes to fix it but I couldn't find a clean way to do it. A simple
itertools.chain([first_item], tractogram)
is not enough :)The text was updated successfully, but these errors were encountered: