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)
raw.info['bads'] = noisy_chs + flat_chs 
raw.info['bads'] += bad_channels  # bad channels from observation
head_position=input_raw.info['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 raw.info[‘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:

https://mne.tools/stable/auto_tutorials/preprocessing/59_head_positions.html

Best wishes,
Richard

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(raw.info, chpi_amplitudes)
head_position = mne.chpi.compute_head_pos(raw.info, 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,

Bests,

Raphaëlle

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.