Pyerfa

2.0.1.5 · active · verified Fri Apr 10

PyERFA provides Python bindings for the ERFA library (Essential Routines for Fundamental Astronomy), a C library based on the IAU SOFA library. It wraps ERFA's C routines as NumPy universal functions, allowing them to be called with scalar or array inputs. The library is actively maintained, with frequent patch releases addressing compatibility, especially with NumPy versions. The current version is 2.0.1.5.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import `erfa` and use two common functions: `jd2cal` for Julian Date to calendar conversion and `plan94` to get a planet's heliocentric position and velocity.

import erfa

# Convert Julian Date to Calendar Date
julian_date = 2460000.0
calendar_result = erfa.jd2cal(julian_date, [0]) # The second argument is for fractional days, here 0 for simplicity
print(f"Julian Date {julian_date} corresponds to year={calendar_result.iy[0]}, month={calendar_result.im[0]}, day={calendar_result.id[0]}, fraction={calendar_result.fd[0]}")

# Example of a planet's heliocentric position and velocity
# erfa.plan94(jd1, jd2, planet_id) where jd1+jd2 is Julian Date, planet_id (1=Mercury, ..., 9=Pluto)
position_velocity = erfa.plan94(julian_date, 0.0, 1) # Mercury
print(f"Mercury's position (x, y, z): {position_velocity['p'][0]}")
print(f"Mercury's velocity (vx, vy, vz): {position_velocity['v'][0]}")

view raw JSON →