skued.bragg_peaks_persistence

skued.bragg_peaks_persistence(im, mask=None, center=None, min_dist=None, bd_threshold=0.0, prominence=0.0)

Extract the position of Bragg peaks in a single-crystal diffraction pattern using 2D persistence of the image landscape. If detected peaks fall above certain thresholds, they are deamed acceptable peaks and returned.

New in version 2.1.11.

Parameters:
  • im (ndarray, shape (N,M)) – Single-crystal diffraction pattern.

  • mask (ndarray, shape (N,M), dtype bool, optional) – Mask that evaluates to True on valid pixels of im.

  • center (2-tuple, optional) – Center of the diffraction pattern, in (row, col) format. If None, the center will be determined via autocenter().

  • min_dist (float or list (size 2) or None, optional) – Minimum distance between Bragg peaks (in pixel coordinates). Peaks that are closer than this distance will be considered the same peak, and only one of them will be returned. If passing only single number, minimum distance is determined by the degree of radial separation. Else, minimum distancing is determined by thresholding x and y coordinates separately with min_dist[0] and min_dist[1]. If None (default), the minimum distance criterion is not enforced, and all peaks passing the prominence threshold are returned.

  • bd_threshold (float, optional) – Specifies the persistence threshold for the determination of birth/death parameters in the persistence calculations

  • prominence (float, optional) – Specifies the persistence threshold for the distinction between acceptable peaks and ‘ghost’ peaks. Lower values will yield more peaks.

Returns:

  • peaks (ndarray, shape (N,2)) – Array of coordinates [row, col] for every detected peak, sorted in order of how close they are to the center of the image.

  • birth_death (ndarray, shape (N,2)) – Array of birth, death attributes for every detected peak.

  • birth_index_indices (list) – Indices of candidate peaks who pass the bd_threshold prominence criterion

  • persistencies (list of floats) – List of persistencies of the detected peaks. Useful for determining which threshold to use to accurate peak determination.

References

Huber, S. (2021). Persistent Homology in Data Science. In: Haber, P., Lampoltshammer, T., Mayr, M., Plankensteiner, K. (eds) Data Science - Analytics and Applications. Springer Vieweg, Wiesbaden. https://doi.org/10.1007/978-3-658-32182-6_13

Edelsbrunner, H. and John L Harer (2010). Computational Topology. In: American Mathematical Society.

Example

To generate the peak determination from a 2D array and visualize the results, as well as the birth-death persistence diagram:

from skued import bragg_peak_persistence
peaks, birth_death, indices = bragg_peak_persistence(image)
axis.imshow(image, extent='lower')
for i, peak in enumerate(peaks):
    x, y = peak
    ax.plot([x], [y], '.', c='b')
    ax.text(x, y+0.25, str(i+1), color='b')

ax2.set_title("Peristence diagram")
for i, (index, bd) in enumerate(zip(indices, birth_death)):
    x, y = bd
    ax2.plot([x], [y], '.', c='b')
    ax2.text(x, y+2, str(index+1), color='b')
ax2.set_xlabel("Birth level")
ax2.set_ylabel("Death level")