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

NF - Particle Filtering Tractography (merge) #1384

Merged
merged 49 commits into from
Feb 6, 2018
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
183c676
NF - added CMC tissue classifier
gabknight Jun 5, 2016
d0213d5
TST - test CMC tissue classifier
gabknight Jun 5, 2016
c87da16
WIP - particle filtering tractography
gabknight Jun 1, 2017
047ee3b
WIP - PFT fixed rebased conflicts
gabknight Jun 1, 2017
f566927
WIP - fixed error in PFT tracking class
gabknight Jul 4, 2017
a574c32
NF - added getters for include/exclude maps
gabknight Aug 10, 2017
bfad3e1
RF - rename getters
gabknight Aug 10, 2017
deadc76
NF - added PFT tracker
gabknight Aug 10, 2017
86328b4
NF - added from PVE map constructor for ACT and CMC tissue classifier
gabknight Aug 17, 2017
29e55ba
BF - fixed memory error in PFT
gabknight Aug 29, 2017
9f51480
PEP8 - PFT
gabknight Aug 29, 2017
bfea2b2
TST - add CMC tissueclassifier tests
gabknight Aug 29, 2017
faf805f
PEP - remove unused code
gabknight Aug 29, 2017
a444eab
TST - add test for PFT
gabknight Aug 29, 2017
4263ffc
RF - rename test file for tracking
gabknight Aug 29, 2017
708ace2
DOC - add doc in the ConstrainedTissueClassifier class
gabknight Aug 29, 2017
d77f175
DOC - add PFT example
gabknight Aug 29, 2017
5573a2f
DOC - remove unused code
gabknight Aug 29, 2017
89e530b
DOC - update references
gabknight Aug 30, 2017
65027ae
DOC - add PFT example to valid_examples.txt
gabknight Aug 30, 2017
0e4b8ad
changed np.stack to np.dstack for backward compatibility
gabknight Sep 24, 2017
5361aa6
MERGE following pr#1342
gabknight Nov 24, 2017
31b0e1d
RF - name variable pft_nbr_particles to particle_count
gabknight Nov 27, 2017
96e7b1d
RF - rename variable pft_nbr_particles to particle_count
gabknight Nov 27, 2017
7785830
RF - replaced if statements with a cast to TissueClass type
gabknight Nov 29, 2017
ffa421c
Some quick fixes for @gabknight PR.
jchoude Dec 19, 2017
c6ed1e4
Merge pull request #4 from jchoude/fixes_gab_pr
gabknight Dec 21, 2017
e6264b7
RF - replaced 'grey' with 'gray'
gabknight Jan 8, 2018
0606a20
RF - added elements to __all__ variable
gabknight Jan 8, 2018
17a772d
STYLE - pep8 white space
gabknight Jan 8, 2018
481ca12
RF - replaced for loops with copypoint(.)
gabknight Jan 8, 2018
bd59979
Merge branch 'NF_cmc_pft_merged' into NF_cmc_pft_merged2
gabknight Jan 11, 2018
ec692ec
RF - cython optimization folowing PR comments
gabknight Jan 15, 2018
a71c6f7
STYLE - PEP8 conformance, add ValueError msg, removed typos
gabknight Jan 19, 2018
7bd66a7
TEST - added new tests for PFT
gabknight Jan 19, 2018
a8aed0b
DOC - changed fvtk to dipy.viz
gabknight Jan 19, 2018
cfd9881
RF - clarified pft steamline length return, reduced memory usage
gabknight Jan 21, 2018
1191dea
BF/TEST - handle trilinear_interpolation4d ouside image error
gabknight Jan 22, 2018
706bdc2
BF/TEST - ConstrainedTissueClassifier get_include/_exclude return 0 f…
gabknight Jan 22, 2018
5d672dd
BF/TEST - fixed missing point for streamline with small maxlen
gabknight Jan 22, 2018
223541c
BF - properly handle OUSIDEIMAGE TissueType in localtrack._pft_tracke…
gabknight Jan 23, 2018
a63ae09
TEST - all streamline points are within the image volume
gabknight Jan 24, 2018
78e4eff
BF - remove nans from particle weights
gabknight Jan 25, 2018
6167be6
TST - pft particle count
gabknight Jan 25, 2018
14b4c5d
RF - split pft particle_states array into 2 arrays
gabknight Jan 25, 2018
a4e72ef
DOC - added figures to the PFT example
gabknight Jan 25, 2018
498dd86
TEST - replaced assert_ with assert_equal
gabknight Jan 29, 2018
3c95b3a
DOC - added ref
gabknight Feb 5, 2018
14f4c76
DOC - updated exemple with the new standard
gabknight Feb 5, 2018
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
23 changes: 15 additions & 8 deletions dipy/direction/pmf.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ cdef class SimplePmfGen(PmfGen):
self.out = np.empty(pmf_array.shape[3])

cdef double[:] get_pmf_c(self, double* point) nogil:
trilinear_interpolate4d_c(self.pmf_array, point, self.out)
cdef:
size_t len_pmf = self.out.shape[0]
if trilinear_interpolate4d_c(self.pmf_array, point, self.out):
for i in range(len_pmf):
self.out[i] = 0.0
return self.out


Expand Down Expand Up @@ -62,13 +66,16 @@ cdef class SHCoeffPmfGen(PmfGen):
size_t len_B = self.B.shape[1]
double _sum

trilinear_interpolate4d_c(self.shcoeff, point, self.coeff)
for i in range(len_pmf):
_sum = 0
for j in range(len_B):
_sum += self.B[i, j] * self.coeff[j]
self.pmf[i] = _sum
if self.pmf[i] < 0.0:
if trilinear_interpolate4d_c(self.shcoeff, point, self.coeff):
for i in range(len_pmf):
self.pmf[i] = 0.0
else:
for i in range(len_pmf):
_sum = 0
for j in range(len_B):
_sum += self.B[i, j] * self.coeff[j]
self.pmf[i] = _sum
if self.pmf[i] < 0.0:
self.pmf[i] = 0.0

return self.pmf
43 changes: 43 additions & 0 deletions dipy/direction/tests/test_pmf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import numpy as np
import numpy.testing as npt

from dipy.core.sphere import HemiSphere, unit_octahedron
from dipy.direction.pmf import SimplePmfGen, SHCoeffPmfGen


def test_pmf_from_sh():
sphere = HemiSphere.from_sphere(unit_octahedron)
pmfgen = SHCoeffPmfGen(np.ones([2, 2, 2, 28]), sphere, None)

# Test that the pmf is greater than 0 for a valid point
pmf = pmfgen.get_pmf(np.array([0, 0, 0], dtype='float'))
npt.assert_equal(np.sum(pmf) > 0, True)

# Test that the pmf is 0 for invalid Points
npt.assert_array_equal(pmfgen.get_pmf(np.array([-1, 0, 0], dtype='float')),
np.zeros(len(sphere.vertices)))
npt.assert_array_equal(pmfgen.get_pmf(np.array([0, 0, 10], dtype='float')),
np.zeros(len(sphere.vertices)))


def test_pmf_from_array():
sphere = HemiSphere.from_sphere(unit_octahedron)
pmfgen = SimplePmfGen(np.ones([2, 2, 2, len(sphere.vertices)]))

# Test that the pmf is greater than 0 for a valid point
pmf = pmfgen.get_pmf(np.array([0, 0, 0], dtype='float'))
npt.assert_equal(np.sum(pmf) > 0, True)

# Test that the pmf is 0 for invalid Points
npt.assert_array_equal(pmfgen.get_pmf(np.array([-1, 0, 0], dtype='float')),
np.zeros(len(sphere.vertices)))
npt.assert_array_equal(pmfgen.get_pmf(np.array([0, 0, 10], dtype='float')),
np.zeros(len(sphere.vertices)))

npt.assert_raises(
ValueError,
lambda: SimplePmfGen(np.ones([2, 2, 2, len(sphere.vertices)])*-1))


if __name__ == '__main__':
npt.run_module_suite()
10 changes: 5 additions & 5 deletions dipy/segment/tests/test_mrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
square_1[99:157, 99:157, :] = temp_3


def test_greyscale_image():
def test_grayscale_image():

com = ConstantObservationModel()
icm = IteratedConditionalModes()
Expand Down Expand Up @@ -124,7 +124,7 @@ def test_greyscale_image():
npt.assert_(icm_segmentation.min() == 0)


def test_greyscale_iter():
def test_grayscale_iter():

max_iter = 15
beta = np.float64(0.1)
Expand Down Expand Up @@ -195,11 +195,11 @@ def test_greyscale_iter():
npt.assert_(PLY[100, 100, 1, 3] > PLY[100, 100, 1, 1])
npt.assert_(PLY[100, 100, 1, 3] > PLY[100, 100, 1, 2])

mu_upd, sigmasq_upd = com.update_param(image_gauss, PLY, mu, nclasses)
mu_upd, sigmasq_upd = com.update_param(image_gauss, PLY, mu, nclasses)
npt.assert_(mu_upd[0] >= 0.0)
npt.assert_(mu_upd[1] >= 0.0)
npt.assert_(mu_upd[2] >= 0.0)
npt.assert_(mu_upd[3] >= 0.0)
npt.assert_(mu_upd[3] >= 0.0)
npt.assert_(sigmasq_upd[0] >= 0.0)
npt.assert_(sigmasq_upd[1] >= 0.0)
npt.assert_(sigmasq_upd[2] >= 0.0)
Expand Down Expand Up @@ -294,7 +294,7 @@ def test_square_iter():
npt.assert_(mu_upd[0] >= 0.0)
npt.assert_(mu_upd[1] >= 0.0)
npt.assert_(mu_upd[2] >= 0.0)
npt.assert_(mu_upd[3] >= 0.0)
npt.assert_(mu_upd[3] >= 0.0)
npt.assert_(sigmasq_upd[0] >= 0.0)
npt.assert_(sigmasq_upd[1] >= 0.0)
npt.assert_(sigmasq_upd[2] >= 0.0)
Expand Down
18 changes: 12 additions & 6 deletions dipy/tracking/local/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
from .localtracking import LocalTracking
from .tissue_classifier import (
ActTissueClassifier, BinaryTissueClassifier, ThresholdTissueClassifier,
TissueClassifier)
from .direction_getter import DirectionGetter
from .localtracking import LocalTracking, ParticleFilteringTracking
from .tissue_classifier import (ActTissueClassifier,
BinaryTissueClassifier,
CmcTissueClassifier,
ConstrainedTissueClassifier,
ThresholdTissueClassifier,
TissueClassifier)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imported but never used. Is this intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it to __all__. Thx


from dipy.tracking import utils

__all__ = ["ActTissueClassifier", "BinaryTissueClassifier", "LocalTracking",
"ThresholdTissueClassifier"]
__all__ = ["ActTissueClassifier", "BinaryTissueClassifier",
"CmcTissueClassifier", "ConstrainedTissueClassifier",
"DirectionGetter", "LocalTracking", "ParticleFilteringTracking",
"ThresholdTissueClassifier", "TissueClassifier"]