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
ENH: Reading TFRs lazily from disk (h5io to h5py) #14454
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.
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 includeregex 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.
Activity
larsoner commentedon Oct 24, 2026
It would be a very large change at the MNE-Python end and would end up forcing us to support a superset of
h5iofeatures, which I don't think we want to do.Instead I'd suggest to add a new param to
h5ioto allow it to lazy-load features. I'm not totally sure what it would be named or how it would work... easiest might be anexcludeandincluderegexoptions, 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 beexclude='data'or similar, which would read everything but things whose hdf5 data keys match'data'. Then the on-demand read would useinculde='data', which would only read that.raj-magesh commentedon Oct 26, 2026
I didn't realize
h5iowas maintained by the MNE project!I'll try sending a PR when I have time.
divya-git03 commentedon Nov 17, 2026
Hi!
I came across this issue and I'm interested in contributing to the proposed lazy-loading functionality.
I noticed the suggestion to implement
includeandexcluderegex parameters in h5io rather than migrating MNE-Python to h5py.I also noticed that h5io already has glob-style pattern matching in
list_hdf()andread_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!