Fix raw formatter loading for empty detections and large outputs - #74
Merged
Conversation
… into fix/raw-format-stack
There was a problem hiding this comment.
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/featuresarrays 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=Trueandtqdmisn’t installed (see optional import above), callingtqdm(...)will fail with aTypeError. Raise a clear error when progress is requested buttqdmis 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=Truebuttqdmisn’t installed, wrappingpool.imap(...)withtqdm(...)will fail. Add an explicit check and raise a helpfulImportError.
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), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR improves the raw output formatter for larger prediction sets and fixes round-trip handling for clips with no detections.
Changes include:
np.stackon empty class score / feature arrays when saving raw outputsn_jobssupport for loading raw prediction files in parallel.sel(...)callsTesting
uv run pytest tests/test_data/test_predictions/test_raw.py