# OPM sensor direction set

**URL:** https://mne.discourse.group/t/opm-sensor-direction-set/6926
**Category:** Support & Discussions
**Created:** [May 19, 2023, 11:36am UTC](https://mne.discourse.group/t/opm-sensor-direction-set/6926 "2023-05-19T11:36:20Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![yuyu](https://avatars.discourse-cdn.com/v4/letter/y/71e660/32.png) [@yuyu](https://mne.discourse.group/u/yuyu)
#### Post date: [May 19, 2023, 11:36am UTC](https://mne.discourse.group/t/opm-sensor-direction-set/6926/1 "2023-05-19T11:36:20Z")

</div>

For OPM MEG, [**raw.info**](http://raw.info/)**[‘chs’][**  **‘**  **num**  **’** **][‘loc’]** **[3:12]** give the OPM sensor direction,called rotation matrix. But if the normal direction of meg sensor is know (n1,n2,n3) only，How can we get the rotation matrix (e11,e12,e13;e21,e22,e23;e31,e32,e33)?

- MNE version: 1.3
- operating system: Windows 10

---

<div class="post-metadata">

### Author: ![UrbanM](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/urbanm/32/2641_2.png) [@UrbanM](https://mne.discourse.group/u/UrbanM)
#### Post date: [May 21, 2023, 6:52am UTC](https://mne.discourse.group/t/opm-sensor-direction-set/6926/2 "2023-05-21T06:52:35Z")

</div>

Hello!

I had the same problem, I had to calculate the rotation matrix which transforms the unit vector (0,0,1) to normal direction of meg sensor (n1,n2,n3). You can try this function `create_rot_matrix(v1, v2)` which can be found in my package megtools inside vector\_functions.py (see [megtools/vector\_functions.py at master · UrbanM/megtools · GitHub](https://github.com/UrbanM/megtools/blob/master/megtools/vector_functions.py))

I used this as following, where holders[i,0:6] is my array of sensor locations and directions.

```python
	unit_v = np.array([0.0, 0.0, 1.0])
	for i in range(len(raw.ch_names)):
		rot_mat = vfun.create_rot_matrix(holders[i, 3:6], unit_v)
		raw.info['chs'][i]['loc'] = np.array(
			[holders[i, 0], holders[i, 1], holders[i, 2], rot_mat[0, 0], rot_mat[0, 1], rot_mat[0, 2],
			rot_mat[1, 0], rot_mat[1, 1], rot_mat[1, 2], rot_mat[2, 0], rot_mat[2, 1], rot_mat[2, 2]])

```
