# Median Angle Correction¶

`CPAC.median_angle.``create_median_angle_correction`(name='median_angle_correction')[source]

Median Angle Correction

name : string, optional
Name of the workflow.
median_angle_correction : nipype.pipeline.engine.Workflow
Median Angle Correction workflow.

Workflow Inputs:

```inputspec.subject : string (nifti file)
Realigned nifti file of a subject
inputspec.target_angle : integer
Target angle in degrees to correct the median angle to
```

Workflow Outputs:

```outputspec.subject : string (nifti file)
Median angle corrected nifti file of the given subject
outputspec.pc_angles : string (.npy file)
Numpy file (.npy file) containing the angles (in radians) of all voxels with
the 5 largest principal components.
```

Median Angle Correction Procedure:

1. Compute the median angle with respect to the first principal component of the subject
2. Shift the angle of every voxel so that the new median angle equals the target angle

Workflow Graph:

Detailed Workflow Graph:

`CPAC.median_angle.``create_target_angle`(name='target_angle')[source]

Target Angle Calculation

name : string, optional
Name of the workflow.
target_angle : nipype.pipeline.engine.Workflow
Target angle workflow.

Workflow Inputs:

```inputspec.subjects : list (nifti files)
List of subject paths.
```

Workflow Outputs:

```outputspec.target_angle : float
Target angle over the provided group of subjects.
```

Target Angle procedure:

1. Compute the median angle and mean bold amplitude of each subject in the group.
2. Fit a linear model with median angle as the dependent variable.
3. Calculate the corresponding median_angle on the fitted model for the subject with the smallest mean bold amplitude of the group.

Workflow Graph:

Detailed Workflow Graph:

`CPAC.median_angle.``median_angle_correct`(target_angle_deg, realigned_file)[source]

Performs median angle correction on fMRI data. Median angle correction algorithm based on [1].

target_angle_deg : float
Target median angle to adjust the time-series data.
realigned_file : string
Path of a realigned nifti file.
corrected_file : string
Path of corrected file (nifti file).
angles_file : string
Path of numpy file (.npy file) containing the angles (in radians) of all voxels with the 5 largest principal components.
 [1] He and T. T. Liu, “A geometric view of global signal confounds in resting-state functional MRI,” NeuroImage, Sep. 2011.
`CPAC.median_angle.``calc_median_angle_params`(subject)[source]

Calculates median angle parameters of a subject

subject : string
Path of a subject’s nifti file.
mean_bold : float
Mean bold amplitude of a subject.
median_angle : float
Median angle of a subject.
`CPAC.median_angle.``calc_target_angle`(mean_bolds, median_angles)[source]

Calculates a target angle based on median angle parameters of the group.

mean_bolds : list (floats)
List of mean bold amplitudes of the group
median_angles : list (floats)
List of median angles of the group
target_angle : float
Calculated target angle of the given group