# Is it possible to append new figure to an existing	html generated by mne.report module

**URL:** <https://mne.discourse.group/t/is-it-possible-to-append-new-figure-to-an-existing-html-generated-by-mne-report-module/2298>\
**Category:** Mailing List Archive (read-only)\
**Tags:** list-archive\
**Created:** [August 26, 2020, 1:11pm UTC](https://mne.discourse.group/t/is-it-possible-to-append-new-figure-to-an-existing-html-generated-by-mne-report-module/2298 "2020-08-26T13:11:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [August 26, 2020, 1:11pm UTC](https://mne.discourse.group/t/is-it-possible-to-append-new-figure-to-an-existing-html-generated-by-mne-report-module/2298/1 "2020-08-26T13:11:24Z")

</div>

External Email - Use Caution

Dear group,

I would like to know whether it is possible to append a new figure to an  
offline html report that generated by mne\_report.

For example, say we have a report\_raw\_to\_first\_phase.html (e.g., html) .  
Then, in other run, I would like to append a new figure (e.g., Fig1) to the  
report\_raw\_to\_first\_phase.html and save a new html file.

I am thinking of something lime rep.ANY\_FUNCTION\_APPEND\_FIG1(html\_old ,Fig1  
) as shown in the function second\_run() below.

import mne

from mne.datasets import sample

from mne.report import Report

data\_path = sample.data\_path()

raw\_fname = data\_path + '/MEG/sample/sample\_audvis\_raw.fif'

raw = mne.io.read\_raw\_fif(raw\_fname, preload=True)

def first\_run():

&nbsp;&nbsp;&nbsp;&nbsp;raw1 = raw.copy().crop(0, 20)

&nbsp;&nbsp;&nbsp;&nbsp;raw1.save(data\_path + '/MEG/sample/sub-01\_raw.fif', overwrite=True)

&nbsp;&nbsp;&nbsp;&nbsp;event\_id = {'Auditory/Left': 3, 'Auditory/Right': 4}

&nbsp;&nbsp;&nbsp;&nbsp;def raw\_to\_evoked(raw\_fname, tmin=-0.1, tmax=0.5):

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;raw = mne.io.read\_raw\_fif(data\_path + '/MEG/sample/' + raw\_fname,  
preload=True)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;raw.filter(0, 40.)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;events = mne.find\_events(raw, stim\_channel='STI 014')

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;epochs = mne.Epochs(raw, events, event\_id, tmin, tmax)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fig2 = epochs.plot();

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;evoked\_l = epochs['Left'].average();

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fig3 = evoked\_l.plot\_topomap()

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fig4 = evoked\_l.plot();

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return [fig2, fig3, fig4]

&nbsp;&nbsp;&nbsp;&nbsp;rep = Report()

&nbsp;&nbsp;&nbsp;&nbsp;rep.add\_figs\_to\_section(raw\_to\_evoked('sub-01\_raw.fif'),  
captions=['Epochs', 'Topomap', 'Butterfly'])

&nbsp;&nbsp;&nbsp;&nbsp;rep.save('report\_raw\_to\_first\_phase.html')

def second\_run():

&nbsp;&nbsp;&nbsp;&nbsp;fig1 = raw.plot();

&nbsp;&nbsp;&nbsp;&nbsp;html\_old = open('report\_raw\_to\_first\_phase.html')

&nbsp;&nbsp;&nbsp;&nbsp;rep = Report()

&nbsp;&nbsp;&nbsp;&nbsp;rep.ANY\_FUNCTION\_APPEND\_FIG1(html\_old ,Fig1 )

&nbsp;&nbsp;&nbsp;&nbsp;rep.save('report\_raw\_to\_second\_run.html')

first\_run()

second\_run()

If this is not possible, what is the best advice to generate a  
pre\_processing report given that I would like to monitor the quality of the  
pre\_processing at each step.

Regards

Rodney

-------------- next part --------------  
An HTML attachment was scrubbed...  
URL: [http://mail.nmr.mgh.harvard.edu/pipermail/mne\_analysis/attachments/20200826/91287fd6/attachment-0001.html](http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20200826/91287fd6/attachment-0001.html)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [August 26, 2020, 1:45pm UTC](https://mne.discourse.group/t/is-it-possible-to-append-new-figure-to-an-existing-html-generated-by-mne-report-module/2298/2 "2020-08-26T13:45:36Z")

</div>

External Email - Use Caution

Hi Rodney,

this is possible if you save the report as .h5 file: report.save('my\_report.h5')  
and later open it using: mne.open\_report('my\_report.h5'). Since you probably  
also want the report as HTML so you can view it in the browser, I suggest saving  
it twice, once as .h5 and once as .html.

You can see this technique in action in my "conpy" analysis pipeline, for  
example here:  
[https://github.com/AaltoImagingLanguage/conpy/blob/master/scripts/04\_epochs.py#L71](https://github.com/AaltoImagingLanguage/conpy/blob/master/scripts/04_epochs.py#L71)

best,  
Marijn.
