Skip to content

Fix objectivecontroller#201

Merged
beniroquai merged 13 commits intomasterfrom
fix_objectivecontroller
Dec 16, 2025
Merged

Fix objectivecontroller#201
beniroquai merged 13 commits intomasterfrom
fix_objectivecontroller

Conversation

@beniroquai
Copy link
Copy Markdown
Collaborator

This pull request introduces several improvements to the project's CI/CD workflows, dependency management, and repository hygiene. The main changes include the addition of automated version bumping and PyPI release workflows, enhancements to Docker build and publish processes, and updates to testing and dependency management configurations.

CI/CD and Release Automation:

  • Added a new workflow .github/workflows/auto-version-bump.yml to automatically bump the patch version and publish releases to PyPI when changes are pushed to master. This streamlines the release process and reduces manual intervention.
  • Updated the PyPI publishing workflow .github/workflows/imswitch-pypi.yml to use more recent GitHub Actions and simplified steps for building and publishing packages.

Docker Build and Publish Improvements:

  • Replaced the old multi-architecture Docker workflow .github/workflows/imswitch-docker-multiarch-noqt.yaml with a new, more robust workflow .github/workflows/imswitch-docker-noqt.yaml. The new workflow supports multi-platform builds, improved tagging, and better handling of GitHub Container Registry edge cases. [1] [2]

Dependency Management:

  • Introduced a dependabot.yml configuration to automate dependency updates for GitHub Actions, pip, and Docker, scheduled monthly.
  • Updated .flake8 to exclude the ImTools directory from linting.

Testing and Build Process Updates:

  • Updated the test matrix in .github/workflows/imswitch-test.yml to use Python 3.11 and 3.12, and adjusted test commands to run only relevant test directories, improving efficiency and compatibility. [1] [2] [3]
  • Modified the bundle workflow to use uv for dependency installation, replacing pip for potentially faster and more reproducible installs.

Repository Hygiene:

  • Added .dockerignore and .gitignore files to .arkitekt_next to prevent committing sensitive or unnecessary files such as credentials and caches.

Let me know if you want to dive deeper into any of these changes!

ObjectiveController now manages all runtime state and motor movements using ESP32StageManager axis A, decoupling from ObjectiveManager which is now only responsible for configuration persistence. ObjectiveManager is simplified to provide read/write access to setup JSON parameters, including new zPositions for Z focus offsets. The controller caches config values, updates detector pixel size, and provides new API methods for Z calibration and position saving. Legacy hardware interface and state management in ObjectiveManager are removed.
Corrects the calculation of scan positions in AutofocusController by replacing integer division with float division. Updates the copyright year in ObjectiveManager to 2026.
Objective movement now runs in a separate thread via moveToObjectiveThread for improved responsiveness. Z focus adjustment is applied asynchronously, and logic for updating the current objective and pixel size has been reorganized for clarity.
Introduced debug plotting in FocusLockController for visualizing focus metric results and current images when is_debug is enabled. Updated focus metric computation to allow passing a debug flag, adjusted peak distance parameter, and refactored PeakMetric1D for simplified 1D peak finding. Also fixed focus offset calculation and stage movement logic, and improved calibration plot labeling.
Rewrote the PeakMetric class to focus exclusively on robust left-dot peak detection, adding ROI logic, improved tracking, and fallback mechanisms. Enhanced peak selection, baseline removal, and noise scaling, and added detailed reporting fields. Updated subpixel fitting and error handling for 2D grayscale input. No changes to CenterOfMassFocusMetric.
Introduces parameters for specifying autofocus target focus setpoint and maximum attempts in ExperimentController, FocusLockController, and experiment_normal_mode. Updates autofocus methods to accept and propagate these parameters, and adds background threading support for hardware autofocus. Also adds a method to stop focus calibration. Binary files updated.
Replaces usage of 'safeDistanceZHoming' with 'safePositionZHoming' for Z axis movements during homing procedures. This change clarifies intent and ensures the Z axis moves to a defined safe position rather than a relative distance.
Copilot AI review requested due to automatic review settings December 16, 2025 12:08
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request refactors the objective control system and focus lock functionality in ImSwitch. The main changes include decoupling hardware interface from state management, improving focus metric computation, and enhancing autofocus capabilities.

Key changes:

  • Refactored ObjectiveController to be the single source of truth for objective state, removing direct hardware dependencies
  • Unified focus computation logic in FocusLockController through a single _captureAndComputeFocus method
  • Enhanced PeakMetric focus algorithms with left-dot-only tracking to prevent peak jumping

Reviewed changes

Copilot reviewed 10 out of 12 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test.png Binary test image added (PNG file)
calibration_plot.png Binary calibration plot image added (PNG file)
PositionerManager.py Removed saveStageOffset method, delegating persistence to controller
ESP32StageManager.py Added frame homing procedure and fixed safe position homing logic
ObjectiveManager.py Simplified to configuration-only manager, removed runtime state
ObjectiveController.py Refactored as single source of truth for objective state and motor control
focusmetrics.py Enhanced PeakMetric with left-dot tracking and added PeakMetric1D
experiment_normal_mode.py Added autofocus parameters (max_attempts, target_focus_setpoint)
PositionerController.py Implemented saveStageOffset for config persistence
FocusLockController.py Unified focus computation and enhanced calibration threading
ExperimentController.py Added autofocus parameter forwarding and logging improvements
AutofocusController.py Fixed integer division bug in scan position calculation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

"final_error_um": None
}

performOneStepAutofocus = self.currentZPosition
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

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

Variable performOneStepAutofocus is not used.

Suggested change
performOneStepAutofocus = self.currentZPosition

Copilot uses AI. Check for mistakes.
Comment thread imswitch/imcontrol/controller/controllers/FocusLockController.py Outdated

# Update manager state with 0-based index (will emit signal)
self._manager.setCurrentObjective(internal_slot)
if False and slot == self._currentObjective:
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

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

This statement is unreachable.

Suggested change
if False and slot == self._currentObjective:
if slot == self._currentObjective:

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@beniroquai beniroquai merged commit c304272 into master Dec 16, 2025
2 of 14 checks passed
@beniroquai beniroquai deleted the fix_objectivecontroller branch December 16, 2025 12:48
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