<s> """<STR_LIT>""" <EOL> import os . path as op <EOL> import numpy as np <EOL> from numpy . random import randn <EOL> from scipy import stats as stats <EOL> import mne <EOL> from mne import ( io , spatial_tris_connectivity , compute_morph_matrix , <EOL> grade_to_tris ) <EOL> from mne . epochs import equalize_epoch_counts <EOL> from mne . stats import ( spatio_temporal_cluster_1samp_test , <EOL> summarize_clusters_stc ) <EOL> from mne . minimum_norm import apply_inverse , read_inverse_operator <EOL> from mne . datasets import sample <EOL> print ( __doc__ ) <EOL> data_path = sample . data_path ( ) <EOL> raw_fname = data_path + '<STR_LIT>' <EOL> event_fname = data_path + '<STR_LIT>' <EOL> subjects_dir = data_path + '<STR_LIT>' <EOL> tmin = - <NUM_LIT> <EOL> tmax = <NUM_LIT> <EOL> raw = io . read_raw_fif ( raw_fname ) <EOL> events = mne . read_events ( event_fname ) <EOL> raw . info [ '<STR_LIT>' ] += [ '<STR_LIT>' ] <EOL> picks = mne . pick_types ( raw . info , meg = True , eog = True , exclude = '<STR_LIT>' ) <EOL> event_id = <NUM_LIT:1> <EOL> reject = dict ( grad = <NUM_LIT> , mag = <NUM_LIT> , eog = <NUM_LIT> ) <EOL> epochs1 = mne . Epochs ( raw , events , event_id , tmin , tmax , picks = picks , <EOL> baseline = ( None , <NUM_LIT:0> ) , reject = reject , preload = True ) <EOL> event_id = <NUM_LIT:3> <EOL> epochs2 = mne . Epochs ( raw , events , event_id , tmin , tmax , picks = picks , <EOL> baseline = ( None , <NUM_LIT:0> ) , reject = reject , preload = True ) <EOL> equalize_epoch_counts ( [ epochs1 , epochs2 ] ) <EOL> fname_inv = data_path + '<STR_LIT>' <EOL> snr = <NUM_LIT> <EOL> lambda2 = <NUM_LIT:1.0> / snr ** <NUM_LIT:2> <EOL> method = "<STR_LIT>" <EOL> inverse_operator = read_inverse_operator ( fname_inv ) <EOL> sample_vertices = [ s [ '<STR_LIT>' ] for s in inverse_operator [ '<STR_LIT:src>' ] ] <EOL> evoked1 = epochs1 . average ( ) <EOL> evoked1 . resample ( <NUM_LIT:50> , npad = '<STR_LIT>' ) <EOL> condition1 = apply_inverse ( evoked1 , inverse_operator , lambda2 , method ) <EOL> evoked2 = epochs2 . average ( ) <EOL> evoked2 . resample ( <NUM_LIT:50> , npad = '<STR_LIT>' ) <EOL> condition2 = apply_inverse ( evoked2 , inverse_operator , lambda2 , method ) <EOL> condition1 . crop ( <NUM_LIT:0> , None ) <EOL> condition2 . crop ( <NUM_LIT:0> , None ) <EOL> tmin = condition1 . tmin <EOL> tstep = condition1 . tstep <EOL> n_vertices_sample , n_times = condition1 . data . shape <EOL> n_subjects = <NUM_LIT:7> <EOL> print ( '<STR_LIT>' % n_subjects ) <EOL> np . random . seed ( <NUM_LIT:0> ) <EOL> X = randn ( n_vertices_sample , n_times , n_subjects , <NUM_LIT:2> ) * <NUM_LIT:10> <EOL> X [ : , : , : , <NUM_LIT:0> ] += condition1 . data [ : , : , np . newaxis ] <EOL> X [ : , : , : , <NUM_LIT:1> ] += condition2 . data [ : , : , np . newaxis ] <EOL> fsave_vertices = [ np . arange ( <NUM_LIT> ) , np . arange ( <NUM_LIT> ) ] <EOL> morph_mat = compute_morph_matrix ( '<STR_LIT>' , '<STR_LIT>' , sample_vertices , <EOL> fsave_vertices , <NUM_LIT:20> , subjects_dir ) <EOL> n_vertices_fsave = morph_mat . shape [ <NUM_LIT:0> ] <EOL> X = X . reshape ( n_vertices_sample , n_times * n_subjects * <NUM_LIT:2> ) <EOL> print ( '<STR_LIT>' ) <EOL> X = morph_mat . dot ( X ) <EOL> X = X . reshape ( n_vertices_fsave , n_times , n_subjects , <NUM_LIT:2> ) <EOL> X = np . abs ( X ) <EOL> X = X [ : , : , : , <NUM_LIT:0> ] - X [ : , : , : , <NUM_LIT:1> ] <EOL> print ( '<STR_LIT>' ) <EOL> connectivity = spatial_tris_connectivity ( grade_to_tris ( <NUM_LIT:5> ) ) <EOL> X = np . transpose ( X , [ <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:0> ] ) <EOL> p_threshold = <NUM_LIT> <EOL> t_threshold = - stats . distributions . t . ppf ( p_threshold / <NUM_LIT> , n_subjects - <NUM_LIT:1> ) <EOL> print ( '<STR_LIT>' ) <EOL> T_obs , clusters , cluster_p_values , H0 = clu = spatio_temporal_cluster_1samp_test ( X , connectivity = connectivity , n_jobs = <NUM_LIT:1> , <EOL> threshold = t_threshold ) <EOL> good_cluster_inds = np . where ( cluster_p_values < <NUM_LIT> ) [ <NUM_LIT:0> ] <EOL> print ( '<STR_LIT>' ) <EOL> stc_all_cluster_vis = summarize_clusters_stc ( clu , tstep = tstep , <EOL> vertices = fsave_vertices , <EOL> subject = '<STR_LIT>' ) <EOL> subjects_dir = op . join ( data_path , '<STR_LIT>' ) <EOL> brain = stc_all_cluster_vis . plot ( hemi = '<STR_LIT>' , subjects_dir = subjects_dir , <EOL> time_label = '<STR_LIT>' ) <EOL> brain . set_data_time_index ( <NUM_LIT:0> ) <EOL> brain . show_view ( '<STR_LIT>' ) <EOL> brain . save_image ( '<STR_LIT>' ) </s>
