Handle empty and tiny localization inputs without crashing#14
Merged
Conversation
frameconnect and its building blocks crashed on a BasicSMLD with 0 (or
untyped/abstract) emitters: reductions like `counts`/`mean`/`extrema` ran
over empty collections, e.g. `MethodError: zero(Type{Any})` from
`reduce_empty(+, Type{Any})` and "reducing over an empty collection".
This surfaced from the SMLMAnalysis pipeline on near-empty dSTORM cells.
Add isempty guards at the empty-input sites so 0-localization data
degrades gracefully (passthrough/empty result) instead of crashing:
- frameconnect: early-return the (empty) input + zeroed info before the
pipeline. When calibration is configured, still emit a graceful fallback
CalibrationResult (calibration_applied=false) so downstream code sees a
uniform shape for 0 and 1-2 localizations.
- precluster: return the input unchanged for 0 emitters (guards `counts`
on datasetnum/framenum and `first(emitters)`).
- combinelocalizations: return the input unchanged for 0 emitters.
The calibration path was already empty-safe (n_pairs < 100 -> fallback);
1-2 localization inputs already worked and are now covered by tests.
Add test/test_empty_input.jl covering 0/1/2 localizations (default and
calibration-enabled, concrete and abstract emitter eltype) plus the
combinelocalizations/precluster building blocks.
Patch bump 0.3.2 -> 0.3.3.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
frameconnectand its building blocks crashed on aBasicSMLDwith 0 (or untyped/abstract) emitters: internal reductions (counts/mean/extrema) ran over empty collections, producingMethodError: zero(Type{Any})fromreduce_empty(+, Type{Any})and"reducing over an empty collection". This surfaced from the SMLMAnalysis pipeline on near-empty dSTORM cells (some cells yield ~0 localizations) — the pipeline should degrade gracefully, not crash.Changes
isemptyguards at the empty-input sites so 0-localization data returns a passthrough/empty result instead of crashing:frameconnect— early-return the (empty) input + a zeroedFrameConnectInfobefore the pipeline. When calibration is configured, it still emits a graceful fallbackCalibrationResult(calibration_applied=false) so downstream code readinginfo.calibration.*sees a uniform shape for 0 vs 1–2 localizations.precluster— return the input unchanged for 0 emitters (guardscountson datasetnum/framenum andfirst(emitters)).combinelocalizations— return the input unchanged for 0 emitters.calibration.jl— no change needed;analyze_calibrationalready falls back atn_pairs < 100before any reduction, and the empty branch reuses it.Tests
New
test/test_empty_input.jlcovers 0/1/2 localizations × (default + calibration-enabled) × (concrete + abstractEmitter2DFiteltype), plus thecombinelocalizations/preclusterbuilding blocks.Full suite: 224/224 pass. 0-emitter
BasicSMLDnow returns(empty_smld, info)withn_combined=0; 1/2/9-loc inputs return cleanly; calibration-enabled empty/tiny →calibration_applied=false.Notes
Infdensity → Optim/LAP spins. Does not occur with real sub-pixel data; can be a follow-up if a real cell ever triggers it.🤖 Generated with Claude Code