neuromti / tool-libeep

A fork of https://gitlab.com/smeeze/libeep/ to load eego datafiles with python
GNU Lesser General Public License v3.0
0 stars 5 forks source link

for .cnt Neuroscan and EEProbe_64bit_extended files segments and markers are not read #5

Closed NVPavlova closed 3 years ago

NVPavlova commented 3 years ago

data recorded and exported with eego software into .cnt Neuroscan and EEProbe_64bit_extended formats does not show any segment data when opened with libeep. That returns a system error:

Screenshot from 2020-10-23 17-05-29

While at least, EEProbe_64bit_extended data is exported as 3 files (.cnt, .evt, .seg) and in the example .seg file contains information about 3 segments Screenshot from 2020-10-23 17-58-03

agricolab commented 3 years ago
import libeep
import matplotlib.pyplot as plt
import numpy as np

fname = "test.cnt"
fname = "test_EEProbe_64bit_extended/sub-MaPe_ses-007_eeg.cnt"
cnt = libeep.cnt_file(fname)
print(f"Within the file {fname} are")
print(f"{cnt.get_channel_count()} channels and ")
print(f"{cnt.get_sample_count()} samples and")
print(f"{cnt.get_trigger_count()} events")

# load 1s before and after the second event
fs = cnt.get_sample_frequency()
gmfp = []
for ix in range(0, cnt.get_trigger_count(), 100):
    marker, tstamp, *info = cnt.get_trigger(ix)
    # marker, tstamp, *info = cnt.get_trigger(2)
    print(marker, tstamp)
    a, b = tstamp - fs, tstamp + fs
    if a < 0 or b > cnt.get_sample_count():
        continue
    else:
        data = np.atleast_2d(cnt.get_samples(a, b))
    gmfp.append(np.std(data, 1))
    # plot the data
plt.plot(np.mean(gmfp, 0))

sucessfully loads the data. The bug you describe was caused with the single-file .cnt because there was only one event, and for the multifile format (.cnt, .seg, .evt) trying to access data from before the first sample would also not work. Please note, that for speed, i only load 1% of the thousands of events)

agricolab commented 3 years ago

We could trace this back to the export function of the eego GUI. When one exports in .cnt as eego format, without ticking the Apply Montage flag, it also creates a .evt file. The .cnt only contains basic information about events, like sampleindex and event type. The .evt contains additonal information about the events. When triggers are read from a .cnt with libeep, and the .evt is in the same folder as the .cnt, this additional information is also loaded.

This allowed us to recreate all relevant information about the events.