From 5566a8cadb779be131c9557216faff8711f751bc Mon Sep 17 00:00:00 2001 From: Bishakh Ghosh Date: Sat, 19 Mar 2016 21:23:38 +0530 Subject: [PATCH] Fix PEP8 in sims and remove unnecessary imports fixes #884 --- dipy/sims/__init__.py | 2 +- dipy/sims/phantom.py | 74 ++++++++++++++++----------------- dipy/sims/tests/__init__.py | 2 +- dipy/sims/tests/test_phantom.py | 28 ++++++------- dipy/sims/voxel.py | 2 - 5 files changed, 51 insertions(+), 57 deletions(-) diff --git a/dipy/sims/__init__.py b/dipy/sims/__init__.py index 324655804d..d2bd4662ce 100644 --- a/dipy/sims/__init__.py +++ b/dipy/sims/__init__.py @@ -1 +1 @@ -#init for simulations +# init for simulations diff --git a/dipy/sims/phantom.py b/dipy/sims/phantom.py index 7aba63dc92..6592c036e9 100644 --- a/dipy/sims/phantom.py +++ b/dipy/sims/phantom.py @@ -62,7 +62,7 @@ def add_noise(vol, snr=1.0, S0=None, noise_type='rician'): return np.reshape(vol_flat, orig_shape) -def diff2eigenvectors(dx,dy,dz): +def diff2eigenvectors(dx, dy, dz): """ numerical derivatives 2 eigenvectors """ basis = np.eye(3) @@ -197,54 +197,54 @@ def orbital_phantom(gtab=None, if __name__ == "__main__": - ## TODO: this can become a nice tutorial for generating phantoms + # TODO: this can become a nice tutorial for generating phantoms def f(t): - x=np.sin(t) - y=np.cos(t) - #z=np.zeros(t.shape) - z=np.linspace(-1,1,len(x)) - return x,y,z + x = np.sin(t) + y = np.cos(t) + # z=np.zeros(t.shape) + z = np.linspace(-1, 1, len(x)) + return x, y, z - #helix - vol=orbital_phantom(func=f) + # helix + vol = orbital_phantom(func=f) def f2(t): - x=np.linspace(-1,1,len(t)) - y=np.linspace(-1,1,len(t)) - z=np.zeros(x.shape) - return x,y,z + x = np.linspace(-1, 1, len(t)) + y = np.linspace(-1, 1, len(t)) + z = np.zeros(x.shape) + return x, y, z - #first direction - vol2=orbital_phantom(func=f2) + # first direction + vol2 = orbital_phantom(func=f2) def f3(t): - x=np.linspace(-1,1,len(t)) - y=-np.linspace(-1,1,len(t)) - z=np.zeros(x.shape) - return x,y,z + x = np.linspace(-1, 1, len(t)) + y = -np.linspace(-1, 1, len(t)) + z = np.zeros(x.shape) + return x, y, z - #second direction - vol3=orbital_phantom(func=f3) - #double crossing - vol23=vol2+vol3 + # second direction + vol3 = orbital_phantom(func=f3) + # double crossing + vol23 = vol2 + vol3 - #""" + # """ def f4(t): - x=np.zeros(t.shape) - y=np.zeros(t.shape) - z=np.linspace(-1,1,len(t)) - return x,y,z + x = np.zeros(t.shape) + y = np.zeros(t.shape) + z = np.linspace(-1, 1, len(t)) + return x, y, z - #triple crossing - vol4=orbital_phantom(func=f4) - vol234=vol23+vol4 + # triple crossing + vol4 = orbital_phantom(func=f4) + vol234 = vol23 + vol4 - voln=add_rician_noise(vol234) + voln = add_rician_noise(vol234) - #""" + # """ - #r=fvtk.ren() - #fvtk.add(r,fvtk.volume(vol234[...,0])) - #fvtk.show(r) - #vol234n=add_rician_noise(vol234,20) + # r=fvtk.ren() + # fvtk.add(r,fvtk.volume(vol234[...,0])) + # fvtk.show(r) + # vol234n=add_rician_noise(vol234,20) diff --git a/dipy/sims/tests/__init__.py b/dipy/sims/tests/__init__.py index d97075bf1b..fb440a4258 100644 --- a/dipy/sims/tests/__init__.py +++ b/dipy/sims/tests/__init__.py @@ -1,4 +1,4 @@ # Test callable from numpy.testing import Tester test = Tester().test -del Tester \ No newline at end of file +del Tester diff --git a/dipy/sims/tests/test_phantom.py b/dipy/sims/tests/test_phantom.py index 89725cf522..669b538c44 100644 --- a/dipy/sims/tests/test_phantom.py +++ b/dipy/sims/tests/test_phantom.py @@ -1,26 +1,21 @@ from __future__ import division import numpy as np -import nose -import nibabel as nib -import numpy.testing.decorators as dec from numpy.testing import (assert_, assert_equal, assert_array_equal, assert_array_almost_equal, assert_almost_equal, run_module_suite) -from dipy.core.geometry import vec2vec_rotmat from dipy.data import get_data from dipy.reconst.dti import TensorModel -from dipy.sims.phantom import orbital_phantom, add_noise -from dipy.sims.voxel import single_tensor +from dipy.sims.phantom import orbital_phantom from dipy.core.gradients import gradient_table -fimg,fbvals,fbvecs=get_data('small_64D') -bvals=np.load(fbvals) -bvecs=np.load(fbvecs) -bvecs[np.isnan(bvecs)]=0 +fimg, fbvals, fbvecs = get_data('small_64D') +bvals = np.load(fbvals) +bvecs = np.load(fbvecs) +bvecs[np.isnan(bvecs)] = 0 gtab = gradient_table(bvals, bvecs) @@ -29,10 +24,10 @@ def f(t): """ Helper function used to define a mapping time => xyz """ - x = np.linspace(-1,1,len(t)) - y = np.linspace(-1,1,len(t)) - z = np.linspace(-1,1,len(t)) - return x,y,z + x = np.linspace(-1, 1, len(t)) + y = np.linspace(-1, 1, len(t)) + z = np.linspace(-1, 1, len(t)) + return x, y, z def test_phantom(): @@ -55,7 +50,9 @@ def test_phantom(): FA[np.isnan(FA)] = 0 # 686 -> expected FA given diffusivities of [1500, 400, 400] l1, l2, l3 = 1500e-6, 400e-6, 400e-6 - expected_fa = (np.sqrt(0.5) * np.sqrt((l1 - l2)**2 + (l2-l3)**2 + (l3-l1)**2 )/np.sqrt(l1**2 + l2**2 + l3**2)) + expected_fa = (np.sqrt(0.5) * + np.sqrt((l1 - l2)**2 + (l2-l3)**2 + (l3-l1)**2) / + np.sqrt(l1**2 + l2**2 + l3**2)) assert_array_almost_equal(FA.max(), expected_fa, decimal=2) @@ -85,6 +82,5 @@ def test_add_noise(): assert_(np.abs(np.var(vol_noise - vol) - sigma ** 2) < 1) - if __name__ == "__main__": run_module_suite() diff --git a/dipy/sims/voxel.py b/dipy/sims/voxel.py index 71f7fd71da..a1e693fbcf 100644 --- a/dipy/sims/voxel.py +++ b/dipy/sims/voxel.py @@ -307,7 +307,6 @@ def multi_tensor(gtab, mevals, S0=100, angles=[(0, 0), (90, 0)], def multi_tensor_dki(gtab, mevals, S0=100, angles=[(90., 0.), (90., 0.)], fractions=[50, 50], snr=20): - r""" Simulate the diffusion-weight signal, diffusion and kurtosis tensors based on the DKI model @@ -533,7 +532,6 @@ def DKI_signal(gtab, dt, kt, S0=150, snr=None): return S - def single_tensor_odf(r, evals=None, evecs=None): """ Simulated ODF with a single tensor.