Skip to content

Commit 111f53a

Browse files
committed
Clarified Tractogram and LazyTractogram docstring
1 parent 909e0b6 commit 111f53a

File tree

1 file changed

+80
-28
lines changed

1 file changed

+80
-28
lines changed

nibabel/streamlines/tractogram.py

Lines changed: 80 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -193,17 +193,33 @@ def __len__(self):
193193

194194

195195
class Tractogram(object):
196-
""" Class containing information about streamlines.
197-
198-
Tractogram objects have three main properties: `streamlines`,
199-
`data_per_streamline` and `data_per_point`.
196+
""" Container for streamlines and their data information.
200197
201198
Streamlines of a tractogram can be in any coordinate system of your
202199
choice as long as you provide the correct `affine_to_rasmm` matrix, at
203200
construction time, that brings the streamlines back to *RAS+*, *mm* space,
204201
where the coordinates (0,0,0) corresponds to the center of the voxel
205202
(opposed to a corner).
206203
204+
Attributes
205+
----------
206+
streamlines : :class:`ArraySequence` object
207+
Sequence of $T$ streamlines. Each streamline is an ndarray of
208+
shape ($N_t$, 3) where $N_t$ is the number of points of
209+
streamline $t$.
210+
data_per_streamline : dict of 2D arrays
211+
Dictionary where the items are (str, 2D array).
212+
Each key represents an information $i$ to be kept along side every
213+
streamline, and its associated value is a 2D array of shape
214+
($T$, $P_i$) where $T$ is the number of streamlines and $P_i$ is
215+
the number scalar values to store for that particular information $i$.
216+
data_per_point : dict of :class:`ArraySequence` objects
217+
Dictionary where the items are (str, :class:`ArraySequence`).
218+
Each key represents an information $i$ to be kept along side every
219+
point of every streamline, and its associated value is an iterable
220+
of ndarrays of shape ($N_t$, $M_i$) where $N_t$ is the number of
221+
points for a particular streamline $t$ and $M_i$ is the number
222+
scalar values to store for that particular information $i$.
207223
"""
208224
def __init__(self, streamlines=None,
209225
data_per_streamline=None,
@@ -212,19 +228,23 @@ def __init__(self, streamlines=None,
212228
"""
213229
Parameters
214230
----------
215-
streamlines : list of ndarray of shape (Nt, 3) (optional)
216-
Sequence of T streamlines. One streamline is an ndarray of
217-
shape (Nt, 3) where Nt is the number of points of streamline t.
218-
data_per_streamline : dict of list of ndarray of shape (P,) (optional)
219-
Sequence of T ndarrays of shape (P,) where T is the number of
220-
streamlines defined by `streamlines`, P is the number of
221-
properties associated to each streamline.
222-
data_per_point : dict of list of ndarray of shape (Nt, M) (optional)
223-
Sequence of T ndarrays of shape (Nt, M) where T is the number
224-
of streamlines defined by `streamlines`, Nt is the number of
225-
points for a particular streamline t and M is the number of
226-
scalars associated to each point (excluding the three
227-
coordinates).
231+
streamlines : iterable of ndarrays or :class:`ArraySequence`, optional
232+
Sequence of $T$ streamlines. Each streamline is an ndarray of
233+
shape ($N_t$, 3) where $N_t$ is the number of points of
234+
streamline $t$.
235+
data_per_streamline : dict of iterable of ndarrays, optional
236+
Dictionary where the items are (str, iterable).
237+
Each key represents an information $i$ to be kept along side every
238+
streamline, and its associated value is an iterable of ndarrays of
239+
shape ($P_i$,) where $P_i$ is the number scalar values to store
240+
for that particular information $i$.
241+
data_per_point : dict of iterable of ndarrays, optional
242+
Dictionary where the items are (str, iterable).
243+
Each key represents an information $i$ to be kept along side every
244+
point of every streamline, and its associated value is an iterable
245+
of ndarrays of shape ($N_t$, $M_i$) where $N_t$ is the number of
246+
points for a particular streamline $t$ and $M_i$ is the number
247+
scalar values to store for that particular information $i$.
228248
affine_to_rasmm : ndarray of shape (4, 4)
229249
Transformation matrix that brings the streamlines contained in
230250
this tractogram to *RAS+* and *mm* space where coordinate (0,0,0)
@@ -357,26 +377,53 @@ def to_world(self, lazy=False):
357377

358378

359379
class LazyTractogram(Tractogram):
360-
""" Class containing information about streamlines.
380+
""" Lazy container for streamlines and their data information.
381+
382+
This container behaves lazily as it uses generator functions to manage
383+
streamlines and their data information. This container is thus memory
384+
friendly since it doesn't require having all those data loaded in memory.
385+
386+
Streamlines of a lazy tractogram can be in any coordinate system of your
387+
choice as long as you provide the correct `affine_to_rasmm` matrix, at
388+
construction time, that brings the streamlines back to *RAS+*, *mm* space,
389+
where the coordinates (0,0,0) corresponds to the center of the voxel
390+
(opposed to a corner).
361391
362-
Tractogram objects have four main properties: `header`, `streamlines`,
363-
`scalars` and `properties`. Tractogram objects are iterable and
364-
produce tuple of `streamlines`, `scalars` and `properties` for each
365-
streamline.
392+
Attributes
393+
----------
394+
streamlines : generator function
395+
Generator function yielding streamlines. Each streamline is an
396+
ndarray of shape ($N_t$, 3) where $N_t$ is the number of points of
397+
streamline $t$.
398+
data_per_streamline : :class:`LazyDict` object
399+
Dictionary where the items are (str, instantiated generator).
400+
Each key represents an information $i$ to be kept along side every
401+
streamline, and its associated value is a generator function
402+
yielding that information via ndarrays of shape ($P_i$,) where
403+
$P_i$ is the number scalar values to store for that particular
404+
information $i$.
405+
data_per_point : :class:`LazyDict` object
406+
Dictionary where the items are (str, instantiated generator).
407+
Each key represents an information $i$ to be kept along side every
408+
point of every streamline, and its associated value is a generator
409+
function yielding that information via ndarrays of shape
410+
($N_t$, $M_i$) where $N_t$ is the number of points for a particular
411+
streamline $t$ and $M_i$ is the number scalar values to store for
412+
that particular information $i$.
366413
367414
Notes
368415
-----
369-
If provided, `scalars` and `properties` must yield the same number of
370-
values as `streamlines`.
416+
LazyTractogram objects do not support indexing currently.
371417
"""
372418
def __init__(self, streamlines=None,
373419
data_per_streamline=None,
374-
data_per_point=None):
420+
data_per_point=None,
421+
affine_to_rasmm=np.eye(4)):
375422
"""
376423
Parameters
377424
----------
378-
streamlines : generator function yielding, optional
379-
Generator function yielding streamlines. One streamline is an
425+
streamlines : generator function, optional
426+
Generator function yielding streamlines. Each streamline is an
380427
ndarray of shape ($N_t$, 3) where $N_t$ is the number of points of
381428
streamline $t$.
382429
data_per_streamline : dict of generator functions, optional
@@ -394,10 +441,15 @@ def __init__(self, streamlines=None,
394441
($N_t$, $M_i$) where $N_t$ is the number of points for a particular
395442
streamline $t$ and $M_i$ is the number scalar values to store for
396443
that particular information $i$.
444+
affine_to_rasmm : ndarray of shape (4, 4)
445+
Transformation matrix that brings the streamlines contained in
446+
this tractogram to *RAS+* and *mm* space where coordinate (0,0,0)
447+
refers to the center of the voxel.
397448
"""
398449
super(LazyTractogram, self).__init__(streamlines,
399450
data_per_streamline,
400-
data_per_point)
451+
data_per_point,
452+
affine_to_rasmm)
401453
self._nb_streamlines = None
402454
self._data = None
403455
self._affine_to_apply = np.eye(4)

0 commit comments

Comments
 (0)