pyastro — Astronomical Library

pyastro is a Python astronomical library.

Classes

The following classes are provided for the major planetary bodies:

The following functionality is provided for all these classes.

Calculating Right Ascension

To calculate right ascension, first create an instance of the class with the specified time, or for the current time by default.

For instance, to create an instance for Jupiter at the current time:

import pyastro

jup = pyastro.Jupiter()

To create an instance of Jupiter for a specific time, a timezone aware datetime instance must be passed upon initialization. A UTC class has been provided to make this easier. For instance, to create an instance for Jupiter as at 19:23 on May 5, 1980:

import datetime
import pyastro

dtime = datetime.datetime(1980, 5, 5, 19, 23, 0, 0, pyastro.UTC())
jup = pyastro.Jupiter(dtime)

Once you've created the instance, to obtain the right ascension, simply call the right_ascension() method. Passing the argument formatted=True returns an hours, minutes, and seconds string. By default right_ascension() returns the number of degrees.

For instance, the following program:

import datetime
import pyastro

dtime = datetime.datetime(1980, 5, 5, 19, 23, 0, 0, pyastro.UTC())
jup = pyastro.Jupiter(dtime)

print(jup.right_ascension(formatted=True))

outputs:

10h 12m 33s

Calculating Declination

The process is exactly the same as for calculating the right ascension, except the declination() method is called. For instance, the code:

import datetime
import pyastro

dtime = datetime.datetime(1980, 5, 5, 19, 23, 0, 0, pyastro.UTC())
jup = pyastro.Jupiter(dtime)

print(jup.declination(formatted=True))

outputs:

+12d 23m 03s

Other Methods

The distance() method returns the distance of the planet from the earth, in earth radii for the moon, and in astronomical units (AU) for all other planets.

The zodiac_sign() method returns a string containing the sign of the zodiac the planet was in at the time specified during object creation.

Functions

The following functions are also provided:

Source Code and Downloads

View the pyastro source code:

View the source code for a short test program using pyastro:

Python distutils distributions available from the Python Package Index:

Regular compressed archives available locally: