Head radius NA in interpolate_bads

-MNE version 1.9.0.dev71+g97f5b9c34 (just recently downloaded)

  • Windows 11

raw_data = raw.copy().pick(picks=“eeg”)
current_montage = mne.channels.read_custom_montage(filename, head_size = 0.095,coord_frame = None)
raw.set_montage(current_montage,on_missing = “ignore”)
raw_interpolate = raw_data.copy().interpolate_bads(reset_bads = False)

bad is a list that contains “Fp2, F6, F2”

Why do I get an error on raw_interpolate “Automatic origin fit: head of radius nan mm” and
“ValueError: array must not contain infs or NaNs”

Thanks in advance for any assistance.

Hmm I’m guessing that it has to do with this line raw.set_montage(current_montage,on_missing = “ignore”). It might be the case that one of these channels without a corresponding x/y coordinate in your montage is getting used in the head radius calculation.

As a test, you can confirm my hunch by setting on_missing="raise", and then explicitly dropping channels that don’t have a montage location until set_montage no longer throws an error.

Thanks, that worked partially. I had deleted the EKG channel that had NA values. It worked when I added it back. I set it to 1,1,1 for x,y,z (not sure what the correct values would be). However, I then had to divide all the x,y,z co-ordinates by 1000 to get an acceptable head radius (maybe measurement in mm expected to be in m?). Having done that, the interpolation looks really bad though, much more jagged and uneven than the original data and the neighbouring data. Not sure what to do next.

There is no reason to give a position for EKG channels, just set their types correctly like "ecg", "emg", "eog", … and yes all units in MNE are SI, so distance is in meters.

2 Likes

Thanks. I really appreciate all the help.

I’ve set the EKG channel type to “ecg”, but
mne.channels.read_custom_montage(filename,head_size = 0.095, coord_frame = None)
still gives an error that it cannot convert the n/a in the EKG channel to a float.

That seems strange, can you share exactly which line of code you run?
FYI, with correct channel types, you can set montages without errors.

from mne import create_info

info = create_info(["Oz", "O1", "O2", "ECG"], 100, ["eeg"] * 3 + ["ecg"])
info.set_montage("standard_1020")

What file are you reading with read_custom_montage?