<jupyter_start><jupyter_text>Plot frontoparietal networks<jupyter_code>hemi = 'lh'
subid='fsaverage'
brain = Brain(subid, hemi, "semi7", background='white', size=(800,800), cortex=("gray", -2, 7, True))

brain.add_label('frontoparietal', hemi=hemi, color=(204./255, 121./255, 167./255), alpha = 0.7)
brain.add_label('frontoparietal', hemi=hemi, color=(204./255, 121./255, 167./255), borders=True)

brain.add_label('dorsalattn', hemi=hemi, color=(0./255, 158./255, 115./255), alpha = 0.7)
brain.add_label('dorsalattn', hemi=hemi, color=(0./255, 158./255, 115./255), borders=True)

brain.save_imageset('/Users/steph-backup/Dropbox/Stanford/Papers/Dissertation/Figures_defense/AP_frontoparietal_{hemi}_colorblind'.format(hemi=hemi), 
                    ['lat'], filetype='tiff')
hemi = 'lh'
subid='fsaverage'
brain = Brain(subid, hemi, "semi7", background='white', size=(800,800), cortex='low_contrast')
brain.add_label('frontoparietal', hemi=hemi, color=(112./255, 201./255, 231./255), alpha = 0.7)
brain.add_label('frontoparietal', hemi=hemi, color=(112./255, 201./255, 231./255), borders=True)

brain.add_label('dorsalattn', hemi=hemi, color=(202./255, 152./255, 235./255), alpha = 0.7)
brain.add_label('dorsalattn', hemi=hemi, color=(202./255, 152./255, 235./255), borders=True)

brain.save_imageset('/Users/steph-backup/Dropbox/Stanford/Papers/Dissertation/Figures_defense/AP_frontoparietal_{hemi}'.format(hemi=hemi), 
                    ['lat', 'fro'], filetype='tiff')<jupyter_output><empty_output><jupyter_text>localizer coefficients on example brain  Just mask:<jupyter_code>subid = 'ap164'

place_coefs = '/Volumes/group/awagner/sgagnon/AP/analysis/mvpa_raw/'+subid+'/importance_maps/bilat-parahipp_fusi_inftemp_nohipp_coef_place.nii.gz'
mask = '/Volumes/group/awagner/sgagnon/AP/data/'+subid+'/masks/bilat-parahipp_fusi_inftemp_nohipp.nii.gz'

for hemi in ['lh', 'rh']:
    
    brain = Brain(subid, hemi, "inflated", background='white', size=(850,800))

    maskmap = project_volume_data(mask, hemi, subject_id=subid, smooth_fwhm=0).astype(bool)
    
    maskmap = ~maskmap
    brain.add_data(maskmap, min=0, max=10, thresh=.5, hemi=hemi,
                   colormap="bone", alpha=.6, colorbar=False)
    
    brain.show_view("ven")
    
    brain.save_imageset('/Users/steph-backup/Dropbox/Stanford/Papers/Dissertation/Figures/AP_VTCmask_{hemi}_ap164'.format(hemi=hemi), 
                        ['ven'], filetype='tiff')
    brain.save_imageset('/Volumes/group/awagner/sgagnon/AP/results/AP_VTCmask_{hemi}_ap164'.format(hemi=hemi), 
                        ['ven'], filetype='tiff')
brain.show_vi
brain.show_view({'distance': 600}, roll=0)
brain.show_view({'azimuth': -177, 'elevation': 88}, roll=91)
brain.save_image('/Volumes/group/awagner/sgagnon/AP/results/AP_VTCmask_ap164_')
brain.show_view()
subid = 'ap164'

place_coefs = '/Volumes/group/awagner/sgagnon/AP/analysis/mvpa_raw/'+subid+'/importance_maps/bilat-parahipp_fusi_inftemp_nohipp_coef_place.nii.gz'
mask = '/Volumes/group/awagner/sgagnon/AP/data/'+subid+'/masks/bilat-parahipp_fusi_inftemp_nohipp.nii.gz'

for hemi in ['lh', 'rh']:
    
    brain = Brain(subid, hemi, "inflated", background='white', size=(850,800))

    coefmap = project_volume_data(place_coefs, hemi, subject_id=subid, smooth_fwhm=0)
    maskmap = project_volume_data(mask, hemi, subject_id=subid, smooth_fwhm=0).astype(bool)
    
    brain.add_data(coefmap, min=-0.09, max=0.09, colormap="PiYG", hemi=hemi, alpha=.8, colorbar=True)
    
    maskmap = ~maskmap
    brain.add_data(maskmap, min=0, max=10, thresh=.5, hemi=hemi,
                   colormap="bone", alpha=.6, colorbar=False)
    
    brain.show_view("ven")
    
    brain.save_imageset('/Users/steph-backup/Dropbox/Stanford/Papers/Dissertation/Figures/AP_localizercoef_green_cmap_{hemi}_ap164'.format(hemi=hemi), 
                        ['ven'], filetype='tiff')
subid = 'ap164'

place_coefs = '/Volumes/group/awagner/sgagnon/AP/analysis/mvpa_raw/'+subid+'/importance_maps/bilat-parahipp_fusi_inftemp_nohipp_coef_place.nii.gz'
mask = '/Volumes/group/awagner/sgagnon/AP/data/'+subid+'/masks/bilat-parahipp_fusi_inftemp_nohipp.nii.gz'

for hemi in ['lh', 'rh']:
    
    brain = Brain(subid, hemi, "inflated", background='white', size=(850,800))

    coefmap = project_volume_data(place_coefs, hemi, subject_id=subid, smooth_fwhm=0)
    maskmap = project_volume_data(mask, hemi, subject_id=subid, smooth_fwhm=0).astype(bool)
    
    brain.add_data(coefmap, min = 0, thresh=0.000000000000000000000000001, colormap="Greens", hemi=hemi, alpha=.8, colorbar=False)
    brain.add_data(-coefmap, min = 0, thresh=0.000000000000000000000000001, colormap="PuRd", hemi=hemi, alpha=.8, colorbar=False)
    
    maskmap = ~maskmap
    brain.add_data(maskmap, min=0, max=10, thresh=.5, hemi=hemi,
                   colormap="bone", alpha=.6, colorbar=False)
    
    brain.show_view("ven")
    
    brain.save_imageset('/Users/steph-backup/Dropbox/Stanford/Papers/Dissertation/Figures/AP_localizercoef_{hemi}_ap164'.format(hemi=hemi), 
                        ['ven'], filetype='tiff')<jupyter_output>mri_vol2surf --mov /Volumes/group/awagner/sgagnon/AP/analysis/mvpa_raw/ap164/importance_maps/bilat-parahipp_fusi_inftemp_nohipp_coef_place.nii.gz --hemi lh --surf white --regheader ap164 --projfrac-avg 0 1 0.1 --o /var/folders/xp/71y4c8j51293syxqsgb7qsz40000gp/T/pysurfer-v2siN90PX.mgz<jupyter_text>Sphere from SH > CR by group:<jupyter_code>z_thresh = .5
stat_map = op.join('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group_control-stress/mni/sourcehit-cr/zstat1_peak1_5mm_sphere_masked.nii.gz')
                   
fig = plt.figure(dpi=600, figsize=(10,5))
display = nip.plot_stat_map(stat_map, bg_img=mni_template,
                  threshold=z_thresh, 
                  black_bg=False, 
                  cut_coords=[22,-36, -2], draw_cross=False,
                  cmap='PuBu', colorbar=False, annotate=False, figure=fig)
display.annotate(size=20)
fig.savefig('/Users/steph-backup/Dropbox/Stanford/Papers/Dissertation/Figures/DPI150_jpg/AP_sphere_sh-cr_ctrl-str.jpeg', dpi=150)<jupyter_output><empty_output><jupyter_text>Assoc hit > CR  Group interaction (p < 0.05, corrected):<jupyter_code>exp = 'ap_memory_raw'
group = 'group_control-stress'
contrast = 'sourcehit-cr'
z_thresh = 2.3
stat_map = op.join('/Volumes/group/awagner/sgagnon/AP/analysis',
                   exp, group, 'mni', contrast, 'zstat1_threshold.nii.gz')
                   
    
fig = plt.figure(dpi=600, figsize=(10,5))
display = nip.plot_stat_map(stat_map, bg_img=mni_template,
                  threshold=z_thresh, display_mode='yx', 
                  black_bg=False, 
                  cut_coords=[28, -34], 
                  cmap='PuBu', colorbar=True, annotate=True, figure=fig)
display.annotate(size=20)
fig.savefig('/Volumes/group/awagner/sgagnon/AP/results/ap_memory_raw_control-stress_sourcehit-cr.png')
exp = 'ap_memory_raw'
group = 'group_control-stress'
contrast = 'sourcehit-cr'
z_thresh = 2.3
stat_map = op.join('/Volumes/group/awagner/sgagnon/AP/analysis',
                   exp, group, 'mni', contrast, 'zstat1_threshold.nii.gz')
                   
    
fig = plt.figure(dpi=600, figsize=(10,5))
display = nip.plot_stat_map(stat_map, bg_img=mni_template,
                  threshold=z_thresh, display_mode='yx', 
                  black_bg=False, 
                  cut_coords=[28, -34],  draw_cross=False,
                  cmap='PuBu', colorbar=True, annotate=False, figure=fig)
fig.savefig('/Volumes/group/awagner/sgagnon/AP/results/ap_memory_raw_control-stress_sourcehit-cr_nocrossbar.png')
exp = 'ap_memory_raw'
group = 'group_control-stress'
contrast = 'sourcehit-cr'
z_thresh = 2.58
stat_map = op.join('/Volumes/group/awagner/sgagnon/AP/analysis',
                   exp, group, 'mni', contrast, 'zstat1.nii.gz')
                   
    
fig = plt.figure(dpi=600, figsize=(10,5))
display= nip.plot_stat_map(stat_map, bg_img=mni_template,
                  threshold=z_thresh, display_mode='yz', 
                  black_bg=False, 
                  cut_coords=[52, 20], 
                  cmap='PuBu', colorbar=True, annotate=True, figure=fig)
display.annotate(size=20)

fig.savefig('/Volumes/group/awagner/sgagnon/AP/results/ap_memory_raw_control-stress_sourcehit-cr_fpc_p005uncorr.tiff')<jupyter_output><empty_output><jupyter_text>Conjunction<jupyter_code>subj = 'fsaverage'
hemis = ['lh', 'rh']
exp = ['ap_memory_raw']
z_thresh = 2.3 # p < 0.01
contrast = 'sourcehit-CR'
colors = ['Blues_r', 'Oranges_r']

for hemi in hemis:
    plot_groups(subj, hemi, exp, contrast, colors, z_thresh, 
               '/Volumes/group/awagner/sgagnon/AP/results/controlstress_conj_sourcehit-CR/map_nocontour_{hemi}_p05corr.png'.format(hemi=hemi), 
                save_views =['lat', 'med', 'fro'],
                alpha=.8,
               save_file=True, colorbar=True,
               base_exp='/Volumes/group/awagner/sgagnon/AP',
               sig_to_z=False, regspace='mni',
               corrected=True,
               plot_conjunction=True,
               add_border=False)
# add contour for interaction
subj = 'fsaverage'
hemis = ['lh', 'rh']
exp = ['ap_memory_raw']
z_thresh = 2.3 # p < 0.01
contrast = 'sourcehit-CR'
colors = ['Blues_r', 'Oranges_r']

for hemi in hemis:
    plot_groups(subj, hemi, exp, contrast, colors, z_thresh, 
               '/Volumes/group/awagner/sgagnon/AP/results/controlstress_conj_sourcehit-CR/map_{hemi}_p05corr.png'.format(hemi=hemi), 
                save_views =['lat', 'med', 'fro'],
                alpha=.8,
               save_file=True,
               base_exp='/Volumes/group/awagner/sgagnon/AP',
               sig_to_z=False, regspace='mni',
               corrected=True,
               plot_conjunction=True,
               add_border='/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group_control-stress/mni/sourcehit-cr/zstat1_threshold.nii.gz',
               border_max=True)
subj = 'fsaverage'
hemis = ['lh', 'rh']
exp = ['ap_memory_raw']
z_thresh = 2.3 # p < 0.01
contrasts = ['sourcehit-CR']
colors = ['Reds_r']
alpha = 1
snap_views = ['lat', 'med']
plot_conjunction=False

for hemi in hemis:
    b, snapshots = plot_contrasts(subj, hemi, exp, contrasts, colors, z_thresh, '', 
                                  base_exp='/Volumes/group/awagner/sgagnon/AP',
                                  group='group_control',
                                  snap_views=snap_views, sig_to_z=False, regspace='mni',
                                  corrected=True,
                                  save_file=False, plot_conjunction=plot_conjunction)

    plot_snapviews(snapshots, snap_views, hemi=hemi)<jupyter_output>ap_memory_raw sourcehit-CR
mri_vol2surf --mov /Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group_control/mni/sourcehit-CR/zstat1_threshold.nii.gz --hemi lh --surf white --reg /Applications/freesurfer/average/mni152.register.dat --projfrac-avg 0 1 0.1 --surf-fwhm 5 --o /var/folders/xp/71y4c8j51293syxqsgb7qsz40000gp/T/pysurfer-v2sDtWjvf.mgz<jupyter_text>Uncorrected p  stress (assoc hit > CR)<jupyter_code>subj = 'fsaverage'
hemis = ['lh', 'rh']
exp = ['ap_memory_raw']
z_thresh = 2.58 # p < 0.005
contrasts = ['sourcehit-CR']
colors = ['Blues_r']

for hemi in hemis:
    plot_contrasts(subj, hemi, exp, contrasts, colors, z_thresh, 
                  '/Volumes/group/awagner/sgagnon/AP/results/control-stress_sourcehit-CR/map_{hemi}_p005uncorr.png'.format(hemi=hemi), 
                  save_views =['lat', 'med', 'fro'], 
                  base_exp='/Volumes/group/awagner/sgagnon/AP',
                  alpha = 0.8,
                  group='group_control-stress',
                  colorbar=True,
                  sig_to_z=False, regspace='mni',
                  corrected=False)
# Visualize overlaid with Yeo CCN network (maroon / left lateral IPS)
b, snapshots =  plot_contrasts(subj, 'lh', exp, contrasts, colors, z_thresh, '', 
                                  base_exp='/Volumes/group/awagner/sgagnon/AP',
                                  group='group_control-stress',
                                  snap_views=snap_views, sig_to_z=False, regspace='mni',
                                  corrected=False,
                                  save_file=False, plot_conjunction=plot_conjunction)

b.add_label('17Networks_13', borders=True, color='maroon')<jupyter_output>ap_memory_raw sourcehit-CR
mri_vol2surf --mov /Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group_control-stress/mni/sourcehit-CR/zstat1.nii.gz --hemi lh --surf white --reg /Applications/freesurfer/average/mni152.register.dat --projfrac-avg 0 1 0.1 --surf-fwhm 5 --o /var/folders/xp/71y4c8j51293syxqsgb7qsz40000gp/T/pysurfer-v2sz2jmkp.mgz<jupyter_text>Uncorrected p  stress (assoc hit > CR)<jupyter_code>subj = 'fsaverage'
hemis = ['lh', 'rh']
exp = ['ap_memory_raw-byshockCond']
z_thresh = 2.5758 # p < 0.005
contrasts = ['safe_sourcehit-CR']
colors = ['Reds_r']
alpha = 1
snap_views = ['fro', 'lat']
plot_conjunction=False

for hemi in hemis:
    b, snapshots = plot_contrasts(subj, hemi, exp, contrasts, colors, z_thresh, '', 
                                  base_exp='/Volumes/group/awagner/sgagnon/AP',
                                  group='group_control-stress',
                                  snap_views=snap_views, sig_to_z=False, regspace='mni',
                                  corrected=False,
                                  save_file=False, plot_conjunction=plot_conjunction)

    plot_snapviews(snapshots, snap_views, hemi=hemi)<jupyter_output>ap_memory_raw-byshockCond safe_sourcehit-CR
mri_vol2surf --mov /Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw-byshockCond/group_control-stress/mni/safe_sourcehit-CR/zstat1.nii.gz --hemi lh --surf white --reg /Applications/freesurfer/average/mni152.register.dat --projfrac-avg 0 1 0.1 --surf-fwhm 5 --o /var/folders/xp/71y4c8j51293syxqsgb7qsz40000gp/T/pysurfer-v2saA615K.mgz<jupyter_text>By source accuracy<jupyter_code>subj = 'fsaverage'
hemis = ['lh', 'rh']
exp = ['ap_memory_raw']
z_thresh = 2.3 # p < 0.01
contrasts = ['sourcehit-cr']
colors = ['PuBu_r']
alpha = 1
save_views = ['lat', 'med', 'fro']
plot_conjunction=False

# os.mkdir('/Volumes/group/awagner/sgagnon/AP/results/cov_sourceAcc_sh-cr')

for hemi in hemis:
    plot_contrasts(subj, hemi, exp, contrasts, colors, z_thresh, 
                   '/Volumes/group/awagner/sgagnon/AP/results/cov_sourceAcc_sh-cr/map_{hemi}_p05corr.png'.format(hemi=hemi),  
                  base_exp='/Volumes/group/awagner/sgagnon/AP',
                  group='group_cov_sourceAcc',
                  sig_to_z=False, 
                  alpha=.9,
                  regspace='mni',
                  save_views=save_views,
                  skip_reg_dir=False,
                  corrected=True, colorbar=True,
                  save_file=True, plot_conjunction=plot_conjunction)
exp = 'ap_memory_raw'
group = 'group_cov_sourceAcc'
contrast = 'sourcehit-cr'
z_thresh = 2.3
stat_map = op.join('/Volumes/group/awagner/sgagnon/AP/analysis',
                   exp, group, 'mni', contrast, 'zstat1_threshold.nii.gz')
                   
    
fig = plt.figure(dpi=600, figsize=(15,5))
display = nip.plot_stat_map(stat_map, bg_img=mni_template,
                  threshold=z_thresh, display_mode='ortho', 
                  black_bg=False, 
                  cut_coords=[24, -36, -8], 
                  cmap='PuBu', colorbar=True, annotate=True, figure=fig)
display.annotate(size=20)
fig.savefig('/Volumes/group/awagner/sgagnon/AP/results/ap_memory_raw_covSourceAcc_sourcehit-cr.png')<jupyter_output><empty_output><jupyter_text>Plot searchlight localizer<jupyter_code>subj = 'fsaverage'
mask_file = '/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group_control-stress/mni/sourcehit-cr/{hemi}.group_mask.mgz'
stat_temp = '/Volumes/group/awagner/sgagnon/AP/analysis/mvpa_raw/searchlight/localizer_acc_t_tstat1_mask_p05corr.nii.gz'
sign = 'pos'
save_name = '/Volumes/group/awagner/sgagnon/AP/results/searchlight_localizer/{hemi}_localizer'
# os.mkdir('/Volumes/group/awagner/sgagnon/AP/results/searchlight_localizer')
z_thresh = 1.7

for hemi in ['lh', 'rh']:
    b = Brain(subj, hemi, 'semi7', background="white")
    add_mask_overlay(b, mask_file.format(hemi=hemi))

    z_max = calculate_sat_point(stat_temp, '', sign, subj=subj, sig_to_z=False)

    add_stat_overlay(b, stat_temp, z_thresh, z_max, sign,
                     hemi=hemi, sig_to_z=False, color='Greens_r', alpha=.9, 
                     output=True, colorbar=True)

    b.save_imageset(save_name.format(hemi=hemi), ['lat', 'fro', 'med', 'ven'])<jupyter_output>mri_vol2surf --mov /Volumes/group/awagner/sgagnon/AP/analysis/mvpa_raw/searchlight/localizer_acc_t_tstat1_mask_p05corr.nii.gz --hemi lh --surf white --reg /Applications/freesurfer/average/mni152.register.dat --projfrac-avg 0 1 0.1 --surf-fwhm 5 --o /var/folders/xp/71y4c8j51293syxqsgb7qsz40000gp/T/pysurfer-v2sc3AKTx.mgz<jupyter_text>Plot searchlight reinstatement<jupyter_code>subj = 'fsaverage'
mask_file = '/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group_control-stress/mni/sourcehit-cr/{hemi}.group_mask.mgz'
stat_temp = '/Volumes/group/awagner/sgagnon/AP/analysis/mvpa_raw/searchlight_test/sourcehit_time{time}_acc_t_tstat1_mask_p05corr.nii.gz'
sign = 'pos'
save_name = '/Volumes/group/awagner/sgagnon/AP/results/searchlight_test/{hemi}_test_{time}'
# os.mkdir('/Volumes/group/awagner/sgagnon/AP/results/searchlight_test')
z_thresh = 1.7

for time in [0,2,4,6,8,10,12]:
    for hemi in ['lh', 'rh']:
        b = Brain(subj, hemi, 'semi7', background="white")
        add_mask_overlay(b, mask_file.format(hemi=hemi))

        add_stat_overlay(b, stat_temp.format(time=str(time)), z_thresh, 10, sign,
                         hemi=hemi, sig_to_z=False, color='Greens_r', alpha=.9, 
                         output=True, colorbar=True)

        b.save_imageset(save_name.format(hemi=hemi, time=str(time)), ['lat', 'fro', 'med', 'ven'])<jupyter_output>mri_vol2surf --mov /Volumes/group/awagner/sgagnon/AP/analysis/mvpa_raw/searchlight_test/sourcehit_time0_acc_t_tstat1_mask_p05corr.nii.gz --hemi lh --surf white --reg /Applications/freesurfer/average/mni152.register.dat --projfrac-avg 0 1 0.1 --surf-fwhm 5 --o /var/folders/xp/71y4c8j51293syxqsgb7qsz40000gp/T/pysurfer-<KEY>
{'fraction_non_alphanumeric': 0.14323129808479293, 'fraction_numerical': 0.03513941179680253, 'mean_word_length': 3.362770768864556, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 15, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '511414', 'license': 'Unlicense', 'n_tokens_mistral': 7527, 'n_tokens_neox': 6828, 'n_words': 891, 'path': 'SNI/scripts/notebooks/AP Manuscript Figures.ipynb', 'repo_name': 'sgagnon/Gagnon_CerebralCortex_2018', 'size': '18335'}