epoch number from event latency

Hi there,

I was wondering if it would have been possible to obtain epoch numbers based on the latency in the event array. I am merging data and events (which I have modified by adding external information), however, the event array does not contain the epoch number, but just the latencies. On the other hand, the data contain the epoch numbers but not the latency. Therefore, I cannot seem to be able to match the modified events to the epochs as I only have latencies and not epoch numbers. Is there a way to find out the epoch number based on the latency?

I hope my question was clear.
Thank you in advance for your time!
Sabia

Hello, could you make a small example? It’s difficult to understand from this text…

One point that comes to mind:

import numpy as np

from mne import create_info, Epochs
from mne.io import RawArray


info = create_info(["AF7"], 1024, "eeg")
data = np.random.randn(1, 5120)
raw = RawArray(data, info)
events = np.array([[1024, 0, 1], [4096, 0, 1]])
epochs = Epochs(
    raw, events, event_id=dict(my_evt=1), baseline=None, tmin=-0.5, tmax=0.5
)

epochs has an attribute events which holds the original events array:

epochs.events
>>> array([[1024,    0,    1],
           [4096,    0,    1]])

Hi Mathieu,

Thank you very much for your reply. I am trying to reconstruct the epoch number so that I can merge my modified events with the data. The way to merge events and data is by using epoch numbers. However, although I have epoch number information in my raw data, I only have latencies in my event array. Below is my event array:


    Unnamed: 0  latency  1    type sentence_version item_nb condition
0             0    26287  0  222201                2      66       201
1             1    30615  0  222209                3     215       209
2             2    39905  0  222109                2     157       109
3             3    44551  0  222101                3      43       101
4             4    48879  0  222201                2     102       201
..          ...      ... ..     ...              ...     ...       ...
320         320  1881663  0  222101                1      37       101
321         321  1894965  0  222201                2     118       201
322         322  1899610  0  222101                2      44       101
323         323  1903938  0  222201                2      99       201
324         324  1912911  0  222209                3     229       209
[325 rows x 7 columns]

The data, however, look like this:

      epoch   time      part_n  ...        POz        PO4        PO8
0          23 -0.200  6702_Ger_A  ...  -6.042464  -8.418135  -4.495184
1          23 -0.198  6702_Ger_A  ...  -4.718540  -6.808159  -3.550930
2          23 -0.196  6702_Ger_A  ...  -3.568712  -5.532163  -2.866641
3          23 -0.194  6702_Ger_A  ...  -2.705187  -4.686587  -2.534552
4          23 -0.192  6702_Ger_A  ...  -2.225361  -4.303928  -2.589741
       ...    ...         ...  ...        ...        ...        ...
227820   1527  1.192  6702_Ger_A  ... -19.012184 -18.056047 -36.267101
227821   1527  1.194  6702_Ger_A  ... -17.646465 -15.566587 -32.748902
227822   1527  1.196  6702_Ger_A  ... -16.295929 -13.089048 -28.767524
227823   1527  1.198  6702_Ger_A  ... -15.280752 -11.054162 -24.893412
227824   1527  1.200  6702_Ger_A  ... -14.776089  -9.721090 -21.546914
[227825 rows x 64 columns]

Basically, I do not have a linking information between the data and the event array, therefore I cannot merge my data with the modified event information.

I do not get what latency represents, and you are working with DataFrames instead of the Raw, Epochs, and other MNE objects, and neither DataFrames correspond to the output from a .to_data_frame() method from MNE…

I am trying to reconstruct the epoch number so that I can merge my modified events with the data.

It’s a bit far fetch from this sentence, but are you trying to take a continuous recording and combine 2 types of events, e.g. one from a hardware source and a second one defined manually by yourself? And then to create the Epochs corresponding to those events?

I am working with DataFrames. Latency would be the first column in the MNE event array, which I have renamed using Pandas.

The dataframe I have shown you with the data includes already epoched data.

Yes, I am trying to merge the epoched data (rather than the continuous recording) with a set of events (these are the events that are left at the end of pre-processing, e.g.: final_epochs.events, and information that I have manually added, such as item_nb, sentence_version, as can be seen in the event dataframe).

@Scosta Have you considered using Epochs metadata? It’s designed to guarantee direct correspondence between individual epochs and additional information in the form of a pandas DataFrame.

1 Like