Skip to content

Commit

Permalink
Fix bug in maxima detection
Browse files Browse the repository at this point in the history
  • Loading branch information
javicarron committed Feb 20, 2024
1 parent 3f7ca76 commit 367c816
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions pynkowski/data/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
from .base_da import DataField



def _eval_field(field, pix):
return field[tuple(pix[:,ii] for ii in np.arange(field.ndim))]

def _hotspot_array(field):
"""Find the local maxima of the input field.
Expand Down Expand Up @@ -34,7 +38,7 @@ def _hotspot_array(field):
max_mask = np.pad(max_mask, pad_width=1, mode='constant', constant_values=False)

pixels = np.argwhere(max_mask)
values = field[pixels]
values = _eval_field(field, pixels)
return(pixels, values)

class DataArray(DataField):
Expand Down Expand Up @@ -142,8 +146,8 @@ def maxima_list(self):
Values of input map which are local maxima.
"""
values, pixels = _hotspot_array(self.field)
return values[self.mask[pixels]]
pixels, values = _hotspot_array(self.field)
return values[_eval_field(self.mask, pixels)]

def minima_list(self):
"""Find the local minima of the field.
Expand All @@ -154,8 +158,8 @@ def minima_list(self):
Values of input map which are local minima.
"""
values, pixels = _hotspot_array(-self.field)
return -values[self.mask[pixels]]
pixels, values = _hotspot_array(-self.field)
return -values[_eval_field(self.mask, pixels)]



Expand Down

0 comments on commit 367c816

Please sign in to comment.