How to keep track of relationship between file on disk and instance of mne.io.RawArray

I’m dealing with a large number of mne.io.RawArray instances and need to keep track of the underlying files on disk.

I saw that RawArray has an attribute filenames which it inherits from mne.io.BaseRaw, where it can be set via BaseRaw.__init__().

>>> from mne.io import BaseRaw
>>> print(BaseRaw.__doc__)
[...]
filenames : tuple
        Tuple of length one (for unsplit raw files) or length > 1 (for split
        raw files).
[...]

Unfortunately RawArray.__init__() does not have the filenames argument, doesn’t allow setting filenames directly and also doesn’t expose a setter for it:

>>> type(raw)
mne.io.array.array.RawArray
>>> raw.filenames = ("test.xyz",)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[38], line 1
----> 1 raw.filenames = ("test.xyz",)

AttributeError: can't set attribute

I can set RawArray._filenames to achieve the desired effect:

>>> raw._filenames = ("test.xyz",)
>>> raw.filenames
('test.xyz',)

But as one should generally avoid interacting with private attributes directly, I’m wondering if there is a proper way to achive the desired effect with RawArray.

Hi @aplzr ,

Without testing this myself and going solely on your description of the problem, I would imagine that the “above board” approach (i.e. not using private attributes) would be:

  1. Create your Raw object with mne.io.RawArray
  2. Save/export your Raw object to disk (e.g. to .fif or .edf)
  3. Read the Raw object back to disk with mne.io.read_raw. Now the filenames attribute should be filled.

It’s a bit round-about but avoids interacting with private attributes as you did in your example.

If anyone else has a cleaner solution feel free to chime in!

Hi @scott-huberty, that works indeed, thanks. I wasn’t aware that the filenames attribute is always set when using one the mne.io.read_* functions, although that makes perfect sense in hindsight :slight_smile:

I don’t understand why mne doesn’t let you set it when creating RawArrays from scratch, as not every file format can be read with the available reader functions, but maybe there’s a good reason for it.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.