weights#

This module contains the weight functions for azimuthal average.

The weight functions can be used to perform a sector average of the image structure function.

For example:

import fastddm as fddm

# load your images here and get shape of one image (last 2 entries in the shape property)
img_seq = fddm.read_images(...)
shape = img_seq.shape[-2:]

# compute the image structure function
dqt = fddm.ddm(img_seq, range(1, len(img_seq)))

# create a weight 'mask' to be applied to the image structure function
weights = fddm.weights.sector_average_weight(
    full_shape=shape,
    kx=dqt.kx,
    ky=dqt.ky,
    theta_0=90,
    delta_theta=90,
    rep=4,
    kind="uniform"
)

# set bin number and pass the weights to the azimuthal_average function
nbins = max(shape) // 2
az_avg = fddm.azimuthal_average(dqt, bins=nbins, weights=weights)

(Source code, png, hires.png, pdf)

_images/weights-1.png
fastddm.weights.sector_average_weight(full_shape: Tuple[int, int], kx: ndarray | None = None, ky: ndarray | None = None, theta_0: float = 0.0, delta_theta: float = 90.0, rep: int = 2, kind: str | None = 'uniform') ndarray#

Evaluate weights for sector azimuthal average. If kx or ky are not given, the half-plane representation for the 2D image structure function is assumed and we use

kx = 2.0 * np.pi * np.fft.fftfreq(full_shape[1])[:shape[1]]

ky = 2.0 * np.pi * np.fft.fftshift(np.fft.fftfreq(full_shape[0]))

with shape[1] = full_shape[1] // 2 + 1.

Parameters:
  • full_shape (Tuple[int, int]) – Shape of the full 2D image structure function. This is needed in order to correctly account for the spare column (Nyquist frequency). The shape of the output will be (full_shape[0], full_shape[1] // 2 + 1), as for the image structure function data.

  • kx (numpy.ndarray, optional) – The array of spatial frequencies along axis x. Default is None.

  • ky (numpy.ndarray, optional) – The array of spatial frequencies along axis y. Default is None.

  • theta_0 (float, optional) – Reference main angle (in degrees). Default is 0.

  • delta_theta (float, optional) – Sector width (in degrees). If kind is “gauss”, it is the standard deviation of the gaussian function over the angles. Default is 90.

  • rep (int, optional) – Number of equally-spaced theta angles. Default is 2.

  • kind (str, optional) – Type of weight function. Supported types are “uniform” and “gauss”. Default is “uniform”.

Returns:

The weights.

Return type:

numpy.ndarray

Raises:

RuntimeError – If a value for kind other than “uniform” or “gauss” is given.