Skip to content
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

[MRG] Coregistration #3466

Merged
merged 8 commits into from
Feb 24, 2017
Merged

[MRG] Coregistration #3466

merged 8 commits into from
Feb 24, 2017

Conversation

christianbrodbeck
Copy link
Member

@jona-sassenhagen the function is mne.coreg.coregister_fiducials. It currently has a scale parameter to use it with fsaverage, but this does not lead to satisfactory results and should be removed before merge.

The PR also contains some other small modifications.

  • Allow viz.plot_trans to plot fiducials
  • Allow scaling MRI without label files

@codecov-io
Copy link

codecov-io commented Jul 28, 2016

Codecov Report

Merging #3466 into master will decrease coverage by -0.1%.
The diff coverage is 76.92%.

@@            Coverage Diff            @@
##           master    #3466     +/-   ##
=========================================
- Coverage   86.07%   85.97%   -0.1%     
=========================================
  Files         350      350             
  Lines       63028    63209    +181     
  Branches     9639     9659     +20     
=========================================
+ Hits        54251    54344     +93     
- Misses       6097     6181     +84     
- Partials     2680     2684      +4

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 18a02e8...3851698. Read the comment docs.

@larsoner
Copy link
Member

@christianbrodbeck is this worth resurrecting? It seems like at the very least the MRI fiducials would be cool.

@christianbrodbeck
Copy link
Member Author

Sure! I can rebase or split it up if you think some features require more work than others.

Copy link
Member

@larsoner larsoner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise LGTM

raise TypeError('cf must be str or int, not %s' % type(cf))
else:
try:
cf = int(cf)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can instead do from numbers import Integral; if not isinstance(cf, Integral):

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish I'd known this! Simply returning int(cf) (which is in master now) is sufficient though right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I think we already have a function like this somewhere that converts coordinate frame str or int to int. Can you check around, probably in mne/transforms.py?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... oh wait, this is in transforms. Never mind! Yeah int(cf) is fine

mne/viz/_3d.py Outdated
ref_meg : bool
If True (default False), include reference MEG sensors.
fiducials : bool | str
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should probably be mri_fiducials. The digitized fiducials are already displayed as part of dig

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll change. i assume also add the .. versionadded:: 0.14 tag?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes please

mne/viz/_3d.py Outdated
head_dev_t = invert_transform(info['dev_head_t'])
mri_dev_t = combine_transforms(mri_head_t, head_dev_t, 'mri',
'meg')
fid_locs = apply_trans(mri_dev_t, fid_locs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can now be simplified because there is IIRC a mri_transform that is used to take anything originally in MRI space to the destination space

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mne/coreg.py Outdated
"frames")
coord_frame_from = frames_from[0]
coords_to = _fiducial_coords(fiducials, coord_frame_to)
trans = fit_matched_points(coords_from, coords_to, tol=tol)
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 probably isn't the correct function. From fiducials you get a center point and axis directions. Using that geometry analytically is better than using a generic fitting function

'r': np.array(self.nasion[0])},
{'kind': FIFF.FIFFV_POINT_CARDINAL,
'ident': FIFF.FIFFV_POINT_RPA,
'r': np.array(self.rpa[0])}]
write_fiducials(fname, dig, FIFF.FIFFV_COORD_MRI)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good at some point to use mne.io.write_dig instead. This is just a specific use case of it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm write_fiducials() does nothing but call write_dig()... should it be deprecated?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes probably. I think back when I fixed up write_dig I just wasn't sure how to fix the coreg code not to use it anymore.

@larsoner
Copy link
Member

This could use a rebase (might be easier to start from scratch?) then should be good hopefully

@christianbrodbeck
Copy link
Member Author

Well the only thing that's left is the actual coregistration which as you indicated should be rewritten with the analytic approach...

@larsoner
Copy link
Member

For now I think we can keep that. I think that we'll want to write a separate "mode" entirely, e.g. coordinate-frame-center-based instead of nasion-based. It's what I would have expected going in.

@christianbrodbeck christianbrodbeck force-pushed the coreg branch 2 times, most recently from 42e5475 to dde8ed3 Compare February 22, 2017 22:02
@christianbrodbeck
Copy link
Member Author

Rebased and added a test; This is not nasion based, it just finds a transform to minimize points distances.

@christianbrodbeck christianbrodbeck changed the title [WIP] Coregistration [MRG] Coregistration Feb 23, 2017
@@ -63,8 +63,6 @@ def _to_const(cf):
if cf not in _str_to_frame:
raise ValueError('Unknown cf %s' % cf)
cf = _str_to_frame[cf]
elif not isinstance(cf, (int, np.integer)):
raise TypeError('cf must be str or int, not %s' % type(cf))
return int(cf)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this check is superfluous, or am I missing some possibility?

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 it prevents people from accidentally passing float. The correct thing to do, though, is really to check against from numbers import Integral; if isinstance(x, Integral)

@christianbrodbeck
Copy link
Member Author

Looks like numpy.int32 does not qualify as Integral in one configuration? https://travis-ci.org/mne-tools/mne-python/jobs/204443245#L2868

@larsoner
Copy link
Member

Argh, probably an old numpy issue :( Not sure the best way to handle it. Maybe isinstance(..., (Integral, np.int32)) for backward compatibility. We really shouldn't get anything other than int, np.int32, or np.int64 (maybe) anyway.

@christianbrodbeck
Copy link
Member Author

Actually I get an error in this test (https://github.com/mne-tools/mne-python/blob/master/mne/tests/test_coreg.py#L67) and I am not sure how it could run without error?

    src = mne.read_source_spaces(path)
    mne.add_source_space_distances(src)
    src.save(path)

@larsoner
Copy link
Member

Looks like you fixed it already, yes?

@christianbrodbeck
Copy link
Member Author

yes :)

@larsoner
Copy link
Member

Okay great. This looks pretty simple so I'll merge once the CIs come back happy

@larsoner
Copy link
Member

Travis is unhappy with style

https://travis-ci.org/mne-tools/mne-python/jobs/205022035#L3106

@larsoner larsoner merged commit 31c2c28 into mne-tools:master Feb 24, 2017
@larsoner
Copy link
Member

Thanks @christianbrodbeck

@christianbrodbeck christianbrodbeck deleted the coreg branch February 27, 2017 15:44
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.

3 participants