コード例 #1
0
def plot_maps(plot_params, anat_fn, anat_slice_def, fig_dir,
              orientation=['axial','sagittal'], crop_extension=None,
              plot_anat=True, plot_fontsize=25, fig_dpi=75):

    ldata = []
    for p in plot_params:
        c = xndarray.load(p['fn']).sub_cuboid(**p['slice_def'])
        c.set_orientation(orientation)
        ldata.append(c.data)

    c_anat = xndarray.load(anat_fn).sub_cuboid(**anat_slice_def)
    c_anat.set_orientation(orientation)

    resolution = c_anat.meta_data[1]['pixdim'][1:4]
    slice_resolution = resolution[MRI4Daxes.index(orientation[0])], \
      resolution[MRI4Daxes.index(orientation[1])]

    all_data = np.array(ldata)

    if 'prl' in plot_params[0]['fn']:
        norm = normalize(all_data.min(), all_data.max()*1.05)
        print 'norm:', (all_data.min(), all_data.max())
    else:
        norm = normalize(all_data.min(), all_data.max())

    print 'norm:', (all_data.min(), all_data.max())
    for data, plot_param in zip(all_data, plot_params):
        fn = plot_param['fn']
        plt.figure()
        print 'fn:', fn
        print '->', (data.min(), data.max())
        if plot_anat:
            anat_data = c_anat.data
        else:
            anat_data = None
        plot_func_slice(data, anatomy=anat_data,
                        parcellation=plot_param.get('mask'),
                        func_cmap=cmap,
                        parcels_line_width=1., func_norm=norm,
                        resolution=slice_resolution,
                        crop_extension=crop_extension)
        set_ticks_fontsize(plot_fontsize)

        fig_fn = op.join(fig_dir, '%s.png' %op.splitext(op.basename(fn))[0])
        output_fig_fn = plot_param.get('output_fig_fn', fig_fn)

        print 'Save to: %s' %output_fig_fn
        plt.savefig(output_fig_fn, dpi=fig_dpi)
        autocrop(output_fig_fn)
    return norm
コード例 #2
0
def plot_estimation_results(fig_dir, poi, jde_roi, cond, plot_label,
                            glm_fir_output_dir, rfir_output_dir,
                            jde_output_dir, ymin=-1.55, ymax=1.05,
                            plot_fontsize=25):


    ## HRF plots

    fn = op.join(glm_fir_output_dir, 'glm_fir_hrf.nii.gz')
    fir = xndarray.load(fn).sub_cuboid(condition=cond, **poi)
    #fir /= (fir**2).sum()**.5
    fir /= fir.max()

    fn = op.join(rfir_output_dir, 'rfir_ehrf.nii.gz')
    rfir = xndarray.load(fn).sub_cuboid(condition=cond, **poi)
    #rfir /= (rfir**2).sum()**.5
    rfir /= rfir.max()

    fn = op.join(jde_output_dir, 'jde_mcmc_hrf_pm.nii.gz')
    jde = xndarray.load(fn).sub_cuboid(ROI=jde_roi)
    jde /= jde.max()

    plt.figure()
    pargs = {'linewidth' : 2.7}
    plot_cub_as_curve(fir, show_axis_labels=False, plot_kwargs=pargs)
    plot_cub_as_curve(rfir, show_axis_labels=False, plot_kwargs=pargs)
    plot_cub_as_curve(jde, show_axis_labels=False, plot_kwargs=pargs)

    from pyhrf.boldsynth.hrf import getCanoHRF
    time_points, hcano = getCanoHRF()
    hcano /= hcano.max()
    plt.plot(time_points, hcano, 'k.-',linewidth=1.5)

    set_ticks_fontsize(plot_fontsize)
    plt.xlim(0,25)
    plt.ylim(ymin, ymax)

    plt.gca().xaxis.grid(True, 'major', linestyle='--', linewidth=1.2,
                         color='gray')

    hrf_fig_fn = op.join(fig_dir, 'real_data_hrfs_%s.png' %plot_label)
    print 'hrf_fig_fn:', hrf_fig_fn
    plt.savefig(hrf_fig_fn)
    autocrop(hrf_fig_fn)
コード例 #3
0
def plot_detection_results(fig_dir, poi, condition, coi, parcellation_file,
                           plot_label, jde_output_dir, glm_hcano_rs_output_dir,
                           fig_dpi=100):
    """
    coi (str): contrast of interest
    poi (dict): defines the point of interest for plots of HRFs and maps
    """
    if condition == 'audio':
        condition = 'phraseaudio'

    orientation = ['coronal',  'sagittal']
    axial_slice =  poi['axial']

    anat_file = get_data_file_name('real_data_vol_4_regions_anatomy.nii.gz')

    parcellation = xndarray.load(parcellation_file)
    parcellation = parcellation.sub_cuboid(axial=axial_slice)
    parcellation = parcellation.reorient(orientation)

    ## Detection maps
    detection_plots_params = []

    #JDE NRLs
    fn = op.join(jde_output_dir, 'jde_mcmc_nrl_pm.nii.gz')

    slice_def = {'axial':axial_slice, 'condition':condition}
    fig_fn = op.join(fig_dir, 'real_data_jde_mcmc_nrls_%s.png' %condition)
    detection_plots_params.append({'fn':fn, 'slice_def':slice_def,
                                   'mask': parcellation.data,
                                   'output_fig_fn':fig_fn})

    #GLM hcano
    fn = op.join(glm_hcano_rs_output_dir, 'glm_hcano_rs_beta_%s.nii.gz' %condition)

    slice_def = {'axial':axial_slice}

    fig_fn = op.join(fig_dir, 'real_data_glm_hcano_rs_%s.png'%condition)

    detection_plots_params.append({'fn':fn, 'slice_def':slice_def,
                                   'mask': (parcellation.data != 0),
                                   'output_fig_fn':fig_fn})


    perf_norm = plot_maps(detection_plots_params, anat_file,
                          {'axial':axial_slice*3},
                          fig_dir, orientation=orientation,
                          crop_extension=None, plot_anat=True)

    palette_fig_fn = op.join(fig_dir, 'real_data_detection_%s_palette.png' \
                             %condition)
    plot_palette(cmap, perf_norm, 45)
    plt.savefig(palette_fig_fn, dpi=fig_dpi)
    autocrop(palette_fig_fn)


    #JDE Contrast
    fn = op.join(jde_output_dir, 'jde_mcmc_nrl_contrasts.nii.gz')

    slice_def = {'axial':axial_slice, 'contrast':coi}
    fig_fn = op.join(fig_dir, 'real_data_jde_mcmc_con_%s.png' %coi)
    detection_plots_params.append({'fn':fn, 'slice_def':slice_def,
                                   'mask': parcellation.data,
                                   'output_fig_fn':fig_fn})

    #GLM hcano
    fn = op.join(glm_hcano_rs_output_dir, 'glm_hcano_rs_con_effect_%s.nii.gz'%coi)

    slice_def = {'axial':axial_slice}

    fig_fn = op.join(fig_dir, 'real_data_glm_hcano_rs_con_%s.png' %coi)

    detection_plots_params.append({'fn':fn, 'slice_def':slice_def,
                                   'mask': (parcellation.data != 0),
                                   'output_fig_fn':fig_fn})


    perf_norm = plot_maps(detection_plots_params, anat_file,
                          {'axial':axial_slice*3},
                          fig_dir, orientation=orientation,
                          crop_extension=None, plot_anat=True)

    palette_fig_fn = op.join(fig_dir, 'real_data_detection_con_%s_palette.png'
                             %coi)
    plot_palette(cmap, perf_norm, 45)
    plt.savefig(palette_fig_fn, dpi=fig_dpi)
    autocrop(palette_fig_fn)