Mne automatically finds events in raw data, where the actual event is different from the recorded file, so i’m going to compare it. Is there a way to do it efficiently?
MNE should normally preserve the event codes from your original file. Could you provide more context as to what you’re doing and which kind of data you’re loading?
Richard
Aha, what I’m talking about is that the event is calculated when the rawedf function is used, but I wonder if there is a code that can bring only that separately.
This depends on how events are originally stored in the file. If they are available as an analog trigger channel, you need to load the file and parse that channel to get the actual events. If they are stored as discrete events (e.g. annotations in EDF), then you can read these annotations without touching (i.e., loading) the raw (continuous) EEG data.
The files I’m using sage have separate raw EDF files and annotation files. Therefore, when using the function, we want to compare event detection in EDF with the number of events in the annotation file.
OK. But do you know how events are stored in your EDFs? In an analog stim channel? Or as discrete annotations? You can find out by taking a look at the channel types after loading, e.g. by printing raw.info
(look for channels of type stim
) and checking if raw.annotations
contains entries.
I still don’t understand what exactly you would like to do though. Can you show your code so we can see what you have tried?
Well, there are two files, x.edf and x_annotation.edf.
raw = mne.io.read_raw_edf('x.edf', preload=True)
Once run the above code and see several outputs, telling how many events there are. But not all, but some of them were detected incorrectly, so I asked because I needed a process to find out.
This line already prints how many events were detected? I think you have some more code that produces the output you are talking about. Can you also show it?
So, since there are many edf files, I am trying to compare the original number of events and the event detected by mne from code.
I need to remove the wrongly detected files, but I don’t know where they are hiding in order to detect which ones have the wrong number of events.
I understand that. But I have no idea how you detect events in both types of files (x.edf
and x_annotation.edf
). You haven’t shown how you do that yet.
The annotation file is also in edf and txt format, so it is labeled for each epoch so that it can be counted. Rather than reading two EDFs with the mne raw function and comparing them, only need to know the number of events in code. That’s the point. don’t need to know anything else.
I’m sorry, I cannot help you with the information you’re sharing here. I understand what you’re trying to do, but I need more details. Maybe you can share two example files?
Hmm… Actually, I don’t think I asked a question that was difficult to understand.
You’re asking questions about very specific problems without providing enough information for anyone else to fully grasp what it is that you want to achieve or what exactly the problem is you’re running into – as indicated by the sheer endless back-and-forth required here. It’s not nice to anyone involved.
Richard
Yes, it is difficult to understand.
You provided the data in question in your seventh post, so now we know what the data actually looks like. Your question would have been easier to understand if you had done that in your first post. Now please share your code that demonstrates the issue you are seeing using SN001
, namely a discrepancy in the number of events/annotations between the EDF file and the TXT file. Again, you should have done that in your first post if you wanted your question to be easy to understand.
Still not sure what your question is, but could it be that you want to load an EDF file that contains only annotations? When loading SN001_sleepscoring.edf
with mne.io.read_raw("SN001_sleepscoring.edf")
, you get the following information as part of the output:
It is possible that this file only contains annotations and no signals. In that case, please use mne.read_annotations() to load these annotations.
Therefore, you can load the file as suggested:
import mne
annotations = mne.read_annotations("SN001_sleepscoring.edf")
You can use pandas to read the text file:
import pandas as pd
df = pd.read_csv("SN001_sleepscoring.txt")
They both contain 856 annotations:
>>> len(annotations)
856
>>> df.shape
(856, 6)
You still don’t understand the question. If the question is a, the answer to a’ must be provided, but you are asking for information about the situation about b or c.
I was clearly asking how to get the event number that appears when running rawedf, and you answer by getting the event number from another annotation file. This is the answer to b or c. Still not sure what the intention is?
I also compared the numbers of all edf files and all annotation edf or txt files in a similar way, and several files did not match. So, since it takes time to compare them one by one, I asked a question using code to find records with different event numbers.
We are simply not understanding the question because it is poorly described, without a single code snippet that we can use to try to figure out your specific problem. Several post ago, code snippets of what you were doing were requested.
This line already prints how many events were detected? I think you have some more code that produces the output you are talking about. Can you also show it?
We are not magician, we can’t read your mind, so please give us something that we can use to figure out the issue. Ideally, a minimally working example (MWE), i.e., a code snippet that we can directly copy/paste and execute and that will clearly exhibit the error/problem encounter.
get the event number that appears when running rawedf
Again, how are the events stored in that particular file? Trigger channel or annotations?
Mathieu
I’ll just have you know that this behavior of yours is downright outrageous and disrespectful, and I won’t be engaging in any conversation with you any longer unless your demeanor changes.
Richard