|
45 | 45 |
|
46 | 46 | `stride_windows` |
47 | 47 | Get all windows in an array in a memory-efficient manner |
48 | | -
|
49 | | -`stride_repeat` |
50 | | - Repeat an array in a memory-efficient manner |
51 | | -
|
52 | | -`apply_window` |
53 | | - Apply a window along a given axis |
54 | 48 | """ |
55 | 49 |
|
56 | 50 | import functools |
@@ -85,63 +79,6 @@ def window_none(x): |
85 | 79 | return x |
86 | 80 |
|
87 | 81 |
|
88 | | -@cbook.deprecated("3.2") |
89 | | -def apply_window(x, window, axis=0, return_window=None): |
90 | | - """ |
91 | | - Apply the given window to the given 1D or 2D array along the given axis. |
92 | | -
|
93 | | - Parameters |
94 | | - ---------- |
95 | | - x : 1D or 2D array or sequence |
96 | | - Array or sequence containing the data. |
97 | | -
|
98 | | - window : function or array. |
99 | | - Either a function to generate a window or an array with length |
100 | | - *x*.shape[*axis*] |
101 | | -
|
102 | | - axis : int |
103 | | - The axis over which to do the repetition. |
104 | | - Must be 0 or 1. The default is 0 |
105 | | -
|
106 | | - return_window : bool |
107 | | - If true, also return the 1D values of the window that was applied |
108 | | - """ |
109 | | - x = np.asarray(x) |
110 | | - |
111 | | - if x.ndim < 1 or x.ndim > 2: |
112 | | - raise ValueError('only 1D or 2D arrays can be used') |
113 | | - if axis+1 > x.ndim: |
114 | | - raise ValueError('axis(=%s) out of bounds' % axis) |
115 | | - |
116 | | - xshape = list(x.shape) |
117 | | - xshapetarg = xshape.pop(axis) |
118 | | - |
119 | | - if np.iterable(window): |
120 | | - if len(window) != xshapetarg: |
121 | | - raise ValueError('The len(window) must be the same as the shape ' |
122 | | - 'of x for the chosen axis') |
123 | | - windowVals = window |
124 | | - else: |
125 | | - windowVals = window(np.ones(xshapetarg, dtype=x.dtype)) |
126 | | - |
127 | | - if x.ndim == 1: |
128 | | - if return_window: |
129 | | - return windowVals * x, windowVals |
130 | | - else: |
131 | | - return windowVals * x |
132 | | - |
133 | | - xshapeother = xshape.pop() |
134 | | - |
135 | | - otheraxis = (axis+1) % 2 |
136 | | - |
137 | | - windowValsRep = stride_repeat(windowVals, xshapeother, axis=otheraxis) |
138 | | - |
139 | | - if return_window: |
140 | | - return windowValsRep * x, windowVals |
141 | | - else: |
142 | | - return windowValsRep * x |
143 | | - |
144 | | - |
145 | 82 | def detrend(x, key=None, axis=None): |
146 | 83 | """ |
147 | 84 | Return x with its trend removed. |
@@ -343,62 +280,6 @@ def stride_windows(x, n, noverlap=None, axis=0): |
343 | 280 | return np.lib.stride_tricks.as_strided(x, shape=shape, strides=strides) |
344 | 281 |
|
345 | 282 |
|
346 | | -@cbook.deprecated("3.2") |
347 | | -def stride_repeat(x, n, axis=0): |
348 | | - """ |
349 | | - Repeat the values in an array in a memory-efficient manner. Array x is |
350 | | - stacked vertically n times. |
351 | | -
|
352 | | - .. warning:: |
353 | | -
|
354 | | - It is not safe to write to the output array. Multiple |
355 | | - elements may point to the same piece of memory, so |
356 | | - modifying one value may change others. |
357 | | -
|
358 | | - Parameters |
359 | | - ---------- |
360 | | - x : 1D array or sequence |
361 | | - Array or sequence containing the data. |
362 | | -
|
363 | | - n : int |
364 | | - The number of time to repeat the array. |
365 | | -
|
366 | | - axis : int |
367 | | - The axis along which the data will run. |
368 | | -
|
369 | | - References |
370 | | - ---------- |
371 | | - `stackoverflow: Repeat NumPy array without replicating data? |
372 | | - <http://stackoverflow.com/a/5568169>`_ |
373 | | - """ |
374 | | - if axis not in [0, 1]: |
375 | | - raise ValueError('axis must be 0 or 1') |
376 | | - x = np.asarray(x) |
377 | | - if x.ndim != 1: |
378 | | - raise ValueError('only 1-dimensional arrays can be used') |
379 | | - |
380 | | - if n == 1: |
381 | | - if axis == 0: |
382 | | - return np.atleast_2d(x) |
383 | | - else: |
384 | | - return np.atleast_2d(x).T |
385 | | - if n < 1: |
386 | | - raise ValueError('n cannot be less than 1') |
387 | | - |
388 | | - # np.lib.stride_tricks.as_strided easily leads to memory corruption for |
389 | | - # non integer shape and strides, i.e. n. See #3845. |
390 | | - n = int(n) |
391 | | - |
392 | | - if axis == 0: |
393 | | - shape = (n, x.size) |
394 | | - strides = (0, x.strides[0]) |
395 | | - else: |
396 | | - shape = (x.size, n) |
397 | | - strides = (x.strides[0], 0) |
398 | | - |
399 | | - return np.lib.stride_tricks.as_strided(x, shape=shape, strides=strides) |
400 | | - |
401 | | - |
402 | 283 | def _spectral_helper(x, y=None, NFFT=None, Fs=None, detrend_func=None, |
403 | 284 | window=None, noverlap=None, pad_to=None, |
404 | 285 | sides=None, scale_by_freq=None, mode=None): |
|
0 commit comments