Skip to main content

AstrAFocus

A Python package for automated telescope focusing.

logo image

AstrAFocus solves two problems: finding suitable sky regions for focus calibration, and performing the autofocus sweep itself. It is hardware-agnostic — connect real devices by implementing two small interface classes, or use the built-in simulators for development and testing.

Documentation

Installation

pip install astrafocus

Or from source using uv:

git clone https://github.com/dgegen/astrafocus.git
cd astrafocus
uv sync

For development (includes linting, docs, and test dependencies):

uv sync --group dev --group docs --group test

Optional extras:

pip install "astrafocus[alpaca]"       # ASCOM Alpaca device support (alpyca)
pip install "astrafocus[visualization]" # matplotlib, IPython, notebook
pip install "astrafocus[extended]"     # scikit-learn for additional estimators

Quick start

from astrafocus.interface.simulation import CabaretDeviceSimulator
from astrafocus.autofocuser import AnalyticResponseAutofocuser
from astrafocus.star_size_focus_measure_operators import HFRStarFocusMeasure

simulator = CabaretDeviceSimulator(current_position=11_000, allowed_range=(9_000, 13_000))

autofocuser = AnalyticResponseAutofocuser(
    autofocus_device_manager=simulator,
    exposure_time=3.0,
    focus_measure_operator=HFRStarFocusMeasure,
    n_steps=(20, 10),
)
autofocuser.run()
print(f"Best focus position: {autofocuser.best_focus_position}")

See the Getting Started notebook for a full walkthrough, or explorations/speculoos_main.py for a more complete real-world example.

Key components

Autofocus

  • AnalyticResponseAutofocuser — sweeps the focuser through a range of positions, measures focus quality, and fits an analytic curve (e.g. parabola) to locate the optimum.
  • NonParametricResponseAutofocuser — same sweep strategy, but uses a non-parametric smoother (LOWESS, spline, or RBF) instead of an analytic fit. Works with any focus measure operator.
  • FocusMeasureOperatorRegistry — 13 built-in operators: star-size estimators (hfr, gauss) and image-sharpness metrics (fft, tenengrad, laplacian, brenner, …).

Choosing a focus measure

  • Coarse Search (e.g., fft): Best for broad ranges where stars appear as blurry "donuts." These non-parametric operators measure overall frame sharpness without needing to identify individual stars, making them nearly impossible to "confuse" with distorted optics.

  • Fine Tuning (e.g., HFR): Best for precision near the focus peak. These algorithms fit a "V-curve" to the sizes of detected stars (half flux radius or FWHM). They provide great accuracy once stars are point-like, but will fail during wide searches if the stars are too bloated to be recognized by the star-finder.

Sky targeting

  • ZenithNeighbourhoodQuery — queries a Gaia-2MASS catalogue (local SQLite or remote) to find a region near zenith with a suitable density of stars for focus calibration.

Hardware interface

Connect real hardware by implementing two classes:

  • CameraInterface — one method: perform_exposure(texp).
  • FocuserInterface — one method: move_focuser_to_position(position).

Wrap them in AutofocusDeviceManager and pass it to any autofocuser. For hardware-free development and testing, use the built-in CabaretDeviceSimulator (synthetic images) or ObservationBasedDeviceSimulator (replay from FITS files).

The Gaia-2MASS Local Catalogue

The sky-targeting component requires a local Gaia-2MASS catalogue. A citable snapshot is available on Zenodo: https://zenodo.org/records/18214672 (DOI: 10.5281/zenodo.18214672). The original repository with build scripts and source data is available at ppp-one/gaia-tmass-sqlite.

Citation

If you use AstraFocus in your research, please cite it. A DOI is minted via Zenodo for each release. Use the Cite this repository button on GitHub for an up-to-date citation in your preferred format.

May your stars align and your focus be as sharp as a caffeinated owl spotting its prey!

Metadata

Release files for astrafocus 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for astrafocus 0.2.0
File Size Uploaded Provenance Actions
astrafocus-0.2.0.tar.gz 870.8 kB With provenance Details for astrafocus-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for astrafocus 0.2.0
File Interpreter ABI Platform Actions
astrafocus-0.2.0-py3-none-any.whl Python 3 none any Details for astrafocus-0.2.0-py3-none-any.whl

Total release size: 962.3 kB

Release files / astrafocus-0.2.0.tar.gz

Download URL astrafocus-0.2.0.tar.gz
Size 870.8 kB
Tags Source
SHA-256 checksum
How to use checksums
c4e37467aa2be8dae8f13111d79a6b4ae324d2671ed524e6df0c46b8484c36b3
BLAKE2b-256 checksum
How to use checksums
fcc168a133b7b175f31f5c04002cb6ec765d9cd05d2d4a815282ac1325768e10
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.

Transparency log

Release files / astrafocus-0.2.0-py3-none-any.whl

Download URL astrafocus-0.2.0-py3-none-any.whl
Size 91.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
56ec00c68aceb8954156a4c8b91b454f4a55de42a64f65661ef2941d64341fc2
BLAKE2b-256 checksum
How to use checksums
a3f6b1394cec9cd25e75cb2d441bb44f13292ad50055c222ab918c0220a13e66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.

Transparency log

Security for astrafocus 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for astrafocus-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page