Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save EH30/11e4929fe10fa0082d7e6bc12d008fb1 to your computer and use it in GitHub Desktop.
Save EH30/11e4929fe10fa0082d7e6bc12d008fb1 to your computer and use it in GitHub Desktop.
Python script to calculate planet position in zodiac signs
import swisseph as swe
from datetime import datetime
def date_utc_to_julian(year, month, day, hour, minute, second, utc_offset_hours, utc_offset_minutes):
# Convert the date to a datetime object
dt = datetime(year, month, day, hour, minute, second)
# Calculate the Julian date offset
julian_offset = 2440587.5
# Calculate the number of seconds in a day
seconds_per_day = 86400
# Convert the UTC offset to seconds
utc_offset_seconds = (utc_offset_hours * 3600) + (utc_offset_minutes * 60)
# Calculate the Julian date
julian_date = julian_offset + (dt - datetime(1970, 1, 1)).total_seconds() / seconds_per_day - utc_offset_seconds / seconds_per_day
return julian_date
def planets_rashi(juld, latitude, longitude):
"""calculate planet position in rashi"""
swe.set_sid_mode(swe.SIDM_LAHIRI, 0, 0) # Set the Ayanamsa
flags = swe.FLG_SWIEPH + swe.FLG_SPEED + swe.FLG_SIDEREAL
planets = {
"SUN": swe.SUN, "MOON": swe.MOON, "MERCURY": swe.MERCURY, "VENUS": swe.VENUS,
"MARS": swe.MARS, "JUPITER":swe.JUPITER, "SATURN": swe.SATURN, "RAHU": swe.MEAN_NODE, "URANUS": swe.URANUS,
"PLUTO": swe.PLUTO, "NEPTUNE": swe.NEPTUNE,
}
cusps, ascmc = swe.houses_ex(juld, latitude, longitude, b'B', flags)
ascendant = ascmc[0]
output = {}
output["Asc"] = {"sign_num":int(ascendant/30)+1, "lon":ascendant}
xx, ret = swe.calc_ut(juld, planets["SUN"], flags)
for planet in planets:
xx, ret = swe.calc_ut(juld, planets[planet], flags)
rashi_number = xx[0] / 30
output[planet] = {"sign_num":int(rashi_number)+1, "lon": xx[0], "retrograde": False}
if xx[3] < 0:
output[planet]["retrograde"] = True
output["KETU"] = {"sign_num": int(swe.degnorm(output["RAHU"]["lon"]+180) / 30)+1 , "lon": swe.degnorm(output["RAHU"]["lon"]+180), "retrograde": False}
if output["RAHU"]["retrograde"] == True:
output["KETU"]["retrograde"] = True
swe.close()
return output
if __name__ == "__main__":
year = 2009
month = 3
day = 30
hour = 9
minute = 36
second = 0
utc_hour = 5
utc_minute = 30
latitude = 19.0760
longitude = 72.8777
juld = date_utc_to_julian(year, month, day, hour, minute, second, utc_hour, utc_minute)
print(planets_rashi(juld, latitude, longitude))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment