31 lines
1.2 KiB
Python
31 lines
1.2 KiB
Python
"""Sun and Moon on the same sidereal frame as the chart function.
|
|
|
|
The flags match ``_calc_sidereal_planets_for_jd``: legacy true-precession
|
|
profile, then subtract ayanamsa. This is not the apparent-position path.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
def sun_moon_longitudes(jd: float, *, node_mode: str = "mean", ayanamsa_name: str | None = None) -> tuple[float, float]:
|
|
try:
|
|
from jyotish_engine import _apply_ayanamsa, _sidereal_calculation_profile
|
|
import swisseph as swe
|
|
except ImportError:
|
|
from scripts.jyotish_engine import _apply_ayanamsa, _sidereal_calculation_profile
|
|
import swisseph as swe
|
|
if ayanamsa_name:
|
|
_apply_ayanamsa(ayanamsa_name)
|
|
_mode, calc_flags, ayanamsa = _sidereal_calculation_profile(jd, "legacy")
|
|
flags = calc_flags | getattr(swe, "FLG_SPEED", 256)
|
|
sun = _body(swe, jd, swe.SUN, flags, ayanamsa)
|
|
moon = _body(swe, jd, swe.MOON, flags, ayanamsa)
|
|
return sun, moon
|
|
|
|
|
|
def _body(swe, jd: float, body: int, flags: int, ayanamsa: float) -> float:
|
|
pos, ret = swe.calc_ut(jd, body, flags)
|
|
if ret < 0:
|
|
raise RuntimeError(f"swisseph calc_ut failed for body {body} at jd {jd}: code {ret}")
|
|
return (float(pos[0]) - float(ayanamsa)) % 360.0
|