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

[WIP] #1572

Closed
Closed

[WIP] #1572

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
435f47a
Merge pull request #1506 from nipy/nipy-dipy-master
Garyfallidis May 1, 2018
aa03dba
Adds whitespace, to appease the sphinx.
arokem May 3, 2018
dd2c7d6
DOC: add some extra indentation, fixes
matthew-brett May 3, 2018
900de02
Merge pull request #30 from matthew-brett/add-my-fixes-to-ariels
arokem May 3, 2018
af3d7a7
copyright updated to 2008-2018
ShreyasFadnavis May 3, 2018
29b0fbe
fix typo in quick_start
RicciWoo May 3, 2018
e8e588a
Merge pull request #1508 from arokem/math-in-kurtosis
skoudoro May 4, 2018
9a6597a
Merge pull request #1510 from ShreyasFadnavis/patch-1
skoudoro May 4, 2018
327af13
Merge pull request #1513 from RicciWoo/fix-typo-quick_start
skoudoro May 4, 2018
2fa5e5d
adding config file for pep8speaks
skoudoro May 7, 2018
7b5c19c
update max line length
skoudoro May 7, 2018
b262974
Merge pull request #1514 from skoudoro/adding-pep8-speak
Garyfallidis May 8, 2018
f124615
basic installation update
skoudoro May 11, 2018
dbfff0f
Merge pull request #1516 from skoudoro/fix-install-cmd
arokem May 11, 2018
813d5d4
Updated some core dev info
Garyfallidis May 12, 2018
ae41159
Added a few more names
Garyfallidis May 12, 2018
3ecfa3a
Merge pull request #1517 from Garyfallidis/dev_info_update
skoudoro May 12, 2018
1af53ac
DOC: updated some developers affiliations.
jchoude May 14, 2018
f4c7e45
Merge pull request #1518 from jchoude/DOC_some_developers_affiliations
skoudoro May 14, 2018
144cadb
Updating the documentation for the workflow creation tutorial.
May 14, 2018
c5729fc
Removed the trailing whitespaces as per the PEP8 standard.
May 14, 2018
b421f9c
Moved some older highlights and announcements to the old news files.
arokem May 14, 2018
05d4691
Now also remove things from the front page.
arokem May 14, 2018
34937d4
Updated the workflow_creation.py according to the recommendations mad…
May 16, 2018
b7f94ae
Added back two more news announcements.
arokem May 16, 2018
b5001ba
TST: We should be able to read values with Streamline objects.
arokem May 16, 2018
a710850
BF: Enables extracting values with Streamline objects.
arokem May 16, 2018
202028d
PEP8
arokem May 16, 2018
5648281
Merge pull request #1521 from arokem/old_highlights
skoudoro May 16, 2018
23cb625
PEP8 the entire thing.
arokem May 16, 2018
8462d3e
Merge pull request #1524 from arokem/values_from_streamlines_object
skoudoro May 16, 2018
6bee25c
Merge pull request #1520 from parichit/doc_branch
skoudoro May 17, 2018
2fbe4b1
minor typo fix in quickstart
ShreyasFadnavis May 21, 2018
6dda3ac
Merge pull request #1529 from ShreyasFadnavis/micro
arokem May 21, 2018
786deb6
Wrong default value for parameter 'symmetric' False in connectivity_m…
albayenes May 21, 2018
0bdce0d
Merge pull request #1530 from albayenes/connectivity-matrix-wrong-def…
arokem May 21, 2018
db9752e
Changed the icon set in Button2D from dictionary to List of tuples
karandeepSJ May 26, 2018
d7be77e
Fixed pep8 errors
karandeepSJ May 26, 2018
cfc96f9
removed unncessary importd from sims eg
ShreyasFadnavis May 27, 2018
8410945
Explanation that is mistakenly rendered as code fixed in example of DKI
albayenes May 28, 2018
804f4e8
Merge pull request #1537 from ShreyasFadnavis/dipy-sims
Garyfallidis May 28, 2018
54823e7
Remove unused attributes in UI and add better way of handling absolut…
MarcCote Mar 4, 2018
50acf99
Remove FileMenu2D in favor of ListBox2D.
MarcCote Mar 4, 2018
5e061da
BF: button placement in viz_ui.py.
MarcCote Mar 6, 2018
ee6eee3
Rebased + update viz examples
MarcCote Apr 5, 2018
8d29466
Add Disk2D and use it as sliders' handle
MarcCote Apr 7, 2018
f370c80
Do not start session in viz example
MarcCote Apr 10, 2018
98b6565
Addressed @skoudoro comments
MarcCote Apr 20, 2018
bbd9808
Renamed DiskSlider2D to RingSlider2D
MarcCote May 17, 2018
afab328
Refactor get_actors
MarcCote May 29, 2018
c17a642
Rename DiskSlider to RingSlider
MarcCote May 29, 2018
c67a2df
Removed debugging BoundingBox
MarcCote May 29, 2018
866e26c
Remove empty line at the end of dosctring
MarcCote May 29, 2018
3c4eaf0
PEP8
MarcCote May 29, 2018
f1991f0
change for cvxpy - missing strict inequalities
Borda May 30, 2018
8110b02
update test asserts: equal -> almost_equal
Borda May 30, 2018
d1bdee5
DOC: Update Rafael's current institution.
May 26, 2018
ba39896
Merge pull request #1536 from jhlegarreta/UpdateRNHCurrentInstitution
arokem May 31, 2018
acda6e1
Merge pull request #1538 from albayenes/fix-explanation-of-code-in-ex…
arokem Jun 1, 2018
6fdbb63
Add tests files
MarcCote Jun 1, 2018
d8fb000
Merge pull request #1492 from MarcCote/enh_ui_components_positioning2
Garyfallidis Jun 1, 2018
7aeb622
Added DIPY reference in README.rst
Garyfallidis Jun 3, 2018
2c48473
Link the reference
Garyfallidis Jun 3, 2018
f95d1e6
Merge pull request #1545 from Garyfallidis/readme_ref
arokem Jun 3, 2018
df6d880
References to reference
Garyfallidis Jun 3, 2018
e1422d7
Merge pull request #1546 from Garyfallidis/readme_ref2
arokem Jun 4, 2018
38a472d
Changed the icon set in Button2D from dictionary to List of tuples
karandeepSJ May 26, 2018
df5473e
Fixed pep8 errors
karandeepSJ May 26, 2018
2dc471d
Updated
karandeepSJ Jun 4, 2018
1db31a9
Fixed references per request of @garyfallidis.
kesshijordan Jun 4, 2018
5e842f1
ENH: adding ListBox2D
MarcCote Mar 4, 2018
2475685
Merge pull request #1542 from Borda/fix_4_cvxpy
skoudoro Jun 5, 2018
fa7b35e
fix potential zero division in demon regist.
Borda May 30, 2018
88e132a
Merge pull request #1548 from kesshijordan/fix_boot_reference
Garyfallidis Jun 5, 2018
4484514
Merge pull request #1540 from Borda/fix_div_zero
skoudoro Jun 5, 2018
8476282
Fix bug in actor.label
wasserth Jun 8, 2018
e0f7e12
PEP8 + button alignment
MarcCote Jun 11, 2018
905b918
Re-comment line
MarcCote Jun 11, 2018
4fcd755
Changed name to VTK_MAJOR_VERSION and used set_input where possible
karandeepSJ Jun 12, 2018
0bfa3ac
Merge pull request #1355 from MarcCote/enh_ui_listbox
dmreagan Jun 13, 2018
4c9b4f6
Started Image widget in ui
karandeepSJ May 15, 2018
46f8a53
Added tests for image holder
karandeepSJ May 15, 2018
4a82be3
Added log files for image holder to run tests with recording=False
karandeepSJ May 15, 2018
245f9f2
Added image extension variable lower() for comparison
karandeepSJ Jun 5, 2018
3705958
Made Changes requested
karandeepSJ Jun 12, 2018
9be55e7
Minor change
karandeepSJ Jun 12, 2018
3336f73
Rebased
karandeepSJ Jun 14, 2018
a7a6cb6
Added Line slider with 2 disks
karandeepSJ Jun 1, 2018
9e736e5
added rangeslider
karandeepSJ Jun 3, 2018
fb46717
pep8
karandeepSJ Jun 7, 2018
3923edc
Added Rectangular handles
karandeepSJ Jun 7, 2018
4209cd2
Added tests for range slider and double slider
karandeepSJ Jun 8, 2018
2334731
pep8
karandeepSJ Jun 8, 2018
297036f
Added color change on handle click for all sliders
karandeepSJ Jun 12, 2018
7b3b633
Merge pull request #1522 from karandeepSJ/ImageHolder
Garyfallidis Jun 15, 2018
5982147
Merge pull request #1555 from wasserth/actor_label_bugfix
Garyfallidis Jun 15, 2018
afc3749
Merge pull request #1547 from karandeepSJ/ButtonDict2List
Garyfallidis Jun 15, 2018
beca581
Merge pull request #1557 from karandeepSJ/DoubleSlider
Garyfallidis Jun 15, 2018
e138a31
Merge pull request #1563 from karandeepSJ/vtk_version_check
Garyfallidis Jun 15, 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
24 changes: 24 additions & 0 deletions .pep8speaks.yml
@@ -0,0 +1,24 @@
# File : .pep8speaks.yml

message: # Customize the comment made by the bot
opened: # Messages when a new PR is submitted
header: "Hello @{name}, Thank you for submitting the Pull Request !"
# The keyword {name} is converted into the author's username
footer: "Do see the [DIPY coding Style guideline](https://github.com/nipy/dipy/blob/master/doc/devel/coding_style_guideline.rst)"
# The messages can be written as they would over GitHub
updated: # Messages when new commits are added to the PR
header: "Hello @{name}, Thank you for updating !"
footer: "" # Why to comment the link to the style guide everytime? :)
no_errors: "Cheers ! There are no PEP8 issues in this Pull Request. :beers: "

scanner:
diff_only: True # If True, errors caused by only the patch are shown

pycodestyle:
max-line-length: 80 # Default is 79 in PEP8
# ignore: # Errors and warnings to ignore
# - W391
# - E203

only_mention_files_with_errors: True # If False, a separate status comment for each file is made.
descending_issues_order: False # If True, PEP8 issues in message will be displayed in descending order of line numbers in the file
10 changes: 9 additions & 1 deletion README.rst
Expand Up @@ -23,7 +23,7 @@
.. image:: https://img.shields.io/badge/License-BSD%203--Clause-blue.svg
:target: https://github.com/nipy/dipy/blob/master/LICENSE

DIPY is a python toolbox for analysis of MR diffusion imaging.
DIPY [DIPYREF]_ is a python library for analysis of MR diffusion imaging.

DIPY is for research only; please do not use results from DIPY for
clinical decisions.
Expand Down Expand Up @@ -83,3 +83,11 @@ Contributing
============

We welcome contributions from the community. Please read our `Contributing guidelines <https://github.com/nipy/dipy/blob/master/CONTRIBUTING.md>`_.

Reference
=========

.. [DIPYREF] E. Garyfallidis, M. Brett, B. Amirbekian, A. Rokem,
S. Van Der Walt, M. Descoteaux, I. Nimmo-Smith and DIPY contributors,
"DIPY, a library for the analysis of diffusion MRI data",
Frontiers in Neuroinformatics, vol. 8, p. 8, Frontiers, 2014.
6 changes: 3 additions & 3 deletions dipy/align/imwarp.py
Expand Up @@ -1373,9 +1373,9 @@ def _get_energy_derivative(self):
x = range(self.energy_window)
y = self.energy_list[(n_iter - self.energy_window):n_iter]
ss = sum(y)
if(ss > 0):
ss *= -1
y = [v / ss for v in y]
if not ss == 0: # avoid division by zero
ss = - ss if ss > 0 else ss
y = [v / ss for v in y]
der = self._approximate_derivative_direct(x, y)
return der

Expand Down
Binary file removed dipy/data/files/test_ui_file_select_menu_2d.log.gz
Binary file not shown.
Binary file removed dipy/data/files/test_ui_file_select_menu_2d.pkl
Binary file not shown.
Binary file added dipy/data/files/test_ui_image_holder.log.gz
Binary file not shown.
Binary file added dipy/data/files/test_ui_image_holder.pkl
Binary file not shown.
Binary file added dipy/data/files/test_ui_listbox_2d.log.gz
Binary file not shown.
Binary file added dipy/data/files/test_ui_listbox_2d.pkl
Binary file not shown.
67 changes: 42 additions & 25 deletions dipy/reconst/dki.py
Expand Up @@ -121,6 +121,7 @@ def carlson_rd(x, y, z, errtol=1e-4):
defined as:

.. math::

R_D = \frac{3}{2} \int_{0}^{\infty} (t+x)^{-\frac{1}{2}}
(t+y)^{-\frac{1}{2}}(t+z) ^{-\frac{3}{2}}

Expand Down Expand Up @@ -302,6 +303,7 @@ def _F2m(a, b, c):
Function $F_2$ is defined as [1]_:

.. math::

F_2(\lambda_1,\lambda_2,\lambda_3)=
\frac{(\lambda_1+\lambda_2+\lambda_3)^2}
{3(\lambda_2-\lambda_3)^2}
Expand Down Expand Up @@ -574,6 +576,7 @@ def apparent_kurtosis_coef(dki_params, sphere, min_diffusivity=0,
calculation of AKC is done using formula [1]_:

.. math ::

AKC(n)=\frac{MD^{2}}{ADC(n)^{2}}\sum_{i=1}^{3}\sum_{j=1}^{3}
\sum_{k=1}^{3}\sum_{l=1}^{3}n_{i}n_{j}n_{k}n_{l}W_{ijkl}

Expand Down Expand Up @@ -662,36 +665,39 @@ def mean_kurtosis(dki_params, min_kurtosis=-3./7, max_kurtosis=3):
Notes
--------
The MK analytical solution is calculated using the following equation [1]_:

.. math::

MK=F_1(\lambda_1,\lambda_2,\lambda_3)\hat{W}_{1111}+
F_1(\lambda_2,\lambda_1,\lambda_3)\hat{W}_{2222}+
F_1(\lambda_3,\lambda_2,\lambda_1)\hat{W}_{3333}+ \\
F_2(\lambda_1,\lambda_2,\lambda_3)\hat{W}_{2233}+
F_2(\lambda_2,\lambda_1,\lambda_3)\hat{W}_{1133}+
F_2(\lambda_3,\lambda_2,\lambda_1)\hat{W}_{1122}
MK=F_1(\lambda_1,\lambda_2,\lambda_3)\hat{W}_{1111}+
F_1(\lambda_2,\lambda_1,\lambda_3)\hat{W}_{2222}+
F_1(\lambda_3,\lambda_2,\lambda_1)\hat{W}_{3333}+ \\
F_2(\lambda_1,\lambda_2,\lambda_3)\hat{W}_{2233}+
F_2(\lambda_2,\lambda_1,\lambda_3)\hat{W}_{1133}+
F_2(\lambda_3,\lambda_2,\lambda_1)\hat{W}_{1122}

where $\hat{W}_{ijkl}$ are the components of the $W$ tensor in the
coordinates system defined by the eigenvectors of the diffusion tensor
$\mathbf{D}$ and

F_1(\lambda_1,\lambda_2,\lambda_3)=
\frac{(\lambda_1+\lambda_2+\lambda_3)^2}
{18(\lambda_1-\lambda_2)(\lambda_1-\lambda_3)}
[\frac{\sqrt{\lambda_2\lambda_3}}{\lambda_1}
R_F(\frac{\lambda_1}{\lambda_2},\frac{\lambda_1}{\lambda_3},1)+\\
\frac{3\lambda_1^2-\lambda_1\lambda_2-\lambda_2\lambda_3-
\lambda_1\lambda_3}
{3\lambda_1 \sqrt{\lambda_2 \lambda_3}}
R_D(\frac{\lambda_1}{\lambda_2},\frac{\lambda_1}{\lambda_3},1)-1 ]

F_2(\lambda_1,\lambda_2,\lambda_3)=
\frac{(\lambda_1+\lambda_2+\lambda_3)^2}
{3(\lambda_2-\lambda_3)^2}
[\frac{\lambda_2+\lambda_3}{\sqrt{\lambda_2\lambda_3}}
R_F(\frac{\lambda_1}{\lambda_2},\frac{\lambda_1}{\lambda_3},1)+\\
\frac{2\lambda_1-\lambda_2-\lambda_3}{3\sqrt{\lambda_2 \lambda_3}}
R_D(\frac{\lambda_1}{\lambda_2},\frac{\lambda_1}{\lambda_3},1)-2]
.. math::

F_1(\lambda_1,\lambda_2,\lambda_3)=
\frac{(\lambda_1+\lambda_2+\lambda_3)^2}
{18(\lambda_1-\lambda_2)(\lambda_1-\lambda_3)}
[\frac{\sqrt{\lambda_2\lambda_3}}{\lambda_1}
R_F(\frac{\lambda_1}{\lambda_2},\frac{\lambda_1}{\lambda_3},1)+\\
\frac{3\lambda_1^2-\lambda_1\lambda_2-\lambda_2\lambda_3-
\lambda_1\lambda_3}
{3\lambda_1 \sqrt{\lambda_2 \lambda_3}}
R_D(\frac{\lambda_1}{\lambda_2},\frac{\lambda_1}{\lambda_3},1)-1 ]

F_2(\lambda_1,\lambda_2,\lambda_3)=
\frac{(\lambda_1+\lambda_2+\lambda_3)^2}
{3(\lambda_2-\lambda_3)^2}
[\frac{\lambda_2+\lambda_3}{\sqrt{\lambda_2\lambda_3}}
R_F(\frac{\lambda_1}{\lambda_2},\frac{\lambda_1}{\lambda_3},1)+\\
\frac{2\lambda_1-\lambda_2-\lambda_3}{3\sqrt{\lambda_2 \lambda_3}}
R_D(\frac{\lambda_1}{\lambda_2},\frac{\lambda_1}{\lambda_3},1)-2]

where $R_f$ and $R_d$ are the Carlson's elliptic integrals.

Expand Down Expand Up @@ -764,6 +770,7 @@ def _G1m(a, b, c):
Notes
--------
Function $G_1$ is defined as [1]_:

.. math::

G_1(\lambda_1,\lambda_2,\lambda_3)=
Expand Down Expand Up @@ -829,7 +836,9 @@ def _G2m(a, b, c):
Notes
--------
Function $G_2$ is defined as [1]_:

.. math::

G_2(\lambda_1,\lambda_2,\lambda_3)=
\frac{(\lambda_1+\lambda_2+\lambda_3)^2}{(\lambda_2-\lambda_3)^2}
\left ( \frac{\lambda_2+\lambda_3}{\sqrt{\lambda_2\lambda_3}}-2\right )
Expand Down Expand Up @@ -899,14 +908,18 @@ def radial_kurtosis(dki_params, min_kurtosis=-3./7, max_kurtosis=10):

Notes
--------
RK is calculated with the following equation [1]_::
RK is calculated with the following equation [1]_:

.. math::

K_{\bot} = G_1(\lambda_1,\lambda_2,\lambda_3)\hat{W}_{2222} +
G_1(\lambda_1,\lambda_3,\lambda_2)\hat{W}_{3333} +
G_2(\lambda_1,\lambda_2,\lambda_3)\hat{W}_{2233}

where:

.. math::

G_1(\lambda_1,\lambda_2,\lambda_3)=
\frac{(\lambda_1+\lambda_2+\lambda_3)^2}{18\lambda_2(\lambda_2-
\lambda_3)} \left (2\lambda_2 +
Expand All @@ -916,6 +929,7 @@ def radial_kurtosis(dki_params, min_kurtosis=-3./7, max_kurtosis=10):
and

.. math::

G_2(\lambda_1,\lambda_2,\lambda_3)=
\frac{(\lambda_1+\lambda_2+\lambda_3)^2}{(\lambda_2-\lambda_3)^2}
\left ( \frac{\lambda_2+\lambda_3}{\sqrt{\lambda_2\lambda_3}}-2\right )
Expand Down Expand Up @@ -1220,6 +1234,7 @@ def dki_prediction(dki_params, gtab, S0=1.):
.. math::

S=S_{0}e^{-bD+\frac{1}{6}b^{2}D^{2}K}

"""
evals, evecs, kt = split_dki_param(dki_params)

Expand Down Expand Up @@ -1417,13 +1432,15 @@ def akc(self, sphere):
calculation of AKC is done using formula:

.. math ::

AKC(n)=\frac{MD^{2}}{ADC(n)^{2}}\sum_{i=1}^{3}\sum_{j=1}^{3}
\sum_{k=1}^{3}\sum_{l=1}^{3}n_{i}n_{j}n_{k}n_{l}W_{ijkl}

where $W_{ijkl}$ are the elements of the kurtosis tensor, MD the mean
diffusivity and ADC the apparent diffusion coefficent computed as:

.. math ::

ADC(n)=\sum_{i=1}^{3}\sum_{j=1}^{3}n_{i}n_{j}D_{ij}

where $D_{ij}$ are the elements of the diffusion tensor.
Expand Down Expand Up @@ -2014,7 +2031,7 @@ def Wcons(k_elements):
k_elements : (15,)
elements of the kurtosis tensor in the following order:

.. math::
.. math::

\begin{matrix} ( & W_{xxxx} & W_{yyyy} & W_{zzzz} & W_{xxxy} & W_{xxxz}
& ... \\
Expand Down
4 changes: 2 additions & 2 deletions dipy/reconst/mapmri.py
Expand Up @@ -401,8 +401,8 @@ def fit(self, data):
lopt * cvxpy.quad_form(c, laplacian_matrix)
)
M0 = M[self.gtab.b0s_mask, :]
constraints = [M0[0] * c == 1,
K * c > -.1]
constraints = [(M0[0] * c) == 1,
(K * c) >= -0.1]
prob = cvxpy.Problem(objective, constraints)
try:
prob.solve(solver=self.cvxpy_solver)
Expand Down
2 changes: 1 addition & 1 deletion dipy/reconst/shore.py
Expand Up @@ -269,7 +269,7 @@ def fit(self, data):
self.cache_set(
'shore_matrix_positive_constraint',
(self.pos_grid, self.pos_radius), psi)
constraints = [M0[0] * c == 1., psi * c > 1e-3]
constraints = [(M0[0] * c) == 1., (psi * c) >= 1e-3]
prob = cvxpy.Problem(objective, constraints)
try:
prob.solve(solver=self.cvxpy_solver)
Expand Down
4 changes: 2 additions & 2 deletions dipy/reconst/tests/test_forecast.py
Expand Up @@ -50,11 +50,11 @@ def test_forecast_positive_constrain():

sphere = get_sphere('repulsion100')
fodf = f_fit.odf(sphere, clip_negative=False)
assert_equal(fodf[fodf < 0].sum(), 0)
assert_almost_equal(fodf[fodf < 0].sum(), 0, 2)

coeff = f_fit.sh_coeff
c0 = np.sqrt(1.0/(4*np.pi))
assert_almost_equal(coeff[0], c0, 10)
assert_almost_equal(coeff[0], c0, 5)


def test_forecast_csd():
Expand Down
2 changes: 1 addition & 1 deletion dipy/reconst/tests/test_shore.py
Expand Up @@ -53,7 +53,7 @@ def test_shore_positive_constrain():
pos_radius=20e-03)
asmfit = asm.fit(data.S)
eap = asmfit.pdf_grid(11, 20e-03)
assert_equal(eap[eap < 0].sum(), 0)
assert_almost_equal(eap[eap < 0].sum(), 0, 3)


def test_shore_fitting_no_constrain_e0():
Expand Down
67 changes: 35 additions & 32 deletions dipy/tracking/streamline.py
Expand Up @@ -29,16 +29,19 @@

MEGABYTE = 1024 * 1024


class _BuildCache(object):
def __init__(self, arr_seq, common_shape, dtype):
self.offsets = list(arr_seq._offsets)
self.lengths = list(arr_seq._lengths)
self.next_offset = arr_seq._get_next_offset()
self.bytes_per_buf = arr_seq._buffer_size * MEGABYTE
# Use the passed dtype only if null data array
self.dtype = dtype if arr_seq._data.size == 0 else arr_seq._data.dtype
if arr_seq.common_shape != () and common_shape != arr_seq.common_shape:
if arr_seq._data.size == 0:
self.dtype = dtype
else:
arr_seq._data.dtype
if (arr_seq.common_shape != () and
common_shape != arr_seq.common_shape):
raise ValueError(
"All dimensions, except the first one, must match exactly")
self.common_shape = common_shape
Expand All @@ -50,34 +53,32 @@ def update_seq(self, arr_seq):
arr_seq._offsets = np.array(self.offsets)
arr_seq._lengths = np.array(self.lengths)


class Streamlines(ArraySequence):

def __init__(self, *args, **kwargs):
super(Streamlines, self).__init__(*args, **kwargs)

def append(self, element, cache_build=False):
""" Appends `element` to this array sequence.
"""
Appends `element` to this array sequence.

Append can be a lot faster if it knows that it is appending several
elements instead of a single element. In that case it can cache the
parameters it uses between append operations, in a "build cache". To
tell append to do this, use ``cache_build=True``. If you use
``cache_build=True``, you need to finalize the append operations with
:meth:`finalize_append`.
elements instead of a single element. In that case it can cache
the parameters it uses between append operations, in a "build
cache". To tell append to do this, use ``cache_build=True``. If
you use ``cache_build=True``, you need to finalize the append
operations with :meth:`finalize_append`.

Parameters
----------
element : ndarray
Element to append. The shape must match already inserted elements
shape except for the first dimension.
cache_build : {False, True}
Whether to save the build cache from this append routine. If True,
append can assume it is the only player updating `self`, and the
caller must finalize `self` after all append operations, with
``self.finalize_append()``.
Returns
element : ndarray Element to append. The shape must match already
inserted elements shape except for the first dimension.
cache_build : {False, True} Whether to save the build cache
from this append routine. If True, append can assume it is the
only player updating `self`, and the caller must finalize
`self` after all append operations, with
``self.finalize_append()``. Returns
-------
None
Notes
None Notes
-----
If you need to add multiple elements you should consider
`ArraySequence.extend`.
Expand Down Expand Up @@ -124,19 +125,20 @@ def extend(self, elements):
""" Appends all `elements` to this array sequence.
Parameters
----------
elements : iterable of ndarrays or :class:`ArraySequence` object
If iterable of ndarrays, each ndarray will be concatenated along
the first dimension then appended to the data of this
elements : iterable of ndarrays or :class:`ArraySequence` instance

If iterable of ndarrays, each ndarray will be concatenated
along the first dimension then appended to the data of this
ArraySequence.
If :class:`ArraySequence` object, its data are simply appended to
the data of this ArraySequence.
If :class:`ArraySequence` object, its data are simply appended
to the data of this ArraySequence.

Returns
-------
None
Notes
None Notes
-----
The shape of the elements to be added must match the one of the data of
this :class:`ArraySequence` except for the first dimension.
The shape of the elements to be added must match the one of the
data of this :class:`ArraySequence` except for the first dimension.
"""
# If possible try pre-allocating memory.
try:
Expand Down Expand Up @@ -597,7 +599,8 @@ def _extract_vals(data, streamlines, affine=None, threedvec=False):
"""
data = data.astype(np.float)
if (isinstance(streamlines, list) or
isinstance(streamlines, types.GeneratorType)):
isinstance(streamlines, types.GeneratorType) or
isinstance(streamlines, Streamlines)):
if affine is not None:
streamlines = ut.move_streamlines(streamlines,
np.linalg.inv(affine))
Expand Down
3 changes: 3 additions & 0 deletions dipy/tracking/tests/test_streamline.py
Expand Up @@ -1027,6 +1027,9 @@ def test_values_from_volume():
vv = values_from_volume(data, np.array(sl1))
npt.assert_almost_equal(vv, ans1, decimal=decimal)

vv = values_from_volume(data, Streamlines(sl1))
npt.assert_almost_equal(vv, ans1, decimal=decimal)

affine = np.eye(4)
affine[:, 3] = [-100, 10, 1, 1]
x_sl1 = ut.move_streamlines(sl1, affine)
Expand Down