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.
 
 
 
 

93 lines
2.7 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. class Position:
  22. def __init__(self, latitude: float, longitude: float, altitude: float = 0):
  23. self.latitude = latitude
  24. self.longitude = longitude
  25. self.altitude = altitude
  26. self.observation_planet = None
  27. def get_planet_topos(self) -> Topos:
  28. if self.observation_planet is None:
  29. raise TypeError('Observation planet must be set.')
  30. return self.observation_planet + Topos(latitude_degrees=self.latitude, longitude_degrees=self.longitude)
  31. class AsterEphemerides:
  32. def __init__(self,
  33. rise_time: Union[Time, None],
  34. culmination_time: Union[Time, None],
  35. set_time: Union[Time, None]):
  36. self.rise_time = rise_time
  37. self.maximum_time = culmination_time
  38. self.set_time = set_time
  39. class Object(ABC):
  40. """
  41. An astronomical object.
  42. """
  43. def __init__(self,
  44. name: str,
  45. skyfield_name: str,
  46. ephemerides: AsterEphemerides or None = None):
  47. """
  48. Initialize an astronomical object
  49. :param str name: the official name of the object (may be internationalized)
  50. :param str skyfield_name: the internal name of the object in Skyfield library
  51. :param AsterEphemerides ephemerides: the ephemerides associated to the object
  52. """
  53. self.name = name
  54. self.skyfield_name = skyfield_name
  55. self.ephemerides = ephemerides
  56. @abstractmethod
  57. def get_type(self) -> str:
  58. pass
  59. class Star(Object):
  60. def get_type(self) -> str:
  61. return 'star'
  62. class Planet(Object):
  63. def get_type(self) -> str:
  64. return 'planet'
  65. class DwarfPlanet(Planet):
  66. def get_type(self) -> str:
  67. return 'dwarf_planet'
  68. class Satellite(Object):
  69. def get_type(self) -> str:
  70. return 'satellite'