Skip to content

measurement Info shoudl have a _reprt_html method to be printed in a notebook #6846

Closed

Description

@agramfort

and the MNE report should be using the _repr_html method when available to produce HTML rendering of mne objects

Activity

  1. larsoner commented on Sep 30, 2019

    @larsoner
    Member

    I would wait to work on this until we can use sphinx-gallery/sphinx-gallery#540 to see the outputs

  2. agramfort commented on Sep 30, 2019

    @agramfort
    SponsorMemberAuthor
  3. added this to the 0.21 milestone on Apr 27, 2020
  4. larsoner commented on Aug 31, 2020

    @larsoner
    Member

    Anybody want a fun quick one for 0.21? @hoechenberger maybe?

  5. removed this from the 0.21 milestone on Aug 31, 2020
  6. hoechenberger commented on Sep 1, 2020

    @hoechenberger
    Member

    Anybody want a fun quick one for 0.21? @hoechenberger maybe?

    Maybe I can squeeze it in somewhere, but no promises :)

  7. vagechirkov commented on Mar 18, 2021

    @vagechirkov
    Contributor
    import os
    import mne
    
    from IPython.display import display, HTML
    
    sample_data_folder = mne.datasets.sample.data_path()
    sample_data_raw_file = os.path.join(sample_data_folder, 'MEG', 'sample',
                                        'sample_audvis_filt-0-40_raw.fif')
    raw = mne.io.read_raw_fif(sample_data_raw_file)
    
    string = raw.info.__repr__()
    
    
    template_red = '<span1 style="color: red;  margin-left: 150px;">{}</span1>'
    template_blue = '<span1 style="color: blue;">{}</span1>'
    info_html_string = '<div class="MathJax_Display" style="text-align: left; background-color:rgba(201, 76, 76, 0.3);">'
    info_html_string += "<style> span1 {border-radius: 5px;  font-family:fantasy;} </style>"
    info_html_string += '<span1 style="color: green; margin-left: 250px; font-size: large;">INFO</span1><br>'
    
    for line in string.split('\n')[1:-1]:
        line_parts = line.split(':')
        for n, l in enumerate(line_parts):
            if n == 0:
                info_html_string += template_red.format(l + ':')
            else:
                info_html_string += template_blue.format(l)
        info_html_string += "<br>"
    
    display(HTML(info_html_string))

    @hoechenberger @agramfort is it something that you expect in the _repr_html method?

  8. agramfort commented on Mar 18, 2021

    @agramfort
    SponsorMemberAuthor
  9. vagechirkov commented on Mar 18, 2021

    @vagechirkov
    Contributor

    can you share a screen shot?
    …

    The design is random :)

    image

  10. hoechenberger commented on Mar 18, 2021

    @hoechenberger
    Member

    I'm wondering if we could "cast" the Info into a pandas DataFrame and simply use the DataFrame's HTML representation method?

  11. agramfort commented on Mar 18, 2021

    @agramfort
    SponsorMemberAuthor
  12. hoechenberger commented on Mar 18, 2021

    @hoechenberger
    Member

    Ok. Then, how about repurposing what we already have in Report?

    mne-python/mne/report.py

    Lines 819 to 874 in fc3f2b5

    <table class="table table-hover">
    <tr>
    <th>Measurement date</th>
    {{if meas_date is not None}}
    <td>{{meas_date}}</td>
    {{else}}<td>Unknown</td>{{endif}}
    </tr>
    <tr>
    <th>Experimenter</th>
    {{if info['experimenter'] is not None}}
    <td>{{info['experimenter']}}</td>
    {{else}}<td>Unknown</td>{{endif}}
    </tr>
    <tr>
    <th>Digitized points</th>
    {{if info['dig'] is not None}}
    <td>{{len(info['dig'])}} points</td>
    {{else}}
    <td>Not available</td>
    {{endif}}
    </tr>
    <tr>
    <th>Good channels</th>
    <td>{{n_mag}} magnetometer, {{n_grad}} gradiometer,
    and {{n_eeg}} EEG channels</td>
    </tr>
    <tr>
    <th>Bad channels</th>
    {{if info['bads'] is not None}}
    <td>{{', '.join(info['bads'])}}</td>
    {{else}}<td>None</td>{{endif}}
    </tr>
    <tr>
    <th>EOG channels</th>
    <td>{{eog}}</td>
    </tr>
    <tr>
    <th>ECG channels</th>
    <td>{{ecg}}</td>
    <tr>
    <th>Measurement time range</th>
    <td>{{u'%0.2f' % tmin}} to {{u'%0.2f' % tmax}} sec.</td>
    </tr>
    <tr>
    <th>Sampling frequency</th>
    <td>{{u'%0.2f' % info['sfreq']}} Hz</td>
    </tr>
    <tr>
    <th>Highpass</th>
    <td>{{u'%0.2f' % info['highpass']}} Hz</td>
    </tr>
    <tr>
    <th>Lowpass</th>
    <td>{{u'%0.2f' % info['lowpass']}} Hz</td>
    </tr>
    </table>

  13. agramfort commented on Mar 18, 2021

    @agramfort
    SponsorMemberAuthor
  14. vagechirkov commented on Mar 18, 2021

    @vagechirkov
    Contributor

    Ok. Then, how about repurposing what we already have in Report?

    Here is an example of raw_template output using IPython.display.HTML

    image

  15. larsoner commented on Mar 18, 2021

    @larsoner
    Member

    That's great! I think if the html is returned by _repr_html_ it should work properly.

    Incidentally you can show this off in our doc build by modifying some example that talks about meas info, and just having a line at the end of some code block like:

    #############################################
    # We can also get a nice HTML representation in IPython like:
    
    info
    

    Sphinx-gallery will recognize this statement-without-assignment and, if the object has a _repr_html_, add it to the output of the code block...

  16. agramfort commented on Mar 18, 2021

    @agramfort
    SponsorMemberAuthor

    yes I would add _repr_html_ methods and then make sure that report.py just reuses these so we shoot 3 birds with one stone. It will work for the notebook, the doc and the Report

  17. vagechirkov commented on Mar 19, 2021

    @vagechirkov
    Contributor

    Here is am output of rendering plot_report.py tutorial:

    image

  18. drammock commented on Jun 15, 2022

    @drammock
    Member

    this was done in #9161

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions