Hardware control library for microscopes via Pycromanager (Micro-Manager).
Part of the QPSC (QuPath Scope Control) system For complete installation instructions, see: https://github.com/uw-loci/QPSC
- Hardware Abstraction: Platform-independent microscope control interface
- Pycromanager Integration: Full Micro-Manager hardware support
- Autofocus: Multiple autofocus algorithms and metrics
- Stage Control: XYZ stage positioning and movement
- Configuration Management: YAML-based microscope configuration
Part of QPSC (QuPath Scope Control)
Requirements:
- Python 3.9 or later
- pip (Python package installer)
- Git (for
pip install git+https://...commands) - Micro-Manager 2.0+
ppm-library and requires Micro-Manager 2.0+.
See the QPSC Installation Guide for complete setup instructions.
Install dependencies first:
# 1. Install ppm-library
pip install git+https://github.com/uw-loci/ppm_library.git
# 2. Then install microscope-control
pip install git+https://github.com/uw-loci/microscope_control.gitgit clone https://github.com/uw-loci/microscope_control.git
cd microscope_control
pip install -e .For automated setup, use the QPSC setup script.
Cause: Editable install issue with package structure.
Solution:
The repository has been updated to fix this issue. If you encounter this error:
-
Update to latest version:
cd microscope_control git pull -
Verify
pyproject.tomlhas the correct configuration:[tool.hatch.build.targets.wheel] packages = ["."]
-
Reinstall in editable mode:
pip install -e . --force-reinstall --no-deps -
Verify installation:
pip show microscope-control
Cause: Missing OpenCV dependency (required by autofocus metrics).
Solution:
Install OpenCV:
pip install opencv-pythonThis dependency will be added to pyproject.toml requirements in a future update.
For more troubleshooting, see the QPSC Installation Guide.
from microscope_control import init_pycromanager, PycromanagerHardware, ConfigManager
# Initialize hardware
core, studio = init_pycromanager()
config_mgr = ConfigManager()
settings = config_mgr.get_config('config_PPM')
hardware = PycromanagerHardware(core, studio, settings)
# Move stage
from microscope_control import Position
hardware.move_to_position(Position(x=1000, y=2000, z=-3000))
# Run autofocus
from microscope_control import AutofocusUtils
af = AutofocusUtils(hardware, settings)
best_z = af.run_autofocus(current_position)This package includes two types of testing tools:
Hardware characterization and calibration tools are located in the source modules:
microscope_control/autofocus/test.py- Autofocus diagnostic testing
These tools are called from the QuPath QPSC extension GUI during microscope setup and calibration. They:
- Require live hardware connections
- Generate diagnostic plots and CSV data
- Test autofocus algorithms at current microscope position
- Validate autofocus parameter tuning
Not intended for automated CI/CD - these are interactive diagnostic tools.
Automated pytest-compatible unit tests are located in the tests/ directory:
tests/test_autofocus_metrics.py- Tests for 13 autofocus metric calculationstests/test_tissue_detection.py- Tests for empty region detection algorithmstests/test_coordinate_validation.py- Tests for stage safety checkstests/test_config_manager.py- Tests for configuration management
These tests:
- Run without hardware (use synthetic test data)
- Can be integrated into CI/CD pipelines
- Test pure-function components (math, validation, parsing)
Running Unit Tests:
# Install dev dependencies
pip install -e ".[dev]"
# Run all tests
pytest
# Run specific test file
pytest tests/test_autofocus_metrics.py
# Run with coverage report
pytest --cov=microscope_control --cov-report=html
# View coverage report
open htmlcov/index.html # or xdg-open on LinuxTest Coverage:
Current automated tests achieve ~75-85% coverage for testable components:
- ✅ Autofocus metrics (all 13 metrics)
- ✅ Empty region detection (5 detection methods)
- ✅ Coordinate validation (safety-critical)
- ✅ Configuration management
- ⏸️ Hardware-dependent code (requires diagnostic tools, not unit tests)
MIT License