Hi MNE users.

Can anybody tell me where the information regarding dipole orientation is stored when using dipole fitting function on MNE? I need to find the angle that dipole makes with lets say horizontal axis. How can I measure that?

Hi MNE users.

Can anybody tell me where the information regarding dipole orientation is stored when using dipole fitting function on MNE? I need to find the angle that dipole makes with lets say horizontal axis. How can I measure that?

Hello @Rekha,

if you have a dipole object `dip`

, you can get the â€śorientation vectorsâ€ť for all time points via:

```
dip.ori
```

In this array, each row is a â€śunit vectorâ€ť (length 1) with 3 coordinates (x, y, z). Proof that they all have unit length:

```
# %%
# Create dipole fits
import os.path as op
import numpy as np
import mne
data_path = mne.datasets.sample.data_path()
subjects_dir = op.join(data_path, 'subjects')
fname_ave = op.join(data_path, 'MEG', 'sample', 'sample_audvis-ave.fif')
fname_cov = op.join(data_path, 'MEG', 'sample', 'sample_audvis-cov.fif')
fname_bem = op.join(subjects_dir, 'sample', 'bem', 'sample-5120-bem-sol.fif')
fname_trans = op.join(data_path, 'MEG', 'sample',
'sample_audvis_raw-trans.fif')
evoked = mne.read_evokeds(fname_ave, condition='Right Auditory',
baseline=(None, 0))
evoked.pick_types(meg=True)
evoked.crop(0.07, 0.08)
dip, _ = mne.fit_dipole(
evoked, fname_cov, fname_bem, fname_trans, n_jobs=8
)
# calculate lengths of all "ori" vectors
print(np.linalg.norm(dip.ori, axis=1))
```

Returns:

```
array([1., 1., 1., 1., 1., 1., 1.])
```

i.e., the `ori`

vector of each of the 7 dipoles fitted in this example has a length of 1.

Knowing that weâ€™re dealing with unit vectors in 3D space, you can use trigonometric functions to retrieve the angles youâ€™re interested in. For example, this website explains how to do it, but itâ€™s also something you can find in basically any maths book on analytic geometry:

Best wishes,

Richard

2 Likes

Hi @richard, thank you for your reply.

Are these values in the Array equivalent to cosine alpha, cosine beta, cosine gamma of the directional cosines? or what exactly are they?

(I removed my previous answers as I figured I need to get some sleep before thinking about math :))

No these values are not equivalent.

Hello @Rekha, I will look into this again later today and try to provide an answer after Iâ€™ve freshened up my trigonometry knowledge

is the moment in cartesian coordinates. You ask to get it in polar coordinate.

mne has a private function called _cart_to_sph for this.

Alex

I thought a bit about this and the approach Iâ€™d take is consider the 3 2D-planes xy, xz, yz separately and then use 2D trigonometry to solve the problem (calculating the one relevant angle of the right-angled triangle formed by vector and plane). `ori`

then provides the lengths of the legs of the triangle.

But like @agramfort said, itâ€™s not really clear **why** youâ€™d even want to perform these calculations, as itâ€™s usually a spherical coordinate system one would use to describe the angle(s) in 3D space.

Best wishes,

Richard

1 Like

Haha, Thank you so much for the effort Richard, I really appreciate it.

1 Like