1- ''' Functions to manipualte array dimensions.'''
1+ ''' Functions to manipulate array dimensions.'''
22
33import numpy as np
44
@@ -9,23 +9,26 @@ def aggregate_fields_time(R, metadata, time_window_min, method="mean"):
99 Parameters
1010 ----------
1111 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.
1314 They must be evenly spaced in time.
1415 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".
1618 time_window_min : float or None
1719 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.
1921 If set to None, it returns a copy of the original R and metadata.
2022 method : string
2123 Optional argument that specifies the operation to use to aggregate the values within the time
22- window.
24+ window. Default to mean operator.
2325
2426 Returns
2527 -------
2628 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.
2932 metadata : dict
3033 The metadata with updated attributes.
3134
@@ -71,7 +74,7 @@ def aggregate_fields_time(R, metadata, time_window_min, method="mean"):
7174
7275 return R , metadata
7376
74- def aggregate_fields (R , window_size , axis = 0 , method = "sum " ):
77+ def aggregate_fields (R , window_size , axis = 0 , method = "mean " ):
7578 """Aggregate fields.
7679 It attemps to aggregate the given R axis in an integer number of sections of
7780 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"):
8588 axis : int
8689 The axis where to perform the aggregation.
8790 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.
9093
9194 Returns
9295 -------
9396 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
9598
9699 """
97100
98101 N = R .shape [axis ]
99102 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+
101105 R = R .copy ().swapaxes (axis , 0 )
102106 shape = list (R .shape )
103107 R_ = R .reshape ((N , - 1 ))
0 commit comments