kerykeion.aspects.aspects_utils

This is part of Kerykeion (C) 2025 Giacomo Battaglia

 1# -*- coding: utf-8 -*-
 2"""
 3    This is part of Kerykeion (C) 2025 Giacomo Battaglia
 4"""
 5# TODO: Better documentation and unit tests
 6
 7from kerykeion import AstrologicalSubject
 8from kerykeion.settings import KerykeionSettingsModel
 9from swisseph import difdeg2n
10from typing import Union
11from kerykeion.kr_types.kr_models import AstrologicalSubjectModel
12from kerykeion.kr_types.kr_literals import Planet, AxialCusps
13from kerykeion.kr_types.settings_models import KerykeionSettingsCelestialPointModel, KerykeionSettingsAspectModel
14
15
16def get_aspect_from_two_points(
17    aspects_settings: Union[list[KerykeionSettingsAspectModel], list[dict]],
18    point_one: Union[float, int],
19    point_two: Union[float, int],
20):
21    """
22    Utility function to calculate the aspects between two points.
23
24    Args:
25        aspects_settings (dict): Dictionary containing aspect settings.
26        point_one (Union[float, int]): First point.
27        point_two (Union[float, int]): Second point.
28
29    Returns:
30        dict: Dictionary containing the aspect details.
31    """
32    distance = abs(difdeg2n(point_one, point_two))
33    diff = abs(point_one - point_two)
34
35    for aid, aspect in enumerate(aspects_settings):
36        # TODO: Remove the "degree" element EVERYWHERE!
37        aspect_degree = aspect["degree"] # type: ignore
38        aspect_orb = aspect["orb"] # type: ignore
39
40        if (aspect_degree - aspect_orb) <= int(distance) <= (aspect_degree + aspect_orb):
41            name = aspect["name"] # type: ignore
42            aspect_degrees = aspect_degree
43            verdict = True
44            break
45    else:
46        verdict = False
47        name = None
48        aspect_degrees = 0
49
50    return {
51        "verdict": verdict,
52        "name": name,
53        "orbit": distance - aspect_degrees,
54        "distance": distance - aspect_degrees,
55        "aspect_degrees": aspect_degrees,
56        "diff": diff,
57    }
58
59
60def planet_id_decoder(planets_settings: list[KerykeionSettingsCelestialPointModel], name: str) -> int:
61    """
62    Check if the name of the planet is the same in the settings and return
63    the correct id for the planet.
64    """
65    str_name = str(name)
66    for planet in planets_settings:
67        if planet["name"] == str_name:
68            result = planet["id"]
69            return result
70
71    raise ValueError(f"Planet {name} not found in the settings")
72
73
74def get_active_points_list(
75    subject: Union[AstrologicalSubject, AstrologicalSubjectModel], settings: Union[KerykeionSettingsModel, dict], active_points: list = []
76) -> list:
77    """
78    Given an astrological subject and the settings, return a list of the active points.
79    Args:
80        subject (AstrologicalSubject): The astrological subject to get the active points from.
81        settings (Union[KerykeionSettingsModel, dict]): Settings model o dictionary.
82
83    Returns:
84        list: List of the active points.
85    """
86    point_list = []
87    for planet in settings["celestial_points"]:
88        if planet["name"] in active_points:
89            point_list.append(subject[planet["name"].lower()])
90
91    return point_list
def get_aspect_from_two_points( aspects_settings: Union[list[kerykeion.kr_types.settings_models.KerykeionSettingsAspectModel], list[dict]], point_one: Union[float, int], point_two: Union[float, int]):
17def get_aspect_from_two_points(
18    aspects_settings: Union[list[KerykeionSettingsAspectModel], list[dict]],
19    point_one: Union[float, int],
20    point_two: Union[float, int],
21):
22    """
23    Utility function to calculate the aspects between two points.
24
25    Args:
26        aspects_settings (dict): Dictionary containing aspect settings.
27        point_one (Union[float, int]): First point.
28        point_two (Union[float, int]): Second point.
29
30    Returns:
31        dict: Dictionary containing the aspect details.
32    """
33    distance = abs(difdeg2n(point_one, point_two))
34    diff = abs(point_one - point_two)
35
36    for aid, aspect in enumerate(aspects_settings):
37        # TODO: Remove the "degree" element EVERYWHERE!
38        aspect_degree = aspect["degree"] # type: ignore
39        aspect_orb = aspect["orb"] # type: ignore
40
41        if (aspect_degree - aspect_orb) <= int(distance) <= (aspect_degree + aspect_orb):
42            name = aspect["name"] # type: ignore
43            aspect_degrees = aspect_degree
44            verdict = True
45            break
46    else:
47        verdict = False
48        name = None
49        aspect_degrees = 0
50
51    return {
52        "verdict": verdict,
53        "name": name,
54        "orbit": distance - aspect_degrees,
55        "distance": distance - aspect_degrees,
56        "aspect_degrees": aspect_degrees,
57        "diff": diff,
58    }

Utility function to calculate the aspects between two points.

Args: aspects_settings (dict): Dictionary containing aspect settings. point_one (Union[float, int]): First point. point_two (Union[float, int]): Second point.

Returns: dict: Dictionary containing the aspect details.

def planet_id_decoder( planets_settings: list[kerykeion.kr_types.settings_models.KerykeionSettingsCelestialPointModel], name: str) -> int:
61def planet_id_decoder(planets_settings: list[KerykeionSettingsCelestialPointModel], name: str) -> int:
62    """
63    Check if the name of the planet is the same in the settings and return
64    the correct id for the planet.
65    """
66    str_name = str(name)
67    for planet in planets_settings:
68        if planet["name"] == str_name:
69            result = planet["id"]
70            return result
71
72    raise ValueError(f"Planet {name} not found in the settings")

Check if the name of the planet is the same in the settings and return the correct id for the planet.

def get_active_points_list( subject: Union[kerykeion.astrological_subject.AstrologicalSubject, kerykeion.kr_types.kr_models.AstrologicalSubjectModel], settings: Union[kerykeion.kr_types.settings_models.KerykeionSettingsModel, dict], active_points: list = []) -> list:
75def get_active_points_list(
76    subject: Union[AstrologicalSubject, AstrologicalSubjectModel], settings: Union[KerykeionSettingsModel, dict], active_points: list = []
77) -> list:
78    """
79    Given an astrological subject and the settings, return a list of the active points.
80    Args:
81        subject (AstrologicalSubject): The astrological subject to get the active points from.
82        settings (Union[KerykeionSettingsModel, dict]): Settings model o dictionary.
83
84    Returns:
85        list: List of the active points.
86    """
87    point_list = []
88    for planet in settings["celestial_points"]:
89        if planet["name"] in active_points:
90            point_list.append(subject[planet["name"].lower()])
91
92    return point_list

Given an astrological subject and the settings, return a list of the active points. Args: subject (AstrologicalSubject): The astrological subject to get the active points from. settings (Union[KerykeionSettingsModel, dict]): Settings model o dictionary.

Returns: list: List of the active points.