Extracting and visualizing subject head movement

Continuous head movement can be encoded during MEG recordings by use of HPI coils that continuously emit sinusoidal signals. These signals can then be extracted from the recording and used to estimate head position as a function of time. Here we show an example of how to do this, and how to visualize the result.

HPI frequencies

First let’s load a short bit of raw data where the subject intentionally moved their head during the recording. Its power spectral density shows five peaks (most clearly visible in the gradiometers) corresponding to the HPI coil frequencies, plus other peaks related to power line interference (60 Hz and harmonics).

# Authors: Eric Larson <larson.eric.d@gmail.com>
#
# License: BSD (3-clause)

from os import path as op

import mne

print(__doc__)

data_path = op.join(mne.datasets.testing.data_path(verbose=True), 'SSS')
fname_raw = op.join(data_path, 'test_move_anon_raw.fif')
raw = mne.io.read_raw_fif(fname_raw, allow_maxshield='yes').load_data()
raw.plot_psd()
Magnetometers, Gradiometers, EEG

Out:

Opening raw data file /home/circleci/mne_data/MNE-testing-data/SSS/test_move_anon_raw.fif...
    Read a total of 12 projection items:
        mag.fif : PCA-v1 (1 x 306)  idle
        mag.fif : PCA-v2 (1 x 306)  idle
        mag.fif : PCA-v3 (1 x 306)  idle
        mag.fif : PCA-v4 (1 x 306)  idle
        mag.fif : PCA-v5 (1 x 306)  idle
        mag.fif : PCA-v6 (1 x 306)  idle
        mag.fif : PCA-v7 (1 x 306)  idle
        grad.fif : PCA-v1 (1 x 306)  idle
        grad.fif : PCA-v2 (1 x 306)  idle
        grad.fif : PCA-v3 (1 x 306)  idle
        grad.fif : PCA-v4 (1 x 306)  idle
        Average EEG reference (1 x 60)  idle
    Range : 10800 ... 31199 =      9.000 ...    25.999 secs
Ready.
Current compensation grade : 0
Reading 0 ... 20399  =      0.000 ...    16.999 secs...
Effective window size : 1.707 (s)
Effective window size : 1.707 (s)
Effective window size : 1.707 (s)

Estimating continuous head position

First, let’s extract the HPI coil amplitudes as a function of time:

Out:

Using 5 HPI coils: 83 143 203 263 323 Hz
Using time window: 60.2 ms
Line interference frequencies: 60 120 180 240 300 360 Hz
Fitting 5 HPI coil locations at up to 1697 time points (17.0 sec duration)

  0%|          | cHPI amplitudes : 0/1697 [00:00<?,       ?it/s]
  1%|          | cHPI amplitudes : 10/1697 [00:00<00:02,  624.15it/s]
  1%|1         | cHPI amplitudes : 22/1697 [00:00<00:02,  628.86it/s]
  2%|2         | cHPI amplitudes : 34/1697 [00:00<00:02,  633.74it/s]
  3%|2         | cHPI amplitudes : 47/1697 [00:00<00:02,  638.90it/s]
  3%|3         | cHPI amplitudes : 59/1697 [00:00<00:02,  643.65it/s]
  4%|4         | cHPI amplitudes : 71/1697 [00:00<00:02,  646.72it/s]
  5%|4         | cHPI amplitudes : 84/1697 [00:00<00:02,  651.76it/s]
  6%|5         | cHPI amplitudes : 97/1697 [00:00<00:02,  657.02it/s]
  6%|6         | cHPI amplitudes : 110/1697 [00:00<00:02,  661.94it/s]
  7%|7         | cHPI amplitudes : 123/1697 [00:00<00:02,  666.79it/s]
  8%|8         | cHPI amplitudes : 136/1697 [00:00<00:02,  671.16it/s]
  9%|8         | cHPI amplitudes : 149/1697 [00:00<00:02,  675.82it/s]
 10%|9         | cHPI amplitudes : 162/1697 [00:00<00:02,  680.15it/s]
 10%|#         | cHPI amplitudes : 175/1697 [00:00<00:02,  684.53it/s]
 11%|#1        | cHPI amplitudes : 187/1697 [00:00<00:02,  686.95it/s]
 12%|#1        | cHPI amplitudes : 200/1697 [00:00<00:02,  690.11it/s]
 13%|#2        | cHPI amplitudes : 213/1697 [00:00<00:02,  693.62it/s]
 13%|#3        | cHPI amplitudes : 226/1697 [00:00<00:02,  697.36it/s]
 14%|#4        | cHPI amplitudes : 238/1697 [00:00<00:02,  699.73it/s]
 15%|#4        | cHPI amplitudes : 251/1697 [00:00<00:02,  702.99it/s]
 16%|#5        | cHPI amplitudes : 264/1697 [00:00<00:02,  706.11it/s]
 16%|#6        | cHPI amplitudes : 277/1697 [00:00<00:02,  708.72it/s]
 17%|#7        | cHPI amplitudes : 289/1697 [00:00<00:01,  709.16it/s]
 18%|#7        | cHPI amplitudes : 302/1697 [00:00<00:01,  712.21it/s]
 19%|#8        | cHPI amplitudes : 314/1697 [00:00<00:01,  713.54it/s]
 19%|#9        | cHPI amplitudes : 327/1697 [00:00<00:01,  716.08it/s]
 20%|##        | cHPI amplitudes : 340/1697 [00:00<00:01,  718.43it/s]
 21%|##        | cHPI amplitudes : 353/1697 [00:00<00:01,  720.83it/s]
 22%|##1       | cHPI amplitudes : 365/1697 [00:00<00:01,  721.07it/s]
 22%|##2       | cHPI amplitudes : 378/1697 [00:00<00:01,  723.08it/s]
 23%|##3       | cHPI amplitudes : 391/1697 [00:00<00:01,  726.06it/s]
 24%|##3       | cHPI amplitudes : 404/1697 [00:00<00:01,  728.65it/s]
 25%|##4       | cHPI amplitudes : 417/1697 [00:00<00:01,  731.17it/s]
 25%|##5       | cHPI amplitudes : 430/1697 [00:00<00:01,  733.54it/s]
 26%|##6       | cHPI amplitudes : 443/1697 [00:00<00:01,  734.56it/s]
 27%|##6       | cHPI amplitudes : 456/1697 [00:00<00:01,  737.06it/s]
 28%|##7       | cHPI amplitudes : 469/1697 [00:00<00:01,  739.06it/s]
 28%|##8       | cHPI amplitudes : 482/1697 [00:00<00:01,  741.08it/s]
 29%|##9       | cHPI amplitudes : 495/1697 [00:00<00:01,  742.78it/s]
 30%|##9       | cHPI amplitudes : 508/1697 [00:00<00:01,  744.53it/s]
 31%|###       | cHPI amplitudes : 521/1697 [00:00<00:01,  744.72it/s]
 31%|###1      | cHPI amplitudes : 534/1697 [00:00<00:01,  746.28it/s]
 32%|###2      | cHPI amplitudes : 547/1697 [00:00<00:01,  747.59it/s]
 33%|###2      | cHPI amplitudes : 560/1697 [00:00<00:01,  749.22it/s]
 34%|###3      | cHPI amplitudes : 573/1697 [00:00<00:01,  750.44it/s]
 35%|###4      | cHPI amplitudes : 586/1697 [00:00<00:01,  752.39it/s]
 35%|###5      | cHPI amplitudes : 599/1697 [00:00<00:01,  754.05it/s]
 36%|###6      | cHPI amplitudes : 612/1697 [00:00<00:01,  754.95it/s]
 37%|###6      | cHPI amplitudes : 625/1697 [00:00<00:01,  755.47it/s]
 38%|###7      | cHPI amplitudes : 638/1697 [00:00<00:01,  755.29it/s]
 38%|###8      | cHPI amplitudes : 651/1697 [00:00<00:01,  756.91it/s]
 39%|###9      | cHPI amplitudes : 664/1697 [00:00<00:01,  757.82it/s]
 40%|###9      | cHPI amplitudes : 677/1697 [00:00<00:01,  758.43it/s]
 41%|####      | cHPI amplitudes : 690/1697 [00:00<00:01,  759.83it/s]
 41%|####1     | cHPI amplitudes : 703/1697 [00:00<00:01,  760.66it/s]
 42%|####2     | cHPI amplitudes : 716/1697 [00:00<00:01,  761.40it/s]
 43%|####2     | cHPI amplitudes : 729/1697 [00:00<00:01,  760.74it/s]
 44%|####3     | cHPI amplitudes : 741/1697 [00:00<00:01,  759.35it/s]
 44%|####4     | cHPI amplitudes : 754/1697 [00:00<00:01,  760.30it/s]
 45%|####5     | cHPI amplitudes : 766/1697 [00:01<00:01,  758.82it/s]
 46%|####5     | cHPI amplitudes : 779/1697 [00:01<00:01,  758.59it/s]
 47%|####6     | cHPI amplitudes : 792/1697 [00:01<00:01,  759.24it/s]
 47%|####7     | cHPI amplitudes : 804/1697 [00:01<00:01,  757.69it/s]
 48%|####8     | cHPI amplitudes : 817/1697 [00:01<00:01,  758.80it/s]
 49%|####8     | cHPI amplitudes : 830/1697 [00:01<00:01,  760.33it/s]
 50%|####9     | cHPI amplitudes : 843/1697 [00:01<00:01,  761.73it/s]
 50%|#####     | cHPI amplitudes : 856/1697 [00:01<00:01,  762.92it/s]
 51%|#####1    | cHPI amplitudes : 869/1697 [00:01<00:01,  762.73it/s]
 52%|#####1    | cHPI amplitudes : 882/1697 [00:01<00:01,  763.29it/s]
 53%|#####2    | cHPI amplitudes : 895/1697 [00:01<00:01,  765.14it/s]
 54%|#####3    | cHPI amplitudes : 908/1697 [00:01<00:01,  766.23it/s]
 54%|#####4    | cHPI amplitudes : 921/1697 [00:01<00:01,  766.63it/s]
 55%|#####4    | cHPI amplitudes : 933/1697 [00:01<00:00,  765.35it/s]
 56%|#####5    | cHPI amplitudes : 946/1697 [00:01<00:00,  766.02it/s]
 57%|#####6    | cHPI amplitudes : 959/1697 [00:01<00:00,  766.97it/s]
 57%|#####7    | cHPI amplitudes : 972/1697 [00:01<00:00,  767.82it/s]
 58%|#####8    | cHPI amplitudes : 985/1697 [00:01<00:00,  768.07it/s]
 59%|#####8    | cHPI amplitudes : 998/1697 [00:01<00:00,  768.37it/s]
 60%|#####9    | cHPI amplitudes : 1011/1697 [00:01<00:00,  769.75it/s]
 60%|######    | cHPI amplitudes : 1024/1697 [00:01<00:00,  770.31it/s]
 61%|######1   | cHPI amplitudes : 1037/1697 [00:01<00:00,  771.08it/s]
 62%|######1   | cHPI amplitudes : 1050/1697 [00:01<00:00,  772.26it/s]
 63%|######2   | cHPI amplitudes : 1063/1697 [00:01<00:00,  773.26it/s]
 63%|######3   | cHPI amplitudes : 1076/1697 [00:01<00:00,  774.39it/s]
 64%|######4   | cHPI amplitudes : 1089/1697 [00:01<00:00,  775.54it/s]
 65%|######4   | cHPI amplitudes : 1102/1697 [00:01<00:00,  775.90it/s]
 66%|######5   | cHPI amplitudes : 1115/1697 [00:01<00:00,  776.52it/s]
 66%|######6   | cHPI amplitudes : 1128/1697 [00:01<00:00,  776.09it/s]
 67%|######7   | cHPI amplitudes : 1141/1697 [00:01<00:00,  776.54it/s]
 68%|######8   | cHPI amplitudes : 1154/1697 [00:01<00:00,  777.60it/s]
 69%|######8   | cHPI amplitudes : 1167/1697 [00:01<00:00,  777.85it/s]
 70%|######9   | cHPI amplitudes : 1180/1697 [00:01<00:00,  779.22it/s]
 70%|#######   | cHPI amplitudes : 1193/1697 [00:01<00:00,  779.76it/s]
 71%|#######1  | cHPI amplitudes : 1206/1697 [00:01<00:00,  780.15it/s]
 72%|#######1  | cHPI amplitudes : 1219/1697 [00:01<00:00,  780.89it/s]
 73%|#######2  | cHPI amplitudes : 1232/1697 [00:01<00:00,  780.78it/s]
 73%|#######3  | cHPI amplitudes : 1245/1697 [00:01<00:00,  780.92it/s]
 74%|#######4  | cHPI amplitudes : 1258/1697 [00:01<00:00,  780.02it/s]
 75%|#######4  | cHPI amplitudes : 1271/1697 [00:01<00:00,  780.98it/s]
 76%|#######5  | cHPI amplitudes : 1284/1697 [00:01<00:00,  781.62it/s]
 76%|#######6  | cHPI amplitudes : 1297/1697 [00:01<00:00,  780.77it/s]
 77%|#######7  | cHPI amplitudes : 1310/1697 [00:01<00:00,  781.39it/s]
 78%|#######7  | cHPI amplitudes : 1323/1697 [00:01<00:00,  782.47it/s]
 79%|#######8  | cHPI amplitudes : 1336/1697 [00:01<00:00,  783.05it/s]
 79%|#######9  | cHPI amplitudes : 1349/1697 [00:01<00:00,  783.91it/s]
 80%|########  | cHPI amplitudes : 1362/1697 [00:01<00:00,  784.79it/s]
 81%|########1 | cHPI amplitudes : 1375/1697 [00:01<00:00,  785.54it/s]
 82%|########1 | cHPI amplitudes : 1388/1697 [00:01<00:00,  784.67it/s]
 83%|########2 | cHPI amplitudes : 1401/1697 [00:01<00:00,  784.50it/s]
 83%|########3 | cHPI amplitudes : 1414/1697 [00:01<00:00,  784.19it/s]
 84%|########4 | cHPI amplitudes : 1427/1697 [00:01<00:00,  785.14it/s]
 85%|########4 | cHPI amplitudes : 1440/1697 [00:01<00:00,  785.64it/s]
 86%|########5 | cHPI amplitudes : 1453/1697 [00:01<00:00,  785.77it/s]
 86%|########6 | cHPI amplitudes : 1466/1697 [00:01<00:00,  785.85it/s]
 87%|########7 | cHPI amplitudes : 1479/1697 [00:01<00:00,  786.15it/s]
 88%|########7 | cHPI amplitudes : 1492/1697 [00:01<00:00,  784.73it/s]
 89%|########8 | cHPI amplitudes : 1506/1697 [00:01<00:00,  786.96it/s]
 90%|########9 | cHPI amplitudes : 1520/1697 [00:01<00:00,  789.50it/s]
 90%|######### | cHPI amplitudes : 1535/1697 [00:01<00:00,  793.65it/s]
 92%|#########1| cHPI amplitudes : 1553/1697 [00:01<00:00,  805.00it/s]
 93%|#########2| cHPI amplitudes : 1573/1697 [00:02<00:00,  818.37it/s]
 94%|#########3| cHPI amplitudes : 1592/1697 [00:02<00:00,  829.90it/s]
 95%|#########4| cHPI amplitudes : 1611/1697 [00:02<00:00,  842.08it/s]
 96%|#########6| cHPI amplitudes : 1632/1697 [00:02<00:00,  856.51it/s]
 97%|#########7| cHPI amplitudes : 1650/1697 [00:02<00:00,  864.83it/s]
 98%|#########8| cHPI amplitudes : 1664/1697 [00:02<00:00,  864.16it/s]
 99%|#########8| cHPI amplitudes : 1680/1697 [00:02<00:00,  868.97it/s]
100%|##########| cHPI amplitudes : 1697/1697 [00:02<00:00,  797.86it/s]

Second, let’s compute time-varying HPI coil locations from these:

Out:

Computing 4385 HPI location guesses (1 cm grid in a 10.7 cm sphere)
HPIFIT: 5 coils digitized in order 5 1 4 3 2
HPI consistency of isotrak and hpifit is OK.

  0%|          | cHPI locations  : 0/1697 [00:00<?,       ?it/s]
  0%|          | cHPI locations  : 1/1697 [00:00<02:34,   10.97it/s]
  2%|2         | cHPI locations  : 39/1697 [00:00<02:23,   11.54it/s]
  5%|4         | cHPI locations  : 81/1697 [00:00<02:13,   12.14it/s]
  6%|5         | cHPI locations  : 101/1697 [00:00<02:05,   12.75it/s]
  8%|8         | cHPI locations  : 142/1697 [00:00<01:55,   13.42it/s]
 11%|#         | cHPI locations  : 183/1697 [00:00<01:47,   14.12it/s]
 12%|#1        | cHPI locations  : 201/1697 [00:00<01:40,   14.82it/s]
 14%|#3        | cHPI locations  : 236/1697 [00:00<01:33,   15.59it/s]
 16%|#6        | cHPI locations  : 277/1697 [00:00<01:26,   16.41it/s]
 18%|#7        | cHPI locations  : 301/1697 [00:00<01:21,   17.23it/s]
 20%|#9        | cHPI locations  : 339/1697 [00:00<01:14,   18.13it/s]
 22%|##2       | cHPI locations  : 375/1697 [00:00<01:09,   19.07it/s]
 24%|##3       | cHPI locations  : 401/1697 [00:00<01:04,   20.02it/s]
 26%|##5       | cHPI locations  : 441/1697 [00:00<00:59,   21.06it/s]
 28%|##7       | cHPI locations  : 473/1697 [00:00<00:55,   22.16it/s]
 30%|##9       | cHPI locations  : 501/1697 [00:00<00:51,   23.25it/s]
 32%|###1      | cHPI locations  : 541/1697 [00:00<00:47,   24.46it/s]
 33%|###2      | cHPI locations  : 560/1697 [00:00<00:44,   25.57it/s]
 34%|###3      | cHPI locations  : 569/1697 [00:00<00:42,   26.55it/s]
 34%|###3      | cHPI locations  : 575/1697 [00:00<00:41,   27.14it/s]
 34%|###4      | cHPI locations  : 579/1697 [00:01<00:40,   27.78it/s]
 34%|###4      | cHPI locations  : 583/1697 [00:01<00:39,   28.32it/s]
 35%|###4      | cHPI locations  : 590/1697 [00:01<00:37,   29.18it/s]
 36%|###6      | cHPI locations  : 611/1697 [00:01<00:35,   30.43it/s]
 37%|###7      | cHPI locations  : 633/1697 [00:01<00:33,   31.99it/s]
 39%|###9      | cHPI locations  : 663/1697 [00:01<00:30,   33.65it/s]
 40%|####      | cHPI locations  : 686/1697 [00:01<00:28,   35.37it/s]
 42%|####1     | cHPI locations  : 710/1697 [00:01<00:26,   37.19it/s]
 42%|####1     | cHPI locations  : 711/1697 [00:01<00:29,   33.63it/s]
 43%|####3     | cHPI locations  : 732/1697 [00:01<00:27,   35.35it/s]
 44%|####4     | cHPI locations  : 751/1697 [00:01<00:25,   37.15it/s]
 46%|####5     | cHPI locations  : 774/1697 [00:01<00:23,   39.05it/s]
 47%|####6     | cHPI locations  : 791/1697 [00:01<00:22,   40.38it/s]
 47%|####6     | cHPI locations  : 796/1697 [00:01<00:22,   40.22it/s]
 47%|####7     | cHPI locations  : 802/1697 [00:01<00:22,   40.27it/s]
 48%|####7     | cHPI locations  : 807/1697 [00:02<00:22,   39.95it/s]
 48%|####7     | cHPI locations  : 812/1697 [00:02<00:22,   39.62it/s]
 48%|####8     | cHPI locations  : 817/1697 [00:02<00:22,   39.36it/s]
 48%|####8     | cHPI locations  : 821/1697 [00:02<00:22,   38.52it/s]
 49%|####8     | cHPI locations  : 825/1697 [00:02<00:23,   37.74it/s]
 49%|####8     | cHPI locations  : 830/1697 [00:02<00:23,   37.67it/s]
 49%|####9     | cHPI locations  : 840/1697 [00:03<00:22,   38.52it/s]
 51%|#####     | cHPI locations  : 861/1697 [00:03<00:20,   39.90it/s]
 52%|#####2    | cHPI locations  : 883/1697 [00:03<00:19,   41.93it/s]
 53%|#####3    | cHPI locations  : 906/1697 [00:03<00:17,   44.07it/s]
 55%|#####4    | cHPI locations  : 929/1697 [00:03<00:16,   46.31it/s]
 56%|#####6    | cHPI locations  : 954/1697 [00:03<00:15,   48.68it/s]
 57%|#####6    | cHPI locations  : 961/1697 [00:03<00:14,   49.29it/s]
 58%|#####8    | cHPI locations  : 988/1697 [00:03<00:13,   51.80it/s]
 60%|#####9    | cHPI locations  : 1015/1697 [00:03<00:12,   54.44it/s]
 61%|######1   | cHPI locations  : 1042/1697 [00:03<00:11,   56.68it/s]
 62%|######2   | cHPI locations  : 1053/1697 [00:03<00:11,   58.38it/s]
 63%|######2   | cHPI locations  : 1064/1697 [00:03<00:10,   60.03it/s]
 63%|######3   | cHPI locations  : 1074/1697 [00:03<00:10,   61.61it/s]
 64%|######4   | cHPI locations  : 1089/1697 [00:03<00:09,   63.69it/s]
 67%|######6   | cHPI locations  : 1129/1697 [00:03<00:08,   66.95it/s]
 69%|######8   | cHPI locations  : 1170/1697 [00:03<00:07,   70.38it/s]
 70%|#######   | cHPI locations  : 1189/1697 [00:03<00:06,   72.89it/s]
 72%|#######2  | cHPI locations  : 1222/1697 [00:03<00:06,   76.58it/s]
 74%|#######3  | cHPI locations  : 1255/1697 [00:03<00:05,   80.45it/s]
 76%|#######5  | cHPI locations  : 1289/1697 [00:04<00:04,   83.76it/s]
 76%|#######6  | cHPI locations  : 1298/1697 [00:04<00:04,   84.86it/s]
 77%|#######6  | cHPI locations  : 1303/1697 [00:04<00:04,   82.34it/s]
 77%|#######7  | cHPI locations  : 1308/1697 [00:04<00:04,   78.78it/s]
 77%|#######7  | cHPI locations  : 1313/1697 [00:04<00:05,   76.63it/s]
 78%|#######7  | cHPI locations  : 1317/1697 [00:04<00:05,   74.15it/s]
 78%|#######7  | cHPI locations  : 1322/1697 [00:04<00:05,   73.30it/s]
 78%|#######8  | cHPI locations  : 1328/1697 [00:04<00:05,   73.55it/s]
 79%|#######8  | cHPI locations  : 1335/1697 [00:04<00:04,   74.13it/s]
 79%|#######9  | cHPI locations  : 1349/1697 [00:04<00:04,   76.14it/s]
 81%|########1 | cHPI locations  : 1382/1697 [00:04<00:03,   79.99it/s]
 83%|########3 | cHPI locations  : 1411/1697 [00:04<00:03,   84.00it/s]
 85%|########5 | cHPI locations  : 1449/1697 [00:04<00:02,   87.42it/s]
 88%|########7 | cHPI locations  : 1485/1697 [00:05<00:02,   91.84it/s]
 89%|########9 | cHPI locations  : 1516/1697 [00:05<00:01,   96.43it/s]
 91%|######### | cHPI locations  : 1544/1697 [00:05<00:01,  101.20it/s]
 91%|#########1| cHPI locations  : 1549/1697 [00:05<00:01,   96.32it/s]
 92%|#########2| cHPI locations  : 1567/1697 [00:05<00:01,   97.75it/s]
 93%|#########2| cHPI locations  : 1574/1697 [00:05<00:01,   96.42it/s]
 93%|#########3| cHPI locations  : 1581/1697 [00:05<00:01,   95.24it/s]
 94%|#########3| cHPI locations  : 1587/1697 [00:05<00:01,   93.67it/s]
 94%|#########3| cHPI locations  : 1591/1697 [00:05<00:01,   89.41it/s]
 94%|#########3| cHPI locations  : 1595/1697 [00:05<00:01,   85.03it/s]
 94%|#########4| cHPI locations  : 1600/1697 [00:05<00:01,   83.34it/s]
 95%|#########4| cHPI locations  : 1610/1697 [00:05<00:01,   84.57it/s]
 96%|#########6| cHPI locations  : 1633/1697 [00:05<00:00,   88.74it/s]
 97%|#########7| cHPI locations  : 1651/1697 [00:06<00:00,   90.19it/s]
 99%|#########9| cHPI locations  : 1688/1697 [00:06<00:00,   94.74it/s]
100%|##########| cHPI locations  : 1697/1697 [00:06<00:00,  280.35it/s]

Lastly, compute head positions from the coil locations:

Out:

t=9.000:     5/5 good HPI fits, movements [mm/s] =      0.1 /      0.2 /      0.5 /      0.2 /      0.3
t=10.000:    5/5 good HPI fits, movements [mm/s] =      0.1 /      0.3 /      0.0 /      0.1 /      0.1
t=11.000:    5/5 good HPI fits, movements [mm/s] =      0.0 /      0.1 /      0.1 /      0.0 /      0.0
t=12.000:    5/5 good HPI fits, movements [mm/s] =      0.0 /      0.0 /      0.0 /      0.0 /      0.0
t=13.000:    5/5 good HPI fits, movements [mm/s] =      0.0 /      0.1 /      0.0 /      0.0 /      0.0
t=14.000:    5/5 good HPI fits, movements [mm/s] =      0.1 /      0.1 /      0.1 /      0.1 /      0.1
t=14.590:    5/5 good HPI fits, movements [mm/s] =      4.8 /      4.6 /      5.9 /      5.2 /      4.6
t=14.680:    5/5 good HPI fits, movements [mm/s] =     32.9 /     33.3 /     38.5 /     36.3 /     30.7
t=14.740:    5/5 good HPI fits, movements [mm/s] =     51.2 /     48.5 /     62.5 /     59.7 /     43.6
t=14.780:    5/5 good HPI fits, movements [mm/s] =     63.6 /     65.7 /     76.3 /     75.5 /     60.3
t=14.820:    5/5 good HPI fits, movements [mm/s] =     72.2 /     65.4 /     80.4 /     82.0 /     62.8
t=14.890:    5/5 good HPI fits, movements [mm/s] =     48.8 /     43.9 /     53.2 /     54.7 /     41.0
t=15.100:    5/5 good HPI fits, movements [mm/s] =     12.9 /     12.8 /     13.4 /     15.8 /     11.9
t=16.100:    5/5 good HPI fits, movements [mm/s] =      0.2 /      0.3 /      0.5 /      0.3 /      0.5
t=16.900:    5/5 good HPI fits, movements [mm/s] =      3.1 /      4.2 /      3.8 /      4.7 /      4.1
t=16.950:    5/5 good HPI fits, movements [mm/s] =     57.4 /     56.2 /     60.8 /     70.4 /     61.9
t=17.010:    5/5 good HPI fits, movements [mm/s] =     56.7 /     54.7 /     61.1 /     65.4 /     56.1
t=17.060:    5/5 good HPI fits, movements [mm/s] =     54.6 /     48.1 /     60.3 /     61.0 /     48.5
t=17.110:    5/5 good HPI fits, movements [mm/s] =     56.4 /     48.6 /     67.8 /     66.2 /     51.7
t=17.160:    5/5 good HPI fits, movements [mm/s] =     60.3 /     57.8 /     73.9 /     68.2 /     58.9
t=17.200:    5/5 good HPI fits, movements [mm/s] =     65.7 /     57.6 /     74.9 /     68.8 /     61.7
t=17.240:    5/5 good HPI fits, movements [mm/s] =     64.6 /     60.9 /     73.2 /     68.8 /     64.4
t=17.290:    5/5 good HPI fits, movements [mm/s] =     65.5 /     65.9 /     74.6 /     71.7 /     70.4
t=17.390:    5/5 good HPI fits, movements [mm/s] =     30.2 /     33.2 /     33.3 /     34.6 /     32.2
t=17.600:    5/5 good HPI fits, movements [mm/s] =     13.4 /     17.4 /     13.8 /     15.7 /     12.2
t=18.600:    5/5 good HPI fits, movements [mm/s] =      0.6 /      0.9 /      0.7 /      0.8 /      0.7
t=19.410:    5/5 good HPI fits, movements [mm/s] =      3.1 /      3.4 /      2.4 /      3.6 /      3.2
t=19.520:    5/5 good HPI fits, movements [mm/s] =     22.4 /     25.4 /     19.3 /     29.2 /     28.2
t=19.630:    5/5 good HPI fits, movements [mm/s] =     21.1 /     24.9 /     21.8 /     31.0 /     31.0
t=19.730:    5/5 good HPI fits, movements [mm/s] =     22.3 /     20.6 /     23.5 /     29.6 /     27.9
t=19.880:    5/5 good HPI fits, movements [mm/s] =     15.8 /     14.0 /     17.8 /     20.9 /     19.4
t=20.880:    5/5 good HPI fits, movements [mm/s] =      2.0 /      1.7 /      1.7 /      2.2 /      1.8
t=21.880:    5/5 good HPI fits, movements [mm/s] =      0.7 /      1.9 /      1.9 /      2.2 /      2.1
t=21.970:    5/5 good HPI fits, movements [mm/s] =     33.0 /     30.8 /     27.0 /     35.6 /     30.1
t=22.020:    5/5 good HPI fits, movements [mm/s] =     68.6 /     65.2 /     50.9 /     73.0 /     55.2
t=22.070:    5/5 good HPI fits, movements [mm/s] =     58.0 /     60.3 /     51.8 /     67.3 /     57.4
t=22.120:    5/5 good HPI fits, movements [mm/s] =     66.0 /     66.6 /     58.2 /     74.9 /     66.1
t=22.160:    5/5 good HPI fits, movements [mm/s] =     75.6 /     77.8 /     65.1 /     84.9 /     69.2
t=22.210:    5/5 good HPI fits, movements [mm/s] =     53.6 /     52.0 /     46.7 /     58.4 /     46.5
t=22.270:    5/5 good HPI fits, movements [mm/s] =     37.9 /     38.9 /     36.0 /     47.7 /     44.6
t=22.340:    5/5 good HPI fits, movements [mm/s] =     39.9 /     37.5 /     29.8 /     43.1 /     34.1
t=22.480:    5/5 good HPI fits, movements [mm/s] =     23.4 /     19.6 /     15.9 /     21.4 /     17.2
t=23.480:    5/5 good HPI fits, movements [mm/s] =      0.6 /      0.9 /      0.2 /      0.5 /      0.4
t=24.480:    5/5 good HPI fits, movements [mm/s] =      1.6 /      1.2 /      1.0 /      1.2 /      0.9
t=24.660:    5/5 good HPI fits, movements [mm/s] =     15.0 /     14.1 /     14.5 /     16.1 /     14.0
t=24.730:    5/5 good HPI fits, movements [mm/s] =     32.1 /     34.9 /     32.9 /     41.8 /     38.1
t=24.800:    5/5 good HPI fits, movements [mm/s] =     30.4 /     35.5 /     32.4 /     41.8 /     39.3
t=24.860:    5/5 good HPI fits, movements [mm/s] =     36.4 /     40.8 /     35.6 /     44.5 /     42.5
t=24.900:    5/5 good HPI fits, movements [mm/s] =     49.1 /     52.9 /     48.9 /     61.0 /     54.0
t=24.940:    5/5 good HPI fits, movements [mm/s] =     60.7 /     55.9 /     60.5 /     67.9 /     60.5
t=24.990:    5/5 good HPI fits, movements [mm/s] =     48.0 /     49.2 /     53.1 /     60.6 /     56.3
t=25.090:    5/5 good HPI fits, movements [mm/s] =     23.9 /     18.5 /     23.4 /     27.9 /     25.7
t=25.500:    5/5 good HPI fits, movements [mm/s] =      2.6 /      7.1 /      7.7 /      6.8 /      8.2

Note that these can then be written to disk or read from disk with mne.chpi.write_head_pos() and mne.chpi.read_head_pos(), respectively.

Visualizing continuous head position

We can plot as traces, which is especially useful for long recordings:

Position (mm), Rotation (quat)

Or we can visualize them as a continuous field (with the vectors pointing in the head-upward direction):

plot 59 head positions

These head positions can then be used with mne.preprocessing.maxwell_filter() to compensate for movement, or with mne.preprocessing.annotate_movement() to mark segments as bad that deviate too much from the average head position.

Total running time of the script: ( 0 minutes 15.137 seconds)

Estimated memory usage: 8 MB

Gallery generated by Sphinx-Gallery