def test_noise_correction(): # tests mean_underlying_noise # Case where there is noise. test=np.arange(256) test=test.reshape((4,4,4,4)) val=np.mean(np.arange(0,256,4)) y_mean = mean_underlying_noise(test) assert(all(y_mean==(np.tile(val,4)+np.array([0,1,2,3])) )) # Case where there is no noise. test_2=np.ones(256) test_2=test_2.reshape((4,4,4,4)) y_mean2 = mean_underlying_noise(test_2) assert(all(y_mean2==np.ones(4))) # Test predicting noise with Fourier series. fourier_X, fourier_MRSS, fourier_fitted, fourier_residuals = fourier_predict_underlying_noise(y_mean, 10) naive_resid = y_mean-y_mean.mean() assert_not_equals(naive_resid[0], fourier_residuals[0])
out = stats.probplot(residuals[41, 47, 2], dist="norm", plot=plt) plt.title("Q-Q plot for sub001, voxel [41, 47, 2],fourier 3 fit to voxel") plt.savefig(location_of_images + "noise_correction_fit_to_voxel_residuals_QQ.png") plt.close() ################## # Second Attempt # ################## # Approaching the fourier modeling of cyclic on the individual level, by fitting # the fourier beta values on the means of the single of all voxels y_mean = mean_underlying_noise(data) X_mean, MRSS_mean, fitted_mean, residuals_mean = fourier_predict_underlying_noise(y_mean, 3) # looking at that the y_mean and fitted_mean valuse plt.plot(y_mean, label="voxel mean") plt.plot(fitted_mean, label="fitted") plt.title("Mean plot and Fourier Fitting") plt.xlabel("Time") plt.ylabel("Mean Hemodynamic response") plt.legend(loc="lower right", shadow=True, fontsize="smaller") plt.savefig(location_of_images + "noise_correction_mean_all_fitted.png") plt.close() #### using the fitted_mean
plt.close() out = stats.probplot(residuals[41, 47, 2], dist="norm", plot=plt) plt.title("Q-Q plot for sub001, voxel [41, 47, 2],fourier 3 fit to voxel") plt.savefig(location_of_images + 'noise_correction_fit_to_voxel_residuals_QQ.png') plt.close() ################## # Second Attempt # ################## # Approaching the fourier modeling of cyclic on the individual level, by fitting # the fourier beta values on the means of the single of all voxels y_mean = mean_underlying_noise(data) X_mean, MRSS_mean, fitted_mean, residuals_mean = fourier_predict_underlying_noise( y_mean, 3) # looking at that the y_mean and fitted_mean valuse plt.plot(y_mean, label="voxel mean") plt.plot(fitted_mean, label="fitted") plt.title("Mean plot and Fourier Fitting") plt.xlabel("Time") plt.ylabel("Mean Hemodynamic response") plt.legend(loc='lower right', shadow=True, fontsize="smaller") plt.savefig(location_of_images + 'noise_correction_mean_all_fitted.png') plt.close() #### using the fitted_mean