#NEWLINE# def plot_ica_overlay( ica , inst , exclude = None , picks = None , start = None , stop = None , title = None , show = True ) : #NEWLINE# #INDENT# 'Overlay of raw and cleaned signals given the unmixing matrix.\n\n    This method helps visualizing signal quality and artifact rejection.\n\n    Parameters\n    ----------\n    ica : instance of mne.preprocessing.ICA\n        The ICA object.\n    inst : instance of mne.io.Raw or mne.Evoked\n        The signals to be compared given the ICA solution. If Raw input,\n        The raw data are displayed before and after cleaning. In a second\n        panel the cross channel average will be displayed. Since dipolar\n        sources will be canceled out this display is sensitive to\n        artifacts. If evoked input, butterfly plots for clean and raw\n        signals will be superimposed.\n    exclude : array_like of int\n        The components marked for exclusion. If None (default), ICA.exclude\n        will be used.\n    picks : array-like of int | None (default)\n        Indices of channels to include (if None, all channels\n        are used that were included on fitting).\n    start : int\n        X-axis start index. If None from the beginning.\n    stop : int\n        X-axis stop index. If None to the end.\n    title : str\n        The figure title.\n    show : bool\n        Show figure if True.\n\n    Returns\n    -------\n    fig : instance of pyplot.Figure\n        The figure.\n    ' #NEWLINE# from .. io.base import _BaseRaw #NEWLINE# from .. evoked import Evoked #NEWLINE# from .. preprocessing.ica import _check_start_stop #NEWLINE# if ( not isinstance ( inst , ( _BaseRaw , Evoked ) ) ) : #NEWLINE# #INDENT# raise ValueError ( 'Data input must be of Raw or Evoked type' ) #NEWLINE# #UNINDENT# if ( title is None ) : #NEWLINE# #INDENT# title = 'Signals before (red) and after (black) cleaning' #NEWLINE# #UNINDENT# if ( picks is None ) : #NEWLINE# #INDENT# picks = [ inst . ch_names . index ( k ) for k in ica . ch_names ] #NEWLINE# #UNINDENT# if ( exclude is None ) : #NEWLINE# #INDENT# exclude = ica . exclude #NEWLINE# #UNINDENT# if isinstance ( inst , _BaseRaw ) : #NEWLINE# #INDENT# if ( start is None ) : #NEWLINE# #INDENT# start = 0.0 #NEWLINE# #UNINDENT# if ( stop is None ) : #NEWLINE# #INDENT# stop = 3.0 #NEWLINE# #UNINDENT# ch_types_used = [ k for k in [ 'mag' , 'grad' , 'eeg' ] if ( k in ica ) ] #NEWLINE# ( start_compare , stop_compare ) = _check_start_stop ( inst , start , stop ) #NEWLINE# ( data , times ) = inst [ picks , start_compare : stop_compare ] #NEWLINE# raw_cln = ica . apply ( inst . copy ( ) , exclude = exclude , start = start , stop = stop ) #NEWLINE# ( data_cln , _ ) = raw_cln [ picks , start_compare : stop_compare ] #NEWLINE# fig = _plot_ica_overlay_raw ( data = data , data_cln = data_cln , times = ( times * 1000.0 ) , title = title , ch_types_used = ch_types_used , show = show ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( inst , Evoked ) : #NEWLINE# #INDENT# if ( ( start is not None ) and ( stop is not None ) ) : #NEWLINE# #INDENT# inst = inst . copy ( ) . crop ( start , stop ) #NEWLINE# #UNINDENT# if ( picks is not None ) : #NEWLINE# #INDENT# inst . pick_channels ( [ inst . ch_names [ p ] for p in picks ] ) #NEWLINE# #UNINDENT# evoked_cln = ica . apply ( inst . copy ( ) , exclude = exclude ) #NEWLINE# fig = _plot_ica_overlay_evoked ( evoked = inst , evoked_cln = evoked_cln , title = title , show = show ) #NEWLINE# #UNINDENT# #UNINDENT# return fig