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.
 
 
 
 

130 lines
4.0 KiB

  1. #!/usr/bin/env python3
  2. # Kosmorro - Compute The Next Ephemerides
  3. # Copyright (C) 2019 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 abc import ABC, abstractmethod
  18. from typing import Union
  19. from skyfield.api import Topos
  20. from skyfield.timelib import Time
  21. MOON_PHASES = {
  22. 'NEW_MOON': 'New Moon',
  23. 'WAXING_CRESCENT': 'Waxing crescent',
  24. 'FIRST_QUARTER': 'First Quarter',
  25. 'WAXING_GIBBOUS': 'Waxing gibbous',
  26. 'FULL_MOON': 'Full Moon',
  27. 'WANING_GIBBOUS': 'Waning gibbous',
  28. 'LAST_QUARTER': 'Last Quarter',
  29. 'WANING_CRESCENT': 'Waning crescent'
  30. }
  31. class MoonPhase:
  32. def __init__(self, identifier: str, time: Union[Time, None], next_phase_date: Union[Time, None]):
  33. if identifier not in MOON_PHASES.keys():
  34. raise ValueError('identifier parameter must be one of %s (got %s)' % (', '.join(MOON_PHASES.keys()),
  35. identifier))
  36. self.identifier = identifier
  37. self.time = time
  38. self.next_phase_date = next_phase_date
  39. def get_phase(self):
  40. return MOON_PHASES[self.identifier]
  41. def get_next_phase(self):
  42. if self.identifier == 'NEW_MOON':
  43. next_identifier = 'FIRST_QUARTER'
  44. elif self.identifier == 'FIRST_QUARTER':
  45. next_identifier = 'FULL_MOON'
  46. elif self.identifier == 'FULL_MOON':
  47. next_identifier = 'LAST_QUARTER'
  48. else:
  49. next_identifier = 'NEW_MOON'
  50. return MOON_PHASES[next_identifier]
  51. class Position:
  52. def __init__(self, latitude: float, longitude: float, altitude: float = 0):
  53. self.latitude = latitude
  54. self.longitude = longitude
  55. self.altitude = altitude
  56. self.observation_planet = None
  57. def get_planet_topos(self) -> Topos:
  58. if self.observation_planet is None:
  59. raise TypeError('Observation planet must be set.')
  60. return self.observation_planet + Topos(latitude_degrees=self.latitude, longitude_degrees=self.longitude)
  61. class AsterEphemerides:
  62. def __init__(self,
  63. rise_time: Union[Time, None],
  64. culmination_time: Union[Time, None],
  65. set_time: Union[Time, None]):
  66. self.rise_time = rise_time
  67. self.culmination_time = culmination_time
  68. self.set_time = set_time
  69. class Object(ABC):
  70. """
  71. An astronomical object.
  72. """
  73. def __init__(self,
  74. name: str,
  75. skyfield_name: str,
  76. ephemerides: AsterEphemerides or None = None):
  77. """
  78. Initialize an astronomical object
  79. :param str name: the official name of the object (may be internationalized)
  80. :param str skyfield_name: the internal name of the object in Skyfield library
  81. :param AsterEphemerides ephemerides: the ephemerides associated to the object
  82. """
  83. self.name = name
  84. self.skyfield_name = skyfield_name
  85. self.ephemerides = ephemerides
  86. @abstractmethod
  87. def get_type(self) -> str:
  88. pass
  89. class Star(Object):
  90. def get_type(self) -> str:
  91. return 'star'
  92. class Planet(Object):
  93. def get_type(self) -> str:
  94. return 'planet'
  95. class DwarfPlanet(Planet):
  96. def get_type(self) -> str:
  97. return 'dwarf_planet'
  98. class Satellite(Object):
  99. def get_type(self) -> str:
  100. return 'satellite'