Files
Jyotisha/scripts/shadbala_reference/drik_profiles.py
T
ClaudeandClaude Opus 5.5 80bcfe1ed4 sync(upstream): method layer and calculation fixes from yinduzhanxing ea2a9d65
Product 2026-11-07: stay in sync with the astrologer's latest (5fb8379c..ea2a9d65).

- Method layer: mirror SKILL.md re-imported with import_yinduzhanxing.py from a
  clean ea2a9d65 clone (import record, manifest, import plan); root SKILL.md
  body equals the mirror again (nine-lord editorial reference line). Router and
  sub-skills unchanged upstream except her rectification skill, which is the
  protected commercial skill here.
- 7b43eaf2: rectification question templates say they are templates (basis,
  timing status, answer impact), no regression_hint +5 bias, low confidence
  cap, blocked/external execution status in the audit table, invalid answers
  ignored by the selector, calculation_profile echoed; API rejects a partial
  lat/lon/tz and event rectification without a place.
- a4b4b267: BPHS 27.19 Drik weighting readings as diagnostic variants in
  scripts/shadbala_reference/drik_profiles.py (shadbala.py is frozen, ERR-110;
  default quarter and BPHS piecewise geometry unchanged, BUG-1586 / BUG-1623);
  oracle audit compares rupa with rupa; VP Jain benchmark prints by default.
- bb26dc2d: /api/jaimini special mode carries the Goel fields, no invented
  Aries ascendant.
- d66d13ce: annual report exposes tajika_named_yoga_structures.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbBXoyn7Hj3LCW3BUs5bZ8
2026-11-07 18:12:32 +08:00

91 lines
4.5 KiB
Python

#!/usr/bin/env python3
"""Drik Bala weighting readings of BPHS 27.19 (upstream yinduzhanxing a4b4b267).
Her a4b4b267 adds ``weighting_profile`` to ``calc_drik_bala_precise`` and a
``compare_drik_profiles`` diagnostic. ``scripts/shadbala.py`` is in the
rectification frozen identity (ERR-110), so the readings live here and call
the frozen geometry and classification unchanged.
Defaults stay as recorded: geometry = BPHS 26.9-12 piecewise (BUG-1586),
weighting = the quarter for every aspect (DRIK_MERCURY_JUPITER_CONVENTION,
BUG-1623, astrologer has not ruled). The other two readings are explicit,
diagnostic-only variants; they never enter totals or rankings.
"""
from __future__ import annotations
import math
import os
import sys
from decimal import ROUND_HALF_UP, Decimal
from typing import Dict
# scripts/ on sys.path for the sibling shadbala module (as scripts/arudha_reference).
_scripts_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if _scripts_dir not in sys.path:
sys.path.insert(0, _scripts_dir)
import shadbala as _sb # noqa: E402 (read-only use; shadbala.py stays the default path)
DRIK_WEIGHTING_PROFILES = ("quarter_v1", "mercury_jupiter_full_replacement_v1",
"santhanam27_literal_addition_v1")
DRIK_GEOMETRY_PROFILES = ("bphs", "raman_gbb")
def drik_aspect_contribution(strength: float, aspector: str, benefic: bool, *,
weighting_profile: str = "quarter_v1") -> float:
"""One aspect's signed share. Literal Santhanam 27.19 adds a positive full
Mercury / Jupiter aspect after the signed quarter, so a malefic Mercury
gives +0.75 of the aspect, not -1.25 (the sign stays disputed)."""
if weighting_profile not in DRIK_WEIGHTING_PROFILES:
raise ValueError(f"unknown Drik weighting profile: {weighting_profile}")
if not math.isfinite(float(strength)) or strength < 0:
raise ValueError("aspect strength must be finite and nonnegative")
signed = strength if benefic else -strength
if aspector in {"Mercury", "Jupiter"}:
if weighting_profile == "mercury_jupiter_full_replacement_v1":
return signed
if weighting_profile == "santhanam27_literal_addition_v1":
return signed / 4 + strength
return signed / 4
def calc_drik_bala_profiled(pname: str, all_planets: Dict, variant: str = "bphs", *,
weighting_profile: str = "quarter_v1") -> float:
"""Drik under an explicit weighting; ``quarter_v1`` is the frozen default."""
if weighting_profile not in DRIK_WEIGHTING_PROFILES:
raise ValueError(f"unknown Drik weighting profile: {weighting_profile}")
if weighting_profile == "quarter_v1":
return _sb.calc_drik_bala_precise(pname, all_planets, variant)
if pname not in all_planets:
return 0.0
benefics, malefics = _sb.classify_drik_planets(all_planets, variant)
target_lon = _sb._planet_longitude(pname, all_planets)
total = Decimal(0)
for other_name in sorted(benefics | malefics): # fixed order (BUG-1576)
if other_name == pname:
continue
strength = _sb._sphuta_drishti_virupas(
target_lon - _sb._planet_longitude(other_name, all_planets), other_name, variant)
total += Decimal(str(drik_aspect_contribution(
strength, other_name, other_name in benefics, weighting_profile=weighting_profile)))
return float(total.quantize(Decimal("0.01"), rounding=ROUND_HALF_UP))
def compare_drik_profiles(all_planets: Dict) -> Dict:
"""Replay the disputed readings without changing production totals."""
names = [n for n in ('Sun', 'Moon', 'Mars', 'Mercury', 'Jupiter', 'Venus', 'Saturn') if n in all_planets]
baseline = {n: _sb.calc_drik_bala_precise(n, all_planets) for n in names}
variants = []
for geometry in DRIK_GEOMETRY_PROFILES:
for weighting in DRIK_WEIGHTING_PROFILES:
values = {n: calc_drik_bala_profiled(n, all_planets, geometry, weighting_profile=weighting)
for n in names}
variants.append({'aspect_profile': geometry, 'weighting_profile': weighting,
'virupas': values,
'delta_from_default': {n: round(values[n] - baseline[n], 2) for n in names}})
return {'admission_state': 'diagnostic_only',
'natural_classification': 'existing_classify_drik_planets_unchanged',
'default': {'aspect_profile': 'bphs', 'weighting_profile': 'quarter_v1'},
'variants': variants}