Speed up integrator alt/az via pyerfa + rewritten FastAltAz#423
Merged
Conversation
Replaces the per-iteration skyfield observe()/apparent()/altaz() chain inside Skyfield_utils.radec_to_altaz with erfa.atco13 (pyerfa). Same precession/nutation/aberration math under the hood, ~19x faster, accuracy holds within ~14 arcsec of the prior skyfield output at well-elevated points. Also rewrites FastAltAz around IAU-1982 GMST + spherical trig + Bennett refraction. Fixes the previous LST formula which double-counted the fractional day, and adds the missing refraction term. API unchanged (catalogs.py and calc_object_altitude continue to work). Per-call cost drops from ~3.4 us to ~1.6 us; total accuracy floor of ~0.3 deg (precession-dominated) is unchanged. Skyfield_utils.set_location now no-ops when the location is unchanged, removing wgs84.latlon rebuilds on every integrator tick. Net effect on the integrator's per-frame altaz/constellation work (set_location + 2x radec_to_altaz + constellation): ~1840 us -> ~113 us (~16x faster). Adds pyerfa to requirements.txt and unit tests for FastAltAz and the pyerfa-backed Skyfield_utils.radec_to_altaz. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The integrator's per-frame altaz/constellation work was dominated by skyfield's
observe()/apparent()/altaz()chain, which the integrator called twice per frame (eyepiece + camera center). This PR replaces it witherfa.atco13(pyerfa) — the same SOFA/ERFA precession/nutation/aberration math, ~19× faster, accurate to ~14″.Skyfield_utils.radec_to_altaz: reimplemented viaerfa.atco13. Same(ra, dec, dt, atmos=True)signature. Addspyerfa==2.0.1.5torequirements.txt(small C-extension wheel, ARM-friendly).FastAltAz: body rewritten using IAU-1982 GMST + spherical trig + Bennett refraction. Fixes a subtle LST bug (the prior0.985647 · days_since_j2000term double-counted the fractional day) and adds the previously-missing refraction. API unchanged:__init__(lat, lon, dt)+radec_to_altaz(ra, dec, alt_only=False). Continues to backcatalogs.pyandcalc_object_altitude.Skyfield_utils.set_location: now no-ops when(lat, lon, altitude)is unchanged, removing the per-tickwgs84.latlonrebuilds for callers like the integrator and chart UI.Performance
Measured on macOS dev machine; Pi numbers will scale, but ratios should hold.
Skyfield_utils.radec_to_altazSkyfield_utils.set_location(same loc)FastAltAz.radec_to_altaz¹
set_location + 2× radec_to_altaz + radec_to_constellation.Accuracy
vs raw skyfield
observe()/apparent()/altaz("standard")reference, median angular separation:Skyfield_utils.radec_to_altaz(pyerfa)FastAltAz(rewritten)calc_object_altitudealready lived with)Test plan
nox -s lint— clean (after auto-fixes of unused imports)nox -s format— cleannox -s type_hints— clean on this branch's changed files (only pre-existing errors elsewhere)nox -s smoke_tests— 2/2 passnox -s unit_tests— 107/107 pass, including 9 new tests:TestFastAltAz: bounds,alt_onlyshort-circuit, refraction sign, accuracy floor vs skyfield, LST advances with timeTestSkyfieldUtilsRadecToAltaz: requiresset_location, matches skyfield within 120″ (atmos=True) and 30″ (atmos=False) at well-elevated points,atmosflag lifts altitude🤖 Generated with Claude Code