Stc_near_sensors head coordinates required in 24.0 devel

Dear all,

I have an issue that appear with 0.24 (my code was working with 0.23) with stc_near_sensor.
Basically, for a sEEG analysis, I was importing my data in mri coord_frame, running my analysis and using stc_near_sensor to prepare the plotting. All working well with 0.23.

montage = mne.channels.make_dig_montage(ch_pos, coord_frame='mri')
raw.set_montage(montage)
fig = mne.viz.plot_alignment(raw.info, trans=None, subject=subject,
                                 subjects_dir=subjects_dir, show_axes=True,
                                 surfaces=["pial"], coord_frame='mri')
...
stc = mne.stc_near_sensors(evoked_plot, None, subject, src=vol_src,
                           mode='nearest', subjects_dir=subjects_dir,
                           distance=0.02)

With 0.24, I now get the following issue when using stc_near_sensor:

RuntimeError: Channels must be in the head coordinate frame, got [0 (FIFFV_COORD_UNKNOWN)]

I believe it appeared because of this change introduced by @larsoner in this PR.
From what I could understand, it is a desired feature that all the coord_frames are in the head space.
To adapt to this change, I tried to add a transform as in the sEEG tutorial:

lpa, nasion, rpa = mne.coreg.get_mni_fiducials(
    patient, subjects_dir=subjects_dir)
lpa, nasion, rpa = lpa['r'], nasion['r'], rpa['r']
montage = mne.channels.make_dig_montage(ch_pos, coord_frame='mri', nasion=nasion, lpa=lpa, rpa=rpa)
trans = mne.channels.compute_native_head_t(montage)
raw.set_montage(montage)
fig = mne.viz.plot_alignment(raw.info, trans=trans, subject=subject,
                                 subjects_dir=subjects_dir, show_axes=True,
                                 surfaces=["pial"])

but raw.info['chs'][0]['coord_frame'] still gives me 0 (FIFFV_COORD_UNKNOWN), which will then results in an error in stc_near_sensors.
So my questions:

  • how to set the coordinate frame so that it is in the head space for sEEG data (somehow it works for the sEEG and ECoG tutorials, but I don’t quite get why (BTW, the sEEG electrodes are outside the brain in the sEEG tutorial, is this the desired output?))
  • is it really not possible to leave it open to just use the mri coord_frame as before?

Thanks a lot for the help
Tim

Can you open a GitHub issue to replicate this with the sample dataset? This seems like a bug because raw.set_montage should convert to the HEAD coordinate frame when you set using a montage with LPA/Nasion/RPA set. In other words, your code looks correct and MNE looks wrong.

There are a lot of places in MNE where we assume or use the fact that sensors are in the head coordinate frame (including things like plot_alignment IIRC). So the best solution is to get your I think we can make it possible to use the MRI coordinate frame. However, we have had conversations previously about being more flexible about this, and stc_near_sensors (with sEEG/ECoG/DBS electrodes) is a case where it probably makes sense to make progress toward making this work. So if you can mention this possibility in the GitHub issue you open, we can hopefully fix both issues in one PR!

Sure, I will open a GitHub issue, and also mention the MRI coordinate frame, thanks!