Autofocus

HFR/HFD-based autofocus. The model is learn once, refocus fast: you run a wizard once per optical setup to learn the focus V and write a reusable Refocus recipe, then a fast Refocus re-traces a tight sweep around where you are without re-finding the whole V. There are two ways to learn: Adaptive First Light, which finds everything for you (step, range, backlash) with no numbers to enter, and the plain Wizard, where you drive the sweep yourself.

The engine was rebuilt across v20.28–v20.34 (linear multi-star sweep → two-button Wizard/Refocus → single-pass Wizard); the Adaptive First Light path arrived with v20.51 and the Refocus apex refinement with v20.75. Earlier builds used a two-phase HFD-target navigation model; that is gone from the buttons (the old calibrated path lingers in the backend for compatibility only).

One method, shared rules

Every path — both wizards and Refocus — shares the same global rules, so they take their measurements the same way:

The displayed metric is HFD = 2 × the internal HFR, so the numbers match Voyager (v20.30). Thresholds and the saved recipe are kept internally in HFR.

Adaptive First Light — the no-numbers wizard (recommended)

Adaptive First Light is the self-finding version of the wizard: you don't enter a step, a range, or a sweep offset — it discovers them. Start from your best manual focus with a star field in view and press the button; it does the rest and leaves the scope focused.

  1. Noise floor. It takes a few frames without moving to measure how much the HFD jitters from seeing, so it knows what a real change looks like versus noise.
  2. Focuser resolution probe. It steps outward by doubling amounts until the HFD changes by clearly more than that noise — that tells it the smallest useful step for your focuser (a fine focuser gets a small step, a coarse one a larger step, automatically).
  3. V-curve. With the step and sweep known, it runs the same single adaptive sweep the plain Wizard does, brackets the V, moves to best focus, and saves the Refocus recipe.
  4. Backlash measurement. It then measures the focuser's backlash (lost motion on reversal) from the V-arm slope and writes a focuser report with the recommended backlash steps/direction — see The focuser report below.

The saved recipe records what it learned (adaptive, the learned step, the measured noise, a fit-confidence figure) so Refocus benefits immediately. Because it moves the mount only if you asked it to (it never slews unless Slew to focus star is on), it's safe to run on the field you're already imaging. This is the button to reach for first; the plain Wizard below is there when you want to drive the sweep yourself.

Wizard — drive the sweep yourself (run once per setup)

Run the Wizard once per optical configuration, starting from a position that is already roughly focused. It is a single adaptive pass (v20.34) — one sweep that brackets the V and saves the step that worked. There is no separate coarse-then-fine derivation pass. Use it when you'd rather set the step and out-travel yourself; otherwise prefer Adaptive First Light above, which finds them for you.

  1. From the current position it racks OUT by the coarse offset (coarse_out, default 250 in the runner; the Console drives a larger out-travel), then moves IN by backlash_clear to the first sample.
  2. It samples every step stepping inward, watching HFD drop to a minimum.
  3. It does not climb the whole far arm: once there are ~5–6 real samples (rise_past_min) past the low point, the V is mathematically determined — it stops, fits, and moves to best focus.
  4. If it can't bracket a clean V (no clear minimum, or too few points to fit), it halves the step and restarts from the out position. After a couple of tries it gives up with a "re-center near focus" message rather than fitting junk.

step defaults to whatever worked last time (the saved recipe's step), else 50. Leave the step field blank to reuse it.

On success the Wizard moves to the fitted minimum and writes the Refocus recipe sidecar. The fit uses fit_method (default hybrid): straight V-line slopes for the navigation params, with the focus position refined toward a hyperbolic vertex and the lowest measured HFR reported as the minimum.

Refocus — fast, repeatable

Refocus assumes you are already near focus (you just ran a wizard, or you're partway through a night). Because of that it resolves the apex rather than re-surveying the whole V: it samples with a finer step over a tighter range than the wizard's coarse recipe (a wide coarse sweep gives the sharp bottom only one point and lets the noisy outer wings drag the fit), reusing the same number of exposures. It fits the V with the same fitter, moves to the mathematical minimum, and reports "focus point found at position X" — drawing the two convergence lines and the focus position on the graph. Tune it with [autofocus] refocus_step_frac (the finer step as a fraction of the recipe's step; 1.0 = legacy) and refocus_points_per_arm (how many samples each side of centre).

Pick a filter in the Focuser-card dropdown to refocus through that filter: Refocus moves the wheel there first and focuses at that filter's own exposure, then you're set for imaging through it. Leave it on Current filter to focus where you already are.

Because it re-uses the recipe's half_range / step / backlash_clear, Refocus is a handful of exposures, not a full V hunt. With no recipe it falls back to a sensible default range.

The Refocus recipe (focus_recipe.json)

Either wizard persists its result as a JSON sidecar, focus_recipe.json, next to config.toml (atomic write; JSON-safe). It carries:

When Adaptive First Light wrote the recipe it also stores what it discovered: adaptive: true, the learned min_effective_step, the measured noise_hfr and baseline_hfr, a fit confidence, and the measured backlash (measured_backlash_steps / measured_backlash_direction / measured_backlash_approved). Approving the focuser report (below) flips measured_backlash_approved and sets backlash_clear to the measured value so Refocus uses it.

n_runs accumulates across runs: a fresh run reloads the prior recipe and bumps the count. There is no derivation / learned EMA block — the old two-pass derive-and-learn model was removed in the v20.34 single-pass redesign.

The calibration readout shows focus <pos> · step <n>, and Go to focus drives the focuser straight back to the last saved focus position (from the recipe, falling back to the newest calibration run) — handy after anything moves it off.

The focuser report (focuser_report.json)

When Adaptive First Light measures backlash it writes a second sidecar, focuser_report.json, next to the recipe. It's a human-readable characterisation of your focuser — the learned step, the noise floor, the fitted V slopes and their R², the measured backlash and a confidence figure, and the sampled focus curve — plus the recommended focuser settings (whether to enable backlash and how many steps in which direction).

The report lands awaiting your approval: nothing is applied until you press Approve measured backlash for Refocus. Approving copies the recommended backlash into [focuser] (so it's visible in Settings and saved with profiles), marks the report approved, and points Refocus's backlash_clear at the measured value. Until you approve it, the report is informational only.

Running it

From Console → Focuser card:

The Approve measured backlash for Refocus button (in the wizard modal, enabled once a focuser report exists) applies the report's recommended backlash — see The focuser report above.

Endpoints are POST /api/console/autofocus/adaptive-first-light, /focus-wizard, /refocus, /approve-focuser-report, /goto-focus, and /clear. Every path logs each sample to the ops log: pos … HFD=… (N stars) per point, the start → measured → moving → done phases, and focus point found at … on completion.

In sequences

The Sequencer triggers autofocus two ways, both of which run the validated run_refocus synchronously and cancelably (the sequence's Stop reaches it; v20.32):

Two extras apply after a focus completes:

A refocus failure mid-sequence is journaled but does not abort the run (fail-soft), and the camera is restored to full-frame / bin 1 afterwards so science captures are unaffected. The V-curve streams live into the sequence run view as it samples.

Before running a wizard

Key tunables (Settings → Autofocus)

Measurement

Fit & motion

Wizard

Refocus

Refocus triggers (sequence; master refocus_enabled off by default)

Behind the scenes

Pure NumPy — no photutils, no sep. Star detection is connected-components flood fill on a sigma-thresholded image with eccentricity, size, and saturation filtering. HFR is the radius at which cumulative flux (sorted by distance from the flux-weighted centroid) reaches half the total, within an aperture sized to the star (floor 6 px, grown for real defocus donuts; v20.30) over a local-annulus background. Frames captured during AF stay in memory — they are not written to the IMAGES directory.

What's deferred

See the Roadmap topic. Items still to come: a min/max focus-altitude guard, and on-rig confirmation of the default step / range / exposure for a given optical train. Per-filter focus offsets now ship (see In sequences). The older calibrated HFD-target run_autofocus path remains in the backend for compatibility but is not what the wizard/Refocus buttons use.

Astroworx Starship v22.2.10 · this page is the in-app help of that buildDownload · HTTP API