Skip to content

[MRG] Coregistration - #3466

Merged
larsoner merged 8 commits into
mne-tools:masterfrom
christianbrodbeck:coreg
Feb 24, 2017
Merged

larsoner merged 8 commits into
mne-tools:masterfrom
christianbrodbeck:coreg

Conversation

@christianbrodbeck

Copy link
Copy Markdown
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

codecov-io commented Jul 28, 2016 •

Copy link
Copy Markdown

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
Copy Markdown
Member

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

@christianbrodbeck

Copy link
Copy Markdown
Member Author

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

@larsoner larsoner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Otherwise LGTM

Comment thread mne/transforms.py Outdated
raise TypeError('cf must be str or int, not %s' % type(cf))
else:
try:
cf = int(cf)

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

Comment thread mne/viz/_3d.py Outdated
points only.
ref_meg : bool
If True (default False), include reference MEG sensors.
fiducials : bool | str

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes please

Comment thread 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
Copy Markdown
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
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Comment thread mne/coreg.py
"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
Copy Markdown
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

Comment thread mne/gui/_fiducials_gui.py
{'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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

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

@christianbrodbeck

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Comment thread mne/transforms.py
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

Looks like you fixed it already, yes?

@christianbrodbeck

Copy link
Copy Markdown
Member Author

yes :)

@larsoner

Copy link
Copy Markdown
Member

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

@larsoner

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
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