Functional Preprocessing

Ingress

CPAC.func_preproc.func_ingress.connect_func_ingress(workflow, strat_list, c, sub_dict, subject_id, input_creds_path, unique_id=None)[source]

Motion

Functions for calculating motion parameters.

NodeBlockFunction: calc_motion_stats

CPAC.func_preproc.func_motion.calc_motion_stats(wf, cfg, strat_pool, pipe_num, opt=None)[source]

Calculate motion statistics for motion parameters.

Parameters:
Returns:

CPAC.func_preproc.func_motion.estimate_reference_image(in_file)[source]

fMRIPrep-style BOLD reference.

Generate a reference 3D map from BOLD and SBRef EPI images for BOLD datasets.

Given a 4D BOLD file[…], estimate a reference image for subsequent motion estimation and coregistration steps. For the case of BOLD datasets, it estimates a number of T1w saturated volumes (non-steady state at the beginning of the scan) and calculates the median across them. Otherwise (SBRefs or detected zero non-steady state frames), a median of of a subset of motion corrected volumes is used.

Ref: https://github.com/nipreps/niworkflows/blob/6d4f2b5/niworkflows/interfaces/registration.py#L446-L549

NodeBlockFunction: motion_correction

CPAC.func_preproc.func_motion.func_motion_correct(wf, cfg, strat_pool, pipe_num, opt=None)[source]
Parameters:
Returns:

NodeBlockFunction: motion_correction_only

CPAC.func_preproc.func_motion.func_motion_correct_only(wf, cfg, strat_pool, pipe_num, opt=None)[source]
Parameters:
Returns:

NodeBlockFunction: motion_estimates

CPAC.func_preproc.func_motion.func_motion_estimates(wf, cfg, strat_pool, pipe_num, opt=None)[source]

Calculate motion estimates using 3dVolReg or MCFLIRT.

Parameters:
Returns:

CPAC.func_preproc.func_motion.get_mcflirt_rms_abs(rms_files)[source]

NodeBlockFunction: get_motion_ref

CPAC.func_preproc.func_motion.get_motion_ref(wf, cfg, strat_pool, pipe_num, opt=None)[source]
Parameters:
Returns:

CPAC.func_preproc.func_motion.motion_correct_3dvolreg(wf, cfg, strat_pool, pipe_num)[source]

Calculate motion parameters with 3dvolreg.

CPAC.func_preproc.func_motion.motion_correct_connections(wf, cfg, strat_pool, pipe_num, opt)[source]

Check opt for valid option, then connect that option.

CPAC.func_preproc.func_motion.motion_correct_mcflirt(wf, cfg, strat_pool, pipe_num)[source]

Calculate motion parameters with MCFLIRT.

NodeBlockFunction: motion_estimate_filter

CPAC.func_preproc.func_motion.motion_estimate_filter(wf, cfg, strat_pool, pipe_num, opt=None)[source]

Filter motion parameters.

Changed in version 1.8.6: Beginning with version 1.8.6, C-PAC outputs both the unfiltered and the filtered motion parameters and uses the unfiltered parameters in QC. Previous versions only reported the filtered parameters and used the filtered parameters for QC.

Parameters:
Returns:

CPAC.func_preproc.func_motion.normalize_motion_parameters(in_file)[source]

Convert FSL mcflirt motion parameters to AFNI space.

Preprocessing

Functional preprocessing.

CPAC.func_preproc.func_preproc.anat_based_mask(wf_name='bold_mask')[source]

Generate a functional mask from anatomical data.

Reference DCAN lab BOLD mask.

CPAC.func_preproc.func_preproc.anat_refined_mask(init_bold_mask=True, wf_name='init_bold_mask')[source]

Generate an anatomically refined mask.

NodeBlockFunction: bold_mask_afni

CPAC.func_preproc.func_preproc.bold_mask_afni(wf, cfg, strat_pool, pipe_num, opt=None)[source]

Generate a functional mask with AFNI.

Parameters:
Returns:

NodeBlockFunction: bold_mask_anatomical_based

CPAC.func_preproc.func_preproc.bold_mask_anatomical_based(wf, cfg, strat_pool, pipe_num, opt=None)[source]

Generate the BOLD mask by basing it off of the anatomical brain mask.

Parameters:
Returns:

NodeBlockFunction: bold_mask_anatomical_refined

CPAC.func_preproc.func_preproc.bold_mask_anatomical_refined(wf, cfg, strat_pool, pipe_num, opt=None)[source]

Generate the BOLD mask by basing it off of the refined anatomical brain mask.

Parameters:
Returns:

NodeBlockFunction: bold_mask_anatomical_resampled

CPAC.func_preproc.func_preproc.bold_mask_anatomical_resampled(wf, cfg, strat_pool, pipe_num, opt=None)[source]

Resample anatomical brain mask to get BOLD brain mask in standard space.

Parameters:
Returns:

NodeBlockFunction: bold_mask_ccs

CPAC.func_preproc.func_preproc.bold_mask_ccs(wf, cfg, strat_pool, pipe_num, opt=None)[source]

Generate the BOLD mask by basing it off of the anatomical brain.

Parameters:
Returns:

NodeBlockFunction: bold_mask_fsl

CPAC.func_preproc.func_preproc.bold_mask_fsl(wf, cfg, strat_pool, pipe_num, opt=None)[source]

Generate functional mask with FSL.

Parameters:
Returns:

NodeBlockFunction: bold_mask_fsl_afni

CPAC.func_preproc.func_preproc.bold_mask_fsl_afni(wf, cfg, strat_pool, pipe_num, opt=None)[source]

fMRIPrep-style BOLD mask.

Enhance and run brain extraction on a BOLD EPI image.

This workflow takes in a BOLD fMRI average/summary (e.g., a reference image averaging non-steady-state timepoints), and sharpens the histogram with the application of the N4 algorithm for removing the INU bias field and calculates a signal mask.

Steps of this workflow are:

[1]. Binary dilation of the tentative mask with a sphere of 3mm diameter. [2]. Run ANTs’ N4BiasFieldCorrection on the input

BOLD average, using the mask generated in 1) instead of the internal Otsu thresholding.

[3]. Calculate a loose mask using FSL’s bet, with one mathematical morphology

dilation of one iteration and a sphere of 6mm as structuring element.

[4]. Mask the INU-corrected image

with the latest mask calculated in 3), then use AFNI’s 3dUnifize to standardize the T2* contrast distribution.

[5]. Calculate a mask using AFNI’s 3dAutomask after the contrast

enhancement of 4).

[6]. Calculate a final mask as the intersection of 4) and 6). [7]. Apply final mask on the enhanced reference.

Ref.

Parameters:
Returns:

NodeBlockFunction: bold_masking

CPAC.func_preproc.func_preproc.bold_masking(wf, cfg, strat_pool, pipe_num, opt=None)[source]

Generate a functional brain mask.

Parameters:
Returns:

CPAC.func_preproc.func_preproc.collect_arguments(*args)[source]

Collect arguments.

CPAC.func_preproc.func_preproc.create_scale_func_wf(scaling_factor, wf_name='scale_func')[source]

Workflow to scale func data.

Workflow Inputs::
inputspec.funcfunc file or a list of func/rest nifti file

User input functional(T2*) Image

Workflow Outputs::
outputspec.scaled_funcstr (nifti file)

Path to Output image with scaled data

Order of commands: - Scale the size of the dataset voxels by the factor ‘fac’. For details see 3dcalc:

3drefit -xyzscale fac rest.nii.gz
Parameters:
  • scaling_factor (float) – Scale the size of the dataset voxels by the factor.

  • wf_name (str) – name of the workflow

CPAC.func_preproc.func_preproc.create_wf_edit_func(wf_name='edit_func')[source]

Workflow to edit the scan to the proscribed TRs.

Workflow Inputs:

inputspec.func : func file or a list of func/rest nifti file
    User input functional(T2*) Image

inputspec.start_idx : str
    Starting volume/slice of the functional image (optional)

inputspec.stop_idx : str
    Last volume/slice of the functional image (optional)

Workflow Outputs:

outputspec.edited_func : str (nifti file)
    Path to Output image with the initial few slices dropped

Order of commands:

  • Get the start and the end volume index of the functional run. If not defined by the user, return the first and last volume.

    get_idx(in_files, stop_idx, start_idx)

  • Dropping the initial TRs. For details see 3dcalc:

    3dcalc -a rest.nii.gz[4..299]
           -expr 'a'
           -prefix rest_3dc.nii.gz
    

NodeBlockFunction: func_despike

CPAC.func_preproc.func_preproc.func_despike(wf, cfg, strat_pool, pipe_num, opt=None)[source]

Generate de-spiked functional timeseries in native space with AFNI.

Parameters:
Returns:

NodeBlockFunction: func_despike_template

CPAC.func_preproc.func_preproc.func_despike_template(wf, cfg, strat_pool, pipe_num, opt=None)[source]

Generate de-spiked functional timeseries in template space with AFNI.

Parameters:
Returns:

NodeBlockFunction: func_mask_normalize

CPAC.func_preproc.func_preproc.func_mask_normalize(wf, cfg, strat_pool, pipe_num, opt=None)[source]

Normalize a functional mask.

Parameters:
Returns:

NodeBlockFunction: func_mean

CPAC.func_preproc.func_preproc.func_mean(wf, cfg, strat_pool, pipe_num, opt=None)[source]

Generate a mean functional image.

Parameters:
Returns:

NodeBlockFunction: func_normalize

CPAC.func_preproc.func_preproc.func_normalize(wf, cfg, strat_pool, pipe_num, opt=None)[source]

Normalize a functional image.

Parameters:
Returns:

NodeBlockFunction: func_reorient

CPAC.func_preproc.func_preproc.func_reorient(wf, cfg, strat_pool, pipe_num, opt=None)[source]

Reorient functional timeseries.

Parameters:
Returns:

NodeBlockFunction: func_scaling

CPAC.func_preproc.func_preproc.func_scaling(wf, cfg, strat_pool, pipe_num, opt=None)[source]

Scale functional timeseries.

Parameters:
Returns:

NodeBlockFunction: func_slice_time

CPAC.func_preproc.func_preproc.func_slice_time(wf, cfg, strat_pool, pipe_num, opt=None)[source]

Genetare slice-time correctied timeseries.

Parameters:
Returns:

NodeBlockFunction: func_truncate

CPAC.func_preproc.func_preproc.func_truncate(wf, cfg, strat_pool, pipe_num, opt=None)[source]

Truncate functional timeseries.

Parameters:
Returns:

CPAC.func_preproc.func_preproc.get_idx(in_files, stop_idx=None, start_idx=None)[source]

Get the first and the last slice for the functional run.

Verify the user specified first and last slice. If the values are not valid, calculate and return the very first and the last slice.

Parameters:
  • in_file (str (nifti file)) – Path to input functional run

  • stop_idx (int) – Last volume to be considered, specified by user in the configuration file

  • stop_idx – First volume to be considered, specified by user in the configuration file

Returns:

  • stop_idx (int) – Value of first slice to consider for the functional run

  • start_idx (int) – Value of last slice to consider for the functional run

CPAC.func_preproc.func_preproc.slice_timing_wf(name='slice_timing', tpattern=None, tzero=None)[source]

Calculate corrected slice-timing.

Utilities

CPAC.func_preproc.utils.chunk_ts(func_file, n_chunks=None, chunk_size=None)[source]
CPAC.func_preproc.utils.degrees_to_mm(degrees, head_radius)[source]
CPAC.func_preproc.utils.mm_to_degrees(mm, head_radius)[source]
CPAC.func_preproc.utils.notch_filter_motion(motion_params, filter_type, TR, fc_RR_min=None, fc_RR_max=None, center_freq=None, freq_bw=None, lowpass_cutoff=None, filter_order=4)[source]
CPAC.func_preproc.utils.nullify(value, function=None)[source]
CPAC.func_preproc.utils.oned_text_concat(in_files)[source]
CPAC.func_preproc.utils.split_ts_chunks(func_file, tr_ranges)[source]