kerykeion 4.14.9__py3-none-any.whl → 4.14.11__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.

@@ -8,6 +8,7 @@ from kerykeion import AstrologicalSubject
8
8
  from kerykeion.settings import KerykeionSettingsModel
9
9
  from swisseph import difdeg2n
10
10
  from typing import Union
11
+ from kerykeion.kr_types.kr_models import AstrologicalSubjectModel
11
12
 
12
13
 
13
14
  def get_aspect_from_two_points(aspects_settings: dict, point_one: Union[float, int], point_two: Union[float, int]):
@@ -157,7 +158,7 @@ def planet_id_decoder(planets_settings: dict, name: str):
157
158
  return result
158
159
 
159
160
 
160
- def get_active_points_list(subject: AstrologicalSubject, settings: Union[KerykeionSettingsModel, dict]) -> list:
161
+ def get_active_points_list(subject: Union[AstrologicalSubject, AstrologicalSubjectModel], settings: Union[KerykeionSettingsModel, dict]) -> list:
161
162
  """
162
163
  Given an astrological subject and the settings, return a list of the active points.
163
164
  Args:
@@ -11,6 +11,7 @@ from kerykeion.settings.kerykeion_settings import get_settings
11
11
  from dataclasses import dataclass
12
12
  from functools import cached_property
13
13
  from kerykeion.aspects.aspects_utils import planet_id_decoder, get_aspect_from_two_points, get_active_points_list
14
+ from kerykeion.kr_types.kr_models import AstrologicalSubjectModel
14
15
 
15
16
 
16
17
  AXES_LIST = [
@@ -27,7 +28,7 @@ class NatalAspects:
27
28
  Generates an object with all the aspects of a birthcart.
28
29
  """
29
30
 
30
- user: AstrologicalSubject
31
+ user: Union[AstrologicalSubject, AstrologicalSubjectModel]
31
32
  new_settings_file: Union[Path, None] = None
32
33
 
33
34
  def __post_init__(self):
@@ -11,6 +11,8 @@ from functools import cached_property
11
11
  from kerykeion.aspects.natal_aspects import NatalAspects
12
12
  from kerykeion.settings.kerykeion_settings import get_settings
13
13
  from kerykeion.aspects.aspects_utils import planet_id_decoder, get_aspect_from_two_points, get_active_points_list
14
+ from kerykeion.kr_types.kr_models import AstrologicalSubjectModel
15
+ from typing import Union
14
16
 
15
17
 
16
18
  class SynastryAspects(NatalAspects):
@@ -20,8 +22,8 @@ class SynastryAspects(NatalAspects):
20
22
 
21
23
  def __init__(
22
24
  self,
23
- kr_object_one: AstrologicalSubject,
24
- kr_object_two: AstrologicalSubject,
25
+ kr_object_one: Union[AstrologicalSubject, AstrologicalSubjectModel],
26
+ kr_object_two: Union[AstrologicalSubject, AstrologicalSubjectModel],
25
27
  new_settings_file: Union[Path, None] = None,
26
28
  ):
27
29
  # Subjects
@@ -20,11 +20,13 @@ from kerykeion.kr_types import (
20
20
  PointType,
21
21
  SiderealMode,
22
22
  HousesSystemIdentifier,
23
- PerspectiveType
23
+ PerspectiveType,
24
+ Planet,
25
+ Houses
24
26
  )
25
27
  from kerykeion.utilities import (
26
28
  get_number_from_name,
27
- calculate_position,
29
+ get_kerykeion_point_from_degree,
28
30
  get_planet_house,
29
31
  get_moon_emoji_from_phase_int,
30
32
  get_moon_phase_name_from_phase_int,
@@ -136,7 +138,7 @@ class AstrologicalSubject:
136
138
  true_node: KerykeionPointModel
137
139
  mean_node: KerykeionPointModel
138
140
  chiron: Union[KerykeionPointModel, None]
139
- mean_lilit: Union[KerykeionPointModel, None]
141
+ mean_lilith: Union[KerykeionPointModel, None]
140
142
 
141
143
  # Houses
142
144
  first_house: KerykeionPointModel
@@ -153,15 +155,16 @@ class AstrologicalSubject:
153
155
  twelfth_house: KerykeionPointModel
154
156
 
155
157
  # Lists
156
- houses_list: list[KerykeionPointModel]
157
- planets_list: list[KerykeionPointModel]
158
- planets_degrees_ut: list[float]
159
- houses_degree_ut: list[float]
158
+ _houses_list: list[KerykeionPointModel]
159
+ _houses_degree_ut: list[float]
160
160
 
161
161
  # Enable or disable features
162
- disable_chiron: bool # Deprecated
162
+ disable_chiron: Union[None, bool]
163
163
  disable_chiron_and_lilith: bool
164
164
 
165
+ planets_names_list: list[Planet]
166
+ houses_names_list: list[Houses]
167
+
165
168
  def __init__(
166
169
  self,
167
170
  name="Now",
@@ -178,7 +181,7 @@ class AstrologicalSubject:
178
181
  geonames_username: Union[str, None] = None,
179
182
  zodiac_type: ZodiacType = DEFAULT_ZODIAC_TYPE,
180
183
  online: bool = True,
181
- disable_chiron: bool = False,
184
+ disable_chiron: Union[None, bool] = None, # Deprecated
182
185
  sidereal_mode: Union[SiderealMode, None] = None,
183
186
  houses_system_identifier: HousesSystemIdentifier = DEFAULT_HOUSES_SYSTEM_IDENTIFIER,
184
187
  perspective_type: PerspectiveType = DEFAULT_PERSPECTIVE_TYPE,
@@ -221,41 +224,46 @@ class AstrologicalSubject:
221
224
  # General setup #
222
225
  #---------------#
223
226
 
224
- # This message is set to encourage the user to set a custom geonames username
227
+ # Geonames username
225
228
  if geonames_username is None and online:
226
229
  logging.warning(GEONAMES_DEFAULT_USERNAME_WARNING)
227
230
  self.geonames_username = DEFAULT_GEONAMES_USERNAME
228
231
  else:
229
- self.geonames_username = geonames_username
232
+ self.geonames_username = geonames_username # type: ignore
230
233
 
234
+ # City
231
235
  if not city:
232
236
  self.city = "London"
233
237
  logging.info("No city specified, using London as default")
234
238
  else:
235
239
  self.city = city
236
240
 
241
+ # Nation
237
242
  if not nation:
238
243
  self.nation = "GB"
239
244
  logging.info("No nation specified, using GB as default")
240
245
  else:
241
246
  self.nation = nation
242
247
 
248
+ # Latitude
243
249
  if not lat and not self.online:
244
250
  self.lat = 51.5074
245
251
  logging.info("No latitude specified, using London as default")
246
252
  else:
247
- self.lat = lat
248
-
253
+ self.lat = lat # type: ignore
254
+
255
+ # Longitude
249
256
  if not lng and not self.online:
250
257
  self.lng = 0
251
258
  logging.info("No longitude specified, using London as default")
252
259
  else:
253
- self.lng = lng
260
+ self.lng = lng # type: ignore
254
261
 
262
+ # Timezone
255
263
  if (not self.online) and (not tz_str):
256
264
  raise KerykeionException("You need to set the coordinates and timezone if you want to use the offline mode!")
257
265
  else:
258
- self.tz_str = tz_str
266
+ self.tz_str = tz_str # type: ignore
259
267
 
260
268
  #-----------------------#
261
269
  # Swiss Ephemeris setup #
@@ -303,7 +311,8 @@ class AstrologicalSubject:
303
311
 
304
312
  if self.zodiac_type == "Sidereal":
305
313
  # Check if the sidereal mode is valid
306
- if not self.sidereal_mode in get_args(SiderealMode):
314
+
315
+ if not self.sidereal_mode or not self.sidereal_mode in get_args(SiderealMode):
307
316
  raise KerykeionException(f"\n* ERROR: '{self.sidereal_mode}' is NOT a valid sidereal mode! Available modes are: *" + "\n" + str(get_args(SiderealMode)))
308
317
 
309
318
  self._iflag += swe.FLG_SIDEREAL
@@ -342,11 +351,9 @@ class AstrologicalSubject:
342
351
  self.julian_day = float(swe.julday(utc_object.year, utc_object.month, utc_object.day, utc_float_hour_with_minutes))
343
352
  # <--- UTC, julian day and local time setup
344
353
 
345
- self._planets_degrees_lister()
346
- self._planets()
347
- self._houses()
348
- self._planets_in_houses()
349
- self._lunar_phase_calc()
354
+ self._initialize_houses()
355
+ self._initialize_planets()
356
+ self._initialize_moon_phase()
350
357
 
351
358
  # Deprecated properties
352
359
  self.utc_time
@@ -388,7 +395,7 @@ class AstrologicalSubject:
388
395
  self.lat = float(self.city_data["lat"])
389
396
  self.tz_str = self.city_data["timezonestr"]
390
397
 
391
- def _houses(self) -> None:
398
+ def _initialize_houses(self) -> None:
392
399
  """
393
400
  Calculate positions and store them in dictionaries
394
401
 
@@ -423,7 +430,7 @@ class AstrologicalSubject:
423
430
  """
424
431
 
425
432
  if self.zodiac_type == "Sidereal":
426
- self.houses_degree_ut = swe.houses_ex(
433
+ self._houses_degree_ut = swe.houses_ex(
427
434
  tjdut=self.julian_day,
428
435
  lat=self.lat, lon=self.lng,
429
436
  hsys=str.encode(self.houses_system_identifier),
@@ -431,7 +438,7 @@ class AstrologicalSubject:
431
438
  )[0]
432
439
 
433
440
  elif self.zodiac_type == "Tropic":
434
- self.houses_degree_ut = swe.houses(
441
+ self._houses_degree_ut = swe.houses(
435
442
  tjdut=self.julian_day, lat=self.lat,
436
443
  lon=self.lng,
437
444
  hsys=str.encode(self.houses_system_identifier)
@@ -440,20 +447,23 @@ class AstrologicalSubject:
440
447
  point_type: PointType = "House"
441
448
 
442
449
  # stores the house in singular dictionaries.
443
- self.first_house = calculate_position(self.houses_degree_ut[0], "First_House", point_type=point_type)
444
- self.second_house = calculate_position(self.houses_degree_ut[1], "Second_House", point_type=point_type)
445
- self.third_house = calculate_position(self.houses_degree_ut[2], "Third_House", point_type=point_type)
446
- self.fourth_house = calculate_position(self.houses_degree_ut[3], "Fourth_House", point_type=point_type)
447
- self.fifth_house = calculate_position(self.houses_degree_ut[4], "Fifth_House", point_type=point_type)
448
- self.sixth_house = calculate_position(self.houses_degree_ut[5], "Sixth_House", point_type=point_type)
449
- self.seventh_house = calculate_position(self.houses_degree_ut[6], "Seventh_House", point_type=point_type)
450
- self.eighth_house = calculate_position(self.houses_degree_ut[7], "Eighth_House", point_type=point_type)
451
- self.ninth_house = calculate_position(self.houses_degree_ut[8], "Ninth_House", point_type=point_type)
452
- self.tenth_house = calculate_position(self.houses_degree_ut[9], "Tenth_House", point_type=point_type)
453
- self.eleventh_house = calculate_position(self.houses_degree_ut[10], "Eleventh_House", point_type=point_type)
454
- self.twelfth_house = calculate_position(self.houses_degree_ut[11], "Twelfth_House", point_type=point_type)
455
-
456
- self.houses_list = [
450
+ self.first_house = get_kerykeion_point_from_degree(self._houses_degree_ut[0], "First_House", point_type=point_type)
451
+ self.second_house = get_kerykeion_point_from_degree(self._houses_degree_ut[1], "Second_House", point_type=point_type)
452
+ self.third_house = get_kerykeion_point_from_degree(self._houses_degree_ut[2], "Third_House", point_type=point_type)
453
+ self.fourth_house = get_kerykeion_point_from_degree(self._houses_degree_ut[3], "Fourth_House", point_type=point_type)
454
+ self.fifth_house = get_kerykeion_point_from_degree(self._houses_degree_ut[4], "Fifth_House", point_type=point_type)
455
+ self.sixth_house = get_kerykeion_point_from_degree(self._houses_degree_ut[5], "Sixth_House", point_type=point_type)
456
+ self.seventh_house = get_kerykeion_point_from_degree(self._houses_degree_ut[6], "Seventh_House", point_type=point_type)
457
+ self.eighth_house = get_kerykeion_point_from_degree(self._houses_degree_ut[7], "Eighth_House", point_type=point_type)
458
+ self.ninth_house = get_kerykeion_point_from_degree(self._houses_degree_ut[8], "Ninth_House", point_type=point_type)
459
+ self.tenth_house = get_kerykeion_point_from_degree(self._houses_degree_ut[9], "Tenth_House", point_type=point_type)
460
+ self.eleventh_house = get_kerykeion_point_from_degree(self._houses_degree_ut[10], "Eleventh_House", point_type=point_type)
461
+ self.twelfth_house = get_kerykeion_point_from_degree(self._houses_degree_ut[11], "Twelfth_House", point_type=point_type)
462
+
463
+ self.houses_names_list = list(get_args(Houses))
464
+
465
+ # Deprecated
466
+ self._houses_list = [
457
467
  self.first_house,
458
468
  self.second_house,
459
469
  self.third_house,
@@ -468,10 +478,12 @@ class AstrologicalSubject:
468
478
  self.twelfth_house,
469
479
  ]
470
480
 
471
- def _planets_degrees_lister(self):
472
- """Sidereal or tropic mode."""
481
+ def _initialize_planets(self) -> None:
482
+ """Defines body positon in signs and information and
483
+ stores them in dictionaries"""
484
+
485
+ point_type: PointType = "Planet"
473
486
 
474
- # Calculates the position of the planets and stores it in a list.
475
487
  sun_deg = swe.calc(self.julian_day, 0, self._iflag)[0][0]
476
488
  moon_deg = swe.calc(self.julian_day, 1, self._iflag)[0][0]
477
489
  mercury_deg = swe.calc(self.julian_day, 2, self._iflag)[0][0]
@@ -485,79 +497,34 @@ class AstrologicalSubject:
485
497
  mean_node_deg = swe.calc(self.julian_day, 10, self._iflag)[0][0]
486
498
  true_node_deg = swe.calc(self.julian_day, 11, self._iflag)[0][0]
487
499
 
488
- self.planets_degrees_ut = [
489
- sun_deg,
490
- moon_deg,
491
- mercury_deg,
492
- venus_deg,
493
- mars_deg,
494
- jupiter_deg,
495
- saturn_deg,
496
- uranus_deg,
497
- neptune_deg,
498
- pluto_deg,
499
- mean_node_deg,
500
- true_node_deg,
501
- ]
502
-
503
- if not self.disable_chiron_and_lilith:
504
- chiron_deg = swe.calc(self.julian_day, 15, self._iflag)[0][0]
505
- self.planets_degrees_ut.append(chiron_deg)
506
-
507
- mean_lilith_deg = swe.calc(self.julian_day, 12, self._iflag)[0][0]
508
- self.planets_degrees_ut.append(mean_lilith_deg)
509
-
510
- else:
511
- self.chiron = None
512
- self.mean_lilith = None
513
-
514
-
515
- def _planets(self) -> None:
516
- """Defines body positon in signs and information and
517
- stores them in dictionaries"""
518
-
519
- point_type: PointType = "Planet"
520
- # stores the planets in singular dictionaries.
521
- self.sun = calculate_position(self.planets_degrees_ut[0], "Sun", point_type=point_type)
522
- self.moon = calculate_position(self.planets_degrees_ut[1], "Moon", point_type=point_type)
523
- self.mercury = calculate_position(self.planets_degrees_ut[2], "Mercury", point_type=point_type)
524
- self.venus = calculate_position(self.planets_degrees_ut[3], "Venus", point_type=point_type)
525
- self.mars = calculate_position(self.planets_degrees_ut[4], "Mars", point_type=point_type)
526
- self.jupiter = calculate_position(self.planets_degrees_ut[5], "Jupiter", point_type=point_type)
527
- self.saturn = calculate_position(self.planets_degrees_ut[6], "Saturn", point_type=point_type)
528
- self.uranus = calculate_position(self.planets_degrees_ut[7], "Uranus", point_type=point_type)
529
- self.neptune = calculate_position(self.planets_degrees_ut[8], "Neptune", point_type=point_type)
530
- self.pluto = calculate_position(self.planets_degrees_ut[9], "Pluto", point_type=point_type)
531
- self.mean_node = calculate_position(self.planets_degrees_ut[10], "Mean_Node", point_type=point_type)
532
- self.true_node = calculate_position(self.planets_degrees_ut[11], "True_Node", point_type=point_type)
533
-
534
- if not self.disable_chiron_and_lilith:
535
- self.chiron = calculate_position(self.planets_degrees_ut[12], "Chiron", point_type=point_type)
536
- self.mean_lilith = calculate_position(self.planets_degrees_ut[13], "Mean_Lilith", point_type=point_type)
537
-
538
- else:
539
- self.chiron = None
540
- self.mean_lilith = None
541
-
542
-
543
- def _planets_in_houses(self) -> None:
544
- """Calculates the house of the planet and updates
545
- the planets dictionary."""
546
-
547
- self.sun.house = get_planet_house(self.planets_degrees_ut[0], self.houses_degree_ut)
548
- self.moon.house = get_planet_house(self.planets_degrees_ut[1], self.houses_degree_ut)
549
- self.mercury.house = get_planet_house(self.planets_degrees_ut[2], self.houses_degree_ut)
550
- self.venus.house = get_planet_house(self.planets_degrees_ut[3], self.houses_degree_ut)
551
- self.mars.house = get_planet_house(self.planets_degrees_ut[4], self.houses_degree_ut)
552
- self.jupiter.house = get_planet_house(self.planets_degrees_ut[5], self.houses_degree_ut)
553
- self.saturn.house = get_planet_house(self.planets_degrees_ut[6], self.houses_degree_ut)
554
- self.uranus.house = get_planet_house(self.planets_degrees_ut[7], self.houses_degree_ut)
555
- self.neptune.house = get_planet_house(self.planets_degrees_ut[8], self.houses_degree_ut)
556
- self.pluto.house = get_planet_house(self.planets_degrees_ut[9], self.houses_degree_ut)
557
- self.mean_node.house = get_planet_house(self.planets_degrees_ut[10], self.houses_degree_ut)
558
- self.true_node.house = get_planet_house(self.planets_degrees_ut[11], self.houses_degree_ut)
559
-
560
- self.planets_list = [
500
+ self.sun = get_kerykeion_point_from_degree(sun_deg, "Sun", point_type=point_type)
501
+ self.moon = get_kerykeion_point_from_degree(moon_deg, "Moon", point_type=point_type)
502
+ self.mercury = get_kerykeion_point_from_degree(mercury_deg, "Mercury", point_type=point_type)
503
+ self.venus = get_kerykeion_point_from_degree(venus_deg, "Venus", point_type=point_type)
504
+ self.mars = get_kerykeion_point_from_degree(mars_deg, "Mars", point_type=point_type)
505
+ self.jupiter = get_kerykeion_point_from_degree(jupiter_deg, "Jupiter", point_type=point_type)
506
+ self.saturn = get_kerykeion_point_from_degree(saturn_deg, "Saturn", point_type=point_type)
507
+ self.uranus = get_kerykeion_point_from_degree(uranus_deg, "Uranus", point_type=point_type)
508
+ self.neptune = get_kerykeion_point_from_degree(neptune_deg, "Neptune", point_type=point_type)
509
+ self.pluto = get_kerykeion_point_from_degree(pluto_deg, "Pluto", point_type=point_type)
510
+ self.mean_node = get_kerykeion_point_from_degree(mean_node_deg, "Mean_Node", point_type=point_type)
511
+ self.true_node = get_kerykeion_point_from_degree(true_node_deg, "True_Node", point_type=point_type)
512
+
513
+ self.sun.house = get_planet_house(sun_deg, self._houses_degree_ut)
514
+ self.moon.house = get_planet_house(moon_deg, self._houses_degree_ut)
515
+ self.mercury.house = get_planet_house(mercury_deg, self._houses_degree_ut)
516
+ self.venus.house = get_planet_house(venus_deg, self._houses_degree_ut)
517
+ self.mars.house = get_planet_house(mars_deg, self._houses_degree_ut)
518
+ self.jupiter.house = get_planet_house(jupiter_deg, self._houses_degree_ut)
519
+ self.saturn.house = get_planet_house(saturn_deg, self._houses_degree_ut)
520
+ self.uranus.house = get_planet_house(uranus_deg, self._houses_degree_ut)
521
+ self.neptune.house = get_planet_house(neptune_deg, self._houses_degree_ut)
522
+ self.pluto.house = get_planet_house(pluto_deg, self._houses_degree_ut)
523
+ self.mean_node.house = get_planet_house(mean_node_deg, self._houses_degree_ut)
524
+ self.true_node.house = get_planet_house(true_node_deg, self._houses_degree_ut)
525
+
526
+ # Deprecated
527
+ planets_list = [
561
528
  self.sun,
562
529
  self.moon,
563
530
  self.mercury,
@@ -571,91 +538,70 @@ class AstrologicalSubject:
571
538
  self.mean_node,
572
539
  self.true_node,
573
540
  ]
574
-
541
+
575
542
  if not self.disable_chiron_and_lilith:
576
- self.chiron.house = get_planet_house(self.planets_degrees_ut[12], self.houses_degree_ut)
577
- self.planets_list.append(self.chiron)
543
+ chiron_deg = swe.calc(self.julian_day, 15, self._iflag)[0][0]
544
+ mean_lilith_deg = swe.calc(self.julian_day, 12, self._iflag)[0][0]
578
545
 
579
- self.mean_lilith.house = get_planet_house(self.planets_degrees_ut[13], self.houses_degree_ut)
580
- self.planets_list.append(self.mean_lilith)
546
+ self.chiron = get_kerykeion_point_from_degree(chiron_deg, "Chiron", point_type=point_type)
547
+ self.mean_lilith = get_kerykeion_point_from_degree(mean_lilith_deg, "Mean_Lilith", point_type=point_type)
548
+
549
+ self.chiron.house = get_planet_house(chiron_deg, self._houses_degree_ut)
550
+ self.mean_lilith.house = get_planet_house(mean_lilith_deg, self._houses_degree_ut)
551
+
552
+ # Deprecated
553
+ planets_list.append(self.chiron)
554
+ planets_list.append(self.mean_lilith)
581
555
 
582
556
  else:
583
557
  self.chiron = None
584
558
  self.mean_lilith = None
585
559
 
560
+ # FIXME: Update after removing planets_list
561
+ self.planets_names_list = [planet["name"] for planet in planets_list]
562
+
586
563
  # Check in retrograde or not:
587
- planets_ret = []
588
- for planet in self.planets_list:
564
+ for planet in planets_list:
589
565
  planet_number = get_number_from_name(planet["name"])
590
566
  if swe.calc(self.julian_day, planet_number, self._iflag)[0][3] < 0:
591
567
  planet["retrograde"] = True
592
568
  else:
593
569
  planet["retrograde"] = False
594
- planets_ret.append(planet)
595
570
 
596
- def _lunar_phase_calc(self) -> None:
597
- """Function to calculate the lunar phase"""
598
571
 
599
- # If ther's an error:
600
- moon_phase, sun_phase = None, None
572
+ def _initialize_moon_phase(self) -> None:
573
+ """
574
+ Calculate and initialize the lunar phase based on the positions of the moon and sun.
601
575
 
602
- # anti-clockwise degrees between sun and moon
603
- moon, sun = self.planets_degrees_ut[1], self.planets_degrees_ut[0]
604
- degrees_between = moon - sun
576
+ This function calculates the degrees between the moon and the sun, determines the moon phase
577
+ and sun phase, and initializes the lunar phase model with the calculated values.
578
+ """
579
+ # Initialize moon_phase and sun_phase to None in case of an error
580
+ moon_phase, sun_phase = None, None
605
581
 
606
- if degrees_between < 0:
607
- degrees_between += 360.0
582
+ # Calculate the anti-clockwise degrees between the sun and moon
583
+ moon, sun = self.moon.abs_pos, self.sun.abs_pos
584
+ degrees_between = (moon - sun) % 360
608
585
 
586
+ # Calculate the moon phase (1-28) based on the degrees between the sun and moon
609
587
  step = 360.0 / 28.0
588
+ moon_phase = int(degrees_between // step) + 1
610
589
 
611
- for x in range(28):
612
- low = x * step
613
- high = (x + 1) * step
614
-
615
- if degrees_between >= low and degrees_between < high:
616
- moon_phase = x + 1
617
-
590
+ # Define the sun phase steps
618
591
  sunstep = [
619
- 0,
620
- 30,
621
- 40,
622
- 50,
623
- 60,
624
- 70,
625
- 80,
626
- 90,
627
- 120,
628
- 130,
629
- 140,
630
- 150,
631
- 160,
632
- 170,
633
- 180,
634
- 210,
635
- 220,
636
- 230,
637
- 240,
638
- 250,
639
- 260,
640
- 270,
641
- 300,
642
- 310,
643
- 320,
644
- 330,
645
- 340,
646
- 350,
592
+ 0, 30, 40, 50, 60, 70, 80, 90, 120, 130, 140, 150, 160, 170, 180,
593
+ 210, 220, 230, 240, 250, 260, 270, 300, 310, 320, 330, 340, 350
647
594
  ]
648
595
 
596
+ # Calculate the sun phase (1-28) based on the degrees between the sun and moon
649
597
  for x in range(len(sunstep)):
650
598
  low = sunstep[x]
651
-
652
- if x == 27:
653
- high = 360
654
- else:
655
- high = sunstep[x + 1]
656
- if degrees_between >= low and degrees_between < high:
599
+ high = sunstep[x + 1] if x < len(sunstep) - 1 else 360
600
+ if low <= degrees_between < high:
657
601
  sun_phase = x + 1
602
+ break
658
603
 
604
+ # Create a dictionary with the lunar phase information
659
605
  lunar_phase_dictionary = {
660
606
  "degrees_between_s_m": degrees_between,
661
607
  "moon_phase": moon_phase,
@@ -664,6 +610,7 @@ class AstrologicalSubject:
664
610
  "moon_phase_name": get_moon_phase_name_from_phase_int(moon_phase)
665
611
  }
666
612
 
613
+ # Initialize the lunar phase model with the calculated values
667
614
  self.lunar_phase = LunarPhaseModel(**lunar_phase_dictionary)
668
615
 
669
616
  def json(self, dump=False, destination_folder: Union[str, None] = None, indent: Union[int, None] = None) -> str: