Feature Utilities

pumpia.utilities.feature_utils.flat_top_gauss(pos: ndarray, x0: float, sigma: float, amp: float, rank: float = 1, offset: float = 0) ndarray

Calculates the flat top gaussian given by:

\[amp * exp\bigg(-\bigg(\frac{(pos-x0)^2}{2sigma^2}\bigg)^{rank}\bigg) + offset\]

A rank of 1 is a standard gaussian.

Parameters:
  • pos (np.ndarray)

  • x0 (float)

  • sigma (float)

  • rank (float)

  • amp (float) – by default 1

  • offset (float, optional) – by default 0

Return type:

np.ndarray

pumpia.utilities.feature_utils.split_gauss(pos: ndarray, a: float, b: float, c: float, amp: float, offset: float = 0) ndarray

Returns an array of values for a gaussian split down the middle and joined by a line.

Parameters:
  • pos (np.ndarray) – 1 dimensional array of positions.

  • a (float) – left position of the top of the curve.

  • b (float) – right position of the top of the curve.

  • c (float) – half width of gaussian part.

  • amp (float) – amplitude of the curve.

  • offset (float, optional) – base offset added to the curve (default is 0).

pumpia.utilities.feature_utils.split_gauss_integral(pos: ndarray, a: float, b: float, c: float, amp: float, baseline: float) ndarray

Integrates accross split_gauss and adds baseline

Parameters:
  • pos (np.ndarray) – 1 dimensional array of positions

  • a (float) – left position of the top of the curve

  • b (float) – right position of the top of the curve

  • c (float) – half width of gaussian part

  • amp (float) – amplitude of the curve

  • baseline (float) – baseline to be added onto the integral

Returns:

1 dimensional array, 1 shorter that pos

Return type:

np.ndarray

pumpia.utilities.feature_utils.ellipse_eq(pos: ndarray, xc: float, yc: float, a: float, b: float) ndarray

Ellipse equation.

Parameters:
  • pos (np.ndarray) – The positions array.

  • xc (float) – The x-center of the ellipse.

  • yc (float) – The y-center of the ellipse.

  • a (float) – The width of the ellipse.

  • b (float) – The height of the ellipse.

Returns:

The result of the ellipse equation.

Return type:

np.ndarray

pumpia.utilities.feature_utils.ellipse_eq_min_max(pos: ndarray, xmin: float, ymin: float, xmax: float, ymax: float) ndarray

Ellipse equation using min and max values.

Parameters:
  • pos (np.ndarray) – The positions array.

  • xmin (float) – The minimum x-coordinate.

  • ymin (float) – The minimum y-coordinate.

  • xmax (float) – The maximum x-coordinate.

  • ymax (float) – The maximum y-coordinate.

Returns:

The result of the ellipse equation.

Return type:

np.ndarray

pumpia.utilities.feature_utils.rectangle_eq(pos: ndarray, xmin: float, ymin: float, a: float, b: float) ndarray

Rectangle equation.

Parameters:
  • pos (np.ndarray) – The positions array.

  • xmin (float) – The minimum x-coordinate.

  • ymin (float) – The minimum y-coordinate.

  • a (float) – The width of the rectangle.

  • b (float) – The height of the rectangle.

Returns:

The result of the rectangle equation.

Return type:

np.ndarray

pumpia.utilities.feature_utils.rectangle_eq_min_max(pos: ndarray, xmin: float, ymin: float, xmax: float, ymax: float) ndarray

Rectangle equation using min and max values.

Parameters:
  • pos (np.ndarray) – The positions array.

  • xmin (float) – The minimum x-coordinate.

  • ymin (float) – The minimum y-coordinate.

  • xmax (float) – The maximum x-coordinate.

  • ymax (float) – The maximum y-coordinate.

Returns:

The result of the rectangle equation.

Return type:

np.ndarray

pumpia.utilities.feature_utils.single_feature_boundbox(array: ndarray, divisor: float = 2, top_perc: float = 95) BoundBoxContext

Finds the bounding box for an array with a single feature.

Parameters:
  • array (np.ndarray) – The input array. should be 2 dimensional

  • divisor (float, optional) – The divisor to calculate the nth maximum value (default is 2).

  • top_perc (float, optional) – The percentile to calculate the working maximum from, to exclude outliers (default is 95).

Returns:

The bounding box context.

Return type:

BoundBoxContext

pumpia.utilities.feature_utils.phantom_boundbox_manual(array: ndarray, sensitivity: float = 2, top_perc: float = 95, bubble_offset: int = 0, bubble_side: Literal['top', 'bottom', 'left', 'right'] = 'top') BoundBoxContext

Finds the bounding box for a phantom with bubble info provided manually.

Parameters:
  • array (np.ndarray) – The input array. Should be 2 dimensional

  • sensitivity (float, optional) – The sensitivity for boundary detection. e.g. 2 would use half the maximum, 10 would use a tenth (default is 2).

  • top_perc (float, optional) – The percentile to calculate the working maximum from, to exclude outliers (default is 95).

  • bubble_offset (int, optional) – The bubble offset for boundary detection in pixels (default is 0).

  • bubble_side (SideType, optional) – The side of the phantom the bubble is on (default is “top”).

Returns:

The bounding box context.

Return type:

BoundBoxContext

pumpia.utilities.feature_utils.phantom_boundary_automatic(array: ndarray, sensitivity: float = 3, top_perc: float = 95, iterations: int = 2, cull_perc: float = 80, shape: None | Literal['rectangle', 'ellipse'] | list[Literal['rectangle', 'ellipse']] = None) PhantomContext

Finds the boundary of a phantom automatically.

This is done by finding the pixel positions of the boundary of the phantom, using the nth maximum method. The boundary is then fitted to an ellipse and a rectangle. The worst fitting positions are removed and the fitting is repeated. The best fitting shape after n iterations is returned.

Parameters:
  • array (np.ndarray) – The input array. Should be 2 dimensional

  • sensitivity (float, optional) – The sensitivity for boundary detection. e.g. 2 would use half the maximum, 10 would use a tenth(default is 3).

  • top_perc (float, optional) – The percentile to calculate the working maximum from, to exclude outliers (default is 95).

  • iterations (int, optional) – The number of iterations in the algorithm (default is 2).

  • cull_perc (float, optional) – The percentile to determine how many positions are kept each iteration (default is 80).

  • shape (PhantomShapes, optional) – The shape of the phantom. Calculated if not given (default is None).

Returns:

The phantom context.

Return type:

PhantomContext