def resample_to_average(tex_path, subject, side, verbose=False): """Resample a given texture to fsaverage Parameters ========== tex_path: string, path of the input texture subject: string, subject id in the freesurfer database side: string, on of ['left', 'right'] verbose: boolean, the verbosity mode Returns ======= resmapled: string, path of the result """ resampled = op.join(op.dirname(tex_path), op.basename(tex_path)[:-4] + '_resampled.gii') # convert the input to .mgz format mgz = tex_path[:-4] + '.mgz' tex = load_texture(tex_path)[np.newaxis, np.newaxis].T mghformat.save(Nifti1Image(tex, np.eye(4)), mgz) # run the resmapling using freesurfer tools fs_comment = commands.getoutput( 'mri_surf2surf --srcsubject %s --srcsurfval %s --trgsubject ico --trgsurfval %s --hemi %sh --trgicoorder 7' % ( subject, mgz, resampled, side[0])) if verbose: print fs_comment return resampled
def resample_to_subject(tex_path, subject, side, output_path, verbose=False): """Resample a given texture from fsaverage to subject space Parameters ========== tex_path: string, path of the input texture subject: string, subject id in the freesurfer database side: string, on of ['left', 'right'] outoput_path: string verbose: boolean, the verbosity mode """ # convert the input to .mgz format mgz = tex_path[:-4] + '.mgz' tex = load_texture(tex_path)[np.newaxis, np.newaxis].T mghformat.save(Nifti1Image(tex, np.eye(4)), mgz) fs_comment = commands.getoutput( 'mri_surf2surf --trgsubject %s --trgsurfval %s --srcsubject ico --srcsurfval %s --hemi %sh --srcicoorder 7' % ( subject, output_path, mgz, side[0])) if verbose: print fs_comment return output_path
'sin_wedge_neg', 'cos_wedge_neg', 'sin_wedge_pos', 'cos_wedge_pos' ] offset_ring, offset_wedge = np.pi, -np.pi / 2 do_phase_unwrapping = True do_plot = False for subject in subjects: print subject tex_dir = op.join(paths[subject]['base'], paths[subject]['acquisition'], 'analysis') for side in ['right', 'left']: # First compute a mask of the active regions, by thresholding the # so-called "average stat" map mesh = paths[subject]['%s_inflated' % side] mask = load_texture(op.join(tex_dir, side + '_mask.gii')) > 0 # Then, given the mask, extract the beta data from each subject data = dict([ (r, load_texture(op.join(tex_dir, '%s_%s_con.gii' % (side, r))).ravel()[mask]) for r in all_reg ]) # Compute the phase value of the data phase_wedge, phase_ring, hemo = phase_maps( data, offset_ring, offset_wedge, do_ring=True,
all_reg = ['sin_ring_pos', 'cos_ring_pos', 'sin_ring_neg', 'cos_ring_neg', 'sin_wedge_neg', 'cos_wedge_neg', 'sin_wedge_pos', 'cos_wedge_pos'] offset_ring, offset_wedge = np.pi, - np.pi / 2 do_phase_unwrapping = True do_plot = False for subject in subjects: print subject tex_dir = op.join(paths[subject]['base'], paths[subject]['acquisition'], 'analysis') for side in ['right', 'left']: # First compute a mask of the active regions, by thresholding the # so-called "average stat" map mesh = paths[subject]['%s_inflated' % side] mask = load_texture(op.join(tex_dir, side + '_mask.gii')) > 0 # Then, given the mask, extract the beta data from each subject data = dict([ (r, load_texture( op.join(tex_dir, '%s_%s_con.gii' % (side, r))).ravel() [mask]) for r in all_reg]) # Compute the phase value of the data phase_wedge, phase_ring, hemo = phase_maps( data, offset_ring, offset_wedge, do_ring=True, do_wedge=True, do_phase_unwrapping=do_phase_unwrapping, mesh=mesh, mask=mask) # get planar coordinates on the surface planar_coord = isomap_patch(mesh, mask) # template-based visual area delineation
do_phase_unwrapping = True for side in ['left', 'right']: # First compute a mask of the active regions, by thresholding the # so-called "average stat" map avg_stat = None mesh = op.join(op.dirname(paths[subjects[0]]['base']), 'fsaverage', '%sh.inflated.gii' % side[0]) for subject in subjects: tex_dir = op.join(paths[subject]['base'], paths[subject]['acquisition'], 'analysis') stat_map = op.join(tex_dir, '%s_effects_of_interest_z_map.gii' % side) r_stat_map = resample_to_average(stat_map, subject, side) if avg_stat == None: avg_stat = load_texture(r_stat_map) else: avg_stat += load_texture(r_stat_map) mask = avg_stat / np.sqrt(len(subjects)) > threshold mask = main_cc(mesh, mask) # Then, given the mask, extract the beta data from each subject data = dict([ (r, []) for r in all_reg]) for subject in subjects: tex_dir = op.join(paths[subject]['base'], paths[subject]['acquisition'], 'analysis') for r in all_reg: contrast_file = op.join(tex_dir, '%s_%s_con.gii' % (side, r)) r_cfile = resample_to_average(contrast_file, subject, side) datar = load_texture(r_cfile)[mask] data[r].append(datar)