A package that provides flexible autofocus procedures for telescopes.
Project description
AstrAFocus
A Python package for automated telescope focusing.
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.
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 diameters of detected stars. 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!
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file astrafocus-0.1.4.tar.gz.
File metadata
- Download URL: astrafocus-0.1.4.tar.gz
- Upload date:
- Size: 834.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3d776aab0cc713b2c6fa2383731124a34bc8c3a253d1cbeb97b8e3f049862d6
|
|
| MD5 |
7bb15c6eeb3e1d4278aa9ef6ec68bb2d
|
|
| BLAKE2b-256 |
4df2ab461ed95563e792d673671150e5be8fe7795de74903a61989ae9d4eb907
|
Provenance
The following attestation bundles were made for astrafocus-0.1.4.tar.gz:
Publisher:
python-publish-to-pypi.yml on dgegen/astrafocus
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
astrafocus-0.1.4.tar.gz -
Subject digest:
d3d776aab0cc713b2c6fa2383731124a34bc8c3a253d1cbeb97b8e3f049862d6 - Sigstore transparency entry: 1365479592
- Sigstore integration time:
-
Permalink:
dgegen/astrafocus@c53bddc5e1ee5fc71c88e72f4af0faaf93bd57a4 -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/dgegen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish-to-pypi.yml@c53bddc5e1ee5fc71c88e72f4af0faaf93bd57a4 -
Trigger Event:
release
-
Statement type:
File details
Details for the file astrafocus-0.1.4-py3-none-any.whl.
File metadata
- Download URL: astrafocus-0.1.4-py3-none-any.whl
- Upload date:
- Size: 76.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cbda72790127a4b02bebbe436050fdee09e3e6d4f683792233892fd7dbf3b116
|
|
| MD5 |
2c586fbb140041312cca3eae08908442
|
|
| BLAKE2b-256 |
a3aa6c1a0f0d919c41a6b4c6a5977588b1845d6848117a640dfa76fea288e924
|
Provenance
The following attestation bundles were made for astrafocus-0.1.4-py3-none-any.whl:
Publisher:
python-publish-to-pypi.yml on dgegen/astrafocus
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
astrafocus-0.1.4-py3-none-any.whl -
Subject digest:
cbda72790127a4b02bebbe436050fdee09e3e6d4f683792233892fd7dbf3b116 - Sigstore transparency entry: 1365479593
- Sigstore integration time:
-
Permalink:
dgegen/astrafocus@c53bddc5e1ee5fc71c88e72f4af0faaf93bd57a4 -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/dgegen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish-to-pypi.yml@c53bddc5e1ee5fc71c88e72f4af0faaf93bd57a4 -
Trigger Event:
release
-
Statement type: