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
{{ message }}
Repository navigation
Add support for XDF (labstreaminglayer format) #5180
I think this should be added. I am happy to do this. There is already a python loader for the xdf format so it is just a matter of making output structure compliant with mne.
Reacted by Stefan Appelhoff, Joan Massich, Francesco Chiossi and Haskya
That's a good idea. In the repo for the python XDF loader, there is an ongoing discussion to make a "pyxdf" package, however the discussion is stagnating a bit. Mainly because there is a lack of tests for the robustness/reliability of the loader. See here for the discussion.
Integrating the xdf loader into MNE would not circumvent the issue of (so far) lacking tests, but maybe the stagnation is over now :-)
@dmedine it might not be just as easy as putting the output into a different data structure. Due to the nature of XDF, streams are not necessarily regularly sampled. However, MNE expects all signals to have a fixed sampling frequency. Furthermore, I think that all streams must actually have the same sampling frequency (because everything is stored in a NumPy array) - but I'm not completely sure about that. In any case, this means that some kind of resampling will be necessary.
I thought that we discussed this somewhere, but a low-order spline interp (or even linear!) would probably be sufficient. So I don't see this as too big a hurdle.
Yes, it shouldn't be too difficult, just wanted to bring this up in case this was not obvious. Can you confirm that all signals must have the same sampling frequency? If so, how do we choose which sampling rate to resample to? Most XDF files have nominal sampling rates for each stream, so we could resample to the highest.
Can you confirm that all signals must have the same sampling frequency?
Yes
If so, how do we choose which sampling rate to resample to?
Resampling to the highest data channel rate (by default, we could make different options with resample='auto' kwarg) makes sense to me. In practice I imagine these will all usually match anyway.
@cbrnr check out the discussion in the XDF issue linked above, specifically there is probably the need for some MNE decision on this statement from @dmedine:
I said a long time ago that I would shove xdf into MNE. The issue there (if I understand correctly) is that if there are multiple streams, they all have to have the same sampling rate, first time-stamp, etc. This makes it labor intensive enough for me to avoid doing it. However, if MNE is like EEGLab and it is content to grab only EEG and marker streams, then this might not be such a chore after all.
Personally, I think that being able to extract an EEG stream from XDF is better than nothing and worth an implementation. An even better solution would be to allow the extraction of any single stream out of the XDF file.
... the "best solution" of reading the complete XDF file with all its streams seems tricky indeed
I thought that the existing XDF reader already supports synchronizing time stamps from different streams, so this is one problem already solved. Grabbing a single stream is straightforward, because all streams are returned in a list of dicts, of which we'd need the values for the 'time_series' and 'time_stamps' keys.
MNE only supports "streams" with the same sampling rates. So yes if we can
read the EEG data and mimic what we have already for edf files +1
I also feel that we need more integrated efforts between pyedf, pybv,
pyxdf, neo and MNE to avoid duplication of efforts. I am sure I have time
though to coordinate these efforts. It would be a great topic for a code
sprint.
Reacted by Stefan Appelhoff, Joan Massich and Teon L Brooks
Sure. What would you like me to implement? Just an update to our docs (where)? I'm using the mne.io.RawArray approach in read_raw_xdf, so this could be some sort of reference implementation which we could include directly in MNE. However, this supports only one particular stream which users have to select.
I'm using the mne.io.RawArray approach in MNELAB, so this could be some sort of reference implementation which we could include directly in MNE. However, this supports only one particular stream which users have to select.
Yeah I'd rather just show people a little code snippet, probably we are using the same things like:
data, header = pyxdf.load_xdf(fn_eeg)
data = data[0]['time_series'].T
info = mne.create_info(...)
raw = mne.io.RawArray(data, info)
this could be some sort of reference implementation which we could include directly in MNE
I'd rather not include an actual implementation in MNE because there is too much flexibility in the format, I'd rather just update the docs to say "something like this might work for your use case" and then people can adapt appropriately based on the data they have.
For cases like this (reading in data from a source type that we don't fully support), I think they make more sense as a how-to example rather than integrated as part of the tutorials. The NEO how-to is an example of this.
EDIT On the other hand, that tutorial is a bit unlike the others in that it's a sort of laundry-list. I think I would still lean toward limiting it to the data formats that we fully support (i.e., have readers for) but maybe add a section to the end called "other formats" where we give general comments about RawArray and link out to a couple specific how-to examples like ones for NEO and LSL.
If it is a separate tutorial, I think we should at least link to it from the plot_20_reading_eeg_data.html, since that's where people will probably naturally end up if they look into file formats in MNE
@larsoner OK, this tutorial might be a good place to mention it.
I've linked to my reader in my previous comment, but yeah, I'm basically just doing what you are using. However, I'm also reading custom units as well as marker channels, which I convert to annotations. I would mention my function in addition to some general code snippet, because people can just go ahead and use from mnelab.io.xdf import read_raw_xdf, which is probably OK for many use cases.
@rob-luke by full support I am referring to importing more than one stream from an XDF file. This requires resampling to a common sampling frequency.
The example shown in the docs requires that one stream is selected.
MNELAB has full support now, which includes importing an arbitrary number of streams plus all marker streams (which are converted to annotations). You can use this function in your own scripts, for example:
This will load streams 1, 3, and 5 from a file named fname and resample them to 1000 Hz. If you want to find out which streams are contained in a given XDF file (and their corresponding stream IDs), you can use:
All of this could potentially be moved to MNE, but we have not discussed if this should be done. If so, I can do the work, but for now I think it's easy enough to just use the function from MNELAB directly.
Thanks @cbrnr
I tested out the functions in MNELAB and they worked wonderfully.
Given how robust and well written the function are, can we move this reader to MNE-Python? This will provide I am able to help in the transition.
Or is there some concern with adding this functionality @larsoner@agramfort ?
Activity
cbrnr commentedon May 2, 2018
Yes, this would be a really nice addition! I'm happy to help if you get stuck.
agramfort commentedon May 2, 2018
dmedine commentedon May 2, 2018
sappelhoff commentedon May 3, 2018
That's a good idea. In the repo for the python XDF loader, there is an ongoing discussion to make a "pyxdf" package, however the discussion is stagnating a bit. Mainly because there is a lack of tests for the robustness/reliability of the loader. See here for the discussion.
Integrating the xdf loader into MNE would not circumvent the issue of (so far) lacking tests, but maybe the stagnation is over now :-)
cbrnr commentedon May 4, 2018
@sappelhoff I think MNE would be a great place for the XDF loader!
cbrnr commentedon May 30, 2018
@dmedine it might not be just as easy as putting the output into a different data structure. Due to the nature of XDF, streams are not necessarily regularly sampled. However, MNE expects all signals to have a fixed sampling frequency. Furthermore, I think that all streams must actually have the same sampling frequency (because everything is stored in a NumPy array) - but I'm not completely sure about that. In any case, this means that some kind of resampling will be necessary.
larsoner commentedon May 30, 2018
I thought that we discussed this somewhere, but a low-order spline interp (or even linear!) would probably be sufficient. So I don't see this as too big a hurdle.
cbrnr commentedon May 30, 2018
Yes, it shouldn't be too difficult, just wanted to bring this up in case this was not obvious. Can you confirm that all signals must have the same sampling frequency? If so, how do we choose which sampling rate to resample to? Most XDF files have nominal sampling rates for each stream, so we could resample to the highest.
larsoner commentedon May 30, 2018
Yes
Resampling to the highest data channel rate (by default, we could make different options with
resample='auto'kwarg) makes sense to me. In practice I imagine these will all usually match anyway.sappelhoff commentedon Aug 9, 2018
There are some developments with the python reader for XDF files. Soon, there might be a pip installable package, see: sccn/xdf#21
That would make this issue easier to solve.
trmullen commentedon Nov 13, 2018
this is a great idea, and we would be happy to support this initiative!
cbrnr commentedon Nov 14, 2018
@dmedine @trmullen do you have time to work on this?
sappelhoff commentedon Nov 14, 2018
@cbrnr check out the discussion in the XDF issue linked above, specifically there is probably the need for some MNE decision on this statement from @dmedine:
@larsoner @agramfort
Personally, I think that being able to extract an EEG stream from XDF is better than nothing and worth an implementation. An even better solution would be to allow the extraction of any single stream out of the XDF file.
... the "best solution" of reading the complete XDF file with all its streams seems tricky indeed
cbrnr commentedon Nov 14, 2018
I thought that the existing XDF reader already supports synchronizing time stamps from different streams, so this is one problem already solved. Grabbing a single stream is straightforward, because all streams are returned in a list of dicts, of which we'd need the values for the
'time_series'and'time_stamps'keys.agramfort commentedon Nov 14, 2018
53 remaining items
cbrnr commentedon Mar 30, 2021
Sure. What would you like me to implement? Just an update to our docs (where)? I'm using the
mne.io.RawArrayapproach in read_raw_xdf, so this could be some sort of reference implementation which we could include directly in MNE. However, this supports only one particular stream which users have to select.larsoner commentedon Mar 30, 2021
Probably update https://mne.tools/stable/auto_tutorials/io/plot_20_reading_eeg_data.html
Yeah I'd rather just show people a little code snippet, probably we are using the same things like:
I'd rather not include an actual implementation in MNE because there is too much flexibility in the format, I'd rather just update the docs to say "something like this might work for your use case" and then people can adapt appropriately based on the data they have.
drammock commentedon Mar 30, 2021
For cases like this (reading in data from a source type that we don't fully support), I think they make more sense as a how-to example rather than integrated as part of the tutorials. The NEO how-to is an example of this.
EDIT On the other hand, that tutorial is a bit unlike the others in that it's a sort of laundry-list. I think I would still lean toward limiting it to the data formats that we fully support (i.e., have readers for) but maybe add a section to the end called "other formats" where we give general comments about
RawArrayand link out to a couple specific how-to examples like ones for NEO and LSL.larsoner commentedon Mar 30, 2021
If it is a separate tutorial, I think we should at least link to it from the
plot_20_reading_eeg_data.html, since that's where people will probably naturally end up if they look into file formats in MNEdrammock commentedon Mar 30, 2021
agree... I was just editing my above comment to say something similar.
cbrnr commentedon Mar 30, 2021
@larsoner OK, this tutorial might be a good place to mention it.
I've linked to my reader in my previous comment, but yeah, I'm basically just doing what you are using. However, I'm also reading custom units as well as marker channels, which I convert to annotations. I would mention my function in addition to some general code snippet, because people can just go ahead and use
from mnelab.io.xdf import read_raw_xdf, which is probably OK for many use cases.cbrnr commentedon Feb 25, 2022
Full XDF support is now available in MNELAB (currently in the
mainbranch, but soon in a new release).rob-luke commentedon Mar 31, 2022
@cbrnr
What's involved in getting "Full" support in to MNE-Python? I just followed the https://mne.tools/dev/auto_examples/io/read_xdf.html tutorial. What is missing from this that would be included in a full xdf reader?
I am now using xdf files and may be able to assist in implementing xdf support in MNE.
cbrnr commentedon Apr 1, 2022
@rob-luke by full support I am referring to importing more than one stream from an XDF file. This requires resampling to a common sampling frequency.
The example shown in the docs requires that one stream is selected.
MNELAB has full support now, which includes importing an arbitrary number of streams plus all marker streams (which are converted to annotations). You can use this function in your own scripts, for example:
This will load streams 1, 3, and 5 from a file named
fnameand resample them to 1000 Hz. If you want to find out which streams are contained in a given XDF file (and their corresponding stream IDs), you can use:All of this could potentially be moved to MNE, but we have not discussed if this should be done. If so, I can do the work, but for now I think it's easy enough to just use the function from MNELAB directly.
rob-luke commentedon Apr 6, 2022
Thanks @cbrnr
I tested out the functions in MNELAB and they worked wonderfully.
Given how robust and well written the function are, can we move this reader to MNE-Python? This will provide I am able to help in the transition.
Or is there some concern with adding this functionality @larsoner @agramfort ?
agramfort commentedon Apr 6, 2022
cbrnr commentedon Apr 6, 2022
Then I'll prepare a PR.