Skip to content

Add support for XDF (labstreaminglayer format) #5180

Closed

Description

@dmedine

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.

Activity

  1. cbrnr commented on May 2, 2018

    @cbrnr
    Contributor

    Yes, this would be a really nice addition! I'm happy to help if you get stuck.

  2. agramfort commented on May 2, 2018

    @agramfort
    SponsorMember
  3. dmedine commented on May 2, 2018

    @dmedine
    Author
  4. sappelhoff commented on May 3, 2018

    @sappelhoff
    Member

    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 :-)

  5. cbrnr commented on May 4, 2018

    @cbrnr
    Contributor

    @sappelhoff I think MNE would be a great place for the XDF loader!

  6. cbrnr commented on May 30, 2018

    @cbrnr
    Contributor

    @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.

  7. larsoner commented on May 30, 2018

    @larsoner
    Member

    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.

  8. cbrnr commented on May 30, 2018

    @cbrnr
    Contributor

    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.

  9. larsoner commented on May 30, 2018

    @larsoner
    Member

    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.

  10. sappelhoff commented on Aug 9, 2018

    @sappelhoff
    Member

    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.

  11. trmullen commented on Nov 13, 2018

    @trmullen

    this is a great idea, and we would be happy to support this initiative!

  12. cbrnr commented on Nov 14, 2018

    @cbrnr
    Contributor

    @dmedine @trmullen do you have time to work on this?

  13. sappelhoff commented on Nov 14, 2018

    @sappelhoff
    Member

    @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.

    @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

  14. cbrnr commented on Nov 14, 2018

    @cbrnr
    Contributor

    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.

  15. agramfort commented on Nov 14, 2018

    @agramfort
    SponsorMember
  16. 53 remaining items

  17. added and removed on Mar 30, 2021
  18. cbrnr commented on Mar 30, 2021

    @cbrnr
    Contributor

    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.

  19. larsoner commented on Mar 30, 2021

    @larsoner
    Member

    Just an update to our docs (where)?

    Probably update https://mne.tools/stable/auto_tutorials/io/plot_20_reading_eeg_data.html

    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.

  20. drammock commented on Mar 30, 2021

    @drammock
    Member

    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.

  21. larsoner commented on Mar 30, 2021

    @larsoner
    Member

    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

  22. drammock commented on Mar 30, 2021

    @drammock
    Member

    agree... I was just editing my above comment to say something similar.

  23. cbrnr commented on Mar 30, 2021

    @cbrnr
    Contributor

    @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.

  24. cbrnr commented on Feb 25, 2022

    @cbrnr
    Contributor

    Full XDF support is now available in MNELAB (currently in the main branch, but soon in a new release).

  25. rob-luke commented on Mar 31, 2022

    @rob-luke
    Member

    Full XDF support is now available in MNELAB (currently in the main branch, but soon in a new release).

    @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.

  26. cbrnr commented on Apr 1, 2022

    @cbrnr
    Contributor

    @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:

    from mnelab.io import read_raw
    
    raw = read_raw(fname, stream_ids=[1, 3, 5], fs_new=1000)

    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:

    from pyxdf import resolve_streams
    
    print(resolve_streams(fname))

    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.

  27. rob-luke commented on Apr 6, 2022

    @rob-luke
    Member

    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 ?

  28. agramfort commented on Apr 6, 2022

    @agramfort
    SponsorMember
  29. cbrnr commented on Apr 6, 2022

    @cbrnr
    Contributor

    Then I'll prepare a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions