<s> import os . path as op <EOL> import warnings <EOL> import numpy as np <EOL> from numpy . testing import assert_raises , assert_array_equal <EOL> from nose . tools import assert_true , assert_equal <EOL> from mne import io , read_evokeds , read_proj <EOL> from mne . io . constants import FIFF <EOL> from mne . channels import read_layout , make_eeg_layout <EOL> from mne . datasets import testing <EOL> from mne . time_frequency . tfr import AverageTFR <EOL> from mne . utils import slow_test <EOL> from mne . viz import plot_evoked_topomap , plot_projs_topomap <EOL> from mne . viz . topomap import ( _check_outlines , _onselect , plot_topomap ) <EOL> from mne . viz . utils import _find_peaks <EOL> import matplotlib <EOL> matplotlib . use ( '<STR_LIT>' ) <EOL> warnings . simplefilter ( '<STR_LIT>' ) <EOL> data_dir = testing . data_path ( download = False ) <EOL> subjects_dir = op . join ( data_dir , '<STR_LIT>' ) <EOL> ecg_fname = op . join ( data_dir , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> base_dir = op . join ( op . dirname ( __file__ ) , '<STR_LIT:..>' , '<STR_LIT:..>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:data>' ) <EOL> evoked_fname = op . join ( base_dir , '<STR_LIT>' ) <EOL> fname = op . join ( base_dir , '<STR_LIT>' ) <EOL> raw_fname = op . join ( base_dir , '<STR_LIT>' ) <EOL> event_name = op . join ( base_dir , '<STR_LIT>' ) <EOL> layout = read_layout ( '<STR_LIT>' ) <EOL> def _get_raw ( ) : <EOL> return io . read_raw_fif ( raw_fname , preload = False ) <EOL> @ slow_test <EOL> @ testing . requires_testing_data <EOL> def test_plot_topomap ( ) : <EOL> """<STR_LIT>""" <EOL> import matplotlib . pyplot as plt <EOL> from matplotlib . patches import Circle <EOL> warnings . simplefilter ( '<STR_LIT>' ) <EOL> res = <NUM_LIT:16> <EOL> evoked = read_evokeds ( evoked_fname , '<STR_LIT>' , <EOL> baseline = ( None , <NUM_LIT:0> ) ) <EOL> _ , anim = evoked . animate_topomap ( ch_type = '<STR_LIT>' , times = [ <NUM_LIT:0> , <NUM_LIT:0.1> ] , <EOL> butterfly = False ) <EOL> anim . _func ( <NUM_LIT:1> ) <EOL> plt . close ( '<STR_LIT:all>' ) <EOL> ev_bad = evoked . copy ( ) . pick_types ( meg = False , eeg = True ) <EOL> ev_bad . pick_channels ( ev_bad . ch_names [ : <NUM_LIT:2> ] ) <EOL> ev_bad . plot_topomap ( times = ev_bad . times [ : <NUM_LIT:2> ] - <NUM_LIT> ) <EOL> assert_raises ( ValueError , ev_bad . plot_topomap , ch_type = '<STR_LIT>' ) <EOL> assert_raises ( TypeError , ev_bad . plot_topomap , head_pos = '<STR_LIT:foo>' ) <EOL> assert_raises ( KeyError , ev_bad . plot_topomap , head_pos = dict ( foo = '<STR_LIT:bar>' ) ) <EOL> assert_raises ( ValueError , ev_bad . plot_topomap , head_pos = dict ( center = <NUM_LIT:0> ) ) <EOL> assert_raises ( ValueError , ev_bad . plot_topomap , times = [ - <NUM_LIT:100> ] ) <EOL> assert_raises ( ValueError , ev_bad . plot_topomap , times = [ [ <NUM_LIT:0> ] ] ) <EOL> assert_raises ( ValueError , ev_bad . plot_topomap , times = [ [ <NUM_LIT:0> ] ] ) <EOL> evoked . plot_topomap ( <NUM_LIT:0.1> , layout = layout , scale = dict ( mag = <NUM_LIT:0.1> ) ) <EOL> plt . close ( '<STR_LIT:all>' ) <EOL> axes = [ plt . subplot ( <NUM_LIT> ) , plt . subplot ( <NUM_LIT> ) ] <EOL> evoked . plot_topomap ( axes = axes , colorbar = False ) <EOL> plt . close ( '<STR_LIT:all>' ) <EOL> evoked . plot_topomap ( times = [ - <NUM_LIT:0.1> , <NUM_LIT> ] ) <EOL> plt . close ( '<STR_LIT:all>' ) <EOL> mask = np . zeros_like ( evoked . data , dtype = bool ) <EOL> mask [ [ <NUM_LIT:1> , <NUM_LIT:5> ] , : ] = True <EOL> evoked . plot_topomap ( ch_type = '<STR_LIT>' , outlines = None ) <EOL> times = [ <NUM_LIT:0.1> ] <EOL> evoked . plot_topomap ( times , ch_type = '<STR_LIT>' , res = res , scale = <NUM_LIT:1> ) <EOL> evoked . plot_topomap ( times , ch_type = '<STR_LIT>' , mask = mask , res = res ) <EOL> evoked . plot_topomap ( times , ch_type = '<STR_LIT>' , res = res ) <EOL> evoked . plot_topomap ( times , ch_type = '<STR_LIT>' , res = res ) <EOL> evoked . plot_topomap ( times , ch_type = '<STR_LIT>' , mask = mask , res = res , <EOL> show_names = True , mask_params = { '<STR_LIT>' : '<STR_LIT:x>' } ) <EOL> plt . close ( '<STR_LIT:all>' ) <EOL> assert_raises ( ValueError , evoked . plot_topomap , times , ch_type = '<STR_LIT>' , <EOL> res = res , average = - <NUM_LIT:1000> ) <EOL> assert_raises ( ValueError , evoked . plot_topomap , times , ch_type = '<STR_LIT>' , <EOL> res = res , average = '<STR_LIT>' ) <EOL> p = evoked . plot_topomap ( times , ch_type = '<STR_LIT>' , res = res , <EOL> show_names = lambda x : x . replace ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> image_interp = '<STR_LIT>' ) <EOL> subplot = [ x for x in p . get_children ( ) if <EOL> isinstance ( x , matplotlib . axes . Subplot ) ] [ <NUM_LIT:0> ] <EOL> assert_true ( all ( '<STR_LIT>' not in x . get_text ( ) <EOL> for x in subplot . get_children ( ) <EOL> if isinstance ( x , matplotlib . text . Text ) ) ) <EOL> for ch_type in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> evoked_ = evoked . copy ( ) . pick_types ( eeg = False , meg = ch_type ) <EOL> plot_topomap ( evoked_ . data [ : , <NUM_LIT:0> ] , evoked_ . info ) <EOL> assert_raises ( ValueError , plot_topomap , evoked . data [ <NUM_LIT:0> , : ] , evoked . info ) <EOL> def get_texts ( p ) : <EOL> return [ x . get_text ( ) for x in p . get_children ( ) if <EOL> isinstance ( x , matplotlib . text . Text ) ] <EOL> p = evoked . plot_topomap ( times , ch_type = '<STR_LIT>' , res = res , average = <NUM_LIT> ) <EOL> assert_equal ( len ( get_texts ( p ) ) , <NUM_LIT:0> ) <EOL> p = evoked . plot_topomap ( times , ch_type = '<STR_LIT>' , title = '<STR_LIT>' , res = res ) <EOL> texts = get_texts ( p ) <EOL> assert_equal ( len ( texts ) , <NUM_LIT:1> ) <EOL> assert_equal ( texts [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> plt . close ( '<STR_LIT:all>' ) <EOL> with warnings . catch_warnings ( record = True ) : <EOL> warnings . simplefilter ( '<STR_LIT>' ) <EOL> evoked . plot_topomap ( times , ch_type = '<STR_LIT>' , layout = None , res = res ) <EOL> assert_raises ( RuntimeError , plot_evoked_topomap , evoked , <NUM_LIT:0.1> , '<STR_LIT>' , <EOL> proj = '<STR_LIT>' ) <EOL> evoked = read_evokeds ( evoked_fname , '<STR_LIT>' , <EOL> baseline = ( None , <NUM_LIT:0> ) , proj = False ) <EOL> with warnings . catch_warnings ( record = True ) : <EOL> warnings . simplefilter ( '<STR_LIT>' ) <EOL> evoked . plot_topomap ( <NUM_LIT:0.1> , '<STR_LIT>' , proj = '<STR_LIT>' , res = res ) <EOL> assert_raises ( RuntimeError , plot_evoked_topomap , evoked , <EOL> np . repeat ( <NUM_LIT> , <NUM_LIT:50> ) ) <EOL> assert_raises ( ValueError , plot_evoked_topomap , evoked , [ - <NUM_LIT> , <NUM_LIT> ] ) <EOL> with warnings . catch_warnings ( record = True ) : <EOL> warnings . simplefilter ( '<STR_LIT>' ) <EOL> projs = read_proj ( ecg_fname ) <EOL> projs = [ pp for pp in projs if pp [ '<STR_LIT>' ] . lower ( ) . find ( '<STR_LIT>' ) < <NUM_LIT:0> ] <EOL> plot_projs_topomap ( projs , res = res ) <EOL> plt . close ( '<STR_LIT:all>' ) <EOL> ax = plt . subplot ( <NUM_LIT> ) <EOL> plot_projs_topomap ( [ projs [ <NUM_LIT:0> ] ] , res = res , axes = ax ) <EOL> plt . close ( '<STR_LIT:all>' ) <EOL> for ch in evoked . info [ '<STR_LIT>' ] : <EOL> if ch [ '<STR_LIT>' ] == FIFF . FIFFV_COIL_EEG : <EOL> ch [ '<STR_LIT>' ] . fill ( <NUM_LIT:0> ) <EOL> del evoked . info [ '<STR_LIT>' ] [ <NUM_LIT> ] <EOL> pos = make_eeg_layout ( evoked . info ) . pos [ : , : <NUM_LIT:2> ] <EOL> pos , outlines = _check_outlines ( pos , '<STR_LIT>' ) <EOL> assert_true ( '<STR_LIT>' in outlines . keys ( ) ) <EOL> assert_true ( '<STR_LIT>' in outlines . keys ( ) ) <EOL> assert_true ( '<STR_LIT>' in outlines . keys ( ) ) <EOL> assert_true ( '<STR_LIT>' in outlines . keys ( ) ) <EOL> assert_true ( '<STR_LIT>' in outlines . keys ( ) ) <EOL> assert_true ( outlines [ '<STR_LIT>' ] ) <EOL> assert_true ( '<STR_LIT>' in outlines . keys ( ) ) <EOL> assert_array_equal ( outlines [ '<STR_LIT>' ] , <NUM_LIT:0.5> ) <EOL> pos , outlines = _check_outlines ( pos , '<STR_LIT>' ) <EOL> assert_true ( '<STR_LIT>' in outlines . keys ( ) ) <EOL> assert_true ( '<STR_LIT>' in outlines . keys ( ) ) <EOL> assert_true ( '<STR_LIT>' in outlines . keys ( ) ) <EOL> assert_true ( '<STR_LIT>' in outlines . keys ( ) ) <EOL> assert_true ( '<STR_LIT>' in outlines . keys ( ) ) <EOL> assert_true ( not outlines [ '<STR_LIT>' ] ) <EOL> assert_true ( '<STR_LIT>' in outlines . keys ( ) ) <EOL> assert_array_equal ( outlines [ '<STR_LIT>' ] , <NUM_LIT> ) <EOL> pos , outlines = _check_outlines ( pos , '<STR_LIT>' , <EOL> head_pos = { '<STR_LIT>' : [ <NUM_LIT> , <NUM_LIT> ] } ) <EOL> assert_array_equal ( outlines [ '<STR_LIT>' ] , <NUM_LIT> ) <EOL> evoked . plot_topomap ( times , ch_type = '<STR_LIT>' , outlines = '<STR_LIT>' ) <EOL> evoked . plot_topomap ( times , ch_type = '<STR_LIT>' , outlines = outlines ) <EOL> plt . close ( '<STR_LIT:all>' ) <EOL> def patch ( ) : <EOL> return Circle ( ( <NUM_LIT:0.5> , <NUM_LIT> ) , radius = <NUM_LIT> , <EOL> clip_on = True , transform = plt . gca ( ) . transAxes ) <EOL> outlines [ '<STR_LIT>' ] = patch <EOL> plot_evoked_topomap ( evoked , times , ch_type = '<STR_LIT>' , outlines = outlines ) <EOL> evoked . info [ '<STR_LIT>' ] = None <EOL> assert_raises ( RuntimeError , plot_evoked_topomap , evoked , <EOL> times , ch_type = '<STR_LIT>' ) <EOL> plt . close ( '<STR_LIT:all>' ) <EOL> n_channels = len ( pos ) <EOL> data = np . ones ( n_channels ) <EOL> assert_raises ( ValueError , plot_topomap , data , pos , show_names = True ) <EOL> pos_1d = np . zeros ( n_channels ) <EOL> pos_3d = np . zeros ( ( n_channels , <NUM_LIT:2> , <NUM_LIT:2> ) ) <EOL> assert_raises ( ValueError , plot_topomap , data , pos_1d ) <EOL> assert_raises ( ValueError , plot_topomap , data , pos_3d ) <EOL> assert_raises ( ValueError , plot_topomap , data , pos [ : <NUM_LIT:3> , : ] ) <EOL> pos_x = pos [ : , : <NUM_LIT:1> ] <EOL> pos_xyz = np . c_ [ pos , np . zeros ( n_channels ) [ : , np . newaxis ] ] <EOL> assert_raises ( ValueError , plot_topomap , data , pos_x ) <EOL> assert_raises ( ValueError , plot_topomap , data , pos_xyz ) <EOL> pos_xywh = np . c_ [ pos , np . zeros ( ( n_channels , <NUM_LIT:2> ) ) ] <EOL> plot_topomap ( data , pos_xywh ) <EOL> plt . close ( '<STR_LIT:all>' ) <EOL> axes = [ plt . subplot ( <NUM_LIT> ) , plt . subplot ( <NUM_LIT> ) ] <EOL> with warnings . catch_warnings ( record = True ) : <EOL> evoked . plot_topomap ( times = '<STR_LIT>' , axes = axes ) <EOL> plt . close ( '<STR_LIT:all>' ) <EOL> evoked . data = np . zeros ( evoked . data . shape ) <EOL> evoked . data [ <NUM_LIT:50> ] [ <NUM_LIT:1> ] = <NUM_LIT:1> <EOL> assert_array_equal ( _find_peaks ( evoked , <NUM_LIT:10> ) , evoked . times [ <NUM_LIT:1> ] ) <EOL> evoked . data [ <NUM_LIT> ] [ <NUM_LIT:100> ] = <NUM_LIT:1> <EOL> assert_array_equal ( _find_peaks ( evoked , <NUM_LIT:10> ) , evoked . times [ [ <NUM_LIT:1> , <NUM_LIT:100> ] ] ) <EOL> evoked . data [ <NUM_LIT:2> ] [ <NUM_LIT> ] = <NUM_LIT:2> <EOL> assert_array_equal ( _find_peaks ( evoked , <NUM_LIT:10> ) , evoked . times [ [ <NUM_LIT:1> , <NUM_LIT> ] ] ) <EOL> assert_array_equal ( _find_peaks ( evoked , <NUM_LIT:1> ) , evoked . times [ <NUM_LIT> ] ) <EOL> def test_plot_tfr_topomap ( ) : <EOL> """<STR_LIT>""" <EOL> import matplotlib as mpl <EOL> import matplotlib . pyplot as plt <EOL> raw = _get_raw ( ) <EOL> times = np . linspace ( - <NUM_LIT:0.1> , <NUM_LIT:0.1> , <NUM_LIT:200> ) <EOL> n_freqs = <NUM_LIT:3> <EOL> nave = <NUM_LIT:1> <EOL> rng = np . random . RandomState ( <NUM_LIT> ) <EOL> data = rng . randn ( len ( raw . ch_names ) , n_freqs , len ( times ) ) <EOL> tfr = AverageTFR ( raw . info , data , times , np . arange ( n_freqs ) , nave ) <EOL> tfr . plot_topomap ( ch_type = '<STR_LIT>' , tmin = <NUM_LIT> , tmax = <NUM_LIT> , fmin = <NUM_LIT:0> , fmax = <NUM_LIT:10> , <EOL> res = <NUM_LIT:16> ) <EOL> eclick = mpl . backend_bases . MouseEvent ( '<STR_LIT>' , <EOL> plt . gcf ( ) . canvas , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> eclick . xdata = <NUM_LIT:0.1> <EOL> eclick . ydata = <NUM_LIT:0.1> <EOL> eclick . inaxes = plt . gca ( ) <EOL> erelease = mpl . backend_bases . MouseEvent ( '<STR_LIT>' , <EOL> plt . gcf ( ) . canvas , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1> ) <EOL> erelease . xdata = <NUM_LIT> <EOL> erelease . ydata = <NUM_LIT> <EOL> pos = [ [ <NUM_LIT> , <NUM_LIT> ] , [ <NUM_LIT> , <NUM_LIT:0.5> ] , [ <NUM_LIT:0.0> , <NUM_LIT> ] , [ <NUM_LIT> , <NUM_LIT> ] ] <EOL> _onselect ( eclick , erelease , tfr , pos , '<STR_LIT>' , <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:1> , <NUM_LIT:3> , '<STR_LIT>' , list ( ) ) <EOL> tfr . _onselect ( eclick , erelease , None , '<STR_LIT>' , None ) <EOL> plt . close ( '<STR_LIT:all>' ) </s>
