Skip to content

Fix raw formatter loading for empty detections and large outputs - #74

Merged
mbsantiago merged 7 commits into
mainfrom
fix/raw-format-stack
Aug 8, 2026
Merged

Fix raw formatter loading for empty detections and large outputs#74
mbsantiago merged 7 commits into
mainfrom
fix/raw-format-stack

Conversation

@mbsantiago

Copy link
Copy Markdown
Collaborator

Summary

This PR improves the raw output formatter for larger prediction sets and fixes round-trip handling for clips with no detections.

Changes include:

  • avoid np.stack on empty class score / feature arrays when saving raw outputs
  • add n_jobs support for loading raw prediction files in parallel
  • add optional progress reporting while loading raw predictions
  • speed up raw loading by avoiding per-detection xarray .sel(...) calls
  • preserve recording metadata correctly when loading raw predictions
  • add regression tests for recording metadata, empty detections, and multiprocessing load

Testing

  • uv run pytest tests/test_data/test_predictions/test_raw.py

Copilot AI lite review requested due to automatic review settings August 8, 2026 09:56
@mbsantiago
mbsantiago merged commit d7896c6 into main Aug 8, 2026
5 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the raw output formatter to correctly handle empty detections, improve raw prediction loading performance, and add optional parallel loading/progress reporting; it also adds regression tests for these behaviors.

Changes:

  • Avoid stacking empty class_scores/features arrays when saving raw outputs.
  • Add n_jobs-based parallel loading and optional progress reporting during raw loads.
  • Optimize raw loading by avoiding per-detection xarray .sel(...) calls and improve recording metadata round-tripping.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
tests/test_data/test_predictions/test_raw.py Adds regression tests covering recording metadata round-trip, empty detections, and multiprocessing load.
src/batdetect2/outputs/formats/raw.py Implements empty-detection save fix, parallel/progress-enabled loading, and faster dataset-to-prediction conversion.
Suppressed comments (2)

src/batdetect2/outputs/formats/raw.py:95

  • If show_progress=True and tqdm isn’t installed (see optional import above), calling tqdm(...) will fail with a TypeError. Raise a clear error when progress is requested but tqdm is unavailable.
        if self.show_progress:
            iterable = tqdm(files, total=len(files))

src/batdetect2/outputs/formats/raw.py:106

  • Same as sequential load: when show_progress=True but tqdm isn’t installed, wrapping pool.imap(...) with tqdm(...) will fail. Add an explicit check and raise a helpful ImportError.
        with Pool(self.n_jobs) as pool:
            if not self.show_progress:
                return pool.map(self.load_single_file, files)

            return list(

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

from loguru import logger
from soundevent import data
from soundevent.geometry import compute_bounds
from tqdm import tqdm
Comment on lines +215 to +216
start_time=float(clip_data.clip_start),
end_time=float(clip_data.clip_end),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants