- Notifications
You must be signed in to change notification settings - Fork269
FIX: Change reader to also support tck files from mrtrix3-dev tckedit#957
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
codecovbot commentedSep 14, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Codecov Report
@@ Coverage Diff @@## master #957 +/- ##==========================================- Coverage 91.87% 91.83% -0.05%========================================== Files 98 98 Lines 12451 12451 Branches 2193 2193 ==========================================- Hits 11439 11434 -5- Misses 678 681 +3- Partials 334 336 +2
Continue to review full report at Codecov.
|
valeriejill commentedSep 14, 2020
Attaching an example tck file (3Tissue-tckedit-streamlines-ex.tck) that generates an error with the tck reader. This file was generated with 3Tissue's tckedit@thijsdhollander And here is the error: In [6]: nibabel.streamlines.load('3Tissue-tckedit-streamlines-ex.tck')ValueError Traceback (most recent call last) ~/miniconda3/lib/python3.7/site-packages/nibabel/streamlines/init.py in load(fileobj, lazy_load) ~/miniconda3/lib/python3.7/site-packages/nibabel/streamlines/tck.py in load(cls, fileobj, lazy_load) ~/miniconda3/lib/python3.7/site-packages/nibabel/streamlines/tck.py in _read_header(fileobj) ValueError: dictionary update sequence element#1 has length 1; 2 is required |
The I would imagine what you want is: >>>print(hdr['command_history'])tckgen-angle22.5-maxlen250-minlen10-power1.0/mnt/jux/cnds/ZAPR01/mrtrix_ss3t_csd/FOD_PopulationTemplate/ZAPR01_FOD_Template.mif-seed_image/mnt/jux/cnds/ZAPR01/mrtrix_ss3t_csd/FOD_PopulationTemplate/ZAPR01_FOD_Template_Mask.mif-mask/mnt/jux/cnds/ZAPR01/mrtrix_ss3t_csd/FOD_PopulationTemplate/ZAPR01_FOD_Template_Mask.mif-select2000000-cutoff0.10/mnt/jux/cnds/ZAPR01/mrtrix_ss3t_csd/Tractography_PopulationTemplate/ZAPR01-FOD-Template-tractography-newparams.tck (version=3Tissue_v5.2.8)tckeditZAPR01-FOD-Template-AmygdalaTargetMask-LHAmygdala-tracts.tck-number5tckedit-streamlines.tck (version=3Tissue_v5.2.8) The current approach will lose that second line. I think we probably need to treat |
Since command history isn't a standard part of streamlines data, I think it's reasonable to not fully support it. There definitely isn't anything comparable that will come out of trk headers |
In general we do try to preserve format-specific metadata. I would rather not drop it when the fix is pretty easy: hdr= {}key=Noneforlineinbuf.rstrip().split("\n")[:-1]:fields=line.split(": ",1)iflen(fields)==2:key=fields[0]hdr[key]=fields[1]else:hdr[key]+=f"\n{fields[0]}" (As an example. It might be doable with a little more readability.) |
Matt, WDYT about supporting multi-line header fields? I can submit a PR against your branch if you would prefer. |
I agree with@effigies, we should preserve format-specific metadata as much as possible. I think what you propose is the right direction. |
thijsdhollander commentedDec 3, 2020
I completely overlooked this thread, even though I was tagged early on (my bad)! In any case, the Note that this solution also didn't play 100% perfectly with NiBabel, but at least files weren't marked as corrupted anymore. Before the fix, the issue was indeed a newline characterwithin the value of a specific key/field, leading to it being marked as corrupt. After the fix, the new reality now is multiple lines with thesame key ('command_history'), which currently is not marked as corrupt by NiBabel, but all but the first line are ignored by NiBabel, I believe. So to be "ultimately" compatible or robust, either case (multi-line header fields as well as duplicate keys) would best be detected and essentially be treated in the same way, conceptually as a "multi-line field". |
Well this fell through the cracks.@thijsdhollander Would it be a problem if we read this file: And writing this header to a new file we consolidated it into: That's the straightforward implementation with our current data structure. If instead we need to preserve splits and ordering of header fields, we'll need a different header structure. |
Treat repeated keys as adding lines to the fieldClosesgh-957
Treat repeated keys as adding lines to the fieldClosesgh-957
The mrtrix3-dev and 3Tissue versions added a new
"END"string to the header of tck files that come out oftckedit. This was causing an error in the tck reader. This fix will be compatible with new and old versions of the tck file format.