Skip to content

Commit

Permalink
Use outermost threshold crossing point when detecting field edges
Browse files Browse the repository at this point in the history
This patch resolves issue #323 by switching to detecting the
outermost points that cross the threshold value when detecting
field edges in SingleProfile.
  • Loading branch information
randlet committed Nov 12, 2020
1 parent 14a5296 commit e31a62e
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions pylinac/core/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,20 +285,13 @@ def _penumbra_point(self, side: str='left', x: int=50, interpolate: bool=False,
max_point = y_data.max()
threshold = max_point * (x / 100)

# find the index, moving 1 element at a time until the value is encountered
found = False
at_end = False
try:
while not found and not at_end:
if y_data[peak] < threshold:
found = True
peak -= 1 if side == RIGHT else -1
elif peak == 0:
at_end = True
peak += 1 if side == RIGHT else -1
except IndexError:
not_found = len(np.where(y_data <= threshold)[0]) == 0
if not_found:
raise IndexError("The point of interest was beyond the profile; i.e. the profile may be cut off on the side")

locs = np.where(y_data > threshold)[0]
peak = locs[-1] + 1 if side == RIGHT else locs[0] - 1

if kind == VALUE:
return self._values_interp[peak] if interpolate else self.values[peak]
elif kind == INDEX:
Expand Down

0 comments on commit e31a62e

Please sign in to comment.