Skip to content

Draft: Experimental timed autofocus

This MR is for code written by Henry during his summer project that implements an optimised autofocus algorithm. I've not yet reviewed exactly what the changes are: there are two MRs implementing different versions of the algorithm. Both are draft for now, but we may want to merge one or the other depending on whether it works when tested more widely.

The basic principle is that we use a saved sharpness vs z profile instead of acquiring a new one each time, and we attempt to move down and then back up to the peak, rather than down-up-down-up. This should be significantly faster, and should also reduce overshooting due to latency issues.

This MR contains the following

  • Copies of SharpnessMonitor for X and Y. These should be subclasses/removed.
  • A spline-based autofocus that fits on the fly.

Before merge:

  • Deduplicate SharpnessMonitor classes (or remove X and Y ones)
  • Improve the stopping condition: currently it always tries 50 iterations of the fit, presumably it should keep fitting until the predicted stopping point is close?
  • Save the sharpness sweep, so that it's only re-acquired when needed. This will require defining when a new curve is needed (and providing an option to forcibly acquire one).
  • Add it to the web app.
  • Figure out how to nicely expose multiple autofocus options.
  • Carefully check all relative/absolute moves. My reading of the code is that it has an absolute start point, which could be a very bad move! This will definitely rear its head when tested on more microscopes, ideally we'd fix it first!
  • Test on more microscopes (after checking relative/absolute moves are done appropriately).

Merge checklist:

  • All new/changed functions have up to date typehints and docstrings
  • Any UI updates have a before and after screenshot in the MR description
  • Unit testing of new functionality has similar or better coverage than similar existing code
  • This code has been tested on a microscope
    • With webapp has been recompiled (if changed)
    • With updated settings JSON (if changed)
    • SmartScan and live stitching work
Edited by Richard Bowman

Merge request reports

Loading