A library that computes the ephemerides.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

141 lines
3.7 KiB

  1. #!/usr/bin/env python3
  2. # Kosmorrolib - The Library To Compute Your Ephemerides
  3. # Copyright (C) 2021 Jérôme Deuchnord <jerome@deuchnord.fr>
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU Affero General Public License as
  7. # published by the Free Software Foundation, either version 3 of the
  8. # License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU Affero General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Affero General Public License
  16. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. from enum import Enum
  18. class MoonPhaseType(Enum):
  19. """An enumeration of moon phases."""
  20. NEW_MOON = 0
  21. WAXING_CRESCENT = 1
  22. FIRST_QUARTER = 2
  23. WAXING_GIBBOUS = 3
  24. FULL_MOON = 4
  25. WANING_GIBBOUS = 5
  26. LAST_QUARTER = 6
  27. WANING_CRESCENT = 7
  28. class SeasonType(Enum):
  29. MARCH_EQUINOX = 0
  30. JUNE_SOLSTICE = 1
  31. SEPTEMBER_EQUINOX = 2
  32. DECEMBER_SOLSTICE = 3
  33. def localize(self, position: Position) -> LocalizedSeasonType:
  34. """Return the local season that corresponds to the given position's latitude.
  35. Args:
  36. season (SeasonType): The season to localize.
  37. position (Position): The position to localize the season for.
  38. Returns:
  39. SeasonType: The localized season.
  40. Raises:
  41. ValueError: If the latitude is 0 (equator).
  42. )
  43. >>> from kosmorrolib import Position
  44. >>> SeasonType.MARCH_EQUINOX.localize(Position(0, 1))
  45. Traceback (most recent call last):
  46. ...
  47. ValueError: Cannot localize seasons for this latitude.
  48. >>> SeasonType.MARCH_EQUINOX.localize(Position(1, 1))
  49. <LocalizedSeasonType.SPRING: 1>
  50. >>> SeasonType.MARCH_EQUINOX.localize(Position(-1, 1))
  51. <LocalizedSeasonType.AUTUMN: 3>
  52. """
  53. if position.latitude == 0: # Equator
  54. raise ValueError("Cannot localize seasons for this latitude.")
  55. if position.latitude < 0: # Southern hemisphere
  56. seasons = {
  57. self.MARCH_EQUINOX: LocalizedSeasonType.AUTUMN,
  58. self.JUNE_SOLSTICE: LocalizedSeasonType.WINTER,
  59. self.SEPTEMBER_EQUINOX: LocalizedSeasonType.SPRING,
  60. self.DECEMBER_SOLSTICE: LocalizedSeasonType.SUMMER,
  61. }
  62. else: # Nothern hemisphere
  63. seasons = {
  64. self.MARCH_EQUINOX: LocalizedSeasonType.SPRING,
  65. self.JUNE_SOLSTICE: LocalizedSeasonType.SUMMER,
  66. self.SEPTEMBER_EQUINOX: LocalizedSeasonType.AUTUMN,
  67. self.DECEMBER_SOLSTICE: LocalizedSeasonType.WINTER,
  68. }
  69. return seasons[self]
  70. class LocalizedSeasonType(Enum):
  71. WINTER = 0
  72. SPRING = 1
  73. SUMMER = 2
  74. AUTUMN = 3
  75. class EventType(Enum):
  76. """An enumeration for the supported event types."""
  77. OPPOSITION = 1
  78. CONJUNCTION = 2
  79. OCCULTATION = 3
  80. MAXIMAL_ELONGATION = 4
  81. PERIGEE = 5
  82. APOGEE = 6
  83. SEASON_CHANGE = 7
  84. LUNAR_ECLIPSE = 8
  85. class LunarEclipseType(Enum):
  86. """An enumeration of lunar eclipse types"""
  87. PENUMBRAL = 0
  88. PARTIAL = 1
  89. TOTAL = 2
  90. class ObjectType(Enum):
  91. """An enumeration of object types"""
  92. STAR = 0
  93. PLANET = 1
  94. DWARF_PLANET = 11
  95. SATELLITE = 2
  96. class ObjectIdentifier(Enum):
  97. """An enumeration of identifiers for objects"""
  98. SUN = 0
  99. EARTH = 1
  100. MOON = 11
  101. MERCURY = 2
  102. VENUS = 3
  103. MARS = 4
  104. JUPITER = 5
  105. SATURN = 6
  106. URANUS = 7
  107. NEPTUNE = 8
  108. PLUTO = 9