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

Marijn van Vliet w.m.vanvliet at gmail.com
Wed Aug 26 09:45:36 EDT 2020
Search archives:

        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.

On 26/08/2020 16.11, balandongiv at gmail.com wrote:
>          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():
> 
>      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()
> 
>      rep.add_figs_to_section(raw_to_evoked('sub-01_raw.fif'), 
> captions=['Epochs', 'Topomap', 'Butterfly'])
> 
>      rep.save('report_raw_to_first_phase.html')
> 
> def second_run():
> 
>      fig1 = raw.plot();
> 
>      html_old = open('report_raw_to_first_phase.html')
> 
>      rep = Report()
> 
>      rep.ANY_FUNCTION_APPEND_FIG1(html_old ,Fig1 )
> 
>      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
> 
> 
> _______________________________________________
> Mne_analysis mailing list
> Mne_analysis at nmr.mgh.harvard.edu
> https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
> 




More information about the Mne_analysis mailing list