-
Notifications
You must be signed in to change notification settings - Fork 262
nibabel.freesurfer.write_annot successfully writes files that cannot be read by freesurfer #535
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
@mwaskom Do you have examples of each type of file that you can share? |
@mwaskom Just a bump to see if there's any data you can post. |
Closing as I don't have time to fiddle around with annotations (almost certainly the murkiest Freesurfer file format) right now. |
Alright. Please reopen if you do get time. |
I have a fix for this one but not much time to create a PR. # maxstruc
write(np.max(labels) + 1) to # maxstruc
write(max(np.max(labels) + 1, ctab.shape[0])) That will write the annot file in a way that can be read by |
Hey @rnemec-ng, what version of nibabel have you been using? This shoul hopefully have been resolved as of 2.3.1: |
@pauldmccarthy - from my
I believe the problem is that the annot file docs say the In theory, the I still prefer to fix the |
@rnemec-ng Any contribution you can make would be welcome. If you could submit your patches as a minimal PR, then someone with a bit of time on their hands could try to put together tests and polish it up. For writing those tests, it would be useful to have a file that fails to be read correctly by I appreciate that you said you don't have much time, so whatever you're able to supply would be helpful. |
Not much time, not much shmime... 😉 ... whatever. def reproBug():
nlabels = 3
names = ['label {}'.format(l) for l in range(1, nlabels + 1)]
labels = [1, 1, 1]
labels = np.array(labels, dtype=np.int32)
rgba = np.array(np.random.randint(0, 255, (nlabels, 4)), dtype=np.int32)
annot_path = 'c.annot'
nib.freesurfer.io.write_annot(annot_path, labels, rgba, names)
nib.freesurfer.io.read_annot(annot_path) Fails with current code (and |
@rnemec-ng I'm applying the fix you propose in #763. Looking at this code, I'm not very comfortable with how we do this, as I could create a label with ID Anyway, there's presumably a read issue here, as well, because the read code will simply write to index 1 three times. |
Thank you Chris for looking into this issue. I'm sure you know much more than I do about the code and whether "my fix" is the right one or not. I'll be happy with any improvements, as long as they allow reading files by both nibabel as well as freesurfer. |
Well, I added a round-trip check, and at least on my machine it looks like we read the same things we write, so I guess my worry was misplaced. Do you want to try out #763 and verify it works for your files? |
Not much time to test it (other than the test code you already put in place). At least, I added approval to the PR (but didn't merge). Hope this helps |
Thanks. We can open a new issue if it turns out something else needs doing. |
Uh oh!
There was an error while loading. Please reload this page.
I will edit this issue when I can come up with a good example of this separate from my data, but the headline is that the
write_annot
function can write (without erroring) a file that Freesurfer is unable to read.In the current case,
nib.freesurfer.read_annot
is also unable to read the written file. However, I have also experienced thatnib.freesurfer.read_annot
will read the file but it will be incorrect.Edit: and I have now written an annotation that Freesurfer can read but nibabel cannot.
The text was updated successfully, but these errors were encountered: