The calculation of the duration display in BaseRAW._repr_html_ assumes that the length of the acquisition is the timestamp of the last sample which, for a high sampling rate, is close to the actual duration, but ignores the length of the last sample.
Depending on the acquisition length and the sampling frequency, this might result in a weird display.
Steps to reproduce
In a Jupyter Notebook, open an EDF containing data that is sampled at 500 hz and lasts exactly one hour and then display it. E.g:
To fix it, instead of calculating the duration based on the time of the last sample, use the total amount of samples and divide it by the sampling frequency. E.g:
By the way, Pandas has a very nice representation for time deltas, if you want to remove the hours/minutes/seconds calculation (though that would mean pandas needs to be installed, even though it's an optional dependency for MNE):
>>> str( pd.Timedelta(3597, 's') )
'0 days 00:59:57'
Here is the mne.sys_info() (not that it makes a difference):
Description of the problem
The calculation of the
duration
display inBaseRAW._repr_html_
assumes that the length of the acquisition is the timestamp of the last sample which, for a high sampling rate, is close to the actual duration, but ignores the length of the last sample.Depending on the acquisition length and the sampling frequency, this might result in a weird display.
Steps to reproduce
In a Jupyter Notebook, open an EDF containing data that is sampled at 500 hz and lasts exactly one hour and then display it. E.g:
You'll get an output containing:
Instead of what would be expected:
Link to data
No response
Expected results
As mentioned, I expect to get:
Actual results
Instead I get:
Additional information
The code that calculates the duration is in
BaseRaw._repr_html_
:To fix it, instead of calculating the duration based on the time of the last sample, use the total amount of samples and divide it by the sampling frequency. E.g:
By the way, Pandas has a very nice representation for time deltas, if you want to remove the hours/minutes/seconds calculation (though that would mean pandas needs to be installed, even though it's an optional dependency for MNE):
Here is the
mne.sys_info()
(not that it makes a difference):Platform Linux-6.1.85+-x86_64-with-glibc2.35 Python 3.10.12 (main, Sep 11 2024, 15:47:36) [GCC 11.4.0] Executable /usr/bin/python3 CPU x86_64 (2 cores) Memory 12.7 GB
Core ├☑ mne 1.8.0 (latest release) ├☑ numpy 1.26.4 (OpenBLAS 0.3.23.dev with 2 threads) ├☑ scipy 1.14.1 └☑ matplotlib 3.8.0 (backend=module://matplotlib_inline.backend_inline)
Numerical (optional) ├☑ sklearn 1.5.2 ├☑ numba 0.60.0 ├☑ nibabel 5.3.2 ├☑ pandas 2.2.3 ├☑ h5py 3.12.1 └☐ unavailable nilearn, dipy, openmeeg, cupy, h5io
Visualization (optional) ├☑ ipywidgets 8.1.5 └☐ unavailable pyvista, pyvistaqt, vtk, qtpy, ipympl, pyqtgraph, mne-qt-browser, trame_client, trame_server, trame_vtk, trame_vuetify
Ecosystem (optional) └☐ unavailable mne-bids, mne-nirs, mne-features, mne-connectivity, mne-icalabel, mne-bids-pipeline, neo, eeglabio, edfio, mffpy, pybv