cf.Data.convolution_filter¶
-
Data.
convolution_filter
(window=None, axis=None, mode=None, cval=None, origin=0, inplace=False)[source]¶ Return the data convolved along the given axis with the specified filter.
The magnitude of the integral of the filter (i.e. the sum of the weights defined by the weights parameter) affects the convolved values. For example, filter weights of
[0.2, 0.2 0.2, 0.2, 0.2]
will produce a non-weighted 5-point running mean; and weights of[1, 1, 1, 1, 1]
will produce a 5-point running sum. Note that the weights returned by functions of thescipy.signal.windows
package do not necessarily sum to 1 (see the examples for details).New in version 3.3.0.
- Parameters
- window: sequence of numbers
Specify the window of weights to use for the filter.
- Parameter example:
An unweighted 5-point moving average can be computed with
weights=[0.2, 0.2, 0.2, 0.2, 0.2]
Note that the
scipy.signal.windows
package has suite of window functions for creating weights for filtering (see the examples for details).- axis:
int
Select the axis over which the filter is to be applied. removed. The axis parameter is an integer that selects the axis corresponding to the given position in the list of axes of the data.
- Parameter example:
Convolve the second axis:
axis=1
.- Parameter example:
Convolve the last axis:
axis=-1
.
- mode:
str
, optional The mode parameter determines how the input array is extended when the filter overlaps an array border. The default value is
'constant'
or, if the dimension being convolved is cyclic (as ascertained by theiscyclic
method),'wrap'
. The valid values and their behaviours are as follows:mode
Description
Behaviour
'reflect'
The input is extended by reflecting about the edge
(c b a | a b c | c b a)
'constant'
The input is extended by filling all values beyond the edge with the same constant value (
k
), defined by the cval parameter.(k k k | a b c | k k k)
'nearest'
The input is extended by replicating the last point
(a a a | a b c | c c c )
'mirror'
The input is extended by reflecting about the centre of the last point.
(c b | a b c | b a)
'wrap'
The input is extended by wrapping around to the opposite edge.
(a b c | a b c | a b c)
'periodic'
This is a synonym for
'wrap'
.The position of the window relative to each value can be changed by using the origin parameter.
- cval: scalar, optional
Value to fill past the edges of the array if mode is
'constant'
. Defaults toNone
, in which case the edges of the array will be filled with missing data.- Parameter example:
To extend the input by filling all values beyond the edge with zero:
cval=0
- origin:
int
, optional Controls the placement of the filter. Defaults to 0, which is the centre of the window. If the window has an even number of weights then then a value of 0 defines the index defined by
width/2 -1
.- Parameter example:
For a weighted moving average computed with a weights window of
[0.1, 0.15, 0.5, 0.15, 0.1]
, iforigin=0
then the average is centred on each point. Iforigin=-2
then the average is shifted to include the previous four points. Iforigin=1
then the average is shifted to include the previous point and the and the next three points.
- inplace:
bool
, optional If True then do the operation in-place and return
None
.
- Returns