Channel position unit conversion

Hello,

I have a dataset were the channel positions are given in millimeters instead of meters. Is there a quick fix for such cases or is it necessary to perform an ugly hack:

for ch in range(len(raw.info['chs'])):
    raw.info['chs'][ch]['loc']*=1e-3

followed by

montage = raw.get_montage()
raw.set_montage(montage)

EDIT: I thought I needed to convert units for interpolate_bads due to the warning Estimated head size (85000.0 mm) exceeded 99th percentile for adult head size. But it seems that the interpolation is not affected by the scale.

Yes, this is to be expected, as the underlying mathematical function performs the exact same thing, just scaled by a factor of 1000 when it comes to distances :slight_smile: Think of a recipe for cookies; the recipe says to use a certain amount of ingredients to produce 100 cookies, but you recon you’ll only want to eat 50. So you simply take 50% of the volume / mass of all listed ingredients. :slight_smile: But the produced cookies are just the same :cookie:

I would create a proper transformation and apply it to the montage. Something like this:

import numpy as np
mm_to_m_trans = np.eye(4)
mm_to_m_trans[:3, :3] *= 1e-3
mm_to_m_trans = mne.Transform(
    fro='head',
    to='head',
    trans=mm_to_m_trans
)

montage = raw.get_montage()
montage_scaled = montage.copy().apply_trans(mm_to_m_trans)
raw.set_montage(montage_scaled)
1 Like

That’s a neat solution.

1 Like