Skip to content

Commit

Permalink
fix html repr tables for spectrum objects
Browse files Browse the repository at this point in the history
  • Loading branch information
drammock committed Dec 19, 2024
1 parent 05bd738 commit d5823e3
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 49 deletions.
62 changes: 62 additions & 0 deletions mne/html_templates/repr/_frequencies.html.jinja
Original file line number Diff line number Diff line change
@@ -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' %}

<tr class="repr-element {{ section_class_name }} {{ collapsed_row_class }}">
<td class="mne-repr-section-toggle"></td>
<td>Data type</td>
<td>{{ inst._data_type }}</td>
</tr>
<tr class="repr-element {{ section_class_name }} {{ collapsed_row_class }}">
<td class="mne-repr-section-toggle"></td>
<td>Computed from</td>
<td>{{ computed_from }}</td>
</tr>
<tr class="repr-element {{ section_class_name }} {{ collapsed_row_class }}">
<td class="mne-repr-section-toggle"></td>
<td>Estimation method</td>
<td>{{ inst.method }}</td>
</tr>
<!--
<tr class="repr-element {{ section_class_name }} {{ collapsed_row_class }}">
<td class="mne-repr-section-toggle"></td>
<td>Dims</td>
<td>{{ inst._dims | join(", ") }}</td>
</tr>
-->
{% if "taper" in inst._dims %}
<tr class="repr-element {{ section_class_name }} {{ collapsed_row_class }}">
<td class="mne-repr-section-toggle"></td>
<td>Number of tapers</td>
<td>{{ inst._mt_weights.size }}</td>
</tr>
{% endif %}
{% if inst.freqs is defined %}
<tr class="repr-element {{ section_class_name }} {{ collapsed_row_class }}">
<td class="mne-repr-section-toggle"></td>
<td>Frequency range</td>
<td>{{ '%.2f'|format(inst.freqs[0]) }} – {{ '%.2f'|format(inst.freqs[-1]) }} Hz</td>
</tr>
<tr class="repr-element {{ section_class_name }} {{ collapsed_row_class }}">
<td class="mne-repr-section-toggle"></td>
<td>Number of frequency bins</td>
<td>{{ inst.freqs|length }}</td>
</tr>
{%- for unit in units %}
<tr class="repr-element {{ section_class_name }} {{ collapsed_row_class }}">
<td class="mne-repr-section-toggle"></td>
{%- if loop.index == 1 %}
<td rowspan={{ units | length }}>Units</td>
{%- endif %}
<td class="justify">{{ unit }}</td>
</tr>
{%- endfor %}
{% endif %}
57 changes: 9 additions & 48 deletions mne/html_templates/repr/spectrum.html.jinja
Original file line number Diff line number Diff line change
@@ -1,50 +1,11 @@
{%include '_js_and_css.html.jinja' %}

{% set info = inst.info %}

<table class="table mne-repr-table">
<tr>
<th>Data type</th>
<td>{{ spectrum._data_type }}</td>
</tr>
{%- for unit in units %}
<tr>
{%- if loop.index == 1 %}
<th rowspan={{ units | length }}>Units</th>
{%- endif %}
<td class="justify">{{ unit }}</td>
</tr>
{%- endfor %}
<tr>
<th>Data source</th>
<td>{{ inst_type }}</td>
</tr>
{%- if inst_type == "Epochs" %}
<tr>
<th>Number of epochs</th>
<td>{{ spectrum.shape[0] }}</td>
</tr>
{% endif -%}
<tr>
<th>Dims</th>
<td>{{ spectrum._dims | join(", ") }}</td>
</tr>
<tr>
<th>Estimation method</th>
<td>{{ spectrum.method }}</td>
</tr>
{% if "taper" in spectrum._dims %}
<tr>
<th>Number of tapers</th>
<td>{{ spectrum._mt_weights.size }}</td>
</tr>
{% endif %}
<tr>
<th>Number of channels</th>
<td>{{ spectrum.ch_names|length }}</td>
</tr>
<tr>
<th>Number of frequency bins</th>
<td>{{ spectrum.freqs|length }}</td>
</tr>
<tr>
<th>Frequency range</th>
<td>{{ '%.2f'|format(spectrum.freqs[0]) }} – {{ '%.2f'|format(spectrum.freqs[-1]) }} Hz</td>
</tr>
{%include '_general.html.jinja' %}
{%include '_acquisition.html.jinja' %}
{%include '_channels.html.jinja' %}
{%include '_frequencies.html.jinja' %}
{%include '_filters.html.jinja' %}
</table>
4 changes: 3 additions & 1 deletion mne/time_frequency/spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit d5823e3

Please sign in to comment.