# Where is the sensor location for MEG device pulled from?

**URL:** <https://mne.discourse.group/t/where-is-the-sensor-location-for-meg-device-pulled-from/5435>\
**Category:** Support & Discussions\
**Tags:** visualization\
**Created:** [August 20, 2022, 1:10pm UTC](https://mne.discourse.group/t/where-is-the-sensor-location-for-meg-device-pulled-from/5435 "2022-08-20T13:10:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mscheltienne](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/mscheltienne/32/827_2.png) [@mscheltienne](https://mne.discourse.group/u/mscheltienne)\
**Post date:** [August 20, 2022, 1:10pm UTC](https://mne.discourse.group/t/where-is-the-sensor-location-for-meg-device-pulled-from/5435/1 "2022-08-20T13:10:48Z")

</div>

I’m getting confused about sensor location. Take this example:

```python
from mne.datasets import testing
from mne.io import read_raw_fif

directory = testing.data_path() / "MEG" / "sample"
fname = directory / "sample_audvis_trunc_raw.fif"
raw = read_raw_fif(fname, preload=False)
raw.pick_types(meg=True, eeg=True, eog=True) # 365 channels

```

The montage set on this dataset, `raw.info.get_montage()`, reads as `<DigMontage | 78 extras (headshape), 4 HPIs, 3 fiducials, 59 channels>`. Where is the information about the MEG sensor location stored if it’s not in a montage?

Since I can plot topographic maps from this data with the `grad` or `mag` sensor set which results in a `skirt` outline, information about the sensors must be present somewhere, right?

* * *

EDIT: I’m guessing `raw.info["chs"][...]["loc"]` but why hide it there instead of exposing it as part of the montage API?

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [August 20, 2022, 1:17pm UTC](https://mne.discourse.group/t/where-is-the-sensor-location-for-meg-device-pulled-from/5435/2 "2022-08-20T13:17:08Z")

</div>

> [@mscheltienne](#):
>
> Where is the information about the MEG sensor location stored if it’s not in a montage?

A **montage** stores digitization points. Only for EEG do these typically coincide with the actual sensor locations.

For MEG sensors, you’re commonly working with what MNE calls **layouts.**

Also see this tutorial:  
[https://mne.tools/stable/auto\_tutorials/intro/40\_sensor\_locations.html](https://mne.tools/stable/auto_tutorials/intro/40_sensor_locations.html)

and the last Notes box near the bottom:

> There is no corresponding `make_meg_layout()` function because sensor locations are fixed in an MEG system (unlike in EEG, where sensor caps deform to fit snugly on a specific head).

I suspect (but am not certain) that MNE automatically loads the appropriate builtin layout for a given MEG manufacturer via the [`read_layout()`](https://mne.tools/stable/generated/mne.channels.read_layout.html) function upon loading MEG data.

**Edit:** Layouts are for 2D representations of sensors only. So I don’t think my response actually answers your question, which was about 3D coordinates. Again, I assume that these are just built-in values, or are directly stored in the MEG files by the recording system, from which MNE extracts the values upon reading.

---

<div class="post-metadata">

**Author:** ![mscheltienne](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/mscheltienne/32/827_2.png) [@mscheltienne](https://mne.discourse.group/u/mscheltienne)\
**Post date:** [August 20, 2022, 1:34pm UTC](https://mne.discourse.group/t/where-is-the-sensor-location-for-meg-device-pulled-from/5435/3 "2022-08-20T13:34:23Z")

</div>

I read through the tutorial again, and through another one… it’s adding to the confusion.

→ [Working with sensor locations — MNE 1.6.0 documentation](https://mne.tools/stable/auto_tutorials/intro/40_sensor_locations.html#about-montages-and-layouts)

> [`Montages`](https://mne.tools/stable/generated/mne.channels.DigMontage.html#mne.channels.DigMontage) contain sensor positions in 3D (x, y, z in meters), which can be assigned to existing EEG/MEG data.

So a montage contains the location of a sensor as (x, y, z) coordinates. And MEG is mentioned here…

* * *

But actually, the channel location is stored in `raw.info["chs"][idx]["loc"]` (at least that’s what it looks like to me). The description in the docstring of `mne.Info` gives some information:

> Channel location. For MEG this is the position plus the normal given by a 3x3 rotation matrix. For EEG this is the position followed by reference position (with 6 unused). The values are specified in device coordinates for MEG and in head coordinates for EEG channels, respectively.

That’s more or less the information I was looking for initially.

* * *

What about layouts? I had the same understanding, it’s for 2D representation. Then what about the list of files given in this tutorial: [Working with sensor locations — MNE 1.6.0 documentation](https://mne.tools/stable/auto_tutorials/intro/40_sensor_locations.html#working-with-layout-files)

I recognize both EEG and MEG devices… but I guess we can represent the MEG sensor location as a layout? And finally… [Plotting sensor layouts of MEG systems — MNE 1.6.0 documentation](https://mne.tools/stable/auto_examples/visualization/meg_sensors.html#plotting-sensor-layouts-of-meg-systems) those are definitely not 2D 😉

---

<div class="post-metadata">

**Author:** ![mscheltienne](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/mscheltienne/32/827_2.png) [@mscheltienne](https://mne.discourse.group/u/mscheltienne)\
**Post date:** [August 20, 2022, 1:36pm UTC](https://mne.discourse.group/t/where-is-the-sensor-location-for-meg-device-pulled-from/5435/4 "2022-08-20T13:36:49Z")

</div>

But I get that the sensor position for a MEG device is fixed, so you don’t really need an API to make those locations accessible to the users as for EEG through montage.

---

<div class="post-metadata">

**Author:** ![agramfort](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@agramfort](https://mne.discourse.group/u/agramfort)\
**Post date:** [August 20, 2022, 7:54pm UTC](https://mne.discourse.group/t/where-is-the-sensor-location-for-meg-device-pulled-from/5435/5 "2022-08-20T19:54:41Z")

</div>

an MEG sensors is not a focal point (it requires to define integration points). This is defined by the  
coil type.

As the helmet is rigid the projection to 2D only depends on the device and not the data. The concept  
of layout (taken from Fieldtrip) allows to get 2D locations for sensors but also a box to plot a line plot  
or a time frequency plane.

Alex
