@@ -188,7 +188,7 @@ class TractogramItem(object):
188
188
where N is the number of points.
189
189
data_for_streamline : dict
190
190
Dictionary containing some data associated to this particular
191
- streamline. Each key `k` is mapped to a ndarray of shape (Pk ,), where
191
+ streamline. Each key `k` is mapped to a ndarray of shape (Pt ,), where
192
192
`Pt` is the dimension of the data associated with key `k`.
193
193
data_for_points : dict
194
194
Dictionary containing some data associated to each point of this
@@ -225,17 +225,17 @@ class Tractogram(object):
225
225
streamline $t$.
226
226
data_per_streamline : :class:`PerArrayDict` object
227
227
Dictionary where the items are (str, 2D array).
228
- Each key represents an information $i$ to be kept along side every
228
+ Each key represents an information $i$ to be kept alongside every
229
229
streamline, and its associated value is a 2D array of shape
230
230
($T$, $P_i$) where $T$ is the number of streamlines and $P_i$ is
231
- the number scalar values to store for that particular information $i$.
231
+ the number of values to store for that particular information $i$.
232
232
data_per_point : :class:`PerArraySequenceDict` object
233
233
Dictionary where the items are (str, :class:`ArraySequence`).
234
- Each key represents an information $i$ to be kept along side every
234
+ Each key represents an information $i$ to be kept alongside every
235
235
point of every streamline, and its associated value is an iterable
236
236
of ndarrays of shape ($N_t$, $M_i$) where $N_t$ is the number of
237
237
points for a particular streamline $t$ and $M_i$ is the number
238
- scalar values to store for that particular information $i$.
238
+ values to store for that particular information $i$.
239
239
"""
240
240
def __init__ (self , streamlines = None ,
241
241
data_per_streamline = None ,
@@ -250,13 +250,13 @@ def __init__(self, streamlines=None,
250
250
streamline $t$.
251
251
data_per_streamline : dict of iterable of ndarrays, optional
252
252
Dictionary where the items are (str, iterable).
253
- Each key represents an information $i$ to be kept along side every
253
+ Each key represents an information $i$ to be kept alongside every
254
254
streamline, and its associated value is an iterable of ndarrays of
255
- shape ($P_i$,) where $P_i$ is the number scalar values to store
255
+ shape ($P_i$,) where $P_i$ is the number of scalar values to store
256
256
for that particular information $i$.
257
257
data_per_point : dict of iterable of ndarrays, optional
258
258
Dictionary where the items are (str, iterable).
259
- Each key represents an information $i$ to be kept along side every
259
+ Each key represents an information $i$ to be kept alongside every
260
260
point of every streamline, and its associated value is an iterable
261
261
of ndarrays of shape ($N_t$, $M_i$) where $N_t$ is the number of
262
262
points for a particular streamline $t$ and $M_i$ is the number
@@ -303,6 +303,13 @@ def affine_to_rasmm(self):
303
303
304
304
@affine_to_rasmm .setter
305
305
def affine_to_rasmm (self , value ):
306
+ if value is not None :
307
+ value = np .array (value )
308
+ if value .shape != (4 , 4 ):
309
+ msg = ("Affine matrix has a shape of (4, 4) but a ndarray with"
310
+ "shape {} was provided instead." ).format (value .shape )
311
+ raise ValueError (msg )
312
+
306
313
self ._affine_to_rasmm = value
307
314
308
315
def __iter__ (self ):
@@ -362,6 +369,9 @@ def apply_affine(self, affine, lazy=False):
362
369
if len (self .streamlines ) == 0 :
363
370
return self
364
371
372
+ if np .all (affine == np .eye (4 )):
373
+ return self # No transformation.
374
+
365
375
BUFFER_SIZE = 10000000 # About 128 Mb since pts shape is 3.
366
376
for start in range (0 , len (self .streamlines .data ), BUFFER_SIZE ):
367
377
end = start + BUFFER_SIZE
@@ -408,7 +418,7 @@ class LazyTractogram(Tractogram):
408
418
409
419
This container behaves lazily as it uses generator functions to manage
410
420
streamlines and their data information. This container is thus memory
411
- friendly since it doesn't require having all those data loaded in memory.
421
+ friendly since it doesn't require having all this data loaded in memory.
412
422
413
423
Streamlines of a lazy tractogram can be in any coordinate system of your
414
424
choice as long as you provide the correct `affine_to_rasmm` matrix, at
@@ -424,23 +434,26 @@ class LazyTractogram(Tractogram):
424
434
streamline $t$.
425
435
data_per_streamline : :class:`LazyDict` object
426
436
Dictionary where the items are (str, instantiated generator).
427
- Each key represents an information $i$ to be kept along side every
437
+ Each key represents an information $i$ to be kept alongside every
428
438
streamline, and its associated value is a generator function
429
439
yielding that information via ndarrays of shape ($P_i$,) where
430
- $P_i$ is the number scalar values to store for that particular
440
+ $P_i$ is the number of values to store for that particular
431
441
information $i$.
432
442
data_per_point : :class:`LazyDict` object
433
443
Dictionary where the items are (str, instantiated generator).
434
- Each key represents an information $i$ to be kept along side every
444
+ Each key represents an information $i$ to be kept alongside every
435
445
point of every streamline, and its associated value is a generator
436
446
function yielding that information via ndarrays of shape
437
447
($N_t$, $M_i$) where $N_t$ is the number of points for a particular
438
- streamline $t$ and $M_i$ is the number scalar values to store for
448
+ streamline $t$ and $M_i$ is the number of values to store for
439
449
that particular information $i$.
440
450
441
451
Notes
442
452
-----
443
453
LazyTractogram objects do not support indexing currently.
454
+ LazyTractogram objects are suited for operations that can be linearized
455
+ such as applying an affine transformation or converting streamlines from
456
+ one file format to another.
444
457
"""
445
458
def __init__ (self , streamlines = None ,
446
459
data_per_streamline = None ,
@@ -455,18 +468,18 @@ def __init__(self, streamlines=None,
455
468
streamline $t$.
456
469
data_per_streamline : dict of generator functions, optional
457
470
Dictionary where the items are (str, generator function).
458
- Each key represents an information $i$ to be kept along side every
471
+ Each key represents an information $i$ to be kept alongside every
459
472
streamline, and its associated value is a generator function
460
473
yielding that information via ndarrays of shape ($P_i$,) where
461
- $P_i$ is the number scalar values to store for that particular
474
+ $P_i$ is the number of values to store for that particular
462
475
information $i$.
463
476
data_per_point : dict of generator functions, optional
464
477
Dictionary where the items are (str, generator function).
465
- Each key represents an information $i$ to be kept along side every
478
+ Each key represents an information $i$ to be kept alongside every
466
479
point of every streamline, and its associated value is a generator
467
480
function yielding that information via ndarrays of shape
468
481
($N_t$, $M_i$) where $N_t$ is the number of points for a particular
469
- streamline $t$ and $M_i$ is the number scalar values to store for
482
+ streamline $t$ and $M_i$ is the number of values to store for
470
483
that particular information $i$.
471
484
affine_to_rasmm : ndarray of shape (4, 4) or None, optional
472
485
Transformation matrix that brings the streamlines contained in
@@ -525,7 +538,7 @@ def create_from(cls, data_func):
525
538
Parameters
526
539
----------
527
540
data_func : generator function yielding :class:`TractogramItem` objects
528
- Generator function that whenever it is called starts yielding
541
+ Generator function that whenever is called starts yielding
529
542
:class:`TractogramItem` objects that will be used to instantiate a
530
543
:class:`LazyTractogram`.
531
544
@@ -650,9 +663,7 @@ def __len__(self):
650
663
warn ("Number of streamlines will be determined manually by looping"
651
664
" through the streamlines. If you know the actual number of"
652
665
" streamlines, you might want to set it beforehand via"
653
- " `self.header.nb_streamlines`."
654
- " Note this will consume any generators used to create this"
655
- " `LazyTractogram` object." , Warning )
666
+ " `self.header.nb_streamlines`." , Warning )
656
667
# Count the number of streamlines.
657
668
self ._nb_streamlines = sum (1 for _ in self .streamlines )
658
669
0 commit comments