Ignore plotting failures in gallery plot

This commit is contained in:
mbsantiago 2025-08-08 13:30:44 +01:00
parent c3d377b6e0
commit 2341f822a7
2 changed files with 40 additions and 28 deletions

View File

@ -93,39 +93,51 @@ def plot_class_examples(
for index, match in enumerate(true_positives): for index, match in enumerate(true_positives):
ax = plt.subplot(4, n_examples, index + 1) ax = plt.subplot(4, n_examples, index + 1)
try:
plotting.plot_true_positive_match( plotting.plot_true_positive_match(
match, match,
ax=ax, ax=ax,
preprocessor=preprocessor, preprocessor=preprocessor,
duration=duration, duration=duration,
) )
except ValueError:
continue
for index, match in enumerate(false_positives): for index, match in enumerate(false_positives):
ax = plt.subplot(4, n_examples, n_examples + index + 1) ax = plt.subplot(4, n_examples, n_examples + index + 1)
try:
plotting.plot_false_positive_match( plotting.plot_false_positive_match(
match, match,
ax=ax, ax=ax,
preprocessor=preprocessor, preprocessor=preprocessor,
duration=duration, duration=duration,
) )
except ValueError:
continue
for index, match in enumerate(false_negatives): for index, match in enumerate(false_negatives):
ax = plt.subplot(4, n_examples, 2 * n_examples + index + 1) ax = plt.subplot(4, n_examples, 2 * n_examples + index + 1)
try:
plotting.plot_false_negative_match( plotting.plot_false_negative_match(
match, match,
ax=ax, ax=ax,
preprocessor=preprocessor, preprocessor=preprocessor,
duration=duration, duration=duration,
) )
except ValueError:
continue
for index, match in enumerate(cross_triggers): for index, match in enumerate(cross_triggers):
ax = plt.subplot(4, n_examples, 4 * n_examples + index + 1) ax = plt.subplot(4, n_examples, 4 * n_examples + index + 1)
try:
plotting.plot_cross_trigger_match( plotting.plot_cross_trigger_match(
match, match,
ax=ax, ax=ax,
preprocessor=preprocessor, preprocessor=preprocessor,
duration=duration, duration=duration,
) )
except ValueError:
continue
return fig return fig

View File

@ -22,6 +22,8 @@ __all__ = [
"plot_cross_trigger_match", "plot_cross_trigger_match",
] ]
DEFAULT_DURATION = 0.05
DEFAULT_FALSE_POSITIVE_COLOR = "orange" DEFAULT_FALSE_POSITIVE_COLOR = "orange"
DEFAULT_FALSE_NEGATIVE_COLOR = "red" DEFAULT_FALSE_NEGATIVE_COLOR = "red"
DEFAULT_TRUE_POSITIVE_COLOR = "green" DEFAULT_TRUE_POSITIVE_COLOR = "green"
@ -119,9 +121,6 @@ def plot_matches(
return ax return ax
DEFAULT_DURATION = 0.05
def plot_false_positive_match( def plot_false_positive_match(
match: MatchEvaluation, match: MatchEvaluation,
preprocessor: Optional[PreprocessorProtocol] = None, preprocessor: Optional[PreprocessorProtocol] = None,
@ -149,7 +148,8 @@ def plot_false_positive_match(
clip = data.Clip( clip = data.Clip(
start_time=max(start_time - duration / 2, 0), start_time=max(start_time - duration / 2, 0),
end_time=min( end_time=min(
start_time + duration / 2, sound_event.recording.duration start_time + duration / 2,
sound_event.recording.duration,
), ),
recording=sound_event.recording, recording=sound_event.recording,
) )