Skip to content

[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

Merged
merged 16 commits into from
Jun 17, 2016
Merged

[MRG+2] Surf metadata #460

merged 16 commits into from
Jun 17, 2016

Conversation

jaeilepp
Copy link
Contributor

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.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.003%) to 96.095% when pulling 2e01d49 on jaeilepp:surf-metadata into 9959c74 on nipy:master.

@codecov-io
Copy link

codecov-io commented Jun 10, 2016

Current coverage is 94.11%

Merging #460 into master will increase coverage by <.01%

@@             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   

Powered by Codecov. Last updated by 9959c74...07bd848

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.003%) to 96.095% when pulling b5f1849 on jaeilepp:surf-metadata into 9959c74 on nipy:master.

@larsoner
Copy link
Contributor

@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.

@larsoner larsoner mentioned this pull request Jun 10, 2016
@agramfort
Copy link
Contributor

travis is not happy

def _read_volume_info(fobj):
volume_info = OrderedDict()
head = np.fromfile(fobj, '>i4', 3)
if any(head != [2, 0, 20]):
Copy link
Member

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):

Copy link
Member

@effigies effigies Jun 10, 2016

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'))
Copy link
Contributor Author

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.

@jaeilepp
Copy link
Contributor Author

Comments addressed.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) to 96.107% when pulling 880152a on jaeilepp:surf-metadata into 9959c74 on nipy:master.

@agramfort
Copy link
Contributor

LGTM

@jaeilepp
Copy link
Contributor Author

I suppose Appveyor failures are unrelated?

@agramfort
Copy link
Contributor

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()
Copy link
Member

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?

Copy link
Contributor Author

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,)
Copy link
Contributor

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:

    * ...
    * ...

@jaeilepp
Copy link
Contributor Author

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:

xras=[ -1.00000000e+00   8.56816911e-08   1.49011647e-08]
yras=[  1.15484021e-07   1.57160827e-08  -1.00000000e+00]
zras=[ -1.91852465e-07   1.00000000e+00   6.40284092e-09]
cras=[ -5.27361298   9.03908539 -27.28796387]

becomes:

xras=[-1.  0.  0.]
yras=[ 0.  0. -1.]
zras=[-0.  1.  0.]
cras=[ -5.273613   9.039085 -27.287964]

when written back to a file.

@coveralls
Copy link

coveralls commented Jun 15, 2016

Coverage Status

Coverage increased (+0.003%) to 96.1% when pulling 98930e9 on jaeilepp:surf-metadata into 9959c74 on nipy:master.

@coveralls
Copy link

coveralls commented Jun 15, 2016

Coverage Status

Coverage increased (+0.003%) to 96.1% when pulling e73e3d2 on jaeilepp:surf-metadata into 9959c74 on nipy:master.

@coveralls
Copy link

coveralls commented Jun 15, 2016

Coverage Status

Coverage increased (+0.003%) to 96.1% when pulling bdacad1 on jaeilepp:surf-metadata into 9959c74 on nipy:master.

@larsoner
Copy link
Contributor

I just realized that there are some numerical errors because we read the values to arrays

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(
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@jaeilepp
Copy link
Contributor Author

jaeilepp commented Jun 15, 2016

If I change to general format I get cras=[ -5.27361298 9.03908539 -27.28796387] changed to cras=[ -5.27361 9.03909 -27.288 ]. The others translate fine. I'm not sure if there's a format that works well for all values.
EDIT: 0.10g works.

@coveralls
Copy link

coveralls commented Jun 15, 2016

Coverage Status

Coverage increased (+0.003%) to 96.1% when pulling 10e56f9 on jaeilepp:surf-metadata into 9959c74 on nipy:master.

@coveralls
Copy link

coveralls commented Jun 15, 2016

Coverage Status

Coverage increased (+0.01%) to 96.111% when pulling 07bd848 on jaeilepp:surf-metadata into 9959c74 on nipy:master.

@jaeilepp
Copy link
Contributor Author

Ready for review/merge.


assert_equal(volume_info2['cras'], volume_info['cras'])
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@larsoner
Copy link
Contributor

Other than my last (valid) comment, LGTM

@coveralls
Copy link

coveralls commented Jun 16, 2016

Coverage Status

Coverage increased (+0.01%) to 96.111% when pulling 45f6052 on jaeilepp:surf-metadata into 9959c74 on nipy:master.

@jaeilepp
Copy link
Contributor Author

This is ready for review. Appveyor error seems unrelated.

@agramfort agramfort changed the title Surf metadata [MRG+1] Surf metadata Jun 17, 2016
@agramfort
Copy link
Contributor

+1 for merge on my side

@larsoner
Copy link
Contributor

+1 for merge from me too

@larsoner larsoner changed the title [MRG+1] Surf metadata [MRG+2] Surf metadata Jun 17, 2016
@matthew-brett
Copy link
Member

Thanks @jaeilepp for your patient work on this, and thanks too to y'all for the careful reviews.

@matthew-brett matthew-brett merged commit f4a3e0a into nipy:master Jun 17, 2016
matthew-brett added a commit that referenced this pull request Jun 27, 2016
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: write_geometry and read_geometry don't seem to be in the same coordinate system
7 participants