Skip to main content

Python bindings for ERFA

Project description

PyPI Status DOI 10.5281/zenodo.3940699 GitHub Actions CI Status Documentation Status

PyERFA is the Python wrapper for the ERFA library (Essential Routines for Fundamental Astronomy), a C library containing key algorithms for astronomy, which is based on the SOFA library published by the International Astronomical Union (IAU). All C routines are wrapped as Numpy universal functions, so that they can be called with scalar or array inputs.

The project is a split of astropy._erfa module, developed in the context of Astropy project, into a standalone package. It contains the ERFA C source code as a git submodule. The wrapping is done with help of the Jinja2 template engine.

If you use this package in your research, please cita it via DOI 10.5281/zenodo.3940699.

Installation instructions

The package can be installed from the package directory using a simple:

$ pip install .

and similarly a wheel can be created with:

$ pip wheel .

The package can be obtained from PyPI or directly from the git repository:

$ git clone --recursive https://github.com/liberfa/pyerfa/

Testing

For testing, one can install the packages together with its testing dependencies and then test it with:

$ pip install .[test]
$ pytest

Alternatively, one can use tox, which will set up a separate testing environment for you, with:

$ tox -e test

Usage

The package can be imported as erfa which has all ERFA ufuncs wrapped with python code that tallies errors and warnings. Also exposed are the constants defined by ERFA in erfam.h, as well as numpy.dtype corresponding to structures used by ERFA. Examples:

>>> import erfa
>>> erfa.jd2cal(2460000., [0, 1, 2, 3])
(array([2023, 2023, 2023, 2023], dtype=int32),
 array([2, 2, 2, 2], dtype=int32),
 array([24, 25, 26, 27], dtype=int32),
 array([0.5, 0.5, 0.5, 0.5]))
>>> erfa.plan94(2460000., [0, 1, 2, 3], 1)
array([([ 0.09083713, -0.39041392, -0.21797389], [0.02192341, 0.00705449, 0.00149618]),
       ([ 0.11260694, -0.38275202, -0.21613731], [0.02160375, 0.00826891, 0.00217806]),
       ([ 0.13401992, -0.37387798, -0.21361622], [0.0212094 , 0.00947838, 0.00286503]),
       ([ 0.15500031, -0.36379788, -0.21040601], [0.02073822, 0.01068061, 0.0035561 ])],
      dtype={'names': ['p', 'v'], 'formats': [('<f8', (3,)), ('<f8', (3,))], 'offsets': [0, 24], 'itemsize': 48, 'aligned': True})
>>> erfa.dt_pv
dtype([('p', '<f8', (3,)), ('v', '<f8', (3,))], align=True)
>>> erfa.dt_eraLDBODY
dtype([('bm', '<f8'), ('dl', '<f8'), ('pv', [('p', '<f8', (3,)), ('v', '<f8', (3,))])], align=True)
>>> erfa.DAYSEC
86400.0

It is also possible to use the ufuncs directly, though then one has to deal with the warning and error states explicitly. For instance, compare:

>>> erfa.jd2cal(-600000., [0, 1, 2, 3])
Traceback (most recent call last):
...
ErfaError: ERFA function "jd2cal" yielded 4 of "unacceptable date (Note 1)"
>>> erfa.ufunc.jd2cal(-600000., [0, 1, 2, 3])
(array([-1, -1, -1, -1], dtype=int32),
 ...,
 array([-1, -1, -1, -1], dtype=int32))

License

PyERFA is licensed under a 3-clause BSD style license - see the LICENSE.rst file.

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

pyerfa-2.0.1.1.tar.gz (817.7 kB view hashes)

Uploaded Source

Built Distributions

pyerfa-2.0.1.1-pp39-pypy39_pp73-win_amd64.whl (348.8 kB view hashes)

Uploaded PyPy Windows x86-64

pyerfa-2.0.1.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (345.2 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

pyerfa-2.0.1.1-pp39-pypy39_pp73-macosx_10_9_x86_64.whl (322.4 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

pyerfa-2.0.1.1-cp39-abi3-win_amd64.whl (348.7 kB view hashes)

Uploaded CPython 3.9+ Windows x86-64

pyerfa-2.0.1.1-cp39-abi3-win32.whl (341.5 kB view hashes)

Uploaded CPython 3.9+ Windows x86

pyerfa-2.0.1.1-cp39-abi3-musllinux_1_1_x86_64.whl (750.0 kB view hashes)

Uploaded CPython 3.9+ musllinux: musl 1.1+ x86-64

pyerfa-2.0.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (739.5 kB view hashes)

Uploaded CPython 3.9+ manylinux: glibc 2.17+ x86-64

pyerfa-2.0.1.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (693.7 kB view hashes)

Uploaded CPython 3.9+ manylinux: glibc 2.17+ ARM64

pyerfa-2.0.1.1-cp39-abi3-macosx_11_0_arm64.whl (334.3 kB view hashes)

Uploaded CPython 3.9+ macOS 11.0+ ARM64

pyerfa-2.0.1.1-cp39-abi3-macosx_10_9_x86_64.whl (342.9 kB view hashes)

Uploaded CPython 3.9+ macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page