@@ -0,0 +1,1161 @@
+%0Aimport numpy as np%0Aimport scipy.stats as stats%0A%0A%0Adef rft_correct(image_data, pixdim=%5B2, 2, 2%5D, kernel=%5B8, 8, 8%5D, alpha=0.05):%0A    %22%22%22Random field correction of gauss smoothed data.%0A%0A    Parameters%0A    ----------%0A    image_data: np.ndarray%0A        Volume data array%0A%0A    pixdim: array/list of ints or floats%0A        Size in milimeters of the voxel, e.g., %5B2, 2, 2%5D if the voxel size is 2mm x 2mm x 2mm.%0A%0A    kernel: array/list of ints or floats%0A        Size in milimiters of the FWHM smooothing kernel.%0A%0A    alpha: float%0A        False positive rate threshold for correction.%0A%0A    Returns%0A    -------%0A    p-values volume%0A    %22%22%22%0A    # Non-zero voxels%0A    num_nonzero_voxels = np.count_nonzero(image_data)%0A%0A    # Voxel volume mm%0A    voxel_volume = np.prod(pixdim)%0A%0A    # Tama%C3%B1o del kernel mm%0A    kernel_volume = np.prod(kernel)%0A%0A    # Calculate number of resels%0A    n_resels = (num_nonzero_voxels * voxel_volume)/kernel_volume%0A%0A    # The inverse normal CDF%0A    z_opt = normal_dist.ppf(1 - (alpha / n_resels))%0A%0A    # Apply RFT statistical correction%0A    pos_corr = image_data %3E z_opt%0A    neg_corr = image_data %3C -z_opt%0A%0A    return image_data * (pos_corr+neg_corr)%0A

Add random_fields.py with rft_correct function