Butterfly Fiziks
Butterfly Fiziks

Reputation: 17

How to calculate lunar phase using pyswisseph

Hello I'm working on astrology software but I have a problem

def solar_longitude(jd):
  """Solar longitude at given instant (julian day) jd"""
  data = swe.calc_ut(jd, swe.SUN, flag = swe.FLG_SWIEPH)
  return data[0]   # in degrees

def lunar_longitude(jd):
  """Lunar longitude at given instant (julian day) jd"""
  data = swe.calc_ut(jd, swe.MOON, flag = swe.FLG_SWIEPH)
  return data[0]   # in degrees
def lunar_phase(jd):
  solar_long = solar_longitude(jd)
  lunar_long = lunar_longitude(jd)
  moon_phase = (lunar_long - solar_long) % 360
  return moon_phase
print(lunar_phase(2455027.75138))

output---

    moon_phase = (lunar_long - solar_long) % 360
TypeError: unsupported operand type(s) for -: 'tuple' and 'tuple'

Please help with this problem

Upvotes: 0

Views: 563

Answers (1)

gimix
gimix

Reputation: 3833

According to the docs calc_ut() returns "tuple of 6 float, and returned flags", so when you take data[0] you're still getting a tuple. You probably want data[0][0] instead.

Upvotes: 1

Related Questions