Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions bats_ai/core/utils/contour_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import contextlib
import logging
from pathlib import Path
from typing import Any
Expand Down Expand Up @@ -102,10 +103,8 @@ def compute_auto_levels( # noqa: PLR0913
return []

if mode == "multi-otsu":
try:
with contextlib.suppress(ValueError):
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, this uses a more specific exception, that seems likely to actually be raised by threshold_multiotsu.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BryonLewis Can you verify that the correct behavior on an exception is indeed to silently proceed to the end of the function and call np.percentile instead?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll test it tomorrow. There may be an argument for removing this whole contour extraction from the application. We were using it before to generate contours from spectrogram images for clearer delineation between values, but without some decent filtering (reduction in contour accuracy) and not knowing the size of the wav files, the loading times and data size could be too large to be generally useful.

We have disabled this section of the conversion process from wav to spectrogram + metadata.

Copy link
Copy Markdown
Member Author

@brianhelba brianhelba Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. That is indeed what the code did and still does. I just wondered if it was overly eager to suppress exceptions that should actually be allowed to cause a failure.

return threshold_multiotsu(valid, classes=multi_otsu_classes).tolist()
except Exception:
pass

if mode == "histogram":
return auto_histogram_levels(
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ ignore = [
"PLC0415", # import-outside-top-level
"PLW2901", # redefined-loop-name
"PTH", # flake8-use-pathlib
"S110", # try-except-pass
"TRY300", # try-consider-else
"TRY301", # raise-within-try
]
Expand Down
5 changes: 2 additions & 3 deletions scripts/contours/extract_contours.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from __future__ import annotations

import colorsys
import contextlib
import json
import logging
from pathlib import Path
Expand Down Expand Up @@ -114,10 +115,8 @@ def compute_auto_levels( # noqa: PLR0913
return []

if mode == "multi-otsu":
try:
with contextlib.suppress(ValueError):
return threshold_multiotsu(valid, classes=multi_otsu_classes).tolist()
except Exception:
pass

if mode == "histogram":
return auto_histogram_levels(
Expand Down