From d5823e3d40b543e479e2f20bfc0ef6979b34415b Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Thu, 19 Dec 2024 15:06:33 -0600 Subject: [PATCH 1/8] fix html repr tables for spectrum objects --- .../repr/_frequencies.html.jinja | 62 +++++++++++++++++++ mne/html_templates/repr/spectrum.html.jinja | 57 +++-------------- mne/time_frequency/spectrum.py | 4 +- 3 files changed, 74 insertions(+), 49 deletions(-) create mode 100644 mne/html_templates/repr/_frequencies.html.jinja diff --git a/mne/html_templates/repr/_frequencies.html.jinja b/mne/html_templates/repr/_frequencies.html.jinja new file mode 100644 index 00000000000..b55b8ddf883 --- /dev/null +++ b/mne/html_templates/repr/_frequencies.html.jinja @@ -0,0 +1,62 @@ +{% set section = "Frequencies" %} +{% set section_class_name = section | lower | append_uuid %} + +{# Collapse content during documentation build. #} +{% if collapsed %} +{% set collapsed_row_class = "mne-repr-collapsed" %} +{% else %} +{% set collapsed_row_class = "" %} +{% endif %} + +{%include 'static/_section_header_row.html.jinja' %} + + + + Data type + {{ inst._data_type }} + + + + Computed from + {{ computed_from }} + + + + Estimation method + {{ inst.method }} + + +{% if "taper" in inst._dims %} + + + Number of tapers + {{ inst._mt_weights.size }} + +{% endif %} +{% if inst.freqs is defined %} + + + Frequency range + {{ '%.2f'|format(inst.freqs[0]) }} – {{ '%.2f'|format(inst.freqs[-1]) }} Hz + + + + Number of frequency bins + {{ inst.freqs|length }} + +{%- for unit in units %} + + + {%- if loop.index == 1 %} + Units + {%- endif %} + {{ unit }} + +{%- endfor %} +{% endif %} diff --git a/mne/html_templates/repr/spectrum.html.jinja b/mne/html_templates/repr/spectrum.html.jinja index 11a1d7a886f..40cc2222005 100644 --- a/mne/html_templates/repr/spectrum.html.jinja +++ b/mne/html_templates/repr/spectrum.html.jinja @@ -1,50 +1,11 @@ +{%include '_js_and_css.html.jinja' %} + +{% set info = inst.info %} + - - - - - {%- for unit in units %} - - {%- if loop.index == 1 %} - - {%- endif %} - - - {%- endfor %} - - - - - {%- if inst_type == "Epochs" %} - - - - - {% endif -%} - - - - - - - - - {% if "taper" in spectrum._dims %} - - - - - {% endif %} - - - - - - - - - - - - + {%include '_general.html.jinja' %} + {%include '_acquisition.html.jinja' %} + {%include '_channels.html.jinja' %} + {%include '_frequencies.html.jinja' %} + {%include '_filters.html.jinja' %}
Data type{{ spectrum._data_type }}
Units{{ unit }}
Data source{{ inst_type }}
Number of epochs{{ spectrum.shape[0] }}
Dims{{ spectrum._dims | join(", ") }}
Estimation method{{ spectrum.method }}
Number of tapers{{ spectrum._mt_weights.size }}
Number of channels{{ spectrum.ch_names|length }}
Number of frequency bins{{ spectrum.freqs|length }}
Frequency range{{ '%.2f'|format(spectrum.freqs[0]) }} – {{ '%.2f'|format(spectrum.freqs[-1]) }} Hz
diff --git a/mne/time_frequency/spectrum.py b/mne/time_frequency/spectrum.py index 23317a6c9d3..4421fc045e8 100644 --- a/mne/time_frequency/spectrum.py +++ b/mne/time_frequency/spectrum.py @@ -419,7 +419,9 @@ def _repr_html_(self, caption=None): inst_type_str = _get_instance_type_string(self) units = [f"{ch_type}: {unit}" for ch_type, unit in self.units().items()] t = _get_html_template("repr", "spectrum.html.jinja") - t = t.render(spectrum=self, inst_type=inst_type_str, units=units) + t = t.render( + inst=self, computed_from=inst_type_str, units=units, filenames=None + ) return t def _check_values(self): From 63dc18f9d23ce3c2517b63c3501690624e8dd46f Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Fri, 20 Dec 2024 01:23:58 -0600 Subject: [PATCH 2/8] touch tutorial (reflow) --- tutorials/time-freq/10_spectrum_class.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tutorials/time-freq/10_spectrum_class.py b/tutorials/time-freq/10_spectrum_class.py index 62f6103bfdb..9ba463e18b5 100644 --- a/tutorials/time-freq/10_spectrum_class.py +++ b/tutorials/time-freq/10_spectrum_class.py @@ -35,11 +35,10 @@ raw.compute_psd() # %% -# By default, the spectral estimation method will be the -# :footcite:t:`Welch1967` method for continuous data, and the multitaper -# method :footcite:`Slepian1978` for epoched or averaged data. This default can -# be overridden by passing ``method='welch'`` or ``method='multitaper'`` to the -# :meth:`~mne.io.Raw.compute_psd` method. +# By default, the spectral estimation method will be the :footcite:t:`Welch1967` method +# for continuous data, and the multitaper method :footcite:`Slepian1978` for epoched or +# averaged data. This default can be overridden by passing ``method='welch'`` or +# ``method='multitaper'`` to the :meth:`~mne.io.Raw.compute_psd` method. # # There are many other options available as well; for example we can compute a # spectrum from a given span of times, for a chosen frequency range, and for a From e0ea679e1408de9023c3fd9c3a24db58601d1bd1 Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Fri, 20 Dec 2024 13:56:13 -0600 Subject: [PATCH 3/8] make acquisition subtable compatible with spectra --- mne/html_templates/repr/_acquisition.html.jinja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mne/html_templates/repr/_acquisition.html.jinja b/mne/html_templates/repr/_acquisition.html.jinja index 0016740cdf8..e1ee4f69dd3 100644 --- a/mne/html_templates/repr/_acquisition.html.jinja +++ b/mne/html_templates/repr/_acquisition.html.jinja @@ -81,7 +81,7 @@ {{ "%0.2f" | format(info["sfreq"]) }} Hz {% endif %} -{% if inst is defined and inst.times is defined %} +{% if inst is defined and inst | has_attr("times") and inst.times is defined %} Time points From 609cfa83a68f080cf756e9d08a9acbf174451b23 Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Fri, 20 Dec 2024 14:46:47 -0600 Subject: [PATCH 4/8] figure out why azure precommit fails --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 89adc810eec..80c79edace3 100644 --- a/Makefile +++ b/Makefile @@ -44,7 +44,7 @@ test-doc: sample_data testing_data $(PYTESTS) --doctest-modules --doctest-ignore-import-errors --doctest-glob='*.rst' ./doc/ --ignore=./doc/auto_examples --ignore=./doc/auto_tutorials --ignore=./doc/_build --ignore=./doc/conf.py --ignore=doc/sphinxext --fulltrace pre-commit: - @pre-commit run -a + @pre-commit run -a --show-diff-on-failure # Aliases for stuff we used to support or users might think of ruff: pre-commit From 13b06a31fbd91849f61e747745da641cf53a589b Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Fri, 20 Dec 2024 14:59:45 -0600 Subject: [PATCH 5/8] preempt pre-commit --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 50e0daaa52c..cfa7488324f 100644 --- a/README.rst +++ b/README.rst @@ -72,7 +72,7 @@ The minimum required dependencies to run MNE-Python are: .. ↓↓↓ BEGIN CORE DEPS LIST. DO NOT EDIT! HANDLED BY PRE-COMMIT HOOK ↓↓↓ -- `Python `__ ≥ 3.9 +- `Python `__ ≥ 3.10 - `NumPy `__ ≥ 1.23 - `SciPy `__ ≥ 1.9 - `Matplotlib `__ ≥ 3.6 From 659d58ad7eb45b8780518e44e378132db1ffeb52 Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Fri, 20 Dec 2024 15:28:54 -0600 Subject: [PATCH 6/8] fix dependency sync? --- tools/hooks/sync_dependencies.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/hooks/sync_dependencies.py b/tools/hooks/sync_dependencies.py index 0878a5f56eb..351313177d3 100755 --- a/tools/hooks/sync_dependencies.py +++ b/tools/hooks/sync_dependencies.py @@ -77,7 +77,6 @@ def _prettify_pin(pin): f"- `{key} <{url}>`__{core_deps_pins[key.lower()]}" for key, url in CORE_DEPS_URLS.items() ] -core_deps_rst = "\n" + "\n".join(core_deps_bullets) + "\n" # rewrite the README file lines = README_PATH.read_text("utf-8").splitlines() @@ -87,9 +86,10 @@ def _prettify_pin(pin): if line.strip() == BEGIN: skip = True out_lines.append(line) - out_lines.append(core_deps_rst) + out_lines.extend(["", *core_deps_bullets, ""]) if line.strip() == END: skip = False if not skip: out_lines.append(line) -README_PATH.write_text("\n".join(out_lines) + "\n", encoding="utf-8") + +README_PATH.resolve().write_text("\n".join(out_lines) + "\n", encoding="utf-8") From 020ed0b0af42110273140de22b49beabfe640c15 Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Fri, 20 Dec 2024 15:53:04 -0600 Subject: [PATCH 7/8] remove redundant precommit run from style job --- .github/workflows/tests.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8975e72784b..c6724b5b0b5 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -23,7 +23,6 @@ jobs: - uses: actions/setup-python@v5 with: python-version: '3.12' - - uses: pre-commit/action@v3.0.1 - run: pip install mypy numpy scipy vulture - run: mypy - run: vulture From 1d1dc7c038006611f672eb0e386b7595ce11bb09 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Sat, 21 Dec 2024 20:08:01 -0500 Subject: [PATCH 8/8] MAINT: Revert --- .github/workflows/tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c6724b5b0b5..8975e72784b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -23,6 +23,7 @@ jobs: - uses: actions/setup-python@v5 with: python-version: '3.12' + - uses: pre-commit/action@v3.0.1 - run: pip install mypy numpy scipy vulture - run: mypy - run: vulture