<s> """<STR_LIT>""" <EOL> from nilearn import datasets <EOL> haxby_dataset = datasets . fetch_haxby_simple ( ) <EOL> print ( '<STR_LIT>' % haxby_dataset . mask ) <EOL> print ( '<STR_LIT>' % haxby_dataset . func [ <NUM_LIT:0> ] ) <EOL> mask_filename = haxby_dataset . mask <EOL> from nilearn . input_data import NiftiMasker <EOL> nifti_masker = NiftiMasker ( <EOL> mask_img = mask_filename , <EOL> memory = '<STR_LIT>' , memory_level = <NUM_LIT:1> ) <EOL> func_filename = haxby_dataset . func [ <NUM_LIT:0> ] <EOL> fmri_masked = nifti_masker . fit_transform ( func_filename ) <EOL> import numpy as np <EOL> conditions_encoded , sessions = np . loadtxt ( <EOL> haxby_dataset . session_target [ <NUM_LIT:0> ] ) . astype ( "<STR_LIT:int>" ) . T <EOL> conditions = np . recfromtxt ( haxby_dataset . conditions_target [ <NUM_LIT:0> ] ) [ '<STR_LIT>' ] <EOL> condition_mask = np . logical_or ( conditions == b'<STR_LIT>' , conditions == b'<STR_LIT>' ) <EOL> conditions_encoded = conditions_encoded [ condition_mask ] <EOL> fmri_masked = fmri_masked [ condition_mask ] <EOL> n_sessions = np . unique ( sessions ) . size <EOL> grouped_fmri_masked = np . empty ( ( <NUM_LIT:2> * n_sessions , <EOL> fmri_masked . shape [ <NUM_LIT:1> ] ) ) <EOL> grouped_conditions_encoded = np . empty ( ( <NUM_LIT:2> * n_sessions , <NUM_LIT:1> ) ) <EOL> for s in range ( n_sessions ) : <EOL> session_mask = sessions [ condition_mask ] == s <EOL> session_house_mask = np . logical_and ( session_mask , <EOL> conditions [ condition_mask ] == b'<STR_LIT>' ) <EOL> session_face_mask = np . logical_and ( session_mask , <EOL> conditions [ condition_mask ] == b'<STR_LIT>' ) <EOL> grouped_fmri_masked [ <NUM_LIT:2> * s ] = fmri_masked [ session_house_mask ] . mean ( <NUM_LIT:0> ) <EOL> grouped_fmri_masked [ <NUM_LIT:2> * s + <NUM_LIT:1> ] = fmri_masked [ session_face_mask ] . mean ( <NUM_LIT:0> ) <EOL> grouped_conditions_encoded [ <NUM_LIT:2> * s ] = conditions_encoded [ <EOL> session_house_mask ] [ <NUM_LIT:0> ] <EOL> grouped_conditions_encoded [ <NUM_LIT:2> * s + <NUM_LIT:1> ] = conditions_encoded [ <EOL> session_face_mask ] [ <NUM_LIT:0> ] <EOL> from nilearn . mass_univariate import permuted_ols <EOL> neg_log_pvals , t_scores_original_data , _ = permuted_ols ( <EOL> grouped_conditions_encoded , grouped_fmri_masked , <EOL> n_perm = <NUM_LIT> , two_sided_test = True , <EOL> n_jobs = <NUM_LIT:1> ) <EOL> signed_neg_log_pvals = neg_log_pvals * np . sign ( t_scores_original_data ) <EOL> signed_neg_log_pvals_unmasked = nifti_masker . inverse_transform ( <EOL> signed_neg_log_pvals ) <EOL> from nilearn . _utils . fixes import f_regression <EOL> _ , pvals_bonferroni = f_regression ( <EOL> grouped_fmri_masked , <EOL> grouped_conditions_encoded ) <EOL> pvals_bonferroni *= fmri_masked . shape [ <NUM_LIT:1> ] <EOL> pvals_bonferroni [ np . isnan ( pvals_bonferroni ) ] = <NUM_LIT:1> <EOL> pvals_bonferroni [ pvals_bonferroni > <NUM_LIT:1> ] = <NUM_LIT:1> <EOL> neg_log_pvals_bonferroni = - np . log10 ( pvals_bonferroni ) <EOL> neg_log_pvals_bonferroni_unmasked = nifti_masker . inverse_transform ( <EOL> neg_log_pvals_bonferroni ) <EOL> import matplotlib . pyplot as plt <EOL> from nilearn . plotting import plot_stat_map , show <EOL> from nilearn import image <EOL> mean_fmri_img = image . mean_img ( func_filename ) <EOL> z_slice = - <NUM_LIT> <EOL> from nilearn . image . resampling import coord_transform <EOL> affine = signed_neg_log_pvals_unmasked . get_affine ( ) <EOL> from scipy import linalg <EOL> _ , _ , k_slice = coord_transform ( <NUM_LIT:0> , <NUM_LIT:0> , z_slice , <EOL> linalg . inv ( affine ) ) <EOL> k_slice = np . round ( k_slice ) <EOL> threshold = - np . log10 ( <NUM_LIT:0.1> ) <EOL> vmax = min ( signed_neg_log_pvals . max ( ) , <EOL> neg_log_pvals_bonferroni . max ( ) ) <EOL> fig = plt . figure ( figsize = ( <NUM_LIT:4> , <NUM_LIT> ) , facecolor = '<STR_LIT:k>' ) <EOL> display = plot_stat_map ( neg_log_pvals_bonferroni_unmasked , mean_fmri_img , <EOL> threshold = threshold , cmap = plt . cm . RdBu_r , <EOL> display_mode = '<STR_LIT:z>' , cut_coords = [ z_slice ] , <EOL> figure = fig , vmax = vmax ) <EOL> neg_log_pvals_bonferroni_data = neg_log_pvals_bonferroni_unmasked . get_data ( ) <EOL> neg_log_pvals_bonferroni_slice_data = neg_log_pvals_bonferroni_data [ ... , k_slice ] <EOL> n_detections = ( neg_log_pvals_bonferroni_slice_data > threshold ) . sum ( ) <EOL> title = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) % n_detections <EOL> display . title ( title , y = <NUM_LIT> ) <EOL> fig = plt . figure ( figsize = ( <NUM_LIT:4> , <NUM_LIT> ) , facecolor = '<STR_LIT:k>' ) <EOL> display = plot_stat_map ( signed_neg_log_pvals_unmasked , mean_fmri_img , <EOL> threshold = threshold , cmap = plt . cm . RdBu_r , <EOL> display_mode = '<STR_LIT:z>' , cut_coords = [ z_slice ] , <EOL> figure = fig , vmax = vmax ) <EOL> signed_neg_log_pvals_data = signed_neg_log_pvals_unmasked . get_data ( ) <EOL> signed_neg_log_pvals_slice_data = signed_neg_log_pvals_data [ ... , k_slice , <NUM_LIT:0> ] <EOL> n_detections = ( np . abs ( signed_neg_log_pvals_slice_data ) > threshold ) . sum ( ) <EOL> title = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) % n_detections <EOL> display . title ( title , y = <NUM_LIT> ) <EOL> show ( ) </s>
