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

DOC - explicitly run the streamline generators before saving the trk #1879

Merged
merged 2 commits into from
Jul 8, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions doc/examples/deterministic_fiber_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,13 @@
from dipy.data import default_sphere
from dipy.direction import DeterministicMaximumDirectionGetter
from dipy.io.streamline import save_trk
from dipy.tracking.streamline import Streamlines

detmax_dg = DeterministicMaximumDirectionGetter.from_shcoeff(csd_fit.shm_coeff,
max_angle=30.,
sphere=default_sphere)
streamlines = LocalTracking(detmax_dg, classifier, seeds, affine, step_size=.5)

streamline_generator = LocalTracking(detmax_dg, classifier, seeds, affine,
step_size=.5)
streamlines = Streamlines(streamline_generator)
save_trk("deterministic_maximum_shm_coeff.trk", streamlines, affine,
labels.shape)
5 changes: 1 addition & 4 deletions doc/examples/particle_filtering_fiber_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from dipy.reconst.csdeconv import (ConstrainedSphericalDeconvModel,
auto_response)
from dipy.tracking.local import LocalTracking, ParticleFilteringTracking
from dipy.tracking.streamline import Streamlines
from dipy.tracking import utils
from dipy.viz import window, actor, colormap as cmap

Expand Down Expand Up @@ -68,7 +69,6 @@
"""

from dipy.tracking.local import CmcTissueClassifier
from dipy.tracking.streamline import Streamlines

voxel_size = np.average(img_pve_wm.get_header()['pixdim'][1:4])
step_size = 0.2
Expand Down Expand Up @@ -97,11 +97,9 @@
particle_count=15,
return_all=False)

# streamlines = list(pft_streamline_generator)
streamlines = Streamlines(pft_streamline_generator)
save_trk("pft_streamline.trk", streamlines, affine, shape)


renderer.clear()
renderer.add(actor.line(streamlines, cmap.line_colors(streamlines)))
window.record(renderer, out_path='pft_streamlines.png', size=(600, 600))
Expand All @@ -122,7 +120,6 @@
step_size=step_size,
maxlen=1000,
return_all=False)
# streamlines = list(pro)
streamlines = Streamlines(prob_streamline_generator)
save_trk("probabilistic_streamlines.trk", streamlines, affine, shape)

Expand Down
19 changes: 12 additions & 7 deletions doc/examples/probabilistic_fiber_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@
pmf = fod.clip(min=0)
prob_dg = ProbabilisticDirectionGetter.from_pmf(pmf, max_angle=30.,
sphere=small_sphere)
streamlines_generator = LocalTracking(prob_dg, classifier, seeds, affine, step_size=.5)
save_trk("probabilistic_small_sphere.trk", streamlines_generator, affine, labels.shape)
streamline_generator = LocalTracking(prob_dg, classifier, seeds, affine,
step_size=.5)
streamlines = Streamlines(streamline_generator)
save_trk("probabilistic_small_sphere.trk", streamlines, affine, labels.shape)

"""
One disadvantage of using a discrete PMF to represent possible tracking
Expand All @@ -87,9 +89,10 @@
prob_dg = ProbabilisticDirectionGetter.from_shcoeff(csd_fit.shm_coeff,
max_angle=30.,
sphere=default_sphere)
streamlines_generator = LocalTracking(prob_dg, classifier, seeds, affine, step_size=.5)

save_trk("probabilistic_shm_coeff.trk", streamlines_generator, affine, labels.shape)
streamline_generator = LocalTracking(prob_dg, classifier, seeds, affine,
step_size=.5)
streamlines = Streamlines(streamline_generator)
save_trk("probabilistic_shm_coeff.trk", streamlines, affine, labels.shape)

"""
Not all model fits have the ``shm_coeff`` attribute because not all models use
Expand All @@ -104,6 +107,8 @@
fod_coeff = peaks.shm_coeff
prob_dg = ProbabilisticDirectionGetter.from_shcoeff(fod_coeff, max_angle=30.,
sphere=default_sphere)
streamlines_generator = LocalTracking(prob_dg, classifier, seeds, affine, step_size=.5)
save_trk("probabilistic_peaks_from_model.trk", streamlines_generator, affine,
streamline_generator = LocalTracking(prob_dg, classifier, seeds, affine,
step_size=.5)
streamlines = Streamlines(streamline_generator)
save_trk("probabilistic_peaks_from_model.trk", streamlines, affine,
labels.shape)
6 changes: 3 additions & 3 deletions doc/examples/sfm_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@

from dipy.tracking.local import LocalTracking
from dipy.tracking.streamline import Streamlines
streamlines_generator = LocalTracking(pnm, classifier, seeds, affine, step_size=.5)

streamlines = Streamlines(streamlines_generator)
streamline_generator = LocalTracking(pnm, classifier, seeds, affine,
step_size=.5)
streamlines = Streamlines(streamline_generator)

"""
Next, we will create a visualization of these streamlines, relative to this
Expand Down
80 changes: 36 additions & 44 deletions doc/examples/tracking_tissue_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,18 @@
**Thresholded fractional anisotropy map.**
"""

all_streamlines_threshold_classifier = LocalTracking(dg,
threshold_classifier,
seeds,
affine,
step_size=.5,
return_all=True)

save_trk("deterministic_threshold_classifier_all.trk",
all_streamlines_threshold_classifier,
all_streamline_threshold_tc_generator = LocalTracking(dg,
threshold_classifier,
seeds,
affine,
step_size=.5,
return_all=True)
streamlines = Streamlines(all_streamline_threshold_tc_generator)
save_trk("all_streamlines_threshold_classifier.trk",
streamlines,
affine,
labels.shape)

streamlines = Streamlines(all_streamlines_threshold_classifier)

if have_fury:
window.clear(ren)
ren.add(actor.line(streamlines, cmap.line_colors(streamlines)))
Expand Down Expand Up @@ -183,20 +181,18 @@
**White matter binary mask.**
"""

all_streamlines_binary_classifier = LocalTracking(dg,
binary_classifier,
seeds,
affine,
step_size=.5,
return_all=True)

save_trk("deterministic_binary_classifier_all.trk",
all_streamlines_binary_classifier,
all_streamline_binary_tc_generator = LocalTracking(dg,
binary_classifier,
seeds,
affine,
step_size=.5,
return_all=True)
streamlines = Streamlines(all_streamline_binary_tc_generator)
save_trk("all_streamlines_binary_classifier.trk",
streamlines,
affine,
labels.shape)

streamlines = Streamlines(all_streamlines_binary_classifier)

if have_fury:
window.clear(ren)
ren.add(actor.line(streamlines, cmap.line_colors(streamlines)))
Expand Down Expand Up @@ -276,20 +272,18 @@
**Include (left) and exclude (right) maps for ACT.**
"""

all_streamlines_act_classifier = LocalTracking(dg,
act_classifier,
seeds,
affine,
step_size=.5,
return_all=True)

save_trk("deterministic_act_classifier_all.trk",
all_streamlines_act_classifier,
all_streamline_act_tc_generator = LocalTracking(dg,
act_classifier,
seeds,
affine,
step_size=.5,
return_all=True)
streamlines = Streamlines(all_streamline_act_tc_generator)
save_trk("all_streamlines_act_classifier.trk",
streamlines,
affine,
labels.shape)

streamlines = Streamlines(all_streamlines_act_classifier)

if have_fury:
window.clear(ren)
ren.add(actor.line(streamlines, cmap.line_colors(streamlines)))
Expand All @@ -305,20 +299,18 @@
**Deterministic tractography using ACT stopping criterion.**
"""

valid_streamlines_act_classifier = LocalTracking(dg,
act_classifier,
seeds,
affine,
step_size=.5,
return_all=False)

save_trk("deterministic_act_classifier_valid.trk",
valid_streamlines_act_classifier,
valid_streamline_act_tc_generator = LocalTracking(dg,
act_classifier,
seeds,
affine,
step_size=.5,
return_all=False)
streamlines = Streamlines(valid_streamline_act_tc_generator)
save_trk("valid_streamlines_act_classifier.trk",
streamlines,
affine,
labels.shape)

streamlines = Streamlines(valid_streamlines_act_classifier)

if have_fury:
window.clear(ren)
ren.add(actor.line(streamlines, cmap.line_colors(streamlines)))
Expand Down