Passing head position to maxwell filter

Hi everyone,

I am having trouble passing head position to maxwell filter function.
I need it to concatenate data from each runs of my experience.
Here is the code I used :

noisy_chs, flat_chs = mne.preprocessing.find_bad_channels_maxwell(raw)['bads'] = noisy_chs + flat_chs['bads'] += bad_channels  # bad channels from observation['dev_head_t']
raw_pretreated = mne.preprocessing.maxwell_filter(raw, origin=(0., 0., 0.04), calibration=cal_fname, cross_talk=ct_fname, head_pos = head_position )

Error message : TypeError: head_pos must be an instance of ndarray or None, got <class 'mne.transforms.Transform'> instead.

The problem seems to be that[‘dev_head_t’] is not an array, but I couldn’t find an appropriate method to convert it. Or maybe I am not using the maxwell filter function correctly?

Thank you in advance for your help !

Hello @Raphaelle, and welcome to the forum!

info['dev_head_t'] is the device-to-head coordinate system transformation matrix, not the head positions.

Typically, head positions are loaded e.g. via the read_head_pos() function.

But they can also be computed, please see this tutorial:

Best wishes,

Hi Richard, thank you for your answer.

I tried both methods, but couldn’t do the first one (read_head_pos() function) because I don’t have any separated file ending with .pos.
I tried to compute with the other method :

chpi_amplitudes = mne.chpi.compute_chpi_amplitudes(raw)
chpi_locs = mne.chpi.compute_chpi_locs(, chpi_amplitudes)
head_position = mne.chpi.compute_head_pos(, chpi_locs, verbose=True)

but the first function doesn’t seem to work (it stays at ‘0%’ step for several minutes, then it stops):

Using 4 HPI coils: 293 307 314 321 Hz
Line interference frequencies: 50 100 150 200 250 300 Hz
Using time window: 142.9 ms
Fitting 4 HPI coil locations at up to 75293 time points (753.0 sec duration)
  0%|          | cHPI amplitudes : 0/75293 [00:00<?,       ?it/s]

At the end of the script, the variable “head_position” is an empty array.

Do you have an idea of what is going wrong ?
(I precise we did use HPI during the acquisition)

Thanks in advance,



Which version of MNE is that? I think I read about a similar issue not too long ago and @larsoner fixed it in MNE 1.1, but I might be totally mistaken :thinking:

I have the last version (MNE 1.1), and I work with a mac.