You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to analyze micromed raw EEG data (.TRC) using MNE.
Is there already a way to import this format (that I missed)?
So far, I'm using NEO to import the data on python environment, and this leads me to the #870 issue, talking about interoperability between NEO and MNE.
What would be the best way to carry on my analysis and how could I help solving this issue ?
Hi @Lx37@samuelgarcia do you guys have any NEO toy dataset one could use to demonstrate that?
We meanwhile have mne.RawArray, mne.EpochsArray and mne.EvokedArray to construct mne objects from numpy arrays.
how do I get with NEO the times series as one 2d array (1 row per channels) as well as channel names and also sampling rate. that's the basic need to use RawArray
for EEG data :
seg = neo.MicromedIO(filename = file_name).read_segment() #to import data
-> seg.analogsignals is a list of quantities objects whose shape is (chan, samples)
each elements of the first dimension has a t_start, a t_stop and a sampling rate (here, we have the same for all chan), so
-> seg.analogsignals[0].sampling_rate.rescale('Hz').magnitude gives the sample frequency as a numpy.ndarray
and each elements of the first dimension has also a name which correspond to the channel
-> seg.analogsignals[ii].name for ii in range(np.shape(seg.analogsignals)[0]) gives the channels name.
I gess the code would be something like :
# -*- coding: utf-8 -*-
import sys, os
import neo
import numpy as np
import quantities as pq
import mne
import time
import matplotlib.pyplot as plt
from matplotlib import gridspec
def convert_micromed(filename):
###NEO import of raw data
seg_micromed = neo.MicromedIO(filename = filename).read_segment()
seg_micromed.annotate(material = "micromed") ## TODO add to MicromedIO
### Get informations and data to convert it to MNE needs
##Channels names and types
chan = list()
ch_types = list()
for cc in range(np.shape(seg_micromed.analogsignals)[0]):
chan.append(seg_micromed.analogsignals[cc].name)
if cc < 2:
ch_types.append('eog')
else:
ch_types.append('eeg')
chan.append('STI 014')
ch_types.append('stim')
##Sample frequency
sFreq = seg_micromed.analogsignals[0].sampling_rate ## here we have the same sample rate on all chan
## Data
convert_fac = 1. * seg_micromed.analogsignals[0].units
convert_fac.units = 'V' ## Convertion to Volts
data = np.asarray(seg_micromed.analogsignals)
data = data * convert_fac.magnitude
data = np.concatenate((data, np.zeros((1,np.shape(data)[1]))), axis=0) #adding trigger chan
##Triggers
events_time = np.asarray(seg_micromed.eventarrays[0].times.magnitude * sFreq) ## To get sample number from time
nb_event = len(events_time)
events = np.empty([nb_event,3])
events[:,0] = events_time
events[:,2] = seg_micromed.eventarrays[0].labels.astype(int)
#~ print type( events[0,2]) # np.float64... ?
###MNE raw data format creation with data, infos and events
raw_info = mne.create_info(chan, sFreq,ch_types)
raw = mne.io.RawArray(data, raw_info, verbose =1)
raw.add_events(events, 'STI 014')
##show raw propreties
print raw.ch_names
print raw.info
fig = raw.plot()
plt.show()
return raw
if __name__== '__main__':
dirname = './data_Micromed/'
trc_filename = 'EEG_33.TRC'
file_path = os.path.join(dirname, trc_filename)
convert_micromed(file_path)
i forgot to take the sample rate magnitude for sfreq
event are not always on the fisrt dim of seg.eventarrays
in BrainVision event, triggers contain letter 'S'
ch_type is complitely dependent on the acquisition device and the user's montage (for exemple with brainvision hardware there is no eog, in my team we use some eeg sensor as eog..)
the convertion from uV to V should be cleaner using python.quantities but the ways I tried (looping) was time consuming..
I'm not sure too about the generalization, as neo segment organisation could change over devices.
I will update this if others eeg devices pass through my hands!
for now I would make a new example that explains how to use neo on a
demo dataset. Any idea of a good demo file we could use? A demo on
invasive electrophy data would be great. @apdavison@samuelgarcia any
idea?
Does mne-python support (or plan to) reading in .TRC files (couldn't find anything in API), or is the recommended approach rn to use what @agramfort 's gist does?
Activity
dengemann commentedon Oct 13, 2014
Hi @Lx37 @samuelgarcia do you guys have any NEO toy dataset one could use to demonstrate that?
We meanwhile have mne.RawArray, mne.EpochsArray and mne.EvokedArray to construct mne objects from numpy arrays.
dengemann commentedon Oct 13, 2014
And we need to add an exampe, because this questions is asked again and again.
cc @introspection
agramfort commentedon Oct 13, 2014
@Lx37 please share a code snippet using neo so it can be a good start for an example on the MNE website.
Lx37 commentedon Oct 13, 2014
Please find micromed raw data and a simple neo import and print properties here :
https://www.wetransfer.com/downloads/799c204ba34a59dba890074facf761a720141013161625/0179b1d8d02a5e2fc24cb6c655b509b920141013161625/b400f3
And BrainVision raw data with some first steps to understand NEO format vs MNE format (as both are reading brainvision files):
https://www.wetransfer.com/downloads/bc1720d985b7b8dc1ea67723540f9e2620141013162646/6d49bd0f370b1f3546a700c2e7e2d99b20141013162646/19a549
(I'm affraid this last code is quite dirty..)
Moreover, maybe neo.test.generate_datasets could be usefull ?
let me know if I can help
best
agramfort commentedon Oct 13, 2014
how do I get with NEO the times series as one 2d array (1 row per channels) as well as channel names and also sampling rate. that's the basic need to use RawArray
Lx37 commentedon Oct 14, 2014
for EEG data :
seg = neo.MicromedIO(filename = file_name).read_segment() #to import data
-> seg.analogsignals is a list of quantities objects whose shape is (chan, samples)
each elements of the first dimension has a t_start, a t_stop and a sampling rate (here, we have the same for all chan), so
-> seg.analogsignals[0].sampling_rate.rescale('Hz').magnitude gives the sample frequency as a numpy.ndarray
and each elements of the first dimension has also a name which correspond to the channel
-> seg.analogsignals[ii].name for ii in range(np.shape(seg.analogsignals)[0]) gives the channels name.
I gess the code would be something like :
Lx37 commentedon Oct 15, 2014
sorry for the multiple changes..
agramfort commentedon Oct 15, 2014
here is a quick hacked version from your file:
https://gist.github.com/agramfort/7fc27a18fcdc0e8cff3f
let me know what you think.
I am not sure how we can make it more generic to make a high level MNE
function from it.
Lx37 commentedon Oct 16, 2014
i tried to make it more generic adding BrainVision as possible file format entry :
https://gist.github.com/Lx37/c6783262824b27cddfa3
here are the biggest differencies/notes :
I'm not sure too about the generalization, as neo segment organisation could change over devices.
I will update this if others eeg devices pass through my hands!
best
agramfort commentedon Oct 16, 2014
for now I would make a new example that explains how to use neo on a
demo dataset. Any idea of a good demo file we could use? A demo on
invasive electrophy data would be great. @apdavison @samuelgarcia any
idea?
larsoner commentedon Apr 20, 2015
We now have an example of how to integrate NEO and MNE, feel free to open a new issue if it is unclear or there seems to be a better way
adam2392 commentedon Feb 11, 2021
Does mne-python support (or plan to) reading in .TRC files (couldn't find anything in API), or is the recommended approach rn to use what @agramfort 's gist does?
https://gist.github.com/agramfort/7fc27a18fcdc0e8cff3f
agramfort commentedon Feb 11, 2021