New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FIX: PEP8 in denoise #957
FIX: PEP8 in denoise #957
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
import dipy.data as dpd | ||
import nibabel as nib | ||
|
||
|
||
def test_denoise(): | ||
""" | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,13 @@ | |
|
||
from numpy.testing import (assert_almost_equal, assert_equal, assert_, | ||
assert_array_almost_equal) | ||
from dipy.denoise.noise_estimate import _inv_nchi_cdf, piesno, estimate_sigma, _piesno_3D | ||
from dipy.denoise.noise_estimate import _inv_nchi_cdf, piesno, estimate_sigma | ||
from dipy.denoise.noise_estimate import _piesno_3D | ||
import dipy.data | ||
|
||
# See page 5 of the reference paper for tested values | ||
|
||
|
||
def test_inv_nchi(): | ||
# Values taken from hispeed.MedianPIESNO.lambdaPlus | ||
# and hispeed.MedianPIESNO.lambdaMinus | ||
|
@@ -27,13 +30,15 @@ def test_piesno(): | |
# Values taken from hispeed.OptimalPIESNO with the test data | ||
# in the package computed in matlab | ||
test_piesno_data = nib.load(dipy.data.get_data("test_piesno")).get_data() | ||
sigma = piesno(test_piesno_data, N=8, alpha=0.01, l=1, eps=1e-10, return_mask=False) | ||
sigma = piesno(test_piesno_data, N=8, alpha=0.01, l=1, eps=1e-10, | ||
return_mask=False) | ||
assert_almost_equal(sigma, 0.010749458025559) | ||
|
||
noise1 = (np.random.randn(100, 100, 100) * 50) + 10 | ||
noise2 = (np.random.randn(100, 100, 100) * 50) + 10 | ||
rician_noise = np.sqrt(noise1**2 + noise2**2) | ||
sigma, mask = piesno(rician_noise, N=1, alpha=0.01, l=1, eps=1e-10, return_mask=True) | ||
sigma, mask = piesno(rician_noise, N=1, alpha=0.01, l=1, eps=1e-10, | ||
return_mask=True) | ||
|
||
# less than 3% of error? | ||
assert_(np.abs(sigma - 50) / sigma < 0.03) | ||
|
@@ -49,53 +54,63 @@ def test_piesno(): | |
assert_(np.abs(sigma - 50) / sigma < 0.03) | ||
|
||
sigma = _piesno_3D(rician_noise, N=1, alpha=0.01, l=1, eps=1e-10, | ||
return_mask=False, | ||
initial_estimation=initial_estimation) | ||
return_mask=False, | ||
initial_estimation=initial_estimation) | ||
assert_(np.abs(sigma - 50) / sigma < 0.03) | ||
|
||
sigma = _piesno_3D(np.zeros_like(rician_noise), N=1, alpha=0.01, l=1, eps=1e-10, | ||
return_mask=False, | ||
initial_estimation=initial_estimation) | ||
sigma = _piesno_3D(np.zeros_like(rician_noise), N=1, alpha=0.01, l=1, | ||
eps=1e-10, return_mask=False, | ||
initial_estimation=initial_estimation) | ||
|
||
assert_(np.all(sigma == 0)) | ||
|
||
sigma, mask = _piesno_3D(np.zeros_like(rician_noise), N=1, alpha=0.01, l=1, eps=1e-10, | ||
return_mask=True, | ||
initial_estimation=initial_estimation) | ||
sigma, mask = _piesno_3D(np.zeros_like(rician_noise), N=1, alpha=0.01, l=1, | ||
eps=1e-10, return_mask=True, | ||
initial_estimation=initial_estimation) | ||
|
||
assert_(np.all(sigma == 0)) | ||
assert_(np.all(mask == 0)) | ||
|
||
# Check if no noise points found in array it exits | ||
sigma = _piesno_3D(1000*np.ones_like(rician_noise), N=1, alpha=0.01, l=1, eps=1e-10, | ||
return_mask=False, initial_estimation=10) | ||
sigma = _piesno_3D(1000*np.ones_like(rician_noise), N=1, alpha=0.01, l=1, | ||
eps=1e-10, return_mask=False, initial_estimation=10) | ||
assert_(np.all(sigma == 10)) | ||
|
||
|
||
def test_estimate_sigma(): | ||
|
||
sigma = estimate_sigma(np.ones((7, 7, 7)), disable_background_masking=True) | ||
assert_equal(sigma, 0.) | ||
|
||
sigma = estimate_sigma(np.ones((7, 7, 7, 3)), disable_background_masking=True) | ||
sigma = estimate_sigma(np.ones((7, 7, 7, 3)), | ||
disable_background_masking=True) | ||
assert_equal(sigma, np.array([0., 0., 0.])) | ||
|
||
sigma = estimate_sigma(5 * np.ones((7, 7, 7)), disable_background_masking=False) | ||
sigma = estimate_sigma(5 * np.ones((7, 7, 7)), | ||
disable_background_masking=False) | ||
assert_equal(sigma, 0.) | ||
|
||
sigma = estimate_sigma(5 * np.ones((7, 7, 7, 3)), disable_background_masking=False) | ||
sigma = estimate_sigma(5 * np.ones((7, 7, 7, 3)), | ||
disable_background_masking=False) | ||
assert_equal(sigma, np.array([0., 0., 0.])) | ||
|
||
arr = np.zeros((3, 3, 3)) | ||
arr[0, 0, 0] = 1 | ||
sigma = estimate_sigma(arr, disable_background_masking=False, N=1) | ||
assert_array_almost_equal(sigma, 0.10286889997472792 / np.sqrt(0.42920367320510366)) | ||
assert_array_almost_equal(sigma, | ||
(0.10286889997472792 / | ||
np.sqrt(0.42920367320510366))) | ||
|
||
arr = np.zeros((3, 3, 3, 3)) | ||
arr[0, 0, 0] = 1 | ||
sigma = estimate_sigma(arr, disable_background_masking=False, N=1) | ||
assert_array_almost_equal(sigma, np.array([0.10286889997472792 / np.sqrt(0.42920367320510366), | ||
0.10286889997472792 / np.sqrt(0.42920367320510366), | ||
0.10286889997472792 / np.sqrt(0.42920367320510366)])) | ||
assert_array_almost_equal(sigma, | ||
np.array([0.10286889997472792 / | ||
np.sqrt(0.42920367320510366), | ||
0.10286889997472792 / | ||
np.sqrt(0.42920367320510366), | ||
0.10286889997472792 / | ||
np.sqrt(0.42920367320510366)])) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @samuelstjean Should I even change here? |
||
|
||
arr = np.zeros((3, 3, 3)) | ||
arr[0, 0, 0] = 1 | ||
|
@@ -110,6 +125,10 @@ def test_estimate_sigma(): | |
|
||
arr[0, 0, 0] = 1 | ||
sigma = estimate_sigma(arr, disable_background_masking=True, N=12) | ||
assert_array_almost_equal(sigma, np.array([0.46291005 / np.sqrt(0.4946862482541263), | ||
0.46291005 / np.sqrt(0.4946862482541263), | ||
0.46291005 / np.sqrt(0.4946862482541263)])) | ||
assert_array_almost_equal(sigma, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is hard to read, no need to break lines for the 80 characters rule everytime if it does not really help. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @samuelstjean Should I change it to
or
|
||
np.array([0.46291005 / | ||
np.sqrt(0.4946862482541263), | ||
0.46291005 / | ||
np.sqrt(0.4946862482541263), | ||
0.46291005 / | ||
np.sqrt(0.4946862482541263)])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo (was there before, but maybe we fix it here?):
"inacuracies"=> "inaccuracies"