Acquisition core refactor (Phase 1 of 4): single-loop acquisition, decoupled tracking, design for recording/focus/UI phases#1
Draft
Sebzdead wants to merge 13 commits into
Draft
Conversation
…lan) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Implements the core acquisition loop (ADR 0001): reads both cameras per tick, assigns a single contiguous frame_index, publishes to FrameHub for display/tracking, and forwards AcquiredPairs to an optional sink. A camera failure on one side yields None for that slot without breaking the index sequence, enabling downstream drop detection via index gaps. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Implements find_worm_cms (largest-blob centroid via skimage), simple_to_center (pixel offset to mm move), and Tracker (injected compute callback wired to stage.move_relative), keeping the tracking thread fully decoupled from the AcquisitionEngine per ADR 0001. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Implements core/stage_zaber.py with ZaberStage (lazy zaber_motion imports, opens serial connections once at construction) and connect_stage factory that degrades to NullStage on any connection failure so the server boots without hardware. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Implements the Camera ABC for FLIR/Spinnaker hardware via EasyPySpin. EasyPySpin is imported lazily inside __init__ so the module is parseable/importable without the SDK installed. The camera is configured as the acquisition clock: fixed AcquisitionFrameRate and exposure with auto-exposure/auto-gain disabled, matching ADR 0001 decision #2. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…R 0001) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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
Stability + UX refactor of the WormsPy microscope control software, driven by a grilling/code-review session against the published design. Phase 1 is implemented; Phases 2–4 are drafted as executable plans on this branch. Opened as a draft — Phase 1's hardware adapters and app.py integration are not yet verified on the rig, and recording/focus/manual are intentionally deferred to later phases.
Why
The original
app.pyran each camera inside its own Flask MJPEG generator, so the two streams could drift without bound, the Zaber motors only existed while the left feed streamed (crashingmove_to_center/autofocus/manual on browser disconnect), recorded playback speed relied on a hand-typedFPSconstant, the stage-limit check was an always-true no-op, and "FocusLock" was a PID that couldn't hill-climb an unsigned sharpness metric. SeeCONTEXT.mdanddocs/adr/0001-0003for the decisions.What changed (Phase 1 — implemented, ADR 0001)
WormSpy/backend/code/core/package:frames(thread-safeFrameHub),cameras+cameras_spinnaker,stage+stage_zaber,acquisition(single loop, shared monotonicframe_index),tracking(helpers + decoupledTrackerthread).app.pyrewired: acquisition owned at startup (not in HTTP handlers), Zaber connected once with gracefulNullStagefallback, display served from theFrameHub. Eliminates loop drift and motor-on-disconnect.clamp_native) replacing the no-oporcheck.Design + plans included
CONTEXT.md— glossary (frame-sync, loop drift, Hold Focus).docs/adr/0001-0003— acquisition architecture, Hold Focus (why autofocus is impossible on this rig), recording integrity.docs/superpowers/plans/— four executable phase plans:/statusendpoint, UI reflects backend truth, error toasts, cleanupReviewer notes / known caveats
toggle_af/toggle_manualreturn 500; auto-tracking does nothing — all restored in Phases 2–3. Documented in the Phase 1 plan + the Task 9 commit.Test plan
cd WormSpy/backend/code && python -m pytest→ 38 passing (usePYTEST_DISABLE_PLUGIN_AUTOLOAD=1if a local napari pytest plugin is present)connect_stage/SpinnakerCamerasmoke checks (plan steps 7.5, 8.4)🤖 Generated with Claude Code