Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

data.py 3.0 KiB

il y a 5 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. 'FIRST_QUARTER': 'First Quarter',
  24. 'FULL_MOON': 'Full Moon',
  25. 'LAST_QUARTER': 'Last Quarter'
  26. }
  27. def skyfield_to_moon_phase(val: int) -> str:
  28. phases = list(MOON_PHASES.keys())
  29. return phases[val]
  30. class Position:
  31. def __init__(self, latitude: float, longitude: float, altitude: float = 0):
  32. self.latitude = latitude
  33. self.longitude = longitude
  34. self.altitude = altitude
  35. self.observation_planet = None
  36. def get_planet_topos(self) -> Topos:
  37. if self.observation_planet is None:
  38. raise TypeError('Observation planet must be set.')
  39. return self.observation_planet + Topos(latitude_degrees=self.latitude, longitude_degrees=self.longitude)
  40. class AsterEphemerides:
  41. def __init__(self,
  42. rise_time: Union[Time, None],
  43. culmination_time: Union[Time, None],
  44. set_time: Union[Time, None]):
  45. self.rise_time = rise_time
  46. self.culmination_time = culmination_time
  47. self.set_time = set_time
  48. class Object(ABC):
  49. """
  50. An astronomical object.
  51. """
  52. def __init__(self,
  53. name: str,
  54. skyfield_name: str,
  55. ephemerides: AsterEphemerides or None = None):
  56. """
  57. Initialize an astronomical object
  58. :param str name: the official name of the object (may be internationalized)
  59. :param str skyfield_name: the internal name of the object in Skyfield library
  60. :param AsterEphemerides ephemerides: the ephemerides associated to the object
  61. """
  62. self.name = name
  63. self.skyfield_name = skyfield_name
  64. self.ephemerides = ephemerides
  65. @abstractmethod
  66. def get_type(self) -> str:
  67. pass
  68. class Star(Object):
  69. def get_type(self) -> str:
  70. return 'star'
  71. class Planet(Object):
  72. def get_type(self) -> str:
  73. return 'planet'
  74. class DwarfPlanet(Planet):
  75. def get_type(self) -> str:
  76. return 'dwarf_planet'
  77. class Satellite(Object):
  78. def get_type(self) -> str:
  79. return 'satellite'