2.3.7. vacumm.misc.filters – 1D/2D numeric filters

Functions:

Various 1d and 2D filters

bartlett1d(data, M, **kwargs)[source]

Bartlett 1D filter

Params:
  • data: A MV2 variable.
  • M: Size of the Bartlett window.
  • Keywords are passed to generic1d().
Return:
  • A MV2 variable
blackman1d(data, M, **kwargs)[source]

Blackman 1D filter

Params:
  • data: A MV2 variable.
  • M: Size of the Blackman window.
  • Keywords are passed to generic1d().
Return:
  • A MV2 variable
deriv(data, axis=0, fast=True, fill_value=None, physical=True, lat=None)[source]

Derivative along a given axis

  • data: Data array (converted to MV array if needed)
  • axis: Axis on which the derivative is performed [default: 0]
  • fast: Filled masked array before derivating, so use Numeric which is faster than MA or MV [WARNING default: True]
  • physical: Try physical derivative, taking axis units into account [default: True]
  • lat: Latitude for geographical deriviative to convert positions in degrees to meters
deriv2d(data, direction=None, **kwargs)[source]

Derivative in a 2D space

  • data: 2D variable
  • direction: If not None, derivative is computed in this direction, else the module is returned [default: None]
  • Other keywords are passed to deriv()
gaussian1d(data, nxw, **kwargs)[source]

Gaussian 1D filter

  • data: Data array
  • nxw: Size of gaussian weights array along X
  • Other keywords are passed to generic1d()
gaussian2d(data, nxw, nyw=None, sxw=0.3333333333333333, syw=0.3333333333333333, rmax=3.0, **kwargs)[source]

Gaussian 2D filter

  • data: Data array
  • nxw: Size of gaussian weights array along X (and Y if nyw not given)
  • nyw: Size of gaussian weights array along Y [default: nxw]
  • sxw: Standard deviation of the gaussian distribution along X. If <1, its size is relative to nxw. If > 1, it is directly expressed in grid steps.
  • syw: Same as sxw for Y direction.
  • rmax: Distance relative to sqrt(sxw**2+syw**2) after with weights are nullified.
  • Other keywords are passed to generic2d()
generic1d(data, weights, axis=0, mask='same', copy=True, cyclic=False)[source]

Generic 1D filter applied to MV2 variables using convolution.

Params:
  • data: Atleast 1D MV2 variable.

  • weights: integer, 1D weights. They are expected to be symmetric and of odd sizes.

  • axis, optional: axis on which to operate

  • mask, optional: mode of masking. The mask is also filtered, and its value helps defining the new mask, depending on this parameter:

    • If a float is provided, data are masked if the mask value is greater than this parameter.
    • "minimal": Equivalent to 1.. Data is not masked if a valid value was used to compute data.
    • "maximal": Equivalent to 0.. Data is masked if a invalid value was used to compute data.
    • "same": Mask is the same as input mask.
  • copy, optional: Copy variable before filtering it.

Return:
  • The filtered MV2 variable.
Example:
>>> generic1d(data, 3.) # running mean using a 3-points block
>>> generic1d(data, [1.,2.,1], axis=2) # shapiro filter on third axis
See also:

scipy.signal.convolve2d()

generic2d(data, weights, mask='same', copy=True)[source]

Generic 2D filter applied to 2D (or more) MV2 variables using convolution.

Params:
  • data: Atleast 2D MV2 variable.

  • weights: integer, 2D weights. They are expected to be symmetric and of odd sizes. If an integer is provided, a (weights,weights) array of ones is used.

  • mask, optional: mode of masking. The mask is also filtered, and its value helps defining the new mask, depending on this parameter:

    • If a float is provided, data are masked if the mask value is greater than this parameter.
    • "minimal": Equivalent to 1.. Data is not masked if a valid value was used to compute data.
    • "maximal": Equivalent to 0.. Data is masked if a invalid value was used to compute data.
    • "same": Mask is the same as input mask.
  • copy, optional: Copy variable before filtering it.

Return:
  • The filtered MV2 variable.
Example:
>>> generic2d(data, 3.) # running mean using a 3x3 block
>>> generic2d(data, N.ones(3,3)) # the same
>>> generic2d(data, N.ones(3,3), weights, mode='minimal') # crop coasts
See also:

scipy.signal.convolve2d()

hamming1d(data, M, **kwargs)[source]

Hamming 1D filter

Params:
  • data: A MV2 variable.
  • M: Size of the Hamming window.
  • Keywords are passed to generic1d().
Return:
  • A MV2 variable
hanning1d(data, M, **kwargs)[source]

Hanning 1D filter

Params:
  • data: A MV2 variable.
  • M: Size of the Hanning window.
  • Keywords are passed to generic1d().
Return:
  • A MV2 variable
kaiser1d(data, M, beta, **kwargs)[source]

Kaiser 1D filter

Params:
  • data: A MV2 variable.
  • M: Size of the Kaiser window.
  • beta: Shape of the window.
  • Keywords are passed to generic1d().
Return:
  • A MV2 variable
norm_atan(var, stretch=1.0)[source]

Normalize using arctan (arctan(strecth*var/std(var))

  • stretch: If stretch close to 1, saturates values [default: 1]

Return: Value in [-1,1]

running_average(x, l, d=0, w=None, keep_mask=True)[source]

Perform a running average on an masked array. Average is linearly reduced near bounds, so that the input and output have the same size.

Params:
  • x: Masked array
  • l: Window size
  • d: Dimension over which the average is performed (0)
  • w: Weights (1…)
  • keep_mask: Apply mask from x to output array
Example:
>>> running_average(x, l, d = 0, w = None, keep_mask = 1)

Returns Average array (same size as x)

Warning

This function deprecated. Please use generic1d() instead.

shapiro1d(data, **kwargs)[source]

Shapiro (121) 1D filter

Params:
  • data: A MV2 variable.
  • Keywords are passed to generic1d().
Return:
  • A MV2 variable
shapiro2d(data, corners=0.5, **kwargs)[source]

Shapiro (121) 2D filter

Params:
  • data: A MV2 variable.
  • corner, optional: Value in (4) corners.
  • Keywords are passed to generic2d().
Return:
  • A MV2 variable