From 2341f822a7522e780a44ae37ced59615160c8351 Mon Sep 17 00:00:00 2001 From: mbsantiago Date: Fri, 8 Aug 2025 13:30:44 +0100 Subject: [PATCH] Ignore plotting failures in gallery plot --- src/batdetect2/plotting/evaluation.py | 60 ++++++++++++++++----------- src/batdetect2/plotting/matches.py | 8 ++-- 2 files changed, 40 insertions(+), 28 deletions(-) diff --git a/src/batdetect2/plotting/evaluation.py b/src/batdetect2/plotting/evaluation.py index 856623f..fb8cf42 100644 --- a/src/batdetect2/plotting/evaluation.py +++ b/src/batdetect2/plotting/evaluation.py @@ -93,39 +93,51 @@ def plot_class_examples( for index, match in enumerate(true_positives): ax = plt.subplot(4, n_examples, index + 1) - plotting.plot_true_positive_match( - match, - ax=ax, - preprocessor=preprocessor, - duration=duration, - ) + try: + plotting.plot_true_positive_match( + match, + ax=ax, + preprocessor=preprocessor, + duration=duration, + ) + except ValueError: + continue for index, match in enumerate(false_positives): ax = plt.subplot(4, n_examples, n_examples + index + 1) - plotting.plot_false_positive_match( - match, - ax=ax, - preprocessor=preprocessor, - duration=duration, - ) + try: + plotting.plot_false_positive_match( + match, + ax=ax, + preprocessor=preprocessor, + duration=duration, + ) + except ValueError: + continue for index, match in enumerate(false_negatives): ax = plt.subplot(4, n_examples, 2 * n_examples + index + 1) - plotting.plot_false_negative_match( - match, - ax=ax, - preprocessor=preprocessor, - duration=duration, - ) + try: + plotting.plot_false_negative_match( + match, + ax=ax, + preprocessor=preprocessor, + duration=duration, + ) + except ValueError: + continue for index, match in enumerate(cross_triggers): ax = plt.subplot(4, n_examples, 4 * n_examples + index + 1) - plotting.plot_cross_trigger_match( - match, - ax=ax, - preprocessor=preprocessor, - duration=duration, - ) + try: + plotting.plot_cross_trigger_match( + match, + ax=ax, + preprocessor=preprocessor, + duration=duration, + ) + except ValueError: + continue return fig diff --git a/src/batdetect2/plotting/matches.py b/src/batdetect2/plotting/matches.py index 881a24e..7061918 100644 --- a/src/batdetect2/plotting/matches.py +++ b/src/batdetect2/plotting/matches.py @@ -22,6 +22,8 @@ __all__ = [ "plot_cross_trigger_match", ] + +DEFAULT_DURATION = 0.05 DEFAULT_FALSE_POSITIVE_COLOR = "orange" DEFAULT_FALSE_NEGATIVE_COLOR = "red" DEFAULT_TRUE_POSITIVE_COLOR = "green" @@ -119,9 +121,6 @@ def plot_matches( return ax -DEFAULT_DURATION = 0.05 - - def plot_false_positive_match( match: MatchEvaluation, preprocessor: Optional[PreprocessorProtocol] = None, @@ -149,7 +148,8 @@ def plot_false_positive_match( clip = data.Clip( start_time=max(start_time - duration / 2, 0), end_time=min( - start_time + duration / 2, sound_event.recording.duration + start_time + duration / 2, + sound_event.recording.duration, ), recording=sound_event.recording, )