# Adding a meg-head trans to raw data object

**URL:** <https://mne.discourse.group/t/adding-a-meg-head-trans-to-raw-data-object/3349>\
**Category:** Support & Discussions\
**Created:** [July 3, 2021, 4:45pm UTC](https://mne.discourse.group/t/adding-a-meg-head-trans-to-raw-data-object/3349 "2021-07-03T16:45:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tbardouille](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/tbardouille/32/527_2.png) [@tbardouille](https://mne.discourse.group/u/tbardouille)\
**Post date:** [July 3, 2021, 4:45pm UTC](https://mne.discourse.group/t/adding-a-meg-head-trans-to-raw-data-object/3349/1 "2021-07-03T16:45:42Z")

</div>

HI there,

I’m trying out a new registration method. I’ve generated a trans object based on my data. Is there a way to add my meg-head trans to a raw object?

- MNE-Python version: 0.24.dev0
- operating system: OSx

fifFile = os.path.join(dataDir, subjectID, scanDate, ‘meg’, fifName)  
raw = mne.io.read\_raw\_fif(fifFile, preload=True)

# Note: this raw object does not have an meg-head transform

transMatrix = np.load(os.path.join(procDataDir, subjectID, scanDate, ‘digi’, ‘meg\_head\_trans.npy’))  
trans = mne.transforms.Transform(fro=“meg”, to=“head”, trans=transMatrix)

I’m not sure how to get trans into raw.

Thanks,  
Tim.

---

<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:** [July 5, 2021, 10:00am UTC](https://mne.discourse.group/t/adding-a-meg-head-trans-to-raw-data-object/3349/2 "2021-07-05T10:00:26Z")

</div>

sorry I confused about your workflow. Can you provide a complete gist to see  
in which order you do what?

thx  
A

---

<div class="post-metadata">

**Author:** ![tbardouille](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/tbardouille/32/527_2.png) [@tbardouille](https://mne.discourse.group/u/tbardouille)\
**Post date:** [July 5, 2021, 12:59pm UTC](https://mne.discourse.group/t/adding-a-meg-head-trans-to-raw-data-object/3349/3 "2021-07-05T12:59:35Z")

</div>

Yep. Sorry for the confusion.

This is for FieldLine OPM recordings with a fixed helmet. Basically, my goal is to source localization with my data, but for that I need a successful coordinate frame registration inside MNE. For example, I think that I need the sensor locations in the head coordinate frame, and to check that alignment using viz.plot\_alignment. However, right now the alignment looks bad, and I think that is due to coordinate frame registration issues.

Currently, FieldLine software outputs sensor locations in “meg” (i.e., helmet) coordinate system, and does not have an integrated registration process. That means that there is no meg-head coordinate transform in the raw fif file.

I read in the FieldLine fif file as follows:

- fifFile = os.path.join(dataDir, subjectID, scanDate, ‘meg’, fifName)
- raw = mne.io.read\_raw\_fif(fifFile, preload=True)

I then visualize the sensor locations wrt the fsaverage brain:

- kwargs = dict(eeg=False, coord\_frame=‘meg’, show\_axes=True, verbose=True, trans=‘fsaverage’, subject=‘fsaverage’, subjects\_dir=subjects\_dir, surfaces=(‘head’, ‘pial’))
- mne.viz.plot\_alignment(defaultPosRaw.info, meg=‘sensors’, \*\*kwargs)

I get the same (mis-aligned) result whether I set coord\_frame to ‘meg’ or ‘head’. I think that is because the raw object probably has an identity matrix for the meg-head transform, as a default.

As I mentioned, FieldLine’s prototype acq software does not include a meg-head registration step. I created my own meg-head transform based on Kinect digitization of the head in the OPM sensor array, and save it as a .npy file (in a different loooong script). Then, I load that transform into MNE python:

- transMatrix = np.load(os.path.join(procDataDir, subjectID, scanDate, ‘digi’, ‘meg\_head\_trans.npy’))
- trans = mne.transforms.Transform(fro=“meg”, to=“head”, trans=transMatrix)

I would like to add this transform to the raw object, so that I can check my registration using plot\_aligment, and then move onto localization, as per the OPM example on the MNE website.

I hope that is helpful, but please let me know if there are outstanding questions. Looking forward to your guidance.

Best,  
Tim.

---

<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:** [July 7, 2021, 6:13am UTC](https://mne.discourse.group/t/adding-a-meg-head-trans-to-raw-data-object/3349/4 "2021-07-07T06:13:40Z")

</div>

hi Tim,

I’ve never got my hand on such data. The best I can offer if that you have a look at our doc:

on coord systems:  
[https://mne.tools/dev/auto\_tutorials/forward/20\_source\_alignment.html](https://mne.tools/dev/auto_tutorials/forward/20_source_alignment.html)

on OPM data:  
[https://mne.tools/dev/auto\_examples/datasets/opm\_data.html](https://mne.tools/dev/auto_examples/datasets/opm_data.html)

Alex
