How to use custom dataset in MNE ?

Hello, I use the next simple code for data visualization with MNE dataset. It is works great. But how I can use my custom dataset?

import mne
sample_data_raw_file = ("sample_audvis_filt-0-40_raw.fif")
raw =
raw.plot(duration=5, n_channels=30)
ica = mne.preprocessing.ICA(n_components=20, random_state=97, max_iter=800)
ica.exclude = [1, 2]
ica.plot_properties(raw, picks=ica.exclude)

My dataset presented in the picture

and which software I can use for open “fif” format?

Hello @Ildaron and welcome to the MNE forum!

It looks like you have data in a CSV or TSV file. You can read such files using numpy.loadtxt… you’ll probably need to do it twice (once for the column headings and once for the data:

import numpy as np
ch_names = np.loadtxt('my_data.txt', max_rows=1, dtype=str).tolist()
data = np.loadtxt('my_data.txt', skiprows=1)

Then you can use mne.create_info and our Array constructor to convert those into a Raw object. Note that you’ll also need to know the sampling frequency, and will probably want to specify something other than ch_types='misc' when you call create_info

1 Like

You can use MNE-Python :slight_smile:
You can also open FIF files in MATLAB though I think it requires a plugin? I think @cbrnr knows which one.


The FileIO plugin.


Hi @drammock thank for your reply. Can you clarify about data structure, how do I structure the data in my excel file so that I can read it in mne library. That is why I want to open the data from mne dataset with a external software to understand the data structure

The FIFF format is very complicated and I strongly recommend that you do not try to create a FIFF file yourself. Even looking at an existing FIFF file will probably not be helpful, because we have ways to make MNE-Python objects from NumPy arrays (as I mentioned above) which are much safer and easier than trying to do it yourself.

Based on your screenshot, your data is probably already in a suitable arrangement (channel names in the first row, data for each channel in columns below that). The first step is to export from Excel as a CSV file. Then you can proceed with the commands I offered above. Did you try them yet?

1 Like

@drammock thank you! I will try do your recommendations now

Hi @drammock I am very close to solve this problem. I have a little problem only
When I use the next code:

import numpy as np
import mne
ch_names = np.loadtxt('dataset.txt', max_rows=1, dtype=str).tolist()
data = np.loadtxt('dataset.txt', skiprows=1)
print("len", (data.shape)) # (7120, 8)
sfreq = 2000
info = mne.create_info(ch_names, sfreq, ch_types='eeg', verbose=None)
print ("ch", len(info["ch_names"])) # 8
raw =, info)

I receive the next error
“ValueError: len(data) (7120) does not match len(info[“ch_names”]) (8)”

I can solve it with the next code, but I think that it is not correct

data = np.reshape(data, (8, 7120))

Because after that this parts of code, not operate

raw.plot_psd(fmax=50) # 50
raw.plot(duration=5, n_channels=8)
ica = mne.preprocessing.ICA(n_components=20, random_state=97, max_iter=800)
ica.exclude = [1, 2]  # details on how we picked these are omitted here
ica.plot_properties(raw, picks=ica.exclude)

Can you clarify, which format is correct for data?

I believe you need to transpose the data instead.

data = data.T

Rather than reshape you probably want to do data = data.T before the call to RawArray (to transpose the rows/columns).

1 Like

Hi Drammock, thank you so much for your reply, now is better. Only, can you clarify, where I need add information about Channel location?
I have the next error
“RuntimeWarning: Channel locations not available. Disabling spatial colors.”
I tried used this type

Try raw.set_montage(), see this tutorial.

1 Like

Hi, Thank you, its works!