Skip to content

ENH: Reading TFRs lazily from disk (h5io to h5py) #14454

Open

Description

@raj-magesh

Describe the new feature or enhancement

Currently, mne.time_frequency.read_tfrs reads data eagerly from disk.

This is sometimes annoyingly slow when I don't immediately need to work with that data (which can often be enormous, ~10s of GB) and for e.g. just want to inspect it or pass some of its parameters to a downstream function.

It would be nice to follow e.g. mne.io.Raw and mne.Epochs and allow the loading to be lazy and .load_data() on demand.

Describe your proposed implementation

Currently, MNE-Python appears to use h5io for the HDF5 interface. From a cursory look, h5io doesn't appear to support lazy-loading.

This proposal would require migrating to e.g. h5py, which currently also appears to be the library with more contributors/activity.

I suppose this would be a rather large change, but perhaps it's worth it? It could also be done incrementally.

Describe possible alternatives

We could just let it be and allow eager loading. It's just inconvenient.

Additional context

No response

Activity

  1. larsoner commented on Oct 24, 2026

    @larsoner
    Member

    It would be a very large change at the MNE-Python end and would end up forcing us to support a superset of h5io features, which I don't think we want to do.

    Instead I'd suggest to add a new param to h5io to allow it to lazy-load features. I'm not totally sure what it would be named or how it would work... easiest might be an exclude and include regex options, where h5io loads everything "in include but not in exclude", with the defaults (None, None) meaning "include everything" and "exclude nothing", respectively. Then the first read can be exclude='data' or similar, which would read everything but things whose hdf5 data keys match 'data'. Then the on-demand read would use inculde='data', which would only read that.

  2. raj-magesh commented on Oct 26, 2026

    @raj-magesh
    Author

    I didn't realize h5io was maintained by the MNE project!

    I'll try sending a PR when I have time.

  3. divya-git03 commented on Nov 17, 2026

    @divya-git03

    Hi!

    I came across this issue and I'm interested in contributing to the proposed lazy-loading functionality.

    I noticed the suggestion to implement include and exclude regex parameters in h5io rather than migrating MNE-Python to h5py.

    I also noticed that h5io already has glob-style pattern matching in list_hdf() and read_dict_from_hdf().

    I'd like to investigate building on this existing functionality and implementing selective dataset reading while maintaining backward compatibility.

    Would this be a suitable direction for a first PR? Are there any particular design considerations you'd recommend before I start?

    Thanks!

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