Storing data information in an MNE Info using the non-default units

I’m looking into a way to describe an LSL stream fully using an MNE Info instead of a StreamInfo. One aspects I would like to retain is the unit provided in the description of the stream. For example: an EEG channel streamed in uVolts.

Looking into mne.io.constants, I found the “Multipliers” stored in _ch_unit_mul_named. Am I correct in assuming that:

from mne import create_info
from mne.io.constants import _ch_unit_mul_named

info = create_info(["EEG1"], 1024, "eeg")
info["chs"][0]["unit_mul"] = _ch_unit_mul_named[-6]

Is it the correct and intended use of those FIFF multipliers?

I think @larsoner and @agramfort may be the only ones who can answer this one? (question about FIFF constant unit multipliers)

I don’t know on the top of my head. Do you see the unit_mul used anywhere in MNE?

what rings more bells in the use of a “cal” factor to apply on load for certain
formats. Look for cal in _read_segment_file function

Alex

unit_mul is always 0 (no exponent) and does not seem to be used in MNE. To me, it looks like an attribute that describes the unit measurement; and is “ignored” since MNE expects data in a given unit for a given channel anyway.

cal seems to be different. Running a debugger through the data loading of a FIFF file, it impacts the loaded data with this coefficient, and not only the data description (it’s also stored in the info["chs"] field). Out of curiosity, do you know what this cal factor represents in MEGIN systems? Calibration for?

Thanks!
Mathieu

One way would be to make info['chs'][ii]['unit_mul'] be used/respected across MNE… but it’s not currently. This would be a lot of work.

In practice you could use cal and range as suggested by @agramfort:

But these would just tell you the relationship between your stream values and the SI unit for the channel. You’d need to put this in your own BaseRaw-derived subclass overriding _read_segment_file that would do the multiplication (this IIRC is what our FIF reader actually does). In other words, you couldn’t set this in info, put it in a RawArray with your data and expect it to work…

1 Like

Ok, thank you, now I understand better what cal represents.

For my case, I will leave the responsibility to convert to SI in the hand of the user. My only goal is to attempt to read the (human-readable, non standardize) unit from the stream description, and provide it as an hint to the user that he needs to add a conversion step. Thus, the relation between the stream values and the SI unit is not that important.
Since 'unit_mul' is not used/respected across MNE, the risk to break any MNE-function on an object that uses a modified info with an altered 'unit_mul' seems low, which is great :slight_smile: