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

WIP: Dont center points in head coords #5085

Closed
wants to merge 1 commit into from

Conversation

larsoner
Copy link
Member

@larsoner larsoner commented Apr 3, 2018

So far:

Closes #3987.

Running this code:

import mne
data_path = mne.datasets.sample.data_path()
raw = mne.io.read_raw_fif(data_path + '/MEG/sample/sample_audvis_raw.fif')
raw.load_data().pick_types(meg=True, stim=True)
events = mne.find_events(raw, 'STI 014')
epochs = mne.Epochs(raw, events, proj='delayed')
evoked = epochs.average()
selection = mne.read_selection('Left-temporal')
kwargs = dict(times=[0., 0.1, 0.2], vmin=-240, vmax=240, layout='auto',
              head_pos=dict(center=(0., 0.), scale=(1., 1.)))
evoked.plot_topomap(**kwargs)
evoked.copy().pick_types(selection=selection).plot_topomap(**kwargs)

Gives (ignore the broad smearing plotting "artifact" due to channel subselection in the second one, we can fix this eventually), note that the subselected channels stay put, and that the sensors are rotated relative to the head (in accordance with dev_head_t for this dataset):

screenshot from 2018-04-03 14-27-30
screenshot from 2018-04-03 14-27-32

Omitting the head_pos argument (which basically means "center and scale to fit the circle") the second plot gives the sort of thing that has been confusing people in #3987 and elsewhere:

screenshot from 2018-04-03 14-27-58

Assuming we have geometry information properly in the head coordinate frame (and I would argue we should make people corrrect theirs if they do not), this is incorrect. I'm thinking that we should change the default for head_pos to this (or similar) scheme. Thoughts @jona-sassenhagen ?

@larsoner larsoner added this to the 0.16 milestone Apr 3, 2018
@jona-sassenhagen
Copy link
Contributor

Conceptually: yes, sounds like a no-brainer.

@RashaHyder
Copy link

I'm still having problems even after using the head_pos. Using the following gives figure_1:
image, _ = plot_topomap(f_map, pos, mask=mask,
head_pos=dict(center=(0., 0.), scale=(1., 1.)),
axes=ax_topo,
cmap='Reds', vmin=np.min, vmax=np.max)

where:
my_evo= evoked.pick_types(meg='mag', selection= left_chs)
pos = mne.channels.find_layout(my_evo.info, exclude= excluded_chs).pos

however, when I used the info object instead of the positions (pos) returned from mne.channels.find_layout, I've got correct positions of the sensors but the topography map had all the same color even after using many values of vmin & vmax (figure_2):

image, _ = plot_topomap(f_map, my_evo.info, mask=mask,
head_pos=dict(center=(0., 0.), scale=(1., 1.)),
axes=ax_topo,
cmap='Reds', vmin=np.min, vmax=np.max)

Any idea why I had this problem with the coloring of topography map? and should I be worried that the positions returned from mne.channels.find_layout are incorrect?
figure_1
figure_2

@larsoner
Copy link
Member Author

larsoner commented Apr 4, 2018

when I used the info object instead of the positions (pos) returned from mne.channels.find_layout, I've got correct positions of the sensors

This is the right thing to do, yes.

but the topography map had all the same color even after using many values of vmin & vmax (figure_2):

This looks like the result of clustering (?), which should find sensors all with the same sign. So this is not surprising to me.

@RashaHyder
Copy link

Thank you a lot larsoner. Yes I'm using (spatio_temporal_cluster_1samp_test) for permutations but since my selection of magnetometers is restricted to left sensors only: ['Left-temporal', 'Left-parietal', 'Left-frontal'], shouldn't the topography be similar to what you showed in Figure 2 (upper one) when you selected only left sensors and used head_pos (topography in the left hemisphere only)?

@larsoner
Copy link
Member Author

larsoner commented Apr 4, 2018

That is what is in your second figure, no?

@larsoner
Copy link
Member Author

larsoner commented Apr 4, 2018

... at least the "sensor dots" are in the left hemi I mean. The fact that the red/contours extend into the right hemisphere is a bug / limitation we will fix here.

@RashaHyder
Copy link

I meant the red color extending to the right hemisphere. Anyway thank you for your help,

@jona-sassenhagen
Copy link
Contributor

@RashaHyder why are you trying to plot a topomap for a subset of channels ..?

@RashaHyder
Copy link

@jona-sassenhagen
what I mainly want to do is plotting the results of permutations on a selection of left magnetometers similar to the example here:
https://mne-tools.github.io/dev/auto_tutorials/plot_stats_spatio_temporal_cluster_sensors.html#sphx-glr-auto-tutorials-plot-stats-spatio-temporal-cluster-sensors-py
so I'm basically plotting topography of the f_map:
f_map = T_obs[time_inds, ...].mean(axis=0)
where:
T_obs, clusters, p_values, _ = spatio_temporal_cluster_1samp_test()
time_inds, space_inds = np.squeeze(clusters[i])

@jona-sassenhagen
Copy link
Contributor

I think the interpolated maps are not a good idea here. They'll inherently be extremely distorted. If at all, you'd want to interpolate over all sensors and mask for those you're actually plotting.

@RashaHyder
Copy link

@jona-sassenhagen tank you very much for your suggestion. I was actually concerned about a possible distortion after I saw the uni color topography in figure_2 !
I will definitely try doing it the way you suggested now!

@jona-sassenhagen
Copy link
Contributor

For a non-interpolated legend, you can use mne.viz.evoked._plot_legend. You can feed it colours yourself. You can probably even set to white all the channels you are not using.

@RashaHyder
Copy link

Great! Thank you a lot I really appreciate your help.

@larsoner
Copy link
Member Author

larsoner commented Apr 4, 2018

I think the interpolated maps are not a good idea here. They'll inherently be extremely distorted.

Agreed. The fix I have in mind will take whatever set of sensors you are using and only interpolate some small distance away from them (probably set by the distance to the next-nearest point or so). This should work regardless of whether or not channels have been picked.

@jona-sassenhagen
Copy link
Contributor

@larsoner an easy option would be giving the option of turning off interpolation and just plotting big colored discs.

@larsoner
Copy link
Member Author

larsoner commented Apr 4, 2018

It probably makes sense to interpolate between the sensors in most use cases, no?

I worry that the "disc" idea would look a bit bad in most cases due to the gaps. I imagine something like a voronoi plot would look better. But either way, this should be a new mode we can use in all circumstances, and thus (sufficiently) orthogonal to this PR.

@jona-sassenhagen
Copy link
Contributor

It probably makes sense to interpolate between the sensors in most use cases, no?

I worry that the "disc" idea would look a bit bad in most cases due to the gaps.

Yes. The zero interpolation would be for the remaining few cases :)

The Voroni option will fail for sparse discontinuous channel choices. No-interpolation will never be misleading in the way interpolation methods are in that case.

@larsoner larsoner modified the milestones: 0.16, 0.17 Apr 5, 2018
@larsoner larsoner changed the title FIX: Dont center points in head coords WIP: Dont center points in head coords Apr 5, 2018
@larsoner
Copy link
Member Author

@jona-sassenhagen I am looking at implementing this functionality and from looking at the code image_mask appears to be unused by plot_topomap. Do you have a few minutes to look through mne/viz/topomap.py and confirm?

@jona-sassenhagen
Copy link
Contributor

Ok, will do today.

@larsoner
Copy link
Member Author

To make reviewing easier, I restated the question in PR form: #5140 :)

@larsoner
Copy link
Member Author

Closing this for the proposal in #5471. Basically from talking to @agramfort it probably makes the most sense for MEG topomaps to be in device coords (maybe with a head pos + rotation actually shown), and EEG topomaps in head coords.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants