Dig Bala took |powerless point - planet| / 3 without folding arcs above
180 degrees, so 35 of 140 values on the 19 benchmark charts plus Steve Jobs
exceeded the 60 Virupa maximum (up to 98.98). BPHS 27.7 ("hitva
shadbhadhike sati"; Santhanam: "If the sum is above 180 degrees, deduct the
sum from 360") and Raman, Graha and Bhava Balas section 44-45, Ex. 14-15
(Kuja arc 167 05, Digbala 55.70) both fold. PyJHora's default _dig_bala has
the same unfolded formula, which is why the comparison always "matched";
its own _dig_bala_another, VedAstro source, jyotishganit and saravali fold.
After the fix all 140 values equal PyJHora _dig_bala_another.
Drik Bala summed the aspecting planets in set order. Each Sphuta value is
already rounded to 0.01, so the quarter often sits on a .xx5 edge and the
result moved by 0.01 with PYTHONHASHSEED. Sum whole hundredths in sorted
order and round the quarter half away from zero; 14 of 140 values move by
0.01. Formulas, tables and benefic/malefic classification are unchanged.
New tests lock Raman's Standard Horoscope Ex. 13 (Sthana), Ex. 15 (Dig)
and Ex. 55 (Drik), the fold bounds, and seed-independent Drik. Updated
expectations: test_shadbala_precise_context (PyJHora default Dig carried
the bug) and the Jobs Moon total in test_shadbala_moon_paksha_convention.
shadbala.py is in the rectification frozen identity, so per ERR-110 both
fixes were frozen and replayed once as audit_j_2026_11_04. Compared field
by field with moon_paksha_2026_11_04: sealed holdout 20/20 and reported
offset 900/900 identical, metrics and summary unchanged.
Also records BUG-1575 (jyotish_engine MOOLATRIKONA gives the Moon Taurus
0-3; investigating, not changed).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbBXoyeZrYn6ryNcSe5Y2Y
90 lines
3.9 KiB
Python
90 lines
3.9 KiB
Python
"""BUG-1270: Dig Bala folds the arc to the powerless point into 0-180 degrees.
|
||
|
||
BPHS 27.7 (Santhanam): "If the sum is above 180 degrees, deduct the sum from
|
||
360. The sum arrived in either way be divided by 3, which will be Dig Bal";
|
||
Sanskrit "hitvā ṣaḍbhādhike sati". Raman, Graha and Bhava Balas (1992) §44-45,
|
||
Ex. 14-15: Kuja 229°31' - 36°36' gives the arc 167°05', Digbala 55.70.
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
import contextlib
|
||
import io
|
||
import sys
|
||
from pathlib import Path
|
||
from types import SimpleNamespace
|
||
|
||
import pytest
|
||
|
||
ROOT = Path(__file__).resolve().parents[1]
|
||
if str(ROOT / "scripts") not in sys.path:
|
||
sys.path.insert(0, str(ROOT / "scripts"))
|
||
|
||
import jyotish_engine # noqa: E402
|
||
from shadbala import _DIG_POWERLESS_HOUSE, calc_dig_bala_precise # noqa: E402
|
||
|
||
|
||
def _dms(degrees: int, minutes: int) -> float:
|
||
return degrees + minutes / 60.0
|
||
|
||
|
||
# Raman GBB Standard Horoscope (Ex. 8 bhava madhyas, Ex. 14 longitudes as printed there, Ex. 15 Digbala).
|
||
RAMAN_LONGITUDES = {
|
||
"Sun": _dms(180, 54), "Moon": _dms(311, 17), "Mars": _dms(229, 31), "Mercury": _dms(181, 32),
|
||
"Jupiter": _dms(84, 1), "Venus": _dms(171, 10), "Saturn": _dms(124, 23),
|
||
}
|
||
RAMAN_DIGBALA = {
|
||
"Sun": 48.10, "Moon": 31.56, "Mars": 55.70, "Mercury": 21.09,
|
||
"Jupiter": 11.50, "Venus": 15.15, "Saturn": 58.02,
|
||
}
|
||
|
||
|
||
def _raman_cusps() -> list[float]:
|
||
cusps = [0.0] * 12
|
||
cusps[0], cusps[3], cusps[6], cusps[9] = _dms(298, 27), _dms(36, 36), _dms(118, 27), _dms(216, 36)
|
||
return cusps
|
||
|
||
|
||
def test_raman_standard_horoscope_digbala_example_15() -> None:
|
||
cusps = _raman_cusps()
|
||
for planet, published in RAMAN_DIGBALA.items():
|
||
# 0.07: Raman's printed quotients carry his own rounding (Budha 63°05' / 3 = 21.03, printed 21.09).
|
||
assert calc_dig_bala_precise(planet, RAMAN_LONGITUDES[planet], cusps) == pytest.approx(published, abs=0.07)
|
||
|
||
|
||
def test_mars_arc_over_180_is_folded_as_in_raman_example_14() -> None:
|
||
# 原值: 64.31(229°31' − 36°36' = 192°55',未折回,超过 60)
|
||
# 新值: 55.69(360° − 192°55' = 167°05',Raman 印 55.70)
|
||
# 原因: BUG-1270,BPHS 27.7 与 Raman §44 都要求弧大于 180° 时用 360° 去减
|
||
assert calc_dig_bala_precise("Mars", RAMAN_LONGITUDES["Mars"], _raman_cusps()) == 55.69
|
||
|
||
|
||
@pytest.mark.parametrize("planet", sorted(_DIG_POWERLESS_HOUSE))
|
||
@pytest.mark.parametrize("arc", [0.0, 10.0, 90.0, 179.9, 180.0, 180.1, 190.0, 270.0, 350.0, 359.9])
|
||
def test_digbala_is_bounded_and_symmetric(planet: str, arc: float) -> None:
|
||
cusps = [float(15 * index) for index in range(12)]
|
||
powerless = cusps[_DIG_POWERLESS_HOUSE[planet]]
|
||
expected = round(min(arc, 360.0 - arc) / 3.0, 2)
|
||
assert calc_dig_bala_precise(planet, (powerless + arc) % 360.0, cusps) == expected
|
||
assert calc_dig_bala_precise(planet, (powerless - arc) % 360.0, cusps) == expected
|
||
assert 0.0 <= expected <= 60.0
|
||
|
||
|
||
def test_public_chart_jupiter_dig_matches_the_folded_upstream_value() -> None:
|
||
# Steve Jobs (Rodden AA), Lahiri, mean node; BUG-1270 public comparison.
|
||
args = SimpleNamespace(
|
||
year=1955, month=2, day=24, hour=19, minute=15, second=0,
|
||
lat=37.7749, lon=-122.4194, tz=-8.0, node_mode="mean", ayanamsa="lahiri",
|
||
)
|
||
with contextlib.redirect_stdout(io.StringIO()):
|
||
result = jyotish_engine.cmd_shadbala(args)
|
||
dig = {planet: row["dig_bala"] for planet, row in result["planets"].items()}
|
||
# 原值: 木星 80.59、月亮 95.48、火星 77.41、金星 69.95(未折回)
|
||
# 新值: 39.41、24.52、42.59、50.05(= PyJHora _dig_bala_another 的 60 × (1 − 到最强点距离 / 180))
|
||
# 原因: BUG-1270
|
||
assert dig["Jupiter"] == pytest.approx(39.41, abs=0.02)
|
||
assert dig["Moon"] == pytest.approx(24.52, abs=0.02)
|
||
assert dig["Mars"] == pytest.approx(42.59, abs=0.02)
|
||
assert dig["Venus"] == pytest.approx(50.05, abs=0.02)
|
||
assert all(0.0 <= value <= 60.0 for value in dig.values())
|