pyastro — Astronomical Library
pyastro is a Python astronomical library.
Classes
The following classes are provided for the major planetary bodies:
- Sun
- Moon
- Mercury
- Venus
- Mars
- Jupiter
- Saturn
- Uranus
- Neptune
- Pluto
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:
julian_date(dtime)
— returns the Julian date for the specified time, or for the current time if not provided.kepler(m_anom, eccentricity)
— solves Kepler's equation for the specified mean anomaly and eccentricity.rec_to_sph(rcds)
— returns aSphCoords
named tuple containing the spherical coordinates corresponding to theRectCoords
named tuple passed as the argument.zodiac_sign(rasc)
— returns a string containing the sign of the zodiac corresponding to the provided right ascension.rasc_to_zodiac(rasc)
— returns a string of the form20CN15
corresponding to the provided right ascension, where the string in the provided example means the 15th minute of the 20th degree in the sign of Capricorn.rasc_string(rasc)
— returns a string in an hours, minutes, and seconds format corresponding to the provided right ascension, in degrees.decl_string(decl)
— returns a string in a degrees, minutes and seconds format corresponding to the provided declination, in degrees.positions(dtime)
— prints a table showing various information for all supported planets, either for a specified time, or for the current time if not specified.
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: