Skip to content

Commit

Permalink
fix center detection crash on special signals (fix #615)
Browse files Browse the repository at this point in the history
If a signal has segments with zero variance i.e. constant lines,
the center detection crashes because the histogram can not be created.
This fix catches the ZeroDivision error and returns None in that case.
  • Loading branch information
jopohl committed Feb 20, 2019
1 parent 3966d56 commit f6c3272
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/urh/ainterpretation/AutoInterpretation.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,11 @@ def detect_center(rectangular_signal: np.ndarray, max_size=None):
# If a signal has low variance we need to be more accurate at center detection
hist_step = float(np.var(rect))

y, x = np.histogram(rect, bins=np.arange(hist_min, hist_max + hist_step, hist_step))
try:
y, x = np.histogram(rect, bins=np.arange(hist_min, hist_max + hist_step, hist_step))
except ZeroDivisionError:
# For a segment with zero variance (constant line) it is not possible to find a center
return None

num_values = 2
most_common_levels = []
Expand Down

0 comments on commit f6c3272

Please sign in to comment.