Note
Go to the end to download the full example code.
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>
# Richard Höchenberger <richard.hoechenberger@gmail.com>
# Daniel McCloy <dan@mccloy.info>
#
# License: BSD-3-Clause
# Copyright the MNE-Python contributors.
from os import path as op
import mne
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.compute_psd().plot(picks="data", exclude="bads", amplitude=False)
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.
Reading 0 ... 20399 = 0.000 ... 16.999 secs...
Effective window size : 1.707 (s)
Plotting power spectral density (dB=True).
We can use mne.chpi.get_chpi_info
to retrieve the coil frequencies,
the index of the channel indicating when which coil was switched on, and the
respective “event codes” associated with each coil’s activity.
chpi_freqs, ch_idx, chpi_codes = mne.chpi.get_chpi_info(info=raw.info)
print(f"cHPI coil frequencies extracted from raw: {chpi_freqs} Hz")
Using 5 HPI coils: 83 143 203 263 323 Hz
cHPI coil frequencies extracted from raw: [ 83. 143. 203. 263. 323.] Hz
Estimating continuous head position#
First, let’s extract the HPI coil amplitudes as a function of time:
Using 5 HPI coils: 83 143 203 263 323 Hz
Line interference frequencies: 60.0 120.0 180.0 240.0 300.0 360.0 Hz
Using time window: 83.3 ms
Fitting 5 HPI coil locations at up to 1696 time points (17.0 s duration)
0%| | cHPI amplitudes : 0/1696 [00:00<?, ?it/s]
0%| | cHPI amplitudes : 1/1696 [00:04<2:09:18, 4.58s/it]
1%| | cHPI amplitudes : 18/1696 [00:04<06:48, 4.11it/s]
2%|▏ | cHPI amplitudes : 35/1696 [00:04<03:23, 8.18it/s]
3%|▎ | cHPI amplitudes : 52/1696 [00:04<02:12, 12.43it/s]
4%|▍ | cHPI amplitudes : 69/1696 [00:04<01:36, 16.86it/s]
5%|▌ | cHPI amplitudes : 86/1696 [00:04<01:14, 21.48it/s]
6%|▌ | cHPI amplitudes : 103/1696 [00:04<01:00, 26.31it/s]
7%|▋ | cHPI amplitudes : 121/1696 [00:04<00:49, 31.64it/s]
8%|▊ | cHPI amplitudes : 139/1696 [00:04<00:41, 37.19it/s]
9%|▉ | cHPI amplitudes : 157/1696 [00:04<00:35, 42.97it/s]
10%|█ | cHPI amplitudes : 175/1696 [00:04<00:31, 48.98it/s]
11%|█▏ | cHPI amplitudes : 193/1696 [00:04<00:27, 55.24it/s]
12%|█▏ | cHPI amplitudes : 211/1696 [00:04<00:24, 61.75it/s]
14%|█▎ | cHPI amplitudes : 229/1696 [00:04<00:21, 68.51it/s]
15%|█▍ | cHPI amplitudes : 247/1696 [00:04<00:19, 75.53it/s]
16%|█▌ | cHPI amplitudes : 265/1696 [00:04<00:17, 82.82it/s]
17%|█▋ | cHPI amplitudes : 283/1696 [00:04<00:15, 90.39it/s]
18%|█▊ | cHPI amplitudes : 301/1696 [00:04<00:14, 98.23it/s]
19%|█▉ | cHPI amplitudes : 319/1696 [00:04<00:12, 106.36it/s]
20%|█▉ | cHPI amplitudes : 337/1696 [00:04<00:11, 114.78it/s]
21%|██ | cHPI amplitudes : 355/1696 [00:04<00:10, 123.47it/s]
22%|██▏ | cHPI amplitudes : 373/1696 [00:04<00:09, 132.46it/s]
23%|██▎ | cHPI amplitudes : 391/1696 [00:04<00:09, 141.74it/s]
24%|██▍ | cHPI amplitudes : 409/1696 [00:04<00:08, 151.33it/s]
25%|██▌ | cHPI amplitudes : 427/1696 [00:04<00:07, 161.22it/s]
26%|██▌ | cHPI amplitudes : 445/1696 [00:04<00:07, 171.42it/s]
27%|██▋ | cHPI amplitudes : 463/1696 [00:05<00:06, 181.92it/s]
28%|██▊ | cHPI amplitudes : 481/1696 [00:05<00:06, 192.71it/s]
29%|██▉ | cHPI amplitudes : 499/1696 [00:05<00:05, 203.78it/s]
30%|███ | cHPI amplitudes : 517/1696 [00:05<00:05, 215.08it/s]
32%|███▏ | cHPI amplitudes : 535/1696 [00:05<00:05, 226.71it/s]
33%|███▎ | cHPI amplitudes : 553/1696 [00:05<00:04, 238.63it/s]
34%|███▎ | cHPI amplitudes : 571/1696 [00:05<00:04, 250.80it/s]
35%|███▍ | cHPI amplitudes : 589/1696 [00:05<00:04, 263.25it/s]
36%|███▌ | cHPI amplitudes : 606/1696 [00:05<00:03, 275.12it/s]
37%|███▋ | cHPI amplitudes : 623/1696 [00:05<00:03, 287.11it/s]
38%|███▊ | cHPI amplitudes : 640/1696 [00:05<00:03, 299.34it/s]
39%|███▊ | cHPI amplitudes : 657/1696 [00:05<00:03, 311.76it/s]
40%|███▉ | cHPI amplitudes : 674/1696 [00:05<00:03, 324.53it/s]
41%|████ | cHPI amplitudes : 691/1696 [00:05<00:02, 337.41it/s]
42%|████▏ | cHPI amplitudes : 708/1696 [00:05<00:02, 350.39it/s]
43%|████▎ | cHPI amplitudes : 725/1696 [00:05<00:02, 363.55it/s]
44%|████▍ | cHPI amplitudes : 742/1696 [00:05<00:02, 376.89it/s]
45%|████▍ | cHPI amplitudes : 759/1696 [00:05<00:02, 390.36it/s]
46%|████▌ | cHPI amplitudes : 776/1696 [00:05<00:02, 404.05it/s]
47%|████▋ | cHPI amplitudes : 793/1696 [00:05<00:02, 417.75it/s]
48%|████▊ | cHPI amplitudes : 810/1696 [00:05<00:02, 431.59it/s]
49%|████▉ | cHPI amplitudes : 827/1696 [00:05<00:01, 445.44it/s]
50%|████▉ | cHPI amplitudes : 844/1696 [00:05<00:01, 459.55it/s]
51%|█████ | cHPI amplitudes : 861/1696 [00:05<00:01, 473.51it/s]
52%|█████▏ | cHPI amplitudes : 878/1696 [00:05<00:01, 487.33it/s]
53%|█████▎ | cHPI amplitudes : 895/1696 [00:05<00:01, 501.15it/s]
54%|█████▍ | cHPI amplitudes : 912/1696 [00:05<00:01, 515.24it/s]
55%|█████▍ | cHPI amplitudes : 929/1696 [00:05<00:01, 529.09it/s]
56%|█████▌ | cHPI amplitudes : 946/1696 [00:05<00:01, 543.15it/s]
57%|█████▋ | cHPI amplitudes : 963/1696 [00:05<00:01, 557.23it/s]
58%|█████▊ | cHPI amplitudes : 980/1696 [00:05<00:01, 570.99it/s]
59%|█████▉ | cHPI amplitudes : 997/1696 [00:05<00:01, 584.44it/s]
60%|█████▉ | cHPI amplitudes : 1014/1696 [00:05<00:01, 597.73it/s]
61%|██████ | cHPI amplitudes : 1030/1696 [00:05<00:01, 608.97it/s]
62%|██████▏ | cHPI amplitudes : 1047/1696 [00:05<00:01, 622.26it/s]
63%|██████▎ | cHPI amplitudes : 1064/1696 [00:05<00:00, 634.81it/s]
64%|██████▎ | cHPI amplitudes : 1081/1696 [00:05<00:00, 647.86it/s]
65%|██████▍ | cHPI amplitudes : 1098/1696 [00:05<00:00, 660.59it/s]
66%|██████▌ | cHPI amplitudes : 1115/1696 [00:05<00:00, 672.74it/s]
67%|██████▋ | cHPI amplitudes : 1132/1696 [00:05<00:00, 684.90it/s]
68%|██████▊ | cHPI amplitudes : 1149/1696 [00:05<00:00, 696.74it/s]
69%|██████▉ | cHPI amplitudes : 1166/1696 [00:05<00:00, 708.61it/s]
70%|██████▉ | cHPI amplitudes : 1183/1696 [00:05<00:00, 719.79it/s]
71%|███████ | cHPI amplitudes : 1200/1696 [00:05<00:00, 731.02it/s]
72%|███████▏ | cHPI amplitudes : 1217/1696 [00:05<00:00, 742.10it/s]
73%|███████▎ | cHPI amplitudes : 1234/1696 [00:05<00:00, 753.12it/s]
74%|███████▍ | cHPI amplitudes : 1251/1696 [00:05<00:00, 763.59it/s]
75%|███████▍ | cHPI amplitudes : 1268/1696 [00:05<00:00, 773.75it/s]
76%|███████▌ | cHPI amplitudes : 1284/1696 [00:05<00:00, 781.62it/s]
77%|███████▋ | cHPI amplitudes : 1301/1696 [00:05<00:00, 791.17it/s]
78%|███████▊ | cHPI amplitudes : 1318/1696 [00:05<00:00, 801.14it/s]
79%|███████▊ | cHPI amplitudes : 1335/1696 [00:05<00:00, 810.13it/s]
80%|███████▉ | cHPI amplitudes : 1352/1696 [00:05<00:00, 818.86it/s]
81%|████████ | cHPI amplitudes : 1369/1696 [00:05<00:00, 827.62it/s]
82%|████████▏ | cHPI amplitudes : 1386/1696 [00:05<00:00, 835.89it/s]
83%|████████▎ | cHPI amplitudes : 1403/1696 [00:05<00:00, 843.73it/s]
84%|████████▎ | cHPI amplitudes : 1420/1696 [00:05<00:00, 851.16it/s]
85%|████████▍ | cHPI amplitudes : 1436/1696 [00:05<00:00, 855.87it/s]
86%|████████▌ | cHPI amplitudes : 1453/1696 [00:05<00:00, 862.58it/s]
87%|████████▋ | cHPI amplitudes : 1470/1696 [00:05<00:00, 868.91it/s]
88%|████████▊ | cHPI amplitudes : 1487/1696 [00:05<00:00, 875.32it/s]
89%|████████▊ | cHPI amplitudes : 1504/1696 [00:06<00:00, 881.61it/s]
90%|████████▉ | cHPI amplitudes : 1521/1696 [00:06<00:00, 887.91it/s]
91%|█████████ | cHPI amplitudes : 1538/1696 [00:06<00:00, 893.68it/s]
92%|█████████▏| cHPI amplitudes : 1555/1696 [00:06<00:00, 899.46it/s]
93%|█████████▎| cHPI amplitudes : 1572/1696 [00:06<00:00, 905.35it/s]
94%|█████████▎| cHPI amplitudes : 1589/1696 [00:06<00:00, 910.41it/s]
95%|█████████▍| cHPI amplitudes : 1606/1696 [00:06<00:00, 916.29it/s]
96%|█████████▌| cHPI amplitudes : 1623/1696 [00:06<00:00, 921.34it/s]
97%|█████████▋| cHPI amplitudes : 1640/1696 [00:06<00:00, 926.21it/s]
98%|█████████▊| cHPI amplitudes : 1657/1696 [00:06<00:00, 931.00it/s]
99%|█████████▊| cHPI amplitudes : 1674/1696 [00:06<00:00, 935.54it/s]
100%|█████████▉| cHPI amplitudes : 1691/1696 [00:06<00:00, 939.10it/s]
100%|██████████| cHPI amplitudes : 1696/1696 [00:06<00:00, 273.40it/s]
Second, let’s compute time-varying HPI coil locations from these:
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/1696 [00:00<?, ?it/s]
0%| | cHPI locations : 1/1696 [00:00<26:35, 1.06it/s]
3%|▎ | cHPI locations : 56/1696 [00:00<00:26, 61.44it/s]
5%|▌ | cHPI locations : 91/1696 [00:00<00:16, 100.00it/s]
6%|▌ | cHPI locations : 101/1696 [00:01<00:15, 101.68it/s]
8%|▊ | cHPI locations : 130/1696 [00:01<00:11, 132.32it/s]
9%|▉ | cHPI locations : 159/1696 [00:01<00:09, 163.45it/s]
11%|█ | cHPI locations : 189/1696 [00:01<00:07, 196.08it/s]
12%|█▏ | cHPI locations : 201/1696 [00:01<00:07, 192.56it/s]
14%|█▎ | cHPI locations : 231/1696 [00:01<00:06, 224.30it/s]
15%|█▌ | cHPI locations : 262/1696 [00:01<00:05, 257.76it/s]
17%|█▋ | cHPI locations : 295/1696 [00:01<00:04, 294.03it/s]
18%|█▊ | cHPI locations : 301/1696 [00:01<00:05, 276.73it/s]
20%|██ | cHPI locations : 341/1696 [00:01<00:04, 321.24it/s]
23%|██▎ | cHPI locations : 383/1696 [00:01<00:03, 368.75it/s]
24%|██▎ | cHPI locations : 401/1696 [00:01<00:03, 356.53it/s]
26%|██▌ | cHPI locations : 442/1696 [00:01<00:03, 401.34it/s]
29%|██▊ | cHPI locations : 484/1696 [00:01<00:02, 447.83it/s]
30%|██▉ | cHPI locations : 501/1696 [00:01<00:02, 424.20it/s]
32%|███▏ | cHPI locations : 543/1696 [00:01<00:02, 469.11it/s]
33%|███▎ | cHPI locations : 559/1696 [00:01<00:02, 429.19it/s]
33%|███▎ | cHPI locations : 568/1696 [00:01<00:02, 390.82it/s]
34%|███▍ | cHPI locations : 573/1696 [00:01<00:03, 354.36it/s]
34%|███▍ | cHPI locations : 577/1696 [00:01<00:03, 324.69it/s]
34%|███▍ | cHPI locations : 581/1696 [00:02<00:03, 296.45it/s]
35%|███▍ | cHPI locations : 587/1696 [00:02<00:04, 275.02it/s]
35%|███▌ | cHPI locations : 600/1696 [00:02<00:04, 261.89it/s]
38%|███▊ | cHPI locations : 641/1696 [00:02<00:03, 294.67it/s]
40%|████ | cHPI locations : 683/1696 [00:02<00:03, 329.10it/s]
41%|████▏ | cHPI locations : 700/1696 [00:02<00:03, 313.25it/s]
44%|████▍ | cHPI locations : 742/1696 [00:02<00:02, 346.97it/s]
46%|████▌ | cHPI locations : 784/1696 [00:02<00:02, 381.52it/s]
47%|████▋ | cHPI locations : 789/1696 [00:02<00:02, 352.19it/s]
47%|████▋ | cHPI locations : 794/1696 [00:02<00:02, 326.02it/s]
47%|████▋ | cHPI locations : 800/1696 [00:02<00:02, 304.19it/s]
47%|████▋ | cHPI locations : 805/1696 [00:02<00:03, 282.36it/s]
48%|████▊ | cHPI locations : 810/1696 [00:02<00:03, 262.16it/s]
48%|████▊ | cHPI locations : 815/1696 [00:03<00:03, 245.49it/s]
48%|████▊ | cHPI locations : 819/1696 [00:03<00:03, 229.55it/s]
49%|████▊ | cHPI locations : 823/1696 [00:03<00:04, 214.97it/s]
49%|████▉ | cHPI locations : 827/1696 [00:03<00:04, 202.45it/s]
49%|████▉ | cHPI locations : 833/1696 [00:03<00:04, 191.92it/s]
50%|█████ | cHPI locations : 848/1696 [00:03<00:04, 188.63it/s]
52%|█████▏ | cHPI locations : 879/1696 [00:03<00:03, 208.15it/s]
54%|█████▎ | cHPI locations : 910/1696 [00:03<00:03, 228.22it/s]
55%|█████▌ | cHPI locations : 940/1696 [00:03<00:03, 248.04it/s]
56%|█████▌ | cHPI locations : 948/1696 [00:03<00:03, 235.31it/s]
58%|█████▊ | cHPI locations : 987/1696 [00:03<00:02, 262.21it/s]
61%|██████ | cHPI locations : 1028/1696 [00:03<00:02, 291.44it/s]
61%|██████▏ | cHPI locations : 1040/1696 [00:03<00:02, 278.59it/s]
62%|██████▏ | cHPI locations : 1051/1696 [00:03<00:02, 267.06it/s]
63%|██████▎ | cHPI locations : 1062/1696 [00:04<00:02, 255.23it/s]
63%|██████▎ | cHPI locations : 1072/1696 [00:04<00:02, 244.07it/s]
64%|██████▍ | cHPI locations : 1086/1696 [00:04<00:02, 236.74it/s]
66%|██████▌ | cHPI locations : 1115/1696 [00:04<00:02, 255.18it/s]
68%|██████▊ | cHPI locations : 1146/1696 [00:04<00:01, 275.56it/s]
69%|██████▉ | cHPI locations : 1175/1696 [00:04<00:01, 294.94it/s]
70%|██████▉ | cHPI locations : 1186/1696 [00:04<00:01, 281.30it/s]
72%|███████▏ | cHPI locations : 1216/1696 [00:04<00:01, 301.58it/s]
73%|███████▎ | cHPI locations : 1246/1696 [00:04<00:01, 322.41it/s]
75%|███████▌ | cHPI locations : 1279/1696 [00:04<00:01, 346.30it/s]
76%|███████▌ | cHPI locations : 1286/1696 [00:04<00:01, 325.69it/s]
76%|███████▋ | cHPI locations : 1296/1696 [00:04<00:01, 307.11it/s]
77%|███████▋ | cHPI locations : 1301/1696 [00:04<00:01, 288.22it/s]
77%|███████▋ | cHPI locations : 1306/1696 [00:04<00:01, 270.71it/s]
77%|███████▋ | cHPI locations : 1311/1696 [00:04<00:01, 253.20it/s]
78%|███████▊ | cHPI locations : 1315/1696 [00:05<00:01, 238.35it/s]
78%|███████▊ | cHPI locations : 1319/1696 [00:05<00:01, 223.12it/s]
78%|███████▊ | cHPI locations : 1325/1696 [00:05<00:01, 212.23it/s]
78%|███████▊ | cHPI locations : 1331/1696 [00:05<00:01, 203.37it/s]
79%|███████▉ | cHPI locations : 1341/1696 [00:05<00:01, 195.41it/s]
81%|████████ | cHPI locations : 1371/1696 [00:05<00:01, 214.18it/s]
83%|████████▎ | cHPI locations : 1401/1696 [00:05<00:01, 233.50it/s]
84%|████████▍ | cHPI locations : 1432/1696 [00:05<00:01, 254.04it/s]
85%|████████▍ | cHPI locations : 1441/1696 [00:05<00:01, 243.06it/s]
87%|████████▋ | cHPI locations : 1470/1696 [00:05<00:00, 262.36it/s]
88%|████████▊ | cHPI locations : 1499/1696 [00:05<00:00, 282.14it/s]
90%|█████████ | cHPI locations : 1529/1696 [00:05<00:00, 303.24it/s]
91%|█████████ | cHPI locations : 1541/1696 [00:05<00:00, 288.56it/s]
92%|█████████▏| cHPI locations : 1565/1696 [00:05<00:00, 280.54it/s]
93%|█████████▎| cHPI locations : 1573/1696 [00:05<00:00, 265.25it/s]
93%|█████████▎| cHPI locations : 1580/1696 [00:06<00:00, 252.02it/s]
94%|█████████▎| cHPI locations : 1586/1696 [00:06<00:00, 239.13it/s]
94%|█████████▍| cHPI locations : 1590/1696 [00:06<00:00, 224.18it/s]
94%|█████████▍| cHPI locations : 1594/1696 [00:06<00:00, 209.82it/s]
94%|█████████▍| cHPI locations : 1599/1696 [00:06<00:00, 197.64it/s]
95%|█████████▍| cHPI locations : 1609/1696 [00:06<00:00, 190.44it/s]
97%|█████████▋| cHPI locations : 1639/1696 [00:06<00:00, 208.65it/s]
97%|█████████▋| cHPI locations : 1652/1696 [00:06<00:00, 202.21it/s]
100%|█████████▉| cHPI locations : 1691/1696 [00:06<00:00, 226.80it/s]
100%|██████████| cHPI locations : 1696/1696 [00:06<00:00, 253.25it/s]
Lastly, compute head positions from the coil locations:
head_pos = mne.chpi.compute_head_pos(raw.info, chpi_locs, verbose=True)
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.2 / 0.0 / 0.2 / 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.1 / 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.0 / 0.1 / 0.1 / 0.1 / 0.1
t=14.580: 5/5 good HPI fits, movements [mm/s] = 5.0 / 4.8 / 6.1 / 5.5 / 4.9
t=14.670: 5/5 good HPI fits, movements [mm/s] = 33.3 / 33.8 / 39.9 / 37.9 / 30.2
t=14.720: 5/5 good HPI fits, movements [mm/s] = 49.3 / 47.7 / 60.2 / 59.1 / 44.3
t=14.760: 5/5 good HPI fits, movements [mm/s] = 64.9 / 63.6 / 73.0 / 71.3 / 56.6
t=14.800: 5/5 good HPI fits, movements [mm/s] = 67.4 / 59.1 / 83.1 / 78.2 / 60.9
t=14.860: 5/5 good HPI fits, movements [mm/s] = 54.4 / 52.2 / 57.6 / 62.0 / 47.2
t=14.990: 5/5 good HPI fits, movements [mm/s] = 23.3 / 22.6 / 24.2 / 27.0 / 19.8
t=15.990: 5/5 good HPI fits, movements [mm/s] = 0.7 / 0.9 / 0.8 / 0.8 / 0.9
t=16.880: 5/5 good HPI fits, movements [mm/s] = 2.5 / 3.4 / 3.0 / 3.8 / 3.3
t=16.930: 5/5 good HPI fits, movements [mm/s] = 52.2 / 55.2 / 58.3 / 67.0 / 59.7
t=16.990: 5/5 good HPI fits, movements [mm/s] = 57.1 / 53.8 / 62.0 / 65.1 / 57.7
t=17.040: 5/5 good HPI fits, movements [mm/s] = 53.0 / 50.7 / 60.0 / 61.9 / 49.3
t=17.090: 5/5 good HPI fits, movements [mm/s] = 57.9 / 49.2 / 66.6 / 64.8 / 51.6
t=17.140: 5/5 good HPI fits, movements [mm/s] = 60.4 / 54.7 / 72.6 / 67.3 / 57.7
t=17.180: 5/5 good HPI fits, movements [mm/s] = 63.6 / 58.2 / 74.5 / 72.2 / 61.7
t=17.220: 5/5 good HPI fits, movements [mm/s] = 61.0 / 60.0 / 75.2 / 71.3 / 63.3
t=17.260: 5/5 good HPI fits, movements [mm/s] = 67.9 / 66.3 / 73.4 / 68.9 / 68.9
t=17.320: 5/5 good HPI fits, movements [mm/s] = 49.7 / 50.9 / 54.8 / 55.0 / 52.6
t=17.470: 5/5 good HPI fits, movements [mm/s] = 18.4 / 21.5 / 19.3 / 20.5 / 17.3
t=18.470: 5/5 good HPI fits, movements [mm/s] = 1.9 / 2.7 / 2.0 / 2.4 / 1.9
t=19.390: 5/5 good HPI fits, movements [mm/s] = 2.4 / 2.7 / 1.9 / 2.9 / 2.5
t=19.500: 5/5 good HPI fits, movements [mm/s] = 23.0 / 25.3 / 19.4 / 28.9 / 27.7
t=19.610: 5/5 good HPI fits, movements [mm/s] = 21.2 / 25.7 / 21.8 / 31.6 / 31.3
t=19.710: 5/5 good HPI fits, movements [mm/s] = 22.0 / 20.7 / 23.0 / 29.7 / 27.8
t=19.850: 5/5 good HPI fits, movements [mm/s] = 16.5 / 14.7 / 18.5 / 21.9 / 20.1
t=20.850: 5/5 good HPI fits, movements [mm/s] = 2.3 / 1.9 / 2.0 / 2.5 / 2.2
t=21.850: 5/5 good HPI fits, movements [mm/s] = 0.6 / 1.7 / 1.7 / 2.0 / 1.9
t=21.950: 5/5 good HPI fits, movements [mm/s] = 25.8 / 27.1 / 24.1 / 32.2 / 26.4
t=22.000: 5/5 good HPI fits, movements [mm/s] = 66.0 / 58.9 / 46.4 / 64.8 / 51.9
t=22.050: 5/5 good HPI fits, movements [mm/s] = 59.7 / 62.9 / 51.0 / 69.1 / 57.9
t=22.100: 5/5 good HPI fits, movements [mm/s] = 61.5 / 65.4 / 58.5 / 75.0 / 64.8
t=22.140: 5/5 good HPI fits, movements [mm/s] = 74.4 / 73.6 / 62.3 / 79.9 / 68.2
t=22.180: 5/5 good HPI fits, movements [mm/s] = 63.9 / 59.6 / 52.9 / 67.2 / 53.2
t=22.240: 5/5 good HPI fits, movements [mm/s] = 38.3 / 39.0 / 36.5 / 48.3 / 42.2
t=22.300: 5/5 good HPI fits, movements [mm/s] = 42.0 / 40.4 / 33.7 / 47.1 / 38.9
t=22.400: 5/5 good HPI fits, movements [mm/s] = 31.7 / 28.5 / 22.1 / 30.8 / 25.0
t=23.400: 5/5 good HPI fits, movements [mm/s] = 1.8 / 1.8 / 1.1 / 1.6 / 1.2
t=24.400: 5/5 good HPI fits, movements [mm/s] = 1.2 / 0.8 / 0.7 / 0.8 / 0.7
t=24.640: 5/5 good HPI fits, movements [mm/s] = 12.6 / 11.6 / 11.5 / 13.0 / 11.0
t=24.720: 5/5 good HPI fits, movements [mm/s] = 30.3 / 33.0 / 31.4 / 39.0 / 35.0
t=24.790: 5/5 good HPI fits, movements [mm/s] = 31.3 / 35.7 / 33.0 / 43.0 / 40.8
t=24.850: 5/5 good HPI fits, movements [mm/s] = 37.2 / 41.4 / 35.6 / 44.6 / 42.4
t=24.890: 5/5 good HPI fits, movements [mm/s] = 50.1 / 51.9 / 49.7 / 60.1 / 52.9
t=24.930: 5/5 good HPI fits, movements [mm/s] = 56.4 / 55.3 / 59.1 / 68.3 / 61.9
t=24.980: 5/5 good HPI fits, movements [mm/s] = 47.2 / 47.1 / 51.0 / 58.7 / 53.7
t=25.080: 5/5 good HPI fits, movements [mm/s] = 23.8 / 19.4 / 23.3 / 28.2 / 26.3
t=25.510: 5/5 good HPI fits, movements [mm/s] = 2.4 / 6.6 / 7.4 / 6.5 / 7.8
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:
mne.viz.plot_head_positions(head_pos, mode="traces", totals=True)
Or we can visualize them as a continuous field (with the vectors pointing in the head-upward direction):
mne.viz.plot_head_positions(head_pos, mode="field")
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.
Computing SNR of the HPI signal#
It is also possible to compute the SNR of the continuous HPI measurements.
This can be a useful proxy for head position along the vertical dimension,
i.e., it can indicate the distance between the HPI coils and the MEG sensors.
Using compute_chpi_snr
, the HPI power and SNR are computed
separately for each MEG sensor type and each HPI coil (frequency), along with
the residual power for each sensor type. The results can then be visualized
with plot_chpi_snr
. Here we’ll just show a few seconds, for speed:
raw.crop(tmin=5, tmax=10)
snr_dict = mne.chpi.compute_chpi_snr(raw)
fig = mne.viz.plot_chpi_snr(snr_dict)
Using 5 HPI coils: 83 143 203 263 323 Hz
Line interference frequencies: 60.0 120.0 180.0 240.0 300.0 360.0 Hz
Using time window: 83.3 ms
Fitting 5 HPI coil locations at up to 496 time points (5.0 s duration)
0%| | cHPI SNRs : 0/496 [00:00<?, ?it/s]
0%| | cHPI SNRs : 1/496 [00:06<50:45, 6.15s/it]
1%| | cHPI SNRs : 5/496 [00:06<09:41, 1.19s/it]
2%|▏ | cHPI SNRs : 8/496 [00:06<05:54, 1.38it/s]
2%|▏ | cHPI SNRs : 12/496 [00:06<03:47, 2.12it/s]
3%|▎ | cHPI SNRs : 16/496 [00:06<02:45, 2.90it/s]
4%|▍ | cHPI SNRs : 20/496 [00:06<02:07, 3.72it/s]
5%|▍ | cHPI SNRs : 24/496 [00:06<01:43, 4.57it/s]
5%|▌ | cHPI SNRs : 27/496 [00:06<01:29, 5.23it/s]
6%|▌ | cHPI SNRs : 30/496 [00:06<01:18, 5.92it/s]
6%|▋ | cHPI SNRs : 32/496 [00:06<01:12, 6.39it/s]
7%|▋ | cHPI SNRs : 35/496 [00:06<01:04, 7.15it/s]
8%|▊ | cHPI SNRs : 39/496 [00:06<00:55, 8.21it/s]
9%|▊ | cHPI SNRs : 43/496 [00:06<00:48, 9.31it/s]
9%|▉ | cHPI SNRs : 47/496 [00:06<00:42, 10.47it/s]
10%|█ | cHPI SNRs : 51/496 [00:06<00:38, 11.66it/s]
11%|█ | cHPI SNRs : 54/496 [00:06<00:35, 12.57it/s]
11%|█▏ | cHPI SNRs : 57/496 [00:06<00:32, 13.51it/s]
12%|█▏ | cHPI SNRs : 60/496 [00:06<00:30, 14.49it/s]
13%|█▎ | cHPI SNRs : 64/496 [00:06<00:27, 15.89it/s]
14%|█▎ | cHPI SNRs : 67/496 [00:06<00:25, 16.97it/s]
14%|█▍ | cHPI SNRs : 70/496 [00:06<00:23, 18.08it/s]
15%|█▍ | cHPI SNRs : 73/496 [00:06<00:21, 19.24it/s]
16%|█▌ | cHPI SNRs : 77/496 [00:06<00:20, 20.84it/s]
16%|█▌ | cHPI SNRs : 80/496 [00:06<00:18, 22.08it/s]
17%|█▋ | cHPI SNRs : 83/496 [00:06<00:17, 23.36it/s]
18%|█▊ | cHPI SNRs : 87/496 [00:06<00:16, 25.14it/s]
18%|█▊ | cHPI SNRs : 91/496 [00:06<00:15, 26.99it/s]
19%|█▉ | cHPI SNRs : 94/496 [00:06<00:14, 28.36it/s]
20%|█▉ | cHPI SNRs : 98/496 [00:06<00:13, 30.38it/s]
21%|██ | cHPI SNRs : 102/496 [00:06<00:12, 32.45it/s]
21%|██▏ | cHPI SNRs : 106/496 [00:06<00:11, 34.59it/s]
22%|██▏ | cHPI SNRs : 110/496 [00:06<00:10, 36.79it/s]
23%|██▎ | cHPI SNRs : 113/496 [00:06<00:09, 38.34it/s]
23%|██▎ | cHPI SNRs : 116/496 [00:06<00:09, 39.95it/s]
24%|██▍ | cHPI SNRs : 118/496 [00:06<00:09, 40.90it/s]
24%|██▍ | cHPI SNRs : 120/496 [00:06<00:08, 41.92it/s]
25%|██▍ | cHPI SNRs : 123/496 [00:06<00:08, 43.74it/s]
26%|██▌ | cHPI SNRs : 127/496 [00:06<00:07, 46.38it/s]
26%|██▋ | cHPI SNRs : 131/496 [00:06<00:07, 49.08it/s]
27%|██▋ | cHPI SNRs : 135/496 [00:06<00:06, 51.86it/s]
28%|██▊ | cHPI SNRs : 139/496 [00:06<00:06, 54.64it/s]
29%|██▊ | cHPI SNRs : 142/496 [00:06<00:06, 56.42it/s]
29%|██▉ | cHPI SNRs : 145/496 [00:06<00:06, 58.44it/s]
30%|███ | cHPI SNRs : 151/496 [00:06<00:05, 63.41it/s]
32%|███▏ | cHPI SNRs : 157/496 [00:06<00:04, 68.46it/s]
33%|███▎ | cHPI SNRs : 163/496 [00:06<00:04, 73.59it/s]
34%|███▍ | cHPI SNRs : 169/496 [00:06<00:04, 78.80it/s]
35%|███▌ | cHPI SNRs : 175/496 [00:06<00:03, 84.07it/s]
36%|███▋ | cHPI SNRs : 181/496 [00:07<00:03, 89.46it/s]
38%|███▊ | cHPI SNRs : 187/496 [00:07<00:03, 94.93it/s]
39%|███▉ | cHPI SNRs : 193/496 [00:07<00:03, 100.38it/s]
40%|████ | cHPI SNRs : 199/496 [00:07<00:02, 105.91it/s]
41%|████▏ | cHPI SNRs : 205/496 [00:07<00:02, 111.52it/s]
43%|████▎ | cHPI SNRs : 211/496 [00:07<00:02, 117.05it/s]
44%|████▍ | cHPI SNRs : 217/496 [00:07<00:02, 122.55it/s]
45%|████▍ | cHPI SNRs : 223/496 [00:07<00:02, 128.12it/s]
46%|████▌ | cHPI SNRs : 229/496 [00:07<00:01, 133.80it/s]
47%|████▋ | cHPI SNRs : 235/496 [00:07<00:01, 139.08it/s]
48%|████▊ | cHPI SNRs : 239/496 [00:07<00:01, 140.66it/s]
49%|████▉ | cHPI SNRs : 242/496 [00:07<00:01, 141.82it/s]
49%|████▉ | cHPI SNRs : 245/496 [00:07<00:01, 142.93it/s]
50%|█████ | cHPI SNRs : 248/496 [00:07<00:01, 144.06it/s]
51%|█████ | cHPI SNRs : 251/496 [00:07<00:01, 145.23it/s]
51%|█████ | cHPI SNRs : 254/496 [00:07<00:01, 146.36it/s]
52%|█████▏ | cHPI SNRs : 257/496 [00:07<00:01, 147.43it/s]
52%|█████▏ | cHPI SNRs : 260/496 [00:07<00:01, 148.50it/s]
53%|█████▎ | cHPI SNRs : 264/496 [00:07<00:01, 150.16it/s]
54%|█████▍ | cHPI SNRs : 268/496 [00:07<00:01, 151.82it/s]
55%|█████▍ | cHPI SNRs : 272/496 [00:07<00:01, 153.42it/s]
56%|█████▌ | cHPI SNRs : 276/496 [00:07<00:01, 154.96it/s]
56%|█████▋ | cHPI SNRs : 280/496 [00:07<00:01, 156.36it/s]
57%|█████▋ | cHPI SNRs : 284/496 [00:07<00:01, 157.68it/s]
58%|█████▊ | cHPI SNRs : 287/496 [00:07<00:01, 158.45it/s]
58%|█████▊ | cHPI SNRs : 290/496 [00:07<00:01, 159.14it/s]
59%|█████▉ | cHPI SNRs : 293/496 [00:07<00:01, 159.88it/s]
60%|█████▉ | cHPI SNRs : 297/496 [00:07<00:01, 161.20it/s]
61%|██████ | cHPI SNRs : 301/496 [00:07<00:01, 162.80it/s]
61%|██████▏ | cHPI SNRs : 305/496 [00:07<00:01, 165.39it/s]
63%|██████▎ | cHPI SNRs : 311/496 [00:07<00:01, 171.89it/s]
64%|██████▍ | cHPI SNRs : 317/496 [00:07<00:01, 178.15it/s]
65%|██████▌ | cHPI SNRs : 323/496 [00:07<00:00, 184.33it/s]
66%|██████▋ | cHPI SNRs : 329/496 [00:07<00:00, 190.33it/s]
68%|██████▊ | cHPI SNRs : 335/496 [00:07<00:00, 196.16it/s]
69%|██████▉ | cHPI SNRs : 341/496 [00:07<00:00, 201.83it/s]
70%|██████▉ | cHPI SNRs : 347/496 [00:07<00:00, 207.16it/s]
71%|███████ | cHPI SNRs : 353/496 [00:07<00:00, 212.50it/s]
72%|███████▏ | cHPI SNRs : 359/496 [00:07<00:00, 217.87it/s]
74%|███████▎ | cHPI SNRs : 365/496 [00:07<00:00, 222.97it/s]
75%|███████▍ | cHPI SNRs : 371/496 [00:07<00:00, 227.78it/s]
76%|███████▌ | cHPI SNRs : 377/496 [00:07<00:00, 232.62it/s]
77%|███████▋ | cHPI SNRs : 383/496 [00:07<00:00, 236.95it/s]
78%|███████▊ | cHPI SNRs : 389/496 [00:07<00:00, 241.59it/s]
79%|███████▉ | cHPI SNRs : 393/496 [00:07<00:00, 240.25it/s]
80%|███████▉ | cHPI SNRs : 396/496 [00:07<00:00, 238.05it/s]
80%|████████ | cHPI SNRs : 399/496 [00:07<00:00, 235.90it/s]
81%|████████▏ | cHPI SNRs : 403/496 [00:07<00:00, 234.06it/s]
82%|████████▏ | cHPI SNRs : 406/496 [00:07<00:00, 231.93it/s]
83%|████████▎ | cHPI SNRs : 410/496 [00:07<00:00, 229.67it/s]
83%|████████▎ | cHPI SNRs : 413/496 [00:07<00:00, 227.54it/s]
84%|████████▍ | cHPI SNRs : 417/496 [00:07<00:00, 225.66it/s]
85%|████████▍ | cHPI SNRs : 420/496 [00:07<00:00, 223.71it/s]
85%|████████▌ | cHPI SNRs : 423/496 [00:07<00:00, 222.16it/s]
86%|████████▌ | cHPI SNRs : 426/496 [00:07<00:00, 220.65it/s]
86%|████████▋ | cHPI SNRs : 429/496 [00:07<00:00, 219.26it/s]
87%|████████▋ | cHPI SNRs : 432/496 [00:08<00:00, 217.59it/s]
88%|████████▊ | cHPI SNRs : 435/496 [00:08<00:00, 216.16it/s]
89%|████████▊ | cHPI SNRs : 439/496 [00:08<00:00, 214.59it/s]
89%|████████▉ | cHPI SNRs : 443/496 [00:08<00:00, 213.26it/s]
90%|█████████ | cHPI SNRs : 447/496 [00:08<00:00, 211.90it/s]
91%|█████████ | cHPI SNRs : 450/496 [00:08<00:00, 210.82it/s]
92%|█████████▏| cHPI SNRs : 454/496 [00:08<00:00, 210.53it/s]
93%|█████████▎| cHPI SNRs : 459/496 [00:08<00:00, 213.55it/s]
93%|█████████▎| cHPI SNRs : 463/496 [00:08<00:00, 214.57it/s]
94%|█████████▍| cHPI SNRs : 467/496 [00:08<00:00, 213.10it/s]
95%|█████████▍| cHPI SNRs : 470/496 [00:08<00:00, 211.13it/s]
96%|█████████▌| cHPI SNRs : 474/496 [00:08<00:00, 210.23it/s]
96%|█████████▋| cHPI SNRs : 478/496 [00:08<00:00, 209.53it/s]
97%|█████████▋| cHPI SNRs : 482/496 [00:08<00:00, 208.84it/s]
98%|█████████▊| cHPI SNRs : 486/496 [00:08<00:00, 208.22it/s]
99%|█████████▉| cHPI SNRs : 490/496 [00:08<00:00, 207.73it/s]
100%|█████████▉| cHPI SNRs : 494/496 [00:08<00:00, 207.13it/s]
100%|██████████| cHPI SNRs : 496/496 [00:08<00:00, 59.49it/s]
Total running time of the script: (0 minutes 44.497 seconds)