playnano.processing.masked_filters module

Module for filtering AFM data in NumPy arrays with a boolean mask.

playnano.processing.masked_filters.polynomial_flatten_masked(data: ndarray, mask: ndarray, order: int = 2) → ndarray[source]

Fit a 2D polynomial using background (mask==False) and subtract it.

Parameters:
  • data (np.ndarray) – 2D AFM image.

  • order (int) – Polynomial order. Default order=2.

  • mask (np.ndarray) – Boolean mask of same shape; True=foreground, False=background.

Returns:

Polynomial-flattened image.

Return type:

np.ndarray

Raises:

ValueError – If mask.shape != data.shape, order is not a positive integer, or there are fewer finite background pixels than polynomial terms.

Notes

NaN and infinite pixels are left out of the fit and stay NaN or infinite in the output. Version 0.2.0 scales x and y to [-1, 1] before fitting, so orders of 3 and above fit correctly on large frames.

playnano.processing.masked_filters.register_mask_filters()[source]

Return list of masking options.

playnano.processing.masked_filters.remove_plane_masked(data: ndarray, mask: ndarray) → ndarray[source]

Fit a 2D plane on background only and subtract it from the full image.

Parameters:
  • data (np.ndarray) – 2D AFM image.

  • mask (np.ndarray) – Boolean mask of same shape; True=foreground (excluded), False=background (used to fit).

Returns:

Plane-removed image.

Return type:

np.ndarray

Raises:

ValueError – If mask.shape != data.shape, or fewer than 3 background pixels are finite.

Notes

NaN and infinite pixels are left out of the fit and stay NaN or infinite in the output. Version 0.1.1 fits with NumPy instead of scikit-learn (same result) and handles NaN pixels instead of raising.

playnano.processing.masked_filters.row_median_align_masked(data: ndarray, mask: ndarray) → ndarray[source]

Compute each row’s median using background pixels and subtract from each full row.

Parameters:
  • data (np.ndarray) – 2D AFM image.

  • mask (np.ndarray) – Boolean mask of same shape; True=foreground, False=background.

Returns:

Row-masked-alignment image.

Return type:

np.ndarray

Raises:

ValueError – If mask.shape != data.shape.

playnano.processing.masked_filters.zero_mean_masked(data: ndarray, mask: ndarray = None) → ndarray[source]

Subtract the overall mean height to center the background around zero.

If a mask is provided, mean is computed only over background (mask == False).

Parameters:
  • data (np.ndarray) – 2D AFM image data.

  • mask (np.ndarray, optional) – Boolean mask of same shape as data; True indicates region to exclude from mean.

Returns:

Zero-mean image.

Return type:

np.ndarray

playnano.processing.masked_filters.zero_median_masked(data: ndarray, mask: ndarray = None) → ndarray[source]

Subtract the overall median height to center the background around zero.

If a mask is provided, median is computed only over background (mask == False).

Parameters:
  • data (np.ndarray) – 2D AFM image data.

  • mask (np.ndarray, optional) – Boolean mask of same shape as data; True indicates regions to exclude from the median.

Returns:

Zero-median image.

Return type:

np.ndarray