Exemplo n.º 1
0
    tag_scans = range(0, n_scans, 2)
    perfusion_file = quantification.compute_perfusion(
        out_realign.outputs.realigned_files,
        ctl_scans=ctl_scans,
        tag_scans=tag_scans)

    # Compute CBF
    quantify = mem.cache(quantification.QuantifyCBF)
    out_quantify = quantify(
        perfusion_file=perfusion_file,
        m0_file=out_smooth_m0.outputs.smoothed_files,
        tr=2500.,
        t1_gm=1331.)

    # Compute brain mask
    brain_mask_file = preprocessing.compute_brain_mask(
        out_coregister_anat.outputs.coregistered_source, frac=.2)

    # Normalize CBF
    normalize = mem.cache(spm.Normalize)
    out_normalize = normalize(
        parameter_file=out_segment.outputs.transformation_mat,
        apply_to_files=[out_quantify.outputs.cbf_file,
                        brain_mask_file],
        write_voxel_sizes=_utils.get_voxel_dims(func_file),
        write_interp=2,
        jobtype='write')

    # Mask CBF map with brain mask
    cbf_map = preprocessing.apply_mask(
        out_normalize.outputs.normalized_files[0],
        out_normalize.outputs.normalized_files[1])
                                      durations=durations)
out_modelspec = modelspec.run()

# Generate an SPM design matrix
from procasl.first_level import Level1PerfusionDesign
from procasl.preprocessing import compute_brain_mask
spm_mat = os.path.join(os.getcwd(), 'SPM.mat')
if os.path.isfile(spm_mat):
    os.remove(spm_mat)  # design crashes if existant SPM.mat

level1design = Level1PerfusionDesign(bases={'hrf': {'derivs': [0, 0]}},
                                     perfusion_bases='bases',
                                     timing_units='secs',
                                     interscan_interval=tr,
                                     model_serial_correlations='AR(1)')
level1design.inputs.mask_image = compute_brain_mask(
    mean_func_file, frac=.2)  # Compute cut neck mask
level1design.inputs.session_info = out_modelspec.outputs.session_info
out_level1design = level1design.run()
os.chdir(current_directory)

# Read the design matrix
from scipy.io import loadmat
spm_mat_struct = loadmat(out_level1design.outputs.spm_mat_file,
                         struct_as_record=False, squeeze_me=True)['SPM']
design_matrix = spm_mat_struct.xX.X
regressor_names = spm_mat_struct.xX.name

# Plot the design matrix
import matplotlib.pyplot as plt
from nilearn.plotting import _set_mpl_backend  # set the backend
_set_mpl_backend
        functional_runs=func_file,
        subject_info=subject_info)

    # Generate an SPM design matrix
    spm_mat = os.path.join(cache_directory, 'SPM.mat')
    if os.path.isfile(spm_mat):
        os.remove(spm_mat)  # design crashes if existant SPM.mat

    level1design = mem.cache(Level1PerfusionDesign)
    out_level1design = level1design(
        bases={'hrf': {'derivs': [0, 0]}},
        perfusion_bases='bases',
        timing_units='secs',
        interscan_interval=tr,
        session_info=out_modelspec.outputs.session_info,
        mask_image=compute_brain_mask(mean_func_file, frac=.2))

    # Estimate the parameters of the model
    level1estimate = mem.cache(spm.EstimateModel)
    out_level1estimate = level1estimate(
        estimation_method={'Classical': 1},
        spm_mat_file=out_level1design.outputs.spm_mat_file)

    # Read regressors names
    spm_mat_struct = loadmat(out_level1design.outputs.spm_mat_file,
                             struct_as_record=False, squeeze_me=True)['SPM']
    regressor_names = spm_mat_struct.xX.name.tolist()

    # Specify contrasts
    cont01 = ('[BOLD] ' + conditions[0] + ' > ' + conditions[1], 'T',
              regressor_names,
Exemplo n.º 4
0
        out_realign.outputs.realigned_files)
    perfusion_file = quantification.compute_perfusion(
        out_realign.outputs.realigned_files,
        ctl_scans=range(1, n_scans, 2),
        tag_scans=range(0, n_scans, 2))

    # Compute CBF
    quantify = mem.cache(quantification.QuantifyCBF)
    out_quantify = quantify(
        perfusion_file=perfusion_file,
        m0_file=out_smooth_m0.outputs.smoothed_files,
        tr=2500.,
        t1_gm=1331.)

    # Compute brain mask
    brain_mask_file = preprocessing.compute_brain_mask(
        out_coregister_anat.outputs.coregistered_source, frac=.2)
    brain_mask_file = preprocessing.compute_brain_mask(
        out_average.outputs.mean_image, frac=.5)

    # Normalize CBF
    normalize = mem.cache(spm.Normalize)
    out_normalize = normalize(
        parameter_file=out_segment.outputs.transformation_mat,
        apply_to_files=[out_quantify.outputs.cbf_file,
                        brain_mask_file],
        write_voxel_sizes=_utils.get_voxel_dims(func_file),
        write_interp=2,
        jobtype='write')

    # Mask CBF map with brain mask
    cbf_map = preprocessing.apply_mask(
Exemplo n.º 5
0
ctl_scans = range(1, n_scans, 2)
tag_scans = range(0, n_scans, 2)
perfusion_file = quantification.compute_perfusion(
    out_realign.outputs.realigned_files,
    ctl_scans=ctl_scans,
    tag_scans=tag_scans)

# Compute CBF
quantify = mem.cache(quantification.QuantifyCBF)
out_quantify = quantify(perfusion_file=perfusion_file,
                        m0_file=out_smooth_m0.outputs.smoothed_files,
                        tr=2500.,
                        t1_gm=1331.)

# Mask CBF map with brain mask
brain_mask_file = preprocessing.compute_brain_mask(
    out_coregister_anat.outputs.coregistered_source, frac=.2)
cbf_map = preprocessing.apply_mask(out_quantify.outputs.cbf_file,
                                   brain_mask_file)

# Plot CBF map on top of anat
import matplotlib.pylab as plt
from nilearn import plotting
cut_coords = (
    -15,
    0,
    15,
    45,
    60,
    75,
)
min_cbf = 1.