-
Notifications
You must be signed in to change notification settings - Fork 2
Home
This page shows the basics of using pyastro.
The following classes are provided for the major planetary bodies:
- Sun
- Moon
- Mercury
- Venus
- Mars
- Jupiter
- Saturn
- Uranus
- Neptune
- Pluto
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
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
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.
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 form 20CN15 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.
pydoc
can be used for help on individual classes and functions, for example:
user@machine:~$ pydoc pyastro.functions.kepler
Help on function kepler in pyastro.functions
pyastro.functions.kepler = kepler(m_anom, eccentricity)
Solves Kepler's equation for the eccentric anomaly
using Newton's method.
Arguments:
m_anom -- mean anomaly in radians
eccentricity -- eccentricity of the ellipse
Returns: eccentric anomaly in radians.
or pydoc -g
for a graphical interface.