Skip to content

[MRG+2] Dipole plotter. - #3966

Merged
larsoner merged 29 commits into
mne-tools:masterfrom
jaeilepp:dipole-plot
Mar 1, 2017
Merged

larsoner merged 29 commits into
mne-tools:masterfrom
jaeilepp:dipole-plot

Conversation

@jaeilepp

@jaeilepp jaeilepp commented Feb 6, 2017

Copy link
Copy Markdown
Contributor

Dipole plotter using mpl 3D.
dipole

Comment thread mne/viz/_3d.py Outdated

import numpy as np
from scipy import linalg
import nibabel as nib

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 will make it a hard dependency ...

@jaeilepp

jaeilepp commented Feb 6, 2017

Copy link
Copy Markdown
Contributor Author

Script for testing:

import os.path as op
import mne
from mne.datasets import testing
data_dir = testing.data_path(download=False)
subjects_dir = op.join(data_dir, 'subjects')
trans_fname = op.join(data_dir, 'MEG', 'sample',
                      'sample_audvis_trunc-trans.fif')
dip_fname = op.join(data_dir, 'MEG', 'sample', 'sample_audvis_trunc_set1.dip')
dipoles = mne.read_dipole(dip_fname)
trans = mne.read_trans(trans_fname)

mne.viz._3d.plot_dipole_3d(dipoles, trans, 'sample', subjects_dir)

It would be nice to compare this to some other plotter. I tried it against plot_locations and it looks somewhat the same, but it's hard to tell if the results are exactly the same since the plotters are so different.

@larsoner

larsoner commented Feb 6, 2017

Copy link
Copy Markdown
Member

The name should be more descriptive and include some subset of orthoview, mri, and/or slices. Something like plot_dipole_mri_orthoview or so.

Did you think about and/or try using OrthoSlicer3D from nibabel? Perhaps that would be a complementary option for another PR...?

It would be nice to compare this to some other plotter

Because you want to check locations? What I would do is pick an MRI voxel in FreeView, which should give the coords in both voxels and MRI surface RAS. Then you can cross-check with your implementation in debug mode after e.g. making it logger.debug the nearest MRI voxel

Looks like a great start on #2995. I assume you examined the other options outlined there and decided this was better? Yours looks better to me so far.

@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/viz/_3d.py Outdated
return view_to_disp_mat


def plot_dipole_3d(dipole, trans, subject, subjects_dir=None, scale_factor=1e9,

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.

trans=None default (i.e., use identity), make subject second argument

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is that safe? Does someone really want to plot the dipoles without applying the transformation?

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 is done this way in (at least) fit_dipole and plot_trans

Comment thread mne/viz/_3d.py Outdated
def plot_dipole_3d(dipole, trans, subject, subjects_dir=None, scale_factor=1e9,
block=False, show=True):
"""Plot dipoles in 3-D. Browse through the dipoles using mouse scroll or
up/down arrows.

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.

single line. More descriptive first line involving "mri", "slices", and/or "orthoview"; put interactivity instructions in separate paragraph

Comment thread mne/viz/_3d.py Outdated

Parameters
----------
dipole : instance of mne.Dipole

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.

just instance of Dipole

Comment thread mne/viz/_3d.py Outdated
SUBJECT.
subjects_dir : None | str
The path to the freesurfer subjects reconstructions. It corresponds to
Freesurfer environment variable SUBJECTS_DIR. The default is None.

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.

subjects_dir is usually toward the end, especially since many people don't need to explicitly set this (it's part of the env vars or config vars)

Comment thread mne/viz/_3d.py Outdated
The path to the freesurfer subjects reconstructions. It corresponds to
Freesurfer environment variable SUBJECTS_DIR. The default is None.
scale_factor : float
The scaling applied to convert amplitudes to voxel sizes for the plot.

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.

To physical units (m), you mean? Voxels could/should be shown in mm. You might need to use the affine to get there

@jaeilepp jaeilepp Feb 7, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, that's the scale factor for the amplitude. i.e. the length of the arrow. I'll update the docstring.

Comment thread mne/viz/_3d.py Outdated
try:
import nibabel as nib
except ImportError:
raise

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.

if not mne.utils.has_nibabel()

Comment thread mne/viz/_3d.py Outdated
np.linspace(0, dims, dims))

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

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.

does fig, ax = plt.subplots(1, projection='3d') work?

Comment thread mne/viz/_3d.py Outdated
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

trans = _get_trans(trans, fro='head', to='mri')[0]

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.

If possible there should be a coord_frame argument. It's might actually be most natural to plot these in head coords

Comment thread mne/viz/_3d.py Outdated
ax.contourf(gridx, gridy, data[:, yidx][::-1].T, offset=0, zdir='z',
cmap='gray', zorder=0, alpha=0.5)
ax.contourf(gridx, data[:, :, zidx][::-1].T[::-1], gridy, offset=0,
zdir='y', cmap='gray', zorder=0, alpha=0.5)

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.

Being able to use a different coordinate frame will be a bit of a pain, but hopefully not too bad. Basically you want to do 3D linear interpolation to choose plane slices through the MRI to show, as opposed to just taking NumPy slices of the 3D array. When in MRI coords you should see that your chosen plane collapses to just use the interpolation grid anyway, so it's a more general way to formulate this.

Not sure if there is a simpler way...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So the idea is to take endpoints of the plane and then transform these to form the plane in mri space and then pick the points from the mri image for plotting? Sounds like a lot of work and computation. I'm not sure it's worth the effort, unless you have a clear idea how to do it efficiently.

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.

So the idea is to take endpoints of the plane

No, nothing about endpoints specifically.

Think about it this way. What coordinate frame is the data currently plotted in? Let's say I want to plot it in the head coordinate frame (which perhaps should be the default). How would we do it?

One way is with LinearNDInterpolator from SciPy. That way we can take slices through our regularly spaced 3D grid (i.e., MRI) in the X/Y/Z directions of the head coordinate frame instead of the only current option, which is taking slices (via NumPy) in the X/Y/Z directions of the MRI coordinate frame.

It's also possible/likely that nibabel actually gives you a way to apply an affine transformation to the MRI -- that would be even easier. In this scheme, you'd just apply the inverse of the head_mri_t to the MRI, and then your current NumPy slices would work.

Make sense?

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 could be as easy as using nibabel.processing.resample_from_to, with the affine being our mri_head_t['trans']. Then you can just take ndarray slices of the resulting resampled image, instead of the original.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think there's a bug in resample_from_to. If I do:

t = resample_from_to(t1, ((256, 256, 256), np.eye(4)))
OrthoSlicer3D(t.get_data())

I get this:
ortho

Comment thread mne/viz/tests/test_3d.py Outdated
fig.canvas.key_press_event('up')
fig.canvas.key_press_event('down')
fig.canvas.key_press_event('a') # some other key
matplotlib.pyplot.close('all')

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 is unsafe. Doing import matplotlib doesn't automatically import the matplotlib.pyplot namespace. This will only work if we have by chance done import matplotilb.pyplot elsewhere, so you should explicitly import it here (as we always do) to be safe

@jaeilepp

jaeilepp commented Feb 7, 2017

Copy link
Copy Markdown
Contributor Author

Did you think about and/or try using OrthoSlicer3D from nibabel? Perhaps that would be a complementary option for another PR...?

Yeah, that could be done. Also, the crosshair plot could be quite easily be implemented with this. So perhaps a second mode for this plotter.

@jaeilepp

jaeilepp commented Feb 7, 2017

Copy link
Copy Markdown
Contributor Author

Maybe I'll leave the crosshair mode to another PR too (if we want it). Mpl does not seem to handle intersecting planes too well, so each segment would have to be plotted separately.

Comment thread mne/viz/_3d.py Outdated
Freesurfer environment variable SUBJECTS_DIR. The default is None.
scale_factor : float
The scaling applied to convert amplitudes to vector (arrow) lengths for
the plot. Defaults to 1e9.

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 know it's the scale factor for the amplitude, that was clear enough already. What isn't clear is the units. I think it should say something like "... to convert from amplitude in Am to arrow length in mm, e.g., 1e9 (default) makes a 10 nAm dipole appear with a length of 10 mm in the plot" (if this is indeed what the conversion factor is)

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.

... And while we're at it, I'd make it the factor to convert from nAm to mm. It's probably the most natural choice for dipole data

Comment thread mne/viz/_3d.py Outdated
ax.contourf(gridx, gridy, data[:, yidx][::-1].T, offset=0, zdir='z',
cmap='gray', zorder=0, alpha=0.5)
ax.contourf(gridx, data[:, :, zidx][::-1].T[::-1], gridy, offset=0,
zdir='y', cmap='gray', zorder=0, alpha=0.5)

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.

So the idea is to take endpoints of the plane

No, nothing about endpoints specifically.

Think about it this way. What coordinate frame is the data currently plotted in? Let's say I want to plot it in the head coordinate frame (which perhaps should be the default). How would we do it?

One way is with LinearNDInterpolator from SciPy. That way we can take slices through our regularly spaced 3D grid (i.e., MRI) in the X/Y/Z directions of the head coordinate frame instead of the only current option, which is taking slices (via NumPy) in the X/Y/Z directions of the MRI coordinate frame.

It's also possible/likely that nibabel actually gives you a way to apply an affine transformation to the MRI -- that would be even easier. In this scheme, you'd just apply the inverse of the head_mri_t to the MRI, and then your current NumPy slices would work.

Make sense?

@larsoner

larsoner commented Feb 8, 2017

Copy link
Copy Markdown
Member

Also, it would be cool if it were possible to choose between plotting the images at the outer axis limits (as it's done now) versus as a "crosshair" centered at the dipole location. I've seen plotters do the latter, too. That can be a follow-up PR, but any idea if it's possible with matplotlib 3D?

@jaeilepp

jaeilepp commented Feb 8, 2017

Copy link
Copy Markdown
Contributor Author

but any idea if it's possible with matplotlib 3D

It may be possible, but all the segments must be plotted individually. Otherwise it does not look too nice:
intersection

@larsoner

larsoner commented Feb 8, 2017

Copy link
Copy Markdown
Member

I think there's a bug in resample_from_to.

Hmm... this would be pretty surprising, since nibabel is pretty rigorously tested.

Here is a complete (copy-paste runnable) version of your example, equivalently called using with orthoview:

import mne
import numpy as np
import nibabel as nib
from nibabel.processing import resample_from_to
data_path = mne.datasets.sample.data_path()
subjects_dir = data_path + '/subjects'
t1 = nib.load(subjects_dir + '/sample/mri/T1.mgz')
t = resample_from_to(t1, ((256, 256, 256), np.eye(4)))
t.orthoview()

It's possible/likely we might need to take into account the existing affine in our transformation. Let's try passing the current affine as our destination:

t = resample_from_to(t1, ((256, 256, 256), t1.affine))
t1.orthoview()
t.orthoview()

Original and resampled match here:
screenshot from 2017-02-08 09-20-31
screenshot from 2017-02-08 09-20-29

In other words, the resampling function needs to to be supplied a final/destination NIfTI affine. So unfortunately we'll need to look through http://nipy.org/nibabel/nifti_images.html#the-nifti-affines to sort this out.

Coming back to our problem, Let's get some handle on what the result should look like:

info = mne.io.read_info(data_path + '/MEG/sample/sample_audvis_raw.fif')
mne.viz.plot_trans(info, subject='sample', trans=trans, coord_frame='mri',
                   subjects_dir=subjects_dir, source='head', dig=True)
mne.viz.plot_trans(info, subject='sample', trans=trans, coord_frame='head',
                   subjects_dir=subjects_dir, source='head', dig=True)

screenshot from 2017-02-08 09-40-43
screenshot from 2017-02-08 09-40-45
And from the side:

>>> from mayavi import mlab
>>> mlab.view(0, 90)

screenshot from 2017-02-08 09-44-05

So the head coordinate frame induces a large forward tilt of the MRI.

We can at least get something like this with a first-pass solution:

affine_to = trans['trans'].copy()
affine_to[:3, 3] *= 1000  # to mm
affine_to = np.dot(affine_to, t1.affine)
t = resample_from_to(t1, ((256,) * 3, affine_to))
fig = t.orthoview()

screenshot from 2017-02-08 10-35-53
This is probably not correct, but it at least shows we can head in the right direction.

One example reason we need to think about these things is that although many MRIs are sampled on a 1mm grid, they aren't all sampled that way. So we should probably always resample to a 1mm grid to be safe. And we might also want to resample so that our affine maps (0., 0., 0.) in world coordinates to the center data[127, 127, 127], point, which would be something like:

affine_to = np.array([[-1, 0, 0, 127],
                      [0, 0, 1, -127],
                      [0, -1, 0, 127],
                      [0, 0, 0, 1.]])
t = resample_from_to(t1, ((256,) * 3, affine_to))

The problem is that, even with this transform, we're talking about RAS space, but I think we need Freesurfer RAS, which comes from t1.header.get_vox2ras_tkr() (it should just be a translation relative to t1.affine i.e. t1.header.get_vox2ras(), though).

In any case, this stuff is annoying to work through, but to properly plot the MRI slices alongside data from MRI or head coordinate frames, I think we need to get through it, assuming we want our X/Y/Z axis labels to be correct in terms of the 0, 0, 0 being at the center of the MRI or head coordinate system.

@jaeilepp jaeilepp changed the title [WIP] Dipole plotter. [MRG] Dipole plotter. Feb 10, 2017
@jaeilepp

Copy link
Copy Markdown
Contributor Author

This is ready for review.

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

Also, have you verified the locations? I think i had suggested using FreeView to select some voxel (which gives you both the voxel index and RAS coordinates) and making sure your plotter shows it in the correct location?

It might also be worth selecting a point that we know is on the cortical surface, and cross-checking the surf['rr'] value to see if it corresponds to the vox2ras or vox2ras_tkr one. I think it'll be the latter...

Comment thread mne/dipole.py Outdated
from .viz import plot_dipole_amplitudes
return plot_dipole_amplitudes([self], [color], show)

def plot_mri_orthoview(self, trans, subject, subjects_dir=None,

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.

can you use the docstring-copying decorator?

Comment thread mne/viz/_3d.py Outdated
Freesurfer environment variable SUBJECTS_DIR. If None (default),
SUBJECTS_DIR is read from environment or config file.
scale_factor : float
The scaling applied to convert amplitudes to vector (arrow) lengths for

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.

Need to mention units first. "... to convert dipole amplitudes (Am) to arrow lengths (mm) for the plot. Default is 1e9, i.e. 1 nAm becomes 1 mm."

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.

is this really necessary? I think it's hard anyway to evaluate dipole strength based on the length of such a tiny arrow.

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.

also you can have dipoles of amplitude 100 nAm and some of 5 nAm so a bit amplitude variation

Comment thread mne/viz/_3d.py Outdated
affine_to = trans['trans'].copy()
affine_to[:3, 3] *= 1000 # to mm
affine_to = np.dot(affine_to, t1.affine)
t1 = resample_from_to(t1, (t1.get_shape(), affine_to))

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 we might always need to resample, otherwise we aren't guaranteed that the units are correct -- MRIs don't have to be sampled in 1mm x 1mm x 1mm voxels...

Did you look into the difference between get_vox2ras and get_vox2ras_tkr? The latter is used in our setup_volume_source_space code so I suspect we'll need to use it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is there some documentation on the difference?

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.

@jaeilepp

Copy link
Copy Markdown
Contributor Author

I've never been able to get freeview working on my computer. I suppose there's some conflicts with the graphics card.

@larsoner

Copy link
Copy Markdown
Member

Here you go:

>>> mne.read_surface(mne.datasets.sample.data_path() + '/subjects/sample/surf/lh.pial')[0][0]
array([-21.12763786, -88.4329071 ,  13.29888344])

Looks like it is the tkr:

screenshot from 2017-02-10 09-30-08

Comment thread mne/viz/_3d.py Outdated
return view_to_disp_mat


def plot_dipole_mri_orthoview(dipole, trans, subject, subjects_dir=None,

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.

could we fuse this with plot_locations or maybe replace it?

Comment thread mne/viz/_3d.py Outdated
return view_to_disp_mat


def plot_dipole_mri_orthoview(dipole, trans, subject, subjects_dir=None,

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.

also how do you specify what dipole you plot? it seems you only plot the first one.

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.

OK I see that I can use interactions to see all dipoles but I am thinking this is a surprising as a default. I would expect to see all dipoles by default. Can we have an interactive=True | False param?

@jaeilepp

Copy link
Copy Markdown
Contributor Author

I'm not sure what the freeview figure is supposed to show, but looking at the code of get_vox2ras_tkr tells me that it just returns the zooms. I don't think we need those.

@codecov-io

codecov-io commented Feb 13, 2017 •

Copy link
Copy Markdown

Codecov Report

Merging #3966 into master will decrease coverage by -8.48%.
The diff coverage is 9.69%.

@@            Coverage Diff             @@
##           master    #3966      +/-   ##
==========================================
- Coverage   86.12%   77.64%   -8.48%     
==========================================
  Files         350      350              
  Lines       63137    63294     +157     
  Branches     9629     9651      +22     
==========================================
- Hits        54375    49143    -5232     
- Misses       6085    11606    +5521     
+ Partials     2677     2545     -132

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 2a1022a...98e6691. Read the comment docs.

@larsoner

larsoner commented Feb 13, 2017 via email

Copy link
Copy Markdown
Member

@jaeilepp

Copy link
Copy Markdown
Contributor Author

Ok, seems like tkr gives results closer to freeview:
tkr

@larsoner

Copy link
Copy Markdown
Member

I still think that the approach here isn't ideal. The X/Y/Z axes are in currently voxels (right?), which is not as useful as them being in the standard coordinate frames we deal with, namely MRI coords or in head depending on the user's choice. The easiest way to get there is by always resampling the MRI to a 1mm grid with the necessary rotation/translation etc., as opposed to the current approach, which seems to be to transform the head (or MRI) coordinate frame data to voxels.

Also, the isoline approach here is a little bit abnormal/unexpected. I'd make that an option, and make the default to be a standard MRI viz.

@larsoner

Copy link
Copy Markdown
Member

...also, maybe the title should have a second line, which is the dipole coordinates in the given (head or MRI) coordinate frame in mm (like ', '.join(['%0.1f' % 1000 * x for x in pos]). It's useful information to have displayed, too

Comment thread mne/viz/_3d.py Outdated
ori = dipole.ori
dd = (dims / 2.) / 1000.
gridx, gridy = np.meshgrid(np.linspace(-dd, dd, dims),
np.linspace(-dd, dd, dims))

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.

Why does the grid depend on the coordinate frame? Can this be unified so that no matter what coordinate frame we're in we can use the same lines here? It might require e.g. just providing dims for the non-head case

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I understand the question. Doesn't it depend on the coordinate frame by definition (eg. -0.1 - 0.1 vs. 0 - 256)?

@larsoner larsoner Feb 21, 2017 •

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.

Doesn't it depend on the coordinate frame by definition (eg. -0.1 - 0.1 vs. 0 - 256)?

The center of the "head coordinate frame" and the "MRI coordinate frame" are both very close to one another:

python -c "import mne; print(mne.read_trans('mne_data/MNE-sample-data/MEG/sample/sample_audvis_raw-trans.fif'))"
<Transform  |  head->MRI (surface RAS)>
[[ 0.99930954  0.01275934  0.0348942   0.00206991]
 [ 0.00998479  0.81240475 -0.58300853  0.01130214]
 [-0.03578702  0.58295429  0.81171638 -0.02755522]
 [ 0.          0.          0.          1.        ]]

So either way the bounds should be very similar, e.g. (-0.1, 0.1).

You're probably thinking of the "MRI voxel coordinate frame", which is not the same as the "MRI coordinate frame". See my old image of FreeView -- the MRI coords (tkr) are centered toward the middle, so something like (-0.1, 0.1) should also work as bounds when plotting in that coordinate frame.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm wondering if there's any sense having the mri space as an option then. The only difference would be having the interpolated slices in head space.

@agramfort

agramfort commented Feb 22, 2017 via email

Copy link
Copy Markdown
Member

@larsoner

larsoner commented Feb 22, 2017 via email

Copy link
Copy Markdown
Member

@agramfort

agramfort commented Feb 22, 2017 via email

Copy link
Copy Markdown
Member

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

Minor plot comments:

  • Label x/y/z axes
  • x: #, y: #, z:# is probably more straightforward as (#, #, #) mm

Comment thread mne/viz/_3d.py
"""
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from .. import Dipole

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 is because from ..dipole import Dipole (as opposed to from .. import Dipole) at the top creates a circular import?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes.

Comment thread mne/viz/_3d.py Outdated
Parameters
----------
dipole : instance of mne.Dipole
The dipole to plot.

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 would actually probably get rid of this docstring since these are all documented above.

But if you want to keep them, this is now out of date (can also be list)

Comment thread mne/viz/_3d.py Outdated
else:
dipole_locs = np.array([apply_trans(trans['trans'], loc) for loc
in dipole.pos])
ori = [apply_trans(trans['trans'], o) for o in dipole.ori]

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 needs a move=False in apply_trans

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.

same here, don't iterate

Comment thread mne/viz/_3d.py Outdated
scatter_points = dipole.pos * 1e3
else:
dipole_locs = np.array([apply_trans(trans['trans'], loc) for loc
in dipole.pos])

@larsoner larsoner Feb 28, 2017 •

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 shouldn't need to iterate over loc, apply_trans handles arrays. You might need a couple of transposes, can't remember

Comment thread mne/viz/_3d.py Outdated
dipole_locs = np.array([apply_trans(trans['trans'], loc) for loc
in dipole.pos])
ori = [apply_trans(trans['trans'], o) for o in dipole.ori]
# Position in meters -> voxels.

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 shouldn't ever be in voxels, but always in mm either in one coordinate frame or the other...?

@agramfort

Copy link
Copy Markdown
Member

@jaeilepp I give you my +1 once you addressed @Eric89GXL 's comments

@larsoner

larsoner commented Mar 1, 2017

Copy link
Copy Markdown
Member

@larsoner

larsoner commented Mar 1, 2017

Copy link
Copy Markdown
Member

... and this looks great:

https://1408-35097627-gh.circle-artifacts.com/0/home/ubuntu/mne-python/doc/_build/html/auto_tutorials/plot_dipole_fit.html

+1 for merge once the minor style things are fixed. Thanks for going through so many iterations with me @jaeilepp!

@larsoner larsoner added this to the 0.14 milestone Mar 1, 2017
@larsoner larsoner changed the title [MRG] Dipole plotter. [MRG+2] Dipole plotter. Mar 1, 2017
@larsoner
larsoner merged commit ec164a0 into mne-tools:master Mar 1, 2017
@agramfort agramfort mentioned this pull request Mar 1, 2017
2 of 4 tasks
@jaeilepp
jaeilepp deleted the dipole-plot branch March 2, 2017 06:01
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.

5 participants