[Mne_analysis] Is it possible to append new figure to an existing html generated by mne.report module
balandongiv at gmail.com
balandongiv at gmail.com
Wed Aug 26 23:01:52 EDT 2020
External Email - Use Caution
Hi Marijin,
Thanks for the suggestion it really help. +1 for the "conpy" analysis
pipeline and your paper.
As per suggestion by Marijin, the code to append existing mne report and
customise html is as below:
Regards
Rodney
Code:
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():
raw1 = raw.copy().crop(0, 20)
raw1.save(data_path + '/MEG/sample/sub-01_raw.fif', overwrite=True)
event_id = {'Auditory/Left': 3, 'Auditory/Right': 4}
def raw_to_evoked(raw_fname, tmin=-0.1, tmax=0.5):
raw = mne.io.read_raw_fif(data_path + '/MEG/sample/' + raw_fname,
preload=True)
raw.filter(0, 40.)
events = mne.find_events(raw, stim_channel='STI 014')
epochs = mne.Epochs(raw, events, event_id, tmin, tmax)
fig2 = epochs.plot();
evoked_l = epochs['Left'].average();
fig3 = evoked_l.plot_topomap()
fig4 = evoked_l.plot();
return [fig2, fig3, fig4]
rep = Report()
figs = raw_to_evoked('sub-01_raw.fif')
rep.add_figs_to_section(figs , captions=['Epochs', 'Topomap',
'Butterfly'])
rep.save('my_report.h5')
def second_run():
fig1 = raw.plot()
html = """
<table class="table table-hover">
<tr>
<th>Meas time range</th>
<th>Sampling freq</th>
</tr>
<tr>
<td> %0.2f to %0.2f </td>
<td> %0.2f </td>
</tr>
</table>
"""
with mne.open_report('my_report.h5') as rep:
# Append new figure to the existing report
rep.add_figs_to_section(fig1,captions=['raw'])
# add custom htmls
rep.add_htmls_to_section(html % (raw.times[0], raw.times[-1],
raw.info['sfreq']), captions='Info table')
rep.save('report_raw_to_second_run.html',overwrite=True,open_browser=False)
first_run()
second_run()
------------------------------
Message: 2
Date: Wed, 26 Aug 2020 16:45:36 +0300
From: Marijn van Vliet <w.m.vanvliet at gmail.com>
Subject: Re: [Mne_analysis] Is it possible to append new figure to an
existing html generated by mne.report module
To: mne_analysis at nmr.mgh.harvard.edu
Message-ID: <a0d1c8dc-1bef-3ee6-0f1c-5b0517a1904f at gmail.com>
Content-Type: text/plain; charset="windows-1252"; format="flowed"
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
best,
Marijn.
More information about the Mne_analysis
mailing list