different dtypes within one raw object

  • MNE version: 1.4.0
  • operating system: Windows 10

I was wondering if there is a possibility to store different dtypes within a single raw object? It appears whenever I create a mne.io.RawArray, float64 dtype is created, even if I want ch_types to be “misc”, and input a bool data.

Here is a minimally produced code snippet:

import mne
import numpy as np

# generate a random 3 channel signal and store as raw object
random_signals = np.random.random((3,100))
info = mne.create_info(ch_names=["ch1", "ch2", "ch3"],
raw = mne.io.RawArray(data=random_signals,
>> Creating RawArray with float64 data, n_channels=3, n_times=100
    Range : 0 ... 99 =      0.000 ...     9.900 secs

# create a binary mask of same length to be stored as misc
random_mask = np.random.randint(0, 2, size=(1, random_signals.shape[1]), dtype=bool)
mask_info = mne.create_info(ch_names=["mask"],
raw_mask = mne.io.RawArray(data=random_mask,
>> Creating RawArray with float64 data, n_channels=1, n_times=100
    Range : 0 ... 99 =      0.000 ...     9.900 secs

# append to raw

# check dtype
>> dtype('float64')

I am hoping to store EEG data as float, but 1 misc channel as bool or int. Am I missing something or is storing different dtypes not supported?

No, this is not possible. The data are always represented as a 2D NumPy array. If you want to implement a mask, you could do it as a separate object.

Thanks for the quick reply. By separate object you mean a non mne object right?

Yes, for example a list or a NumPy array.

I didn’t ask what you want to achieve with your mask. Maybe you can use a different workflow supported by MNE to implement what you need.

They are masks for extracted waveforms that I can highlight when plotting, and I was just hoping to make use of the easy load and saving to disk function of the raw object. But I guess this could also easily implemented with a Numpy array or pandas df, thanks!

If you want to highlight portions of the signal, you might want to consider using annotations. They can be associated with a Raw object via Raw.set_annotations().