Astrologer ruling 2026-11-04 on #166, product decisions the same day (Q9 display only, later; Q12 record, do not switch). - Q4 (BUG-1590): Gemini Saturn (8, 9) and Virgo Saturn (5, 6) are mixed (neutral), not pure benefics by trine priority; the astrologer's table for the eight ambiguous cells rides along as ambiguous_cell_notes. Other lordships are kept. - Q10 (BUG-1591): Chara Dasha with both Scorpio / Aquarius lords in the sign is fixed at 12 years (Ketu exalted in Scorpio gave 13). - Q11 (BUG-1592): legacy Narayana counts only the nine grahas as occupants. - Q8 (BUG-1593): Narayana period reports the adjustment that took effect (Mercury in Virgo: 12, +0, not "12 + 1" capped silently). - Q15 (BUG-1594): upagrahas carry both raw Saturn-part points and name the mapping (PyJHora-compatible Gulika = start, Maandi = midpoint; PVR 4.3 is the reverse and is listed, never claimed). - Q12 / Q13 (BUG-1595): every day/night window, Shadbala and the birth Panchanga record their sunrise convention and hora method. No value changes. - Q5 (BUG-1596): "Gajakesari Yoga" is PVR's strict definition (benefic association, not debilitated, combust or in a natural enemy's sign); the strong-Jupiter variant and the bare Moon-Jupiter kendra relation are separate rules outside the card's closed list. New sandbox helpers combust() and in_natural_enemy_sign(). - Q6 (BUG-1597): Matrunasa split into Raman 198 (named Parashari aspects, nodes for conjunction / hemming only) and Raman 199 (same parents-card row via canonical_mapping); each hit names its trigger; "high confidence" and mother's-health effects removed. Custom rules may set `triggers`. - Q31 (BUG-1598): calc_varga names the D3 / D24 / D30 / D60 method; D3 / D24 / D60 of varga.py and divisional_charts_extended agree on every 0.1 deg. - Q29: the 7-karaka note says PiK does not apply in that scheme. tests/test_astrologer_rulings_166_batch2.py (25 tests). Rectification identity and re-freeze follow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXoyn7Hj3LCW3BUs5bZ8
104 lines
4.5 KiB
Python
104 lines
4.5 KiB
Python
"""Swiss Ephemeris sunrise/sunset evidence for Saham day/night formula selection."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
from typing import Any
|
|
|
|
import swisseph as swe
|
|
|
|
|
|
class SahamDayNightError(ValueError):
|
|
pass
|
|
|
|
|
|
# #166 Q12 (BUG-1595, astrologer 2026-11-04; product: record, do not switch):
|
|
# every day/night window states which sunrise it used, so day/night, hora lord,
|
|
# annual lord and rectification can be traced. Each module keeps its convention.
|
|
SUNRISE_CONVENTIONS = {
|
|
"apparent": {"name": "apparent_upper_limb_with_refraction", "disc": "upper_limb", "refraction": True,
|
|
"horizon_altitude_deg": 0.0, "swisseph_flags": "CALC_RISE / CALC_SET"},
|
|
"hindu": {"name": "hindu_disc_centre_no_refraction", "disc": "centre", "refraction": False,
|
|
"horizon_altitude_deg": 0.0, "swisseph_flags": "BIT_HINDU_RISING"},
|
|
}
|
|
|
|
|
|
def determine_daytime(
|
|
moment: datetime,
|
|
*,
|
|
lat: float,
|
|
lon: float,
|
|
tz: float,
|
|
rising: str = "apparent",
|
|
) -> dict[str, Any]:
|
|
"""Day/night window.
|
|
|
|
``rising="apparent"`` is the historical disk-edge window. Rectification and
|
|
Panchanga rely on that default and must not pick up Hindu rising.
|
|
``rising="hindu"`` is disk-center, no refraction, with the real next
|
|
sunrise. Saham day/night, Gulika, and Shayanadi pass it explicitly.
|
|
"""
|
|
if rising not in ("apparent", "hindu"):
|
|
raise SahamDayNightError("unsupported sunrise convention")
|
|
if not -90 <= float(lat) <= 90 or not -180 <= float(lon) <= 180:
|
|
raise SahamDayNightError("invalid WGS84 latitude/longitude")
|
|
local = moment.replace(tzinfo=None)
|
|
jd = swe.julday(local.year, local.month, local.day, local.hour + local.minute / 60 + local.second / 3600 - float(tz))
|
|
geopos = (float(lon), float(lat), 0.0)
|
|
if rising == "apparent":
|
|
rise_status, rise = swe.rise_trans(jd - 1.0, swe.SUN, swe.CALC_RISE, geopos)
|
|
set_status, sunset = swe.rise_trans(jd - 1.0, swe.SUN, swe.CALC_SET, geopos)
|
|
if rise_status != 0 or set_status != 0:
|
|
raise SahamDayNightError("sunrise_or_sunset_unavailable_for_location_date")
|
|
sunrise_jd, sunset_jd = rise[0], sunset[0]
|
|
# Normalize the next daily events around the queried instant.
|
|
while sunrise_jd > jd:
|
|
sunrise_jd -= 1.0
|
|
while sunset_jd > jd:
|
|
sunset_jd -= 1.0
|
|
is_day = sunrise_jd <= jd < sunset_jd if sunrise_jd < sunset_jd else not (sunset_jd <= jd < sunrise_jd)
|
|
return {
|
|
"scope": "saham_daynight_swiss",
|
|
"status": "computed",
|
|
"is_daytime": is_day,
|
|
"julian_day_ut": jd,
|
|
"sunrise_jd_ut": sunrise_jd,
|
|
"sunset_jd_ut": sunset_jd,
|
|
"method": "swisseph.rise_trans",
|
|
"sunrise_convention": {**SUNRISE_CONVENTIONS["apparent"], "lat": float(lat), "lon": float(lon)},
|
|
"boundary": "Formula-specific +30 degree exceptions must be applied by the Saham rule layer, not inferred from house placement.",
|
|
}
|
|
|
|
flags = swe.FLG_SWIEPH | swe.FLG_TRUEPOS
|
|
|
|
def event(after, kind):
|
|
status, times = swe.rise_trans(after, swe.SUN, kind | swe.BIT_HINDU_RISING, geopos, flags=flags)
|
|
if status != 0:
|
|
raise SahamDayNightError("sunrise_or_sunset_unavailable_for_location_date")
|
|
return times[0]
|
|
|
|
# Consecutive rise/set events. Adding one Julian day to a sunrise is not
|
|
# the next sunrise, and it moves the night-segment endpoint.
|
|
midnight_jd = swe.julday(local.year, local.month, local.day, -float(tz))
|
|
sunrise_jd = event(midnight_jd, swe.CALC_RISE)
|
|
if sunrise_jd > jd:
|
|
midnight_jd -= 1.0
|
|
sunrise_jd = event(midnight_jd, swe.CALC_RISE)
|
|
next_sunrise_jd = event(midnight_jd + 1.0, swe.CALC_RISE)
|
|
sunset_jd = event(midnight_jd, swe.CALC_SET)
|
|
if not sunrise_jd <= jd < next_sunrise_jd or not sunrise_jd < sunset_jd < next_sunrise_jd:
|
|
raise SahamDayNightError("solar_day_window_unavailable")
|
|
is_day = sunrise_jd <= jd < sunset_jd
|
|
return {
|
|
"scope": "saham_daynight_swiss",
|
|
"status": "computed",
|
|
"is_daytime": is_day,
|
|
"julian_day_ut": jd,
|
|
"sunrise_jd_ut": sunrise_jd,
|
|
"sunset_jd_ut": sunset_jd,
|
|
"next_sunrise_jd_ut": next_sunrise_jd,
|
|
"method": "swisseph.rise_trans_hindu_rising",
|
|
"sunrise_convention": {**SUNRISE_CONVENTIONS["hindu"], "lat": float(lat), "lon": float(lon)},
|
|
"boundary": "Formula-specific +30 degree exceptions must be applied by the Saham rule layer, not inferred from house placement.",
|
|
}
|