kerykeion 4.0.7__py3-none-any.whl → 4.1.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of kerykeion might be problematic. Click here for more details.

kerykeion/__init__.py CHANGED
@@ -68,7 +68,7 @@
68
68
  >>> second = AstrologicalSubject("Jane", 1991, 10, 25, 21, 00, "Roma")
69
69
 
70
70
  >>> name = SynastryAspects(first, second)
71
- >>> aspect_list = name.get_relevant_aspects()
71
+ >>> aspect_list = name.relevant_aspects
72
72
  >>> print(aspect_list[0])
73
73
 
74
74
  Generating kerykeion object for Jack...
@@ -105,4 +105,4 @@ from .kr_types import *
105
105
  from .relationship_score import RelationshipScore
106
106
  from .aspects import SynastryAspects, NatalAspects
107
107
  from .report import Report
108
- from .settings import KerykeionSettingsModel, get_settings_dict
108
+ from .settings import KerykeionSettingsModel, get_settings
@@ -0,0 +1,185 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ This is part of Kerykeion (C) 2023 Giacomo Battaglia
4
+ """
5
+ # TODO: Better documentation and unit tests
6
+
7
+ from swisseph import difdeg2n
8
+ from typing import Union
9
+
10
+
11
+ def get_aspect_from_two_points(aspects_settings: dict, point_one: Union[float, int], point_two: Union[float, int]):
12
+ """
13
+ Utility function.
14
+ It calculates the aspects between the 2 points.
15
+ Args: first point, second point.
16
+ """
17
+
18
+ distance = abs(difdeg2n(point_one, point_two))
19
+ diff = abs(point_one - point_two)
20
+
21
+ if int(distance) <= aspects_settings[0]["orb"]:
22
+ name = aspects_settings[0]["name"]
23
+ aspect_degrees = aspects_settings[0]["degree"]
24
+ color = aspects_settings[0]["color"]
25
+ verdict = True
26
+ aid = 0
27
+
28
+ elif (
29
+ (aspects_settings[1]["degree"] - aspects_settings[1]["orb"])
30
+ <= int(distance)
31
+ <= (aspects_settings[1]["degree"] + aspects_settings[1]["orb"])
32
+ ):
33
+ name = aspects_settings[1]["name"]
34
+ aspect_degrees = aspects_settings[1]["degree"]
35
+ color = aspects_settings[1]["color"]
36
+ verdict = True
37
+ aid = 1
38
+
39
+ elif (
40
+ (aspects_settings[2]["degree"] - aspects_settings[2]["orb"])
41
+ <= int(distance)
42
+ <= (aspects_settings[2]["degree"] + aspects_settings[2]["orb"])
43
+ ):
44
+ name = aspects_settings[2]["name"]
45
+ aspect_degrees = aspects_settings[2]["degree"]
46
+ color = aspects_settings[2]["color"]
47
+ verdict = True
48
+ aid = 2
49
+
50
+ elif (
51
+ (aspects_settings[3]["degree"] - aspects_settings[3]["orb"])
52
+ <= int(distance)
53
+ <= (aspects_settings[3]["degree"] + aspects_settings[3]["orb"])
54
+ ):
55
+ name = aspects_settings[3]["name"]
56
+ aspect_degrees = aspects_settings[3]["degree"]
57
+ color = aspects_settings[3]["color"]
58
+ verdict = True
59
+ aid = 3
60
+
61
+ elif (
62
+ (aspects_settings[4]["degree"] - aspects_settings[4]["orb"])
63
+ <= int(distance)
64
+ <= (aspects_settings[4]["degree"] + aspects_settings[4]["orb"])
65
+ ):
66
+ name = aspects_settings[4]["name"]
67
+ aspect_degrees = aspects_settings[4]["degree"]
68
+ color = aspects_settings[4]["color"]
69
+ verdict = True
70
+ aid = 4
71
+
72
+ elif (
73
+ (aspects_settings[5]["degree"] - aspects_settings[5]["orb"])
74
+ <= int(distance)
75
+ <= (aspects_settings[5]["degree"] + aspects_settings[5]["orb"])
76
+ ):
77
+ name = aspects_settings[5]["name"]
78
+ aspect_degrees = aspects_settings[5]["degree"]
79
+ color = aspects_settings[5]["color"]
80
+ verdict = True
81
+ aid = 5
82
+
83
+ elif (
84
+ (aspects_settings[6]["degree"] - aspects_settings[6]["orb"])
85
+ <= int(distance)
86
+ <= (aspects_settings[6]["degree"] + aspects_settings[6]["orb"])
87
+ ):
88
+ name = aspects_settings[6]["name"]
89
+ aspect_degrees = aspects_settings[6]["degree"]
90
+ color = aspects_settings[6]["color"]
91
+ verdict = True
92
+ aid = 6
93
+
94
+ elif (
95
+ (aspects_settings[7]["degree"] - aspects_settings[7]["orb"])
96
+ <= int(distance)
97
+ <= (aspects_settings[7]["degree"] + aspects_settings[7]["orb"])
98
+ ):
99
+ name = aspects_settings[7]["name"]
100
+ aspect_degrees = aspects_settings[7]["degree"]
101
+ color = aspects_settings[7]["color"]
102
+ verdict = True
103
+ aid = 7
104
+
105
+ elif (
106
+ (aspects_settings[8]["degree"] - aspects_settings[8]["orb"])
107
+ <= int(distance)
108
+ <= (aspects_settings[8]["degree"] + aspects_settings[8]["orb"])
109
+ ):
110
+ name = aspects_settings[8]["name"]
111
+ aspect_degrees = aspects_settings[8]["degree"]
112
+ color = aspects_settings[8]["color"]
113
+ verdict = True
114
+ aid = 8
115
+
116
+ elif (
117
+ (aspects_settings[9]["degree"] - aspects_settings[9]["orb"])
118
+ <= int(distance)
119
+ <= (aspects_settings[9]["degree"] + aspects_settings[9]["orb"])
120
+ ):
121
+ name = aspects_settings[9]["name"]
122
+ aspect_degrees = aspects_settings[9]["degree"]
123
+ color = aspects_settings[9]["color"]
124
+ verdict = True
125
+ aid = 9
126
+
127
+ elif (
128
+ (aspects_settings[10]["degree"] - aspects_settings[10]["orb"])
129
+ <= int(distance)
130
+ <= (aspects_settings[10]["degree"] + aspects_settings[10]["orb"])
131
+ ):
132
+ name = aspects_settings[10]["name"]
133
+ aspect_degrees = aspects_settings[10]["degree"]
134
+ color = aspects_settings[10]["color"]
135
+ verdict = True
136
+ aid = 10
137
+
138
+ else:
139
+ verdict = False
140
+ name = None
141
+ distance = 0
142
+ aspect_degrees = 0
143
+ color = None
144
+ aid = None
145
+
146
+ return (
147
+ verdict,
148
+ name,
149
+ distance - aspect_degrees,
150
+ aspect_degrees,
151
+ color,
152
+ aid,
153
+ diff,
154
+ )
155
+
156
+
157
+ def planet_id_decoder(planets_settings: dict, name: str):
158
+ """
159
+ Check if the name of the planet is the same in the settings and return
160
+ the correct id for the planet.
161
+ """
162
+ str_name = str(name)
163
+ for planet in planets_settings:
164
+ if planet["name"] == str_name:
165
+ result = planet["id"]
166
+ return result
167
+
168
+
169
+ def filter_by_settings(planets_settings: dict, init_point_list: list):
170
+ """
171
+ Creates a list of all the desired
172
+ points filtering by the settings.
173
+ """
174
+
175
+ set_points_name = []
176
+ for p in planets_settings:
177
+ if p["is_active"]:
178
+ set_points_name.append(p["name"])
179
+
180
+ point_list = []
181
+ for l in init_point_list:
182
+ if l["name"] in set_points_name:
183
+ point_list.append(l)
184
+
185
+ return point_list
@@ -3,227 +3,58 @@
3
3
  This is part of Kerykeion (C) 2023 Giacomo Battaglia
4
4
  """
5
5
 
6
- import json
7
6
  from pathlib import Path
8
7
  from kerykeion import AstrologicalSubject
9
- from swisseph import difdeg2n
8
+ from logging import getLogger, basicConfig
10
9
  from typing import Union
11
- from kerykeion.settings.kerykeion_settings import get_settings_dict
10
+ from kerykeion.settings.kerykeion_settings import get_settings
11
+ from dataclasses import dataclass
12
+ from kerykeion.aspects.aspects_utils import filter_by_settings, planet_id_decoder, get_aspect_from_two_points
12
13
 
14
+ logger = getLogger(__name__)
15
+ basicConfig(format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level="INFO")
13
16
 
17
+
18
+ @dataclass
14
19
  class NatalAspects:
15
20
  """
16
21
  Generates an object with all the aspects of a birthcart.
17
22
  """
18
23
 
19
- def __init__(self, kr_object: AstrologicalSubject, new_settings_file: Union[Path, None] = None):
20
- self.user = kr_object
21
- self.new_settings_file = new_settings_file
22
- self._parse_json_settings()
23
-
24
- self.init_point_list = self.user.planets_list + self.user.houses_list
24
+ user: AstrologicalSubject
25
+ new_settings_file: Union[Path, None] = None
26
+ _all_aspects: Union[list, None] = None
27
+ _relevant_aspects: Union[list, None] = None
25
28
 
26
- def _parse_json_settings(self):
27
- # Load settings file
29
+ def __post_init__(self):
30
+ settings = get_settings(self.new_settings_file)
28
31
 
29
- settings = get_settings_dict(
30
- self.new_settings_file,
31
- )
32
+ self.init_point_list = self.user.planets_list + self.user.houses_list
32
33
 
33
34
  self.planets_settings = settings["celestial_points"]
34
35
  self.aspects_settings = settings["aspects"]
35
36
  self.axes_orbit_settings = settings["general_settings"]["axes_orbit"]
36
37
 
37
- def asp_calc(self, point_one, point_two):
38
- """
39
- Utility function.
40
- It calculates the aspects between the 2 points.
41
- Args: first point, second point.
42
- """
43
-
44
- distance = abs(difdeg2n(point_one, point_two))
45
- diff = abs(point_one - point_two)
46
-
47
- if int(distance) <= self.aspects_settings[0]["orb"]:
48
- name = self.aspects_settings[0]["name"]
49
- aspect_degrees = self.aspects_settings[0]["degree"]
50
- color = self.aspects_settings[0]["color"]
51
- verdict = True
52
- aid = 0
53
-
54
- elif (
55
- (self.aspects_settings[1]["degree"] - self.aspects_settings[1]["orb"])
56
- <= int(distance)
57
- <= (self.aspects_settings[1]["degree"] + self.aspects_settings[1]["orb"])
58
- ):
59
- name = self.aspects_settings[1]["name"]
60
- aspect_degrees = self.aspects_settings[1]["degree"]
61
- color = self.aspects_settings[1]["color"]
62
- verdict = True
63
- aid = 1
64
-
65
- elif (
66
- (self.aspects_settings[2]["degree"] - self.aspects_settings[2]["orb"])
67
- <= int(distance)
68
- <= (self.aspects_settings[2]["degree"] + self.aspects_settings[2]["orb"])
69
- ):
70
- name = self.aspects_settings[2]["name"]
71
- aspect_degrees = self.aspects_settings[2]["degree"]
72
- color = self.aspects_settings[2]["color"]
73
- verdict = True
74
- aid = 2
75
-
76
- elif (
77
- (self.aspects_settings[3]["degree"] - self.aspects_settings[3]["orb"])
78
- <= int(distance)
79
- <= (self.aspects_settings[3]["degree"] + self.aspects_settings[3]["orb"])
80
- ):
81
- name = self.aspects_settings[3]["name"]
82
- aspect_degrees = self.aspects_settings[3]["degree"]
83
- color = self.aspects_settings[3]["color"]
84
- verdict = True
85
- aid = 3
86
-
87
- elif (
88
- (self.aspects_settings[4]["degree"] - self.aspects_settings[4]["orb"])
89
- <= int(distance)
90
- <= (self.aspects_settings[4]["degree"] + self.aspects_settings[4]["orb"])
91
- ):
92
- name = self.aspects_settings[4]["name"]
93
- aspect_degrees = self.aspects_settings[4]["degree"]
94
- color = self.aspects_settings[4]["color"]
95
- verdict = True
96
- aid = 4
97
-
98
- elif (
99
- (self.aspects_settings[5]["degree"] - self.aspects_settings[5]["orb"])
100
- <= int(distance)
101
- <= (self.aspects_settings[5]["degree"] + self.aspects_settings[5]["orb"])
102
- ):
103
- name = self.aspects_settings[5]["name"]
104
- aspect_degrees = self.aspects_settings[5]["degree"]
105
- color = self.aspects_settings[5]["color"]
106
- verdict = True
107
- aid = 5
108
-
109
- elif (
110
- (self.aspects_settings[6]["degree"] - self.aspects_settings[6]["orb"])
111
- <= int(distance)
112
- <= (self.aspects_settings[6]["degree"] + self.aspects_settings[6]["orb"])
113
- ):
114
- name = self.aspects_settings[6]["name"]
115
- aspect_degrees = self.aspects_settings[6]["degree"]
116
- color = self.aspects_settings[6]["color"]
117
- verdict = True
118
- aid = 6
119
-
120
- elif (
121
- (self.aspects_settings[7]["degree"] - self.aspects_settings[7]["orb"])
122
- <= int(distance)
123
- <= (self.aspects_settings[7]["degree"] + self.aspects_settings[7]["orb"])
124
- ):
125
- name = self.aspects_settings[7]["name"]
126
- aspect_degrees = self.aspects_settings[7]["degree"]
127
- color = self.aspects_settings[7]["color"]
128
- verdict = True
129
- aid = 7
130
-
131
- elif (
132
- (self.aspects_settings[8]["degree"] - self.aspects_settings[8]["orb"])
133
- <= int(distance)
134
- <= (self.aspects_settings[8]["degree"] + self.aspects_settings[8]["orb"])
135
- ):
136
- name = self.aspects_settings[8]["name"]
137
- aspect_degrees = self.aspects_settings[8]["degree"]
138
- color = self.aspects_settings[8]["color"]
139
- verdict = True
140
- aid = 8
141
-
142
- elif (
143
- (self.aspects_settings[9]["degree"] - self.aspects_settings[9]["orb"])
144
- <= int(distance)
145
- <= (self.aspects_settings[9]["degree"] + self.aspects_settings[9]["orb"])
146
- ):
147
- name = self.aspects_settings[9]["name"]
148
- aspect_degrees = self.aspects_settings[9]["degree"]
149
- color = self.aspects_settings[9]["color"]
150
- verdict = True
151
- aid = 9
152
-
153
- elif (
154
- (self.aspects_settings[10]["degree"] - self.aspects_settings[10]["orb"])
155
- <= int(distance)
156
- <= (self.aspects_settings[10]["degree"] + self.aspects_settings[10]["orb"])
157
- ):
158
- name = self.aspects_settings[10]["name"]
159
- aspect_degrees = self.aspects_settings[10]["degree"]
160
- color = self.aspects_settings[10]["color"]
161
- verdict = True
162
- aid = 10
163
-
164
- else:
165
- verdict = False
166
- name = None
167
- distance = 0
168
- aspect_degrees = 0
169
- color = None
170
- aid = None
171
-
172
- return (
173
- verdict,
174
- name,
175
- distance - aspect_degrees,
176
- aspect_degrees,
177
- color,
178
- aid,
179
- diff,
180
- )
181
-
182
- def p_id_decoder(self, name):
183
- """
184
- Check if the name of the planet is the same in the settings and return
185
- the correct id for the planet.
186
- """
187
- str_name = str(name)
188
- for planet in self.planets_settings:
189
- if planet["name"] == str_name:
190
- result = planet["id"]
191
- return result
192
-
193
- def filter_by_settings(self, init_point_list):
194
- """
195
- Creates a list of all the desired
196
- points filtering by the settings.
197
- """
198
-
199
- set_points_name = []
200
- for p in self.planets_settings:
201
- if p["is_active"]:
202
- set_points_name.append(p["name"])
203
-
204
- point_list = []
205
- for l in init_point_list:
206
- if l["name"] in set_points_name:
207
- point_list.append(l)
208
-
209
- return point_list
210
-
211
- def get_all_aspects(self):
38
+ @property
39
+ def all_aspects(self):
212
40
  """
213
41
  Return all the aspects of the points in the natal chart in a dictionary,
214
42
  first all the individual aspects of each planet, second the aspects
215
- whitout repetitions.
43
+ without repetitions.
216
44
  """
217
45
 
218
- point_list = self.filter_by_settings(self.init_point_list)
46
+ if self._all_aspects is not None:
47
+ return self._all_aspects
48
+
49
+ point_list = filter_by_settings(self.planets_settings, self.init_point_list)
219
50
 
220
51
  self.all_aspects_list = []
221
52
 
222
53
  for first in range(len(point_list)):
223
- # Generates the aspects list whitout repetitions
54
+ # Generates the aspects list without repetitions
224
55
  for second in range(first + 1, len(point_list)):
225
- verdict, name, orbit, aspect_degrees, color, aid, diff = self.asp_calc(
226
- point_list[first]["abs_pos"], point_list[second]["abs_pos"]
56
+ verdict, name, orbit, aspect_degrees, color, aid, diff = get_aspect_from_two_points(
57
+ self.aspects_settings, point_list[first]["abs_pos"], point_list[second]["abs_pos"]
227
58
  )
228
59
 
229
60
  if verdict == True:
@@ -238,8 +69,9 @@ class NatalAspects:
238
69
  "color": color,
239
70
  "aid": aid,
240
71
  "diff": diff,
241
- "p1": self.p_id_decoder(point_list[first]["name"]),
242
- "p2": self.p_id_decoder(
72
+ "p1": planet_id_decoder(self.planets_settings, point_list[first]["name"]),
73
+ "p2": planet_id_decoder(
74
+ self.planets_settings,
243
75
  point_list[second]["name"],
244
76
  ),
245
77
  }
@@ -248,7 +80,8 @@ class NatalAspects:
248
80
 
249
81
  return self.all_aspects_list
250
82
 
251
- def get_relevant_aspects(self):
83
+ @property
84
+ def relevant_aspects(self):
252
85
  """
253
86
  Filters the aspects list with the desired points, in this case
254
87
  the most important are hardcoded.
@@ -256,7 +89,12 @@ class NatalAspects:
256
89
  or the numbers of the houses.
257
90
  """
258
91
 
259
- self.get_all_aspects()
92
+ if self._relevant_aspects is not None:
93
+ logger.debug("Relevant aspects already calculated, returning cached value")
94
+ return self._relevant_aspects
95
+
96
+ logger.debug("Relevant aspects not already calculated, calculating now...")
97
+ self.all_aspects
260
98
 
261
99
  aspects_filtered = []
262
100
  for a in self.all_aspects_list:
@@ -291,15 +129,15 @@ class NatalAspects:
291
129
 
292
130
 
293
131
  if __name__ == "__main__":
132
+ basicConfig(level="DEBUG", force=True)
294
133
  johnny = AstrologicalSubject("Johnny Depp", 1963, 6, 9, 0, 0, "Owensboro", "US")
295
134
 
296
135
  # All aspects
297
- aspects = NatalAspects(johnny).get_all_aspects()
298
- print(aspects)
136
+ aspects = NatalAspects(johnny)
137
+ print(aspects.all_aspects)
299
138
 
300
139
  print("\n")
301
140
 
302
141
  # Relevant aspects
303
- aspects = NatalAspects(johnny).get_relevant_aspects()
304
- print(aspects)
305
-
142
+ aspects = NatalAspects(johnny)
143
+ print(aspects.relevant_aspects)
@@ -8,6 +8,8 @@ from pathlib import Path
8
8
  from typing import Union
9
9
 
10
10
  from kerykeion.aspects.natal_aspects import NatalAspects
11
+ from kerykeion.settings.kerykeion_settings import get_settings
12
+ from kerykeion.aspects.aspects_utils import filter_by_settings, planet_id_decoder, get_aspect_from_two_points
11
13
 
12
14
 
13
15
  class SynastryAspects(NatalAspects):
@@ -25,28 +27,41 @@ class SynastryAspects(NatalAspects):
25
27
  self.second_user = kr_object_two
26
28
 
27
29
  self.new_settings_file = new_settings_file
28
- self._parse_json_settings()
29
30
 
30
31
  self.first_init_point_list = self.first_user.planets_list + self.first_user.houses_list
31
32
  self.second_init_point_list = self.second_user.planets_list + self.second_user.houses_list
32
33
 
33
- def get_all_aspects(self):
34
+ self._all_aspects: Union[list, None] = None
35
+ self._relevant_aspects: Union[list, None] = None
36
+
37
+ settings = get_settings(self.new_settings_file)
38
+
39
+ self.planets_settings = settings["celestial_points"]
40
+ self.aspects_settings = settings["aspects"]
41
+ self.axes_orbit_settings = settings["general_settings"]["axes_orbit"]
42
+
43
+ @property
44
+ def all_aspects(self):
34
45
  """
35
46
  Return all the aspects of the points in the natal chart in a dictionary,
36
47
  first all the individual aspects of each planet, second the aspects
37
48
  whiteout repetitions.
38
49
  """
39
50
 
40
- f_1 = self.filter_by_settings(self.first_init_point_list)
41
- f_2 = self.filter_by_settings(self.second_init_point_list)
51
+ if self._all_aspects is not None:
52
+ return self._all_aspects
53
+
54
+ f_1 = filter_by_settings(self.planets_settings, self.first_init_point_list)
55
+
56
+ f_2 = filter_by_settings(self.planets_settings, self.second_init_point_list)
42
57
 
43
58
  self.all_aspects_list = []
44
59
 
45
60
  for first in range(len(f_1)):
46
61
  # Generates the aspects list whitout repetitions
47
62
  for second in range(len(f_2)):
48
- verdict, name, orbit, aspect_degrees, color, aid, diff = self.asp_calc(
49
- f_1[first]["abs_pos"], f_2[second]["abs_pos"]
63
+ verdict, name, orbit, aspect_degrees, color, aid, diff = get_aspect_from_two_points(
64
+ self.aspects_settings, f_1[first]["abs_pos"], f_2[second]["abs_pos"]
50
65
  )
51
66
 
52
67
  if verdict == True:
@@ -61,8 +76,9 @@ class SynastryAspects(NatalAspects):
61
76
  "color": color,
62
77
  "aid": aid,
63
78
  "diff": diff,
64
- "p1": self.p_id_decoder(f_1[first]["name"]),
65
- "p2": self.p_id_decoder(
79
+ "p1": planet_id_decoder(self.planets_settings, f_1[first]["name"]),
80
+ "p2": planet_id_decoder(
81
+ self.planets_settings,
66
82
  f_2[second]["name"],
67
83
  ),
68
84
  }
@@ -79,7 +95,7 @@ if __name__ == "__main__":
79
95
  synastry_aspects = SynastryAspects(john, yoko)
80
96
 
81
97
  # All aspects
82
- print(synastry_aspects.get_all_aspects())
98
+ print(synastry_aspects.all_aspects)
83
99
 
84
100
  # Relevant aspects
85
- print(synastry_aspects.get_relevant_aspects())
101
+ print(synastry_aspects.relevant_aspects)