Skip to content
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 sims and remove unnecessary imports #976

Merged
merged 1 commit into from Mar 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion dipy/sims/__init__.py
@@ -1 +1 @@
#init for simulations
# init for simulations
74 changes: 37 additions & 37 deletions dipy/sims/phantom.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion dipy/sims/tests/__init__.py
@@ -1,4 +1,4 @@
# Test callable
from numpy.testing import Tester
test = Tester().test
del Tester
del Tester
28 changes: 12 additions & 16 deletions 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)

Expand All @@ -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():
Expand All @@ -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)

Expand Down Expand Up @@ -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()
2 changes: 0 additions & 2 deletions dipy/sims/voxel.py
Expand Up @@ -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

Expand Down Expand Up @@ -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.

Expand Down