spatialstats.utils

Averaging

Routines for averaging 2D and 3D images in polar and spherical coordinates.

Adapted from aziavg.py in https://github.com/davidgrier/dgmath/.

aziavg(data, center=None, rad=None, portion=False, stdev=False, avg=True, weight=None)

Average data over bins of azimuthal contours.

Parameters
  • data (np.ndarray) – Two-dimensional data array.

  • center (tuple, shape (2,), optional) – (x, y) coordinates of the point around which to compute average. If None, use the image geometric center.

  • rad (np.ndarray or int, optional) – Array of bins to use in average or maximum radius. of average. If None, use half of the minimum dimension of the data.

  • portion (bool, optional) – Choose whether to portion data by position in bin. Good for small number of bins compared to dimension of data.

  • stdev (bool, optional) – Choose whether to return error bars for each bin. Only works for portion = False.

  • avg (bool, optional) – Choose whether to average data along azimuthal contours or to compute sum.

  • weight (np.ndarray, optional) – Relative weighting of each pixel in data. If None, use uniform weighting.

Returns

  • result (np.ndarray) – One-dimensional azimuthal average.

  • rn (np.ndarray) – Radial bins.

  • stdev (np.ndarray, optional) – Standard deviations from the average.

radialavg(data, center=None, dphi=None, bounds=(0, 6.283185307179586), portion=False, stdev=False, avg=True, weight=None)

Average data over bins of radial slices.

Parameters
  • data (np.ndarray) – Two-dimensional data array.

  • center (tuple, shape (2,), optional) – (x, y) coordinates of the point around which to compute average. If None, use the image geometric center.

  • dphi (float, optional) – Angular division of bins on which to group angles when averaging.

  • bounds (tuple, shape (2,), optional) – Anglular range of average. By default, use (0, 2*np.pi).

  • portion (bool, optional) – Choose whether to scale data according to position in bin. Good for small number of bins and a lot of data.

  • stdev (bool, optional) – Choose whether to return error bars for each bin. Only works for portion = False.

  • avg (bool, optional) – Choose whether to average data along radial contours or compute sum.

  • weight (np.ndarray, optional) – Relative weighting of each pixel in data. If None, use uniform weighting.

Returns

  • result (np.ndarray) – One-dimensional radial average.

  • phin (np.ndarray) – The angular bins.

  • stdev (np.ndarray, optional) – Standard deviations from the average.

shellavg(data, center=None, rad=None, portion=False, stdev=False, avg=True, weight=None)

Average data over bins of spherical shells.

Parameters
  • data (np.ndarray) – Three-dimensional data array.

  • center (tuple, shape (3,), optional) – (x, y, z) coordinates of the point around which to compute average. If None, use the image geometric center.

  • rad (np.ndarray or int, optional) – Array of bins to use in average or maximum radius of average. If None, use half of the minimum dimension of the data.

  • portion (bool, optional) – Choose whether to scale data according to position in bin. Good for small number of bins and a lot of data.

  • stdev (bool, optional) – Choose whether to return error bars for each bin. Only works for portion = False.

  • avg (bool, optional) – Choose whether to average data along shells or compute sum.

  • weight (np.ndarray, optional) – Relative weighting of each pixel in data. If None, use uniform weighting.

Returns

  • result (np.ndarray) – One-dimensional angular average.

  • rn (np.ndarray) – Radial bins.

  • stdev (np.ndarray, optional) – Standard deviations from the average.