@@ -25,18 +25,16 @@ class SliceableDataDict(collections.MutableMapping):
25
25
This container behaves like a standard dictionary but extends key access to
26
26
allow keys for key access to be indices slicing into the contained ndarray
27
27
values.
28
+
29
+ Parameters
30
+ ----------
31
+ \*args :
32
+ \*\*kwargs :
33
+ Positional and keyword arguments, passed straight through the ``dict``
34
+ constructor.
28
35
"""
29
36
def __init__ (self , * args , ** kwargs ):
30
37
self .store = dict ()
31
- # Use the 'update' method to set the keys.
32
- if len (args ) == 1 :
33
- if args [0 ] is None :
34
- return
35
-
36
- if isinstance (args [0 ], SliceableDataDict ):
37
- self .update (** args [0 ])
38
- return
39
-
40
38
self .update (dict (* args , ** kwargs ))
41
39
42
40
def __getitem__ (self , key ):
@@ -47,9 +45,9 @@ def __getitem__(self, key):
47
45
48
46
# Try to interpret key as an index/slice for every data element, in
49
47
# which case we perform (maybe advanced) indexing on every element of
50
- # the dictionnary .
48
+ # the dictionary .
51
49
idx = key
52
- new_dict = type (self )(None )
50
+ new_dict = type (self )()
53
51
try :
54
52
for k , v in self .items ():
55
53
new_dict [k ] = v [idx ]
@@ -81,8 +79,18 @@ class PerArrayDict(SliceableDataDict):
81
79
In addition, it makes sure the amount of data contained in those ndarrays
82
80
matches the number of streamlines given at the instantiation of this
83
81
instance.
82
+
83
+ Parameters
84
+ ----------
85
+ nb_elements : None or int, optional
86
+ Number of elements per value in each key, value pair or None for not
87
+ specified.
88
+ \*args :
89
+ \*\*kwargs :
90
+ Positional and keyword arguments, passed straight through the ``dict``
91
+ constructor.
84
92
"""
85
- def __init__ (self , nb_elements , * args , ** kwargs ):
93
+ def __init__ (self , nb_elements = None , * args , ** kwargs ):
86
94
self .nb_elements = nb_elements
87
95
super (PerArrayDict , self ).__init__ (* args , ** kwargs )
88
96
@@ -105,7 +113,7 @@ def __setitem__(self, key, value):
105
113
self .store [key ] = value
106
114
107
115
108
- class PerArraySequenceDict (SliceableDataDict ):
116
+ class PerArraySequenceDict (PerArrayDict ):
109
117
""" Dictionary for which key access can do slicing on the values.
110
118
111
119
This container behaves like a standard dictionary but extends key access to
@@ -116,10 +124,6 @@ class PerArraySequenceDict(SliceableDataDict):
116
124
sequences matches the number of elements given at the instantiation
117
125
of the instance.
118
126
"""
119
- def __init__ (self , nb_elements , * args , ** kwargs ):
120
- self .nb_elements = nb_elements
121
- super (PerArraySequenceDict , self ).__init__ (* args , ** kwargs )
122
-
123
127
def __setitem__ (self , key , value ):
124
128
value = ArraySequence (value )
125
129
@@ -285,7 +289,8 @@ def data_per_streamline(self):
285
289
286
290
@data_per_streamline .setter
287
291
def data_per_streamline (self , value ):
288
- self ._data_per_streamline = PerArrayDict (len (self .streamlines ), value )
292
+ self ._data_per_streamline = PerArrayDict (
293
+ len (self .streamlines ), {} if value is None else value )
289
294
290
295
@property
291
296
def data_per_point (self ):
@@ -294,7 +299,7 @@ def data_per_point(self):
294
299
@data_per_point .setter
295
300
def data_per_point (self , value ):
296
301
self ._data_per_point = PerArraySequenceDict (
297
- self .streamlines .nb_elements , value )
302
+ self .streamlines .nb_elements , {} if value is None else value )
298
303
299
304
@property
300
305
def affine_to_rasmm (self ):
0 commit comments