mne-tools / mne-python

MNE: Magnetoencephalography (MEG) and Electroencephalography (EEG) in Python
https://mne.tools
BSD 3-Clause "New" or "Revised" License
2.7k stars 1.31k forks source link

Get annotations from TRC file #12455

Closed RojanAsl closed 2 months ago

RojanAsl commented 8 months ago

Proposed documentation enhancement

Hi,

I am working with Micromed data, in which I only have access to TRC and video files. Is there a way I can extract the annotations along with their timestamps from the TRC file?

Thanks in advance!

welcome[bot] commented 8 months ago

Hello! 👋 Thanks for opening your first issue here! ❤️ We will try to get back to you soon. 🚴

mscheltienne commented 7 months ago

Hello, this is related to https://github.com/mne-tools/mne-python/issues/10524 At the moment, I don't believe MNE offers a TRC (micromed) reader. You can look into neo (https://pypi.org/project/neo/) to read this file format and then you can create MNE's datastructure from the loaded file.

I did so a couple of days ago, this is the code snippet I ended up with:

import numpy as np
from mne import create_info
from mne.io import RawArray
from neo.io import MicromedIO

fname = r"/home/scheltie/Downloads/micromed_data.TRC"
reader = MicromedIO(fname)
data = reader.read()[0].segments[0].analogsignals[0]  # (n_samples, n_channels), 31 chs
sfreq = reader.get_signal_sampling_rate()
ch_names = [elt[0] for elt in reader.header["signal_channels"]]
info = create_info(ch_names, sfreq, "eeg")
raw = RawArray(np.array(data.T), info)