-
Notifications
You must be signed in to change notification settings - Fork 261
[MRG+2] Surf metadata #460
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
Conversation
Current coverage is 94.11%@@ master #460 diff @@
==========================================
Files 160 160
Lines 21090 21162 +72
Methods 0 0
Messages 0 0
Branches 2244 2264 +20
==========================================
+ Hits 19849 19917 +68
Misses 823 823
- Partials 418 422 +4
|
@jaeilepp I didn't know you took this over. @agramfort suggested I do it, so I made a commit to #458. It looks like your code is a bit cleaner, but maybe you could make use of the test modifications I made. |
travis is not happy |
def _read_volume_info(fobj): | ||
volume_info = OrderedDict() | ||
head = np.fromfile(fobj, '>i4', 3) | ||
if any(head != [2, 0, 20]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will always fail, as the RHS is a list, not a numpy array. Might do if head not in (0, 2, 20):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see, this is trying to check list equality. In that case, you'd want if not np.array_equal(head, [2, 0, 20])
, but consider also these files, which are just 20.
So maybe:
if head != 20 and not np.array_equal(head, [2, 0, 20]):
key, val[0], val[1], val[2]).encode('utf-8')) | ||
else: | ||
fobj.write('{0} = {1:.4f} {2:.4f} {3:.4f}\n'.format( | ||
key.ljust(6), val[0], val[1], val[2]).encode('utf-8')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that currently this expects the data be in the same format that it was read. So no arbitrary extra data is allowed.
Comments addressed. |
LGTM |
I suppose Appveyor failures are unrelated? |
yes it seems a conda pb |
if pair[0].strip() != key or len(pair) != 2: | ||
raise IOError('Error parsing volume info.') | ||
if key in ('valid', 'filename'): | ||
volume_info[key] = pair[1].strip() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there no way that the filename could have trailing whitespace, such as carriage returns? Worth stripping the pair
values before starting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The values are in effect stripped. See the conditional above.
'xras' : array of float, shape (3,) | ||
'yras' : array of float, shape (3,) | ||
'zras' : array of float, shape (3,) | ||
'cras' : array of float, shape (3,) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect this will look bad when rendered. Have you checked? This is more likely to work:
Valid keys:
* ...
* ...
I just realized that there are some numerical errors because we read the values to arrays, but I suppose it's not a problem. For instance reading:
becomes:
when written back to a file. |
Those values can be stored using double floating point just fine. Maybe you're writing them out in a bad format? |
key, val[0], val[1], val[2]).encode('utf-8')) | ||
else: | ||
val = volume_info[key] | ||
strings.append('{0} = {1:f} {2:f} {3:f}\n'.format( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the problem, try something like {1:0.9g} ...
and you'll see it's written with higher precision.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I missed this comment. 0.10g
seems to work.
If I change to general format I get |
Ready for review/merge. |
|
||
assert_equal(volume_info2['cras'], volume_info['cras']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that you have improved the precision in writing, you can use something more complete like:
for key in ('xras', 'yras', 'zras', 'cras'):
assert_allclose(volume_info2[key], volume_info[key], rtol=1e-7, atol=1e-30)
This would have failed under the %f
writing but passes now with the %0.10g
writing, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory yes, but I couldn't find a test file that would have this kind of precision in the end.
Other than my last (valid) comment, LGTM |
This is ready for review. Appveyor error seems unrelated. |
+1 for merge on my side |
+1 for merge from me too |
Thanks @jaeilepp for your patient work on this, and thanks too to y'all for the careful reviews. |
MRG: Fix to surface reading with new quad. Follow up to PR #460 which implemented read of surface data. The data format is actually different when reading new quad files. Use a file from freesurfer that has this format (added in the nibabel-data submodules) to test.
Takeover from #458
cc: @agramfort @effigies
closes #456
I could not figure out the 'tail' of extra information, so I suggest we just dump it for the time being.