diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 082032c8..d8858336 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,11 @@ Changelog ========= +Release 2.1.12 +-------------- + +* Improved the masking functionality in `bragg_peaks_persistence`. + Release 2.1.11 -------------- diff --git a/skued/__init__.py b/skued/__init__.py index 04dcc378..31df6efa 100644 --- a/skued/__init__.py +++ b/skued/__init__.py @@ -2,7 +2,7 @@ __author__ = "Laurent P. René de Cotret" __email__ = "laurent.renedecotret@mail.mcgill.ca" __license__ = "GPLv3" -__version__ = "2.1.11" +__version__ = "2.1.12" from .affine import ( affine_map, diff --git a/skued/image/indexing.py b/skued/image/indexing.py index 4a1a6422..0d41e0a9 100644 --- a/skued/image/indexing.py +++ b/skued/image/indexing.py @@ -190,10 +190,8 @@ def bragg_peaks_persistence( """ if mask is None: mask = np.ones_like(im, dtype=bool) - im[~mask] = 0.0 if center is None: center = autocenter(im=im, mask=mask) - image = im g0 = Persistence(im).persistence birth_death = list() @@ -237,6 +235,19 @@ def bragg_peaks_persistence( sorted(candidates, key=lambda p: np.linalg.norm(p - center)) ).reshape(-1, 2) birth_death = np.array(birth_death).reshape(-1, 2) + + # remove peaks that are within the masked area + if mask.sum() != mask.shape[0] * mask.shape[1]: + peaks = np.array([p for p in peaks if mask[p[1], p[0]]]) + birth_death = np.array( + [bd for p, bd in zip(peaks, birth_death) if mask[p[1], p[0]]] + ) + birth_death_indices = np.array( + [bdi for p, bdi in zip(peaks, birth_death_indices) if mask[p[1], p[0]]] + ) + persistencies = np.array( + [pers for p, pers in zip(peaks, persistencies) if mask[p[1], p[0]]] + ) return peaks, birth_death, birth_death_indices, persistencies