4
4
5
5
class ActiveOptionsContainer :
6
6
"""
7
- Container for ActiveOptions properties.
7
+ Container for ActiveOptions properties. Only for use within XarrayActive.
8
8
"""
9
9
@property
10
10
def active_options (self ):
@@ -39,19 +39,24 @@ def _set_active_options(self, chunks={}, chunk_limits=True):
39
39
self ._active_chunks = chunks
40
40
self ._chunk_limits = chunk_limits
41
41
42
- # Holds all Active routines.
43
42
class ActiveChunk :
43
+ """
44
+ Container class for all Active-required methods to perform on each chunk.
45
+ All active-per-chunk content should be found here.
46
+ """
44
47
45
- description = "Container class for Active routines performed on each chunk. All active-per-chunk content can be found here. "
48
+ description = "Container class for Active routines performed on each chunk."
46
49
47
50
def _post_process_data (self , data ):
48
- # Perform any post-processing steps on the data here
51
+ """
52
+ Perform any post-processing steps on the data here.
53
+ """
49
54
return data
50
55
51
56
def _standard_sum (self , axes = None , skipna = None , ** kwargs ):
52
57
"""
53
- Standard Mean routine matches the normal routine for dask, required at this
54
- stage if Active mean not available.
58
+ Standard sum routine matches the normal routine for dask, required at this
59
+ stage if Active mean/sum not available.
55
60
"""
56
61
57
62
arr = np .array (self )
@@ -62,12 +67,31 @@ def _standard_sum(self, axes=None, skipna=None, **kwargs):
62
67
return total
63
68
64
69
def _standard_max (self , axes = None , skipna = None , ** kwargs ):
70
+ """
71
+ Standard max routine if Active not available, warning will be given.
72
+ Kwargs may be necessary to add here.
73
+ """
65
74
return np .max (self , axis = axes )
66
75
67
76
def _standard_min (self , axes = None , skipna = None , ** kwargs ):
77
+ """
78
+ Standard min routine if Active not available, warning will be given.
79
+ Kwargs may be necessary to add here.
80
+ """
68
81
return np .min (self , axis = axes )
69
82
70
83
def _numel (self , method , axes = None ):
84
+ """
85
+ Number of elements remaining after a reduction, to allow
86
+ dask to combine reductions from all different chunks.
87
+ Example:
88
+ (2,3,4) chunk reduced along second dimension. Will
89
+ give a (2,3) array where each value is 4 - for the
90
+ length of the dimension along which a reduction
91
+ took place.
92
+
93
+ """
94
+ # Applied reduction across all axes
71
95
if not axes :
72
96
return self .size
73
97
@@ -98,20 +122,20 @@ def active_method(self, method, axis=None, skipna=None, **kwargs):
98
122
'max' : self ._standard_max ,
99
123
'min' : self ._standard_min
100
124
}
101
- ret = None
125
+ partial = None
102
126
n = self ._numel (method , axes = axis )
103
127
104
128
try :
105
129
from activestorage .active import Active
106
130
except ImportError :
107
131
# Unable to import Active package. Default to using normal mean.
108
132
print ("ActiveWarning: Unable to import active module - defaulting to standard method." )
109
- ret = {
133
+ partial = {
110
134
'n' : n ,
111
135
'total' : standard_methods [method ](axes = axis , skipna = skipna , ** kwargs )
112
136
}
113
137
114
- if not ret :
138
+ if not partial :
115
139
116
140
# Create Active client
117
141
active = Active (self .filename , self .address )
@@ -131,13 +155,14 @@ def active_method(self, method, axis=None, skipna=None, **kwargs):
131
155
data = active [extent ]
132
156
t = self ._post_process_data (data ) * n
133
157
134
- ret = {
158
+ partial = {
135
159
'n' : n ,
136
160
'total' : t
137
161
}
138
162
139
- if not ret :
163
+ if not partial :
140
164
# Experimental Recursive requesting to get each 1D column along the axes being requested.
165
+ # - May be very bad performance due to many requests for (1,1,X) shapes
141
166
range_recursives = []
142
167
for dim in range (self .ndim ):
143
168
if dim not in axis :
@@ -147,17 +172,21 @@ def active_method(self, method, axis=None, skipna=None, **kwargs):
147
172
results = np .array (self ._get_elements (active , range_recursives , hyperslab = []))
148
173
149
174
t = self ._post_process_data (results ) * n
150
- ret = {
175
+ partial = {
151
176
'n' : n ,
152
177
'total' : t
153
178
}
154
179
155
180
if method == 'mean' :
156
- return ret
181
+ return partial
157
182
else :
158
- return ret ['total' ]/ ret ['n' ]
183
+ return partial ['total' ]/ partial ['n' ]
159
184
160
185
def _get_elements (self , active , recursives , hyperslab = []):
186
+ """
187
+ Recursive function to fetch and arrange the appropriate column slices
188
+ from Active.
189
+ """
161
190
dimarray = []
162
191
if not len (recursives ) > 0 :
163
192
0 commit comments