Beispiel #1
0
                drift_model=drift_model, hfcut=hf_cut)

            # plot the design matrix
            ax = design_matrix.show()
            ax.set_position([.05, .25, .9, .65])
            ax.set_title('Design matrix')
            pylab.savefig(os.path.join(write_dir, 'design_matrix_%s.png') %\
                              session)
            # get the data
            if side == False:
                Y, _ = data_scaling(np.array([load(f).get_data()[mask_array]
                                              for f in fmri_data]))
                affine = load(fmri_data[0]).get_affine()
            else:
                Y, _ = data_scaling(np.array(
                        [load_texture(f) for f in fmri_data]))
                mask_array = np.var(Y, 0) > 0
                Y = Y[:, mask_array]

            # fit the glm
            print 'Fitting a GLM (this takes time)...'
            result = GeneralLinearModel(design_matrix.matrix)
            result.fit(Y, model='ar1', steps=100)

            for contrast_id, contrast_val in contrasts.iteritems():
                if (contrast_val[session] == 0).all():
                    continue

                if contrast_id in contrast_obj.keys():
                    contrast_obj[contrast_id] = contrast_obj[contrast_id] +\
                        result.contrast(contrast_val[session])
Beispiel #2
0
        right_fmri_tex = fmri_session[:-4] + '_rh.gii'
            
        # run freesrufer command

        commands.getoutput(
            '$FREESURFER_HOME/bin/mri_vol2surf --src %s --o %s '\
                '--out_type gii --regheader %s --hemi lh --projfrac 0.5'
            % (fmri_vol, left_fmri_tex, fs_dir))
        plop = commands.getoutput(
            '$FREESURFER_HOME/bin/mri_vol2surf --src %s --o %s '\
                '--out_type gii --regheader %s --hemi rh --projfrac 0.5'
            % (fmri_vol, right_fmri_tex, fs_dir))

# smooth the data
for subject in subject_info.keys(): 
    fmri_dir = os.path.join(main_dir, subject, 'fmri')
    fs_dir = os.path.join(main_dir, subject, 't1', subject)
    for session in subject_info[subject]['session_keys']:
        for hemi in ['left', 'right']:
            wild_card = '%sh.gii' % hemi[0]
            fmri_series = os.path.join(fmri_dir, '%s_series_%s_%s' %
                                       (subject, session, wild_card))
            tex = load_texture(fmri_series)
            smooth_tex = []
            output = fmri_series[:-4] + '_smooth5.gii'
            plop = commands.getoutput(
                'mri_surf2surf --srcsubject %s --cortex --fwhm %s '\
                    '--hemi %sh --sval %s --tval %s --s %s' % (
                        fs_dir, FWHM, hemi[0], fmri_series, output, fs_dir))
  
Beispiel #3
0
        if side == False:
            # in the volume, compute a mask o fthe brain
            mask_array = compute_mask_files(fmri_series[0], epi_mask, True,
                                            inf_threshold, sup_threshold)[0]
        
        for (sess, (session, fmri_data)) in enumerate(zip(
            sessions, fmri_series)):
             # get the data
            if side == False:
                Y, _ = data_scaling(np.array([load(f).get_data()[mask_array]
                                              for f in fmri_data]))
                affine = load(fmri_data[0]).get_affine()
            else:
                Y, _ = data_scaling(np.array(
                        [load_texture(f) for f in fmri_data]))
                mask_array = np.var(Y, 0) > 0
                Y = Y[:, mask_array]
                
            best_z, best_d = - np.ones(Y.shape[1]), - np.ones(Y.shape[1])
            
            # create design matrices
            for i_delay, delay in enumerate(
                np.linspace(0, 30, n_models + 1)[:-1]):
                paradigm = make_paradigm(
                    delay, duration=duration, length=length, 
                    odd=(subject in ['sujet10', 'sujet12']))
                design_matrix = make_dmtx(
                    frametimes, paradigm, drift_model=drift_model, hfcut=hf_cut)
                
                # plot the design matrix
left_pos, right_pos = [], []
for subject in paths.keys():
    print subject
    func_path = op.join(paths[subject]['base'], paths[subject]['acquisition'],
                        'analysis')
    # set all the paths
    ltex_path = op.join(func_path, 'left_phase_ring.gii')
    rtex_path = op.join(func_path, 'right_phase_ring.gii')

    for side in ['left', 'right']:
        #resample on tyhe average
        tex_path = ltex_path if side == 'left' else rtex_path
        resampled = resample_to_average(tex_path, paths[subject]['fs_subj'],
                                        side)
        # mask the values that are small enough
        rring = load_texture(resampled).ravel()
        mask = rring < rring.min() + 1.
        if side == 'left':
            left_pos.append(left_vertices[mask].mean(0))
        else:
            right_pos.append(right_vertices[mask].mean(0))

left_pos = np.array(left_pos)
right_pos = np.array(right_pos)
print left_pos.std(0), right_pos.std(0)

if True:
    left_fovea_, right_fovea_ = np.median(left_pos, 0), np.median(right_pos, 0)
else:
    left_fovea_, right_fovea_ = np.mean(left_pos, 0), np.mean(right_pos, 0)
        # the .gii files will be put in the same directory as the input fMRI
        left_fmri_tex = fmri_session[:-4] + "_lh.gii"
        right_fmri_tex = fmri_session[:-4] + "_rh.gii"

        # run freesrufer command

        commands.getoutput(
            "$FREESURFER_HOME/bin/mri_vol2surf --src %s --o %s "
            "--out_type gii --regheader %s --hemi lh --projfrac 0.5" % (fmri_vol, left_fmri_tex, fs_dir)
        )
        plop = commands.getoutput(
            "$FREESURFER_HOME/bin/mri_vol2surf --src %s --o %s "
            "--out_type gii --regheader %s --hemi rh --projfrac 0.5" % (fmri_vol, right_fmri_tex, fs_dir)
        )

# smooth the data
for subject in subject_info.keys():
    fmri_dir = os.path.join(main_dir, subject, "fmri")
    fs_dir = os.path.join(main_dir, subject, "t1", subject)
    for session in subject_info[subject]["session_keys"]:
        for hemi in ["left", "right"]:
            wild_card = "%sh.gii" % hemi[0]
            fmri_series = os.path.join(fmri_dir, "%s_series_%s_%s" % (subject, session, wild_card))
            tex = load_texture(fmri_series)
            smooth_tex = []
            output = fmri_series[:-4] + "_smooth5.gii"
            plop = commands.getoutput(
                "mri_surf2surf --srcsubject %s --cortex --fwhm %s "
                "--hemi %sh --sval %s --tval %s --s %s" % (fs_dir, FWHM, hemi[0], fmri_series, output, fs_dir)
            )
Beispiel #6
0
left_pos, right_pos = [], []
for subject in paths.keys():
    print subject
    func_path = op.join(paths[subject]['base'], paths[subject]['acquisition'],
                        'analysis')
    # set all the paths
    ltex_path = op.join(func_path, 'left_phase_ring.gii')
    rtex_path = op.join(func_path, 'right_phase_ring.gii')

    for side in ['left', 'right']:
        #resample on tyhe average
        tex_path = ltex_path if side == 'left' else rtex_path
        resampled = resample_to_average(tex_path, paths[subject]['fs_subj'],
                                        side)
        # mask the values that are small enough
        rring = load_texture(resampled).ravel()
        mask = rring < rring.min() + 1.
        if side == 'left':
            left_pos.append(left_vertices[mask].mean(0))
        else:
            right_pos.append(right_vertices[mask].mean(0))

left_pos = np.array(left_pos)
right_pos = np.array(right_pos)
print left_pos.std(0), right_pos.std(0)

if True:
    left_fovea_, right_fovea_ = np.median(left_pos, 0), np.median(right_pos, 0)
else:
    left_fovea_, right_fovea_ = np.mean(left_pos, 0), np.mean(right_pos, 0)