1
- ''' Functions to manipualte array dimensions.'''
1
+ ''' Functions to manipulate array dimensions.'''
2
2
3
3
import numpy as np
4
4
@@ -9,23 +9,26 @@ def aggregate_fields_time(R, metadata, time_window_min, method="mean"):
9
9
Parameters
10
10
----------
11
11
R : array-like
12
- Array of shape (t,m,n) or (i,t,m,n) containing the input fields.
12
+ Array of shape (t,m,n) or (l,t,m,n) containing a time series of (ensemble)
13
+ input fields.
13
14
They must be evenly spaced in time.
14
15
metadata : dict
15
- The metadata dictionary contains all data-related information.
16
+ The metadata dictionary contains all data-related information. It requires
17
+ the key "timestamps".
16
18
time_window_min : float or None
17
19
The length in minutes of the time window that is used to aggregate the fields.
18
- The total length of R must be a multiple of time_window_min.
20
+ The time spanned by the t dimension of R must be a multiple of time_window_min.
19
21
If set to None, it returns a copy of the original R and metadata.
20
22
method : string
21
23
Optional argument that specifies the operation to use to aggregate the values within the time
22
- window.
24
+ window. Default to mean operator.
23
25
24
26
Returns
25
27
-------
26
28
outputarray : array-like
27
- The new array of aggregated precipitation fields of shape (k,m,n), where
28
- k = int(t*delta/time_window_min)
29
+ The new array of aggregated fields of shape (k,m,n) or (l,k,m,n), where
30
+ k = t*delta/time_window_min and delta is the time interval between two
31
+ successive timestamps.
29
32
metadata : dict
30
33
The metadata with updated attributes.
31
34
@@ -71,7 +74,7 @@ def aggregate_fields_time(R, metadata, time_window_min, method="mean"):
71
74
72
75
return R , metadata
73
76
74
- def aggregate_fields (R , window_size , axis = 0 , method = "sum " ):
77
+ def aggregate_fields (R , window_size , axis = 0 , method = "mean " ):
75
78
"""Aggregate fields.
76
79
It attemps to aggregate the given R axis in an integer number of sections of
77
80
length = window_size. If such a aggregation is not possible, an error is raised.
@@ -85,19 +88,20 @@ def aggregate_fields(R, window_size, axis=0, method="sum"):
85
88
axis : int
86
89
The axis where to perform the aggregation.
87
90
method : string
88
- Optional argument that specifies the operation to use to aggregate the values within the time
89
- window.
91
+ Optional argument that specifies the operation to use to aggregate the values within the
92
+ window. Default to mean operator.
90
93
91
94
Returns
92
95
-------
93
96
outputarray : array-like
94
- The new aggregated array of shape (k,m,n), where k = t/time_window
97
+ The new aggregated array with shape[axis] = k, where k = R.shape[axis]/window_size
95
98
96
99
"""
97
100
98
101
N = R .shape [axis ]
99
102
if N % window_size :
100
- raise ValueError ('window_size does not equally split R' )
103
+ raise ValueError ('window_size %i does not equally split R.shape[axis] %i' % (window_size , N ))
104
+
101
105
R = R .copy ().swapaxes (axis , 0 )
102
106
shape = list (R .shape )
103
107
R_ = R .reshape ((N , - 1 ))
0 commit comments