From 02f848a294bb83f98d67b5955d4da77f4f84e470 Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Tue, 3 Oct 2023 20:53:08 +0300 Subject: [PATCH 1/5] make it work Co-buthored-by: Valerii Chirkov --- mne/_fiff/meas_info.py | 9 ++- mne/html_templates/repr/info.html.jinja | 90 ++++++++++++++++++++++--- mne/html_templates/repr/raw.html.jinja | 13 +--- mne/io/base.py | 8 ++- 4 files changed, 94 insertions(+), 26 deletions(-) diff --git a/mne/_fiff/meas_info.py b/mne/_fiff/meas_info.py index 5f3fa7c0000..88be1c5b4a3 100644 --- a/mne/_fiff/meas_info.py +++ b/mne/_fiff/meas_info.py @@ -14,6 +14,7 @@ import operator from textwrap import shorten import string +import uuid import numpy as np @@ -1877,7 +1878,7 @@ def _get_chs_for_repr(self): return good_channels, bad_channels, ecg, eog @repr_html - def _repr_html_(self, caption=None): + def _repr_html_(self, caption=None, duration=None, filenames=None): """Summarize info for HTML representation.""" if isinstance(caption, str): html = f"

{caption}

" @@ -1909,7 +1910,11 @@ def _repr_html_(self, caption=None): projs = None info_template = _get_html_template("repr", "info.html.jinja") + sections = ("General", "Channels", "Data") + section_ids = [f"section_{str(uuid.uuid4())}" for _ in sections] return html + info_template.render( + sections=sections, + section_ids=section_ids, caption=caption, meas_date=meas_date, projs=projs, @@ -1923,6 +1928,8 @@ def _repr_html_(self, caption=None): highpass=self.get("highpass"), sfreq=self.get("sfreq"), experimenter=self.get("experimenter"), + duration=duration, + filenames=filenames, ) def save(self, fname): diff --git a/mne/html_templates/repr/info.html.jinja b/mne/html_templates/repr/info.html.jinja index ec01af7decd..f6d46c49f34 100644 --- a/mne/html_templates/repr/info.html.jinja +++ b/mne/html_templates/repr/info.html.jinja @@ -1,5 +1,47 @@ + + + + + + + + + {% if meas_date is not none %} @@ -7,7 +49,7 @@ {% endif %} - + {% if experimenter is not none %} @@ -15,8 +57,9 @@ {% endif %} + - {% if subject_info is not none %} + {% if subject_info is defined and subject_info is not none %} {% if 'his_id' in subject_info.keys() %} {% endif %} @@ -25,6 +68,13 @@ {% endif %} + + + {% if dig is not none %} @@ -32,43 +82,63 @@ {% endif %} - + - + - + - + - {% if sfreq is not none %} + + + + {% if sfreq is not none %} + {% endif %} {% if highpass is not none %} - + {% endif %} {% if lowpass is not none %} - + {% endif %} {% if projs is not none %} - + {% endif %} + {% if filenames %} + + + + + {% endif %} + {% if duration %} + + + + + {% endif %}
+ +
Measurement date{{ meas_date }}Unknown
Experimenter{{ experimenter }}Unknown
Participant{{ subject_info['his_id'] }}
+ +
Digitized points{{ dig|length }} pointsNot available
Good channels {{ good_channels }}
Bad channels {{ bad_channels }}
EOG channels {{ eog }}
ECG channels {{ ecg }}
+ +
Sampling frequency {{ '%0.2f'|format(sfreq) }} Hz
Highpass {{ '%0.2f'|format(highpass) }} Hz
Lowpass {{ '%0.2f'|format(lowpass) }} Hz
Projections {{ projs|join('
') | safe }}
Filenames{{ filenames|join('
') }}
Duration{{ duration }} (HH:MM:SS)
diff --git a/mne/html_templates/repr/raw.html.jinja b/mne/html_templates/repr/raw.html.jinja index 7bc8542eaee..9cba46f43bf 100644 --- a/mne/html_templates/repr/raw.html.jinja +++ b/mne/html_templates/repr/raw.html.jinja @@ -1,12 +1 @@ -{{ info_repr[:-9] | safe }} - {% if filenames %} - - Filenames - {{ filenames|join('
') }} - - {% endif %} - - Duration - {{ duration }} (HH:MM:SS) - - +{{ info_repr | safe }} diff --git a/mne/io/base.py b/mne/io/base.py index e4f917a7c29..3950861fed9 100644 --- a/mne/io/base.py +++ b/mne/io/base.py @@ -2069,9 +2069,11 @@ def _repr_html_(self, caption=None): duration = f"{int(hours):02d}:{int(minutes):02d}:{int(seconds):02d}" raw_template = _get_html_template("repr", "raw.html.jinja") return raw_template.render( - info_repr=self.info._repr_html_(caption=caption), - filenames=basenames, - duration=duration, + info_repr=self.info._repr_html_( + caption=caption, + filenames=basenames, + duration=duration, + ) ) def add_events(self, events, stim_channel=None, replace=False): From 03d6883d2746745016e1fb526c92ab36fcde27d2 Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Tue, 3 Oct 2023 21:14:07 +0300 Subject: [PATCH 2/5] touch examples --- tutorials/intro/30_info.py | 2 +- tutorials/intro/70_report.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tutorials/intro/30_info.py b/tutorials/intro/30_info.py index 98e4aab097a..2de72747528 100644 --- a/tutorials/intro/30_info.py +++ b/tutorials/intro/30_info.py @@ -182,7 +182,7 @@ print(mne.pick_info(info, eeg_indices)["nchan"]) # %% -# We can also get a nice HTML representation in IPython like: +# We can also get a nice HTML representation in IPython like this: info diff --git a/tutorials/intro/70_report.py b/tutorials/intro/70_report.py index 0c8c086eff8..b23c8852694 100644 --- a/tutorials/intro/70_report.py +++ b/tutorials/intro/70_report.py @@ -17,7 +17,7 @@ HTML pages it generates are self-contained and do not require a running Python environment. However, it is less flexible as you can't change code and re-run something directly within the browser. This tutorial covers the basics of -building a report. As usual, we'll start by importing the modules and data we +building a report. As usual, we will start by importing the modules and data we need: """ From a2b63d8ea0186e8fce22a75cca903bd780ff70a2 Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Wed, 4 Oct 2023 02:36:34 +0300 Subject: [PATCH 3/5] fix test --- mne/utils/tests/test_misc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mne/utils/tests/test_misc.py b/mne/utils/tests/test_misc.py index 14bfa183175..1309feafbec 100644 --- a/mne/utils/tests/test_misc.py +++ b/mne/utils/tests/test_misc.py @@ -24,7 +24,7 @@ def test_html_repr(): os.environ[key] = "True" # HTML repr on info = mne.create_info(10, 256) r = info._repr_html_() - assert r.startswith("") os.environ[key] = "False" # HTML repr off r = info._repr_html_() From c9e924de016cf0620612e22d3996501e9b69cb03 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Wed, 4 Oct 2023 02:02:28 -0400 Subject: [PATCH 4/5] TST: Ping CircleCI --- tutorials/raw/10_raw_overview.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tutorials/raw/10_raw_overview.py b/tutorials/raw/10_raw_overview.py index 0dbb8491d87..198cb5264ee 100644 --- a/tutorials/raw/10_raw_overview.py +++ b/tutorials/raw/10_raw_overview.py @@ -17,7 +17,6 @@ """ # %% - import os import numpy as np import matplotlib.pyplot as plt From aa19488e579230c42f2c82e7f724e02dcbe427ad Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Wed, 4 Oct 2023 09:28:20 +0300 Subject: [PATCH 5/5] FIX: Pandas --- mne/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mne/conftest.py b/mne/conftest.py index df914120ece..c1e6b36a93b 100644 --- a/mne/conftest.py +++ b/mne/conftest.py @@ -158,7 +158,7 @@ def pytest_configure(config): # h5py ignore:`product` is deprecated as of NumPy.*:DeprecationWarning # pandas - ignore:.*np\.find_common_type is deprecated.*:DeprecationWarning + ignore:In the future `np.long`.*:FutureWarning # https://github.com/joblib/joblib/issues/1454 ignore:.*`byte_bounds` is dep.*:DeprecationWarning # numpy distutils used by SciPy