Converting .mat files to .fif files

Hello all,
I am facing trouble using mne-python as all the EEG readings are in .mat files, and mne-python works with the .fif files.
Can anyone suggest how to convert my data into the fif format?
The pymatreader library allows the .mat files to be loaded and returns a python dictionary, but that isn’t the fif format.

Below is the dictionary data of one of the readings.
Any help or lead is highly appreciated.

Thanks,
Poorva

  • MNE-Python version: latest
  • operating system: Windows
{'__header__': b'MATLAB 5.0 MAT-file, Platform: GLNXA64, Created on: Tue Jul 11 15:16:19 2017',
 '__version__': '1.0',
 '__globals__': [],
 'data21_a': array([[[ -4.02996501,  -5.21812053,  -2.12189425, ...,  -5.24047166,
          -23.1109507 ,  -0.07900585],
         [ -4.07999741,  -4.1793486 ,  -5.30395057, ...,  -8.2638478 ,
          -18.6511773 ,  -4.79279383],
         [ -3.14417591,  -5.76256529,   1.26975923, ...,  -8.32801818,
          -11.31398043,  -8.08436272], 
         ...,
         [ -0.89876645,   4.29588313,   0.57285615, ...,  -0.99713776,
            1.13475826, -14.90647201],
         [ -2.46851891,   5.69858911,  -0.50480844, ...,  -2.37357903,
            0.98512574,  -9.60950669],
         [ -0.69313008,   7.1196399 ,  -0.15364449, ...,  -3.54282948,
           -1.49179595,  -7.06937039]]]),
 'fs': 125,
 'subs21_a': ['S1',
  'S4',
  'S6',
  'S9',
  'S10',
  'S11',
  'S14',
  'S19',
  'S28',
  'S43',
  'S56',
  'S58']}

You can load .mat files with pymatreader or scipy.io.loadmat, access the desired data as a Numpy array and convert that into a Raw object using mne.io.RawArray (see e.g. this tutorial).

2 Likes

Hi @cbrnr
Thanks for the reply. This worked.

1 Like

how would i remove string from the np.array as it has raised a value error whitle calling mne.io.rawArray() function?

Hello @Hasin and welcome to the forum!

We’ll need much more information to be able to help you. Please consider creating a new topic and filling out the template you’ll be presented with.

Best wishes,
Richard

Edit: I see now that you’ve posted at

1 Like

Thanks . Looking forward to a solution :slightly_smiling_face: