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.

ephemerides.py 6.0 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import unittest
  2. from kosmorrolib.enum import MoonPhaseType
  3. from .testutils import expect_assertions
  4. from kosmorrolib import ephemerides
  5. from kosmorrolib.model import Position, MoonPhase
  6. from datetime import date
  7. from kosmorrolib.exceptions import OutOfRangeDateError
  8. class EphemeridesTestCase(unittest.TestCase):
  9. def test_get_ephemerides_for_aster_returns_correct_hours(self):
  10. position = Position(0, 0)
  11. eph = ephemerides.get_ephemerides(date=date(2019, 11, 18), position=position)
  12. @expect_assertions(self.assertRegex, num=3)
  13. def do_assertions(assert_regex):
  14. for ephemeris in eph:
  15. if ephemeris.object.skyfield_name == "SUN":
  16. assert_regex(ephemeris.rise_time.isoformat(), "^2019-11-18T05:42:")
  17. assert_regex(
  18. ephemeris.culmination_time.isoformat(), "^2019-11-18T11:45:"
  19. )
  20. assert_regex(ephemeris.set_time.isoformat(), "^2019-11-18T17:49:")
  21. break
  22. do_assertions()
  23. ###################################################################################################################
  24. ### MOON PHASE TESTS ###
  25. ###################################################################################################################
  26. def test_moon_phase_new_moon(self):
  27. phase = ephemerides.get_moon_phase(date(2019, 11, 25))
  28. self.assertEqual(MoonPhaseType.WANING_CRESCENT, phase.phase_type)
  29. self.assertIsNone(phase.time)
  30. self.assertRegexpMatches(phase.next_phase_date.isoformat(), "^2019-11-26T")
  31. phase = ephemerides.get_moon_phase(date(2019, 11, 26))
  32. self.assertEqual(MoonPhaseType.NEW_MOON, phase.phase_type)
  33. self.assertRegexpMatches(phase.next_phase_date.isoformat(), "^2019-12-04T")
  34. phase = ephemerides.get_moon_phase(date(2019, 11, 27))
  35. self.assertEqual(MoonPhaseType.WAXING_CRESCENT, phase.phase_type)
  36. self.assertIsNone(phase.time)
  37. self.assertRegexpMatches(phase.next_phase_date.isoformat(), "^2019-12-04T")
  38. def test_moon_phase_first_crescent(self):
  39. phase = ephemerides.get_moon_phase(date(2019, 11, 3))
  40. self.assertEqual(MoonPhaseType.WAXING_CRESCENT, phase.phase_type)
  41. self.assertIsNone(phase.time)
  42. self.assertRegexpMatches(phase.next_phase_date.isoformat(), "^2019-11-04T")
  43. phase = ephemerides.get_moon_phase(date(2019, 11, 4))
  44. self.assertEqual(MoonPhaseType.FIRST_QUARTER, phase.phase_type)
  45. self.assertRegexpMatches(phase.next_phase_date.isoformat(), "^2019-11-12T")
  46. phase = ephemerides.get_moon_phase(date(2019, 11, 5))
  47. self.assertEqual(MoonPhaseType.WAXING_GIBBOUS, phase.phase_type)
  48. self.assertIsNone(phase.time)
  49. self.assertRegexpMatches(phase.next_phase_date.isoformat(), "^2019-11-12T")
  50. def test_moon_phase_full_moon(self):
  51. phase = ephemerides.get_moon_phase(date(2019, 11, 11))
  52. self.assertEqual(MoonPhaseType.WAXING_GIBBOUS, phase.phase_type)
  53. self.assertIsNone(phase.time)
  54. self.assertRegexpMatches(phase.next_phase_date.isoformat(), "^2019-11-12T")
  55. phase = ephemerides.get_moon_phase(date(2019, 11, 12))
  56. self.assertEqual(MoonPhaseType.FULL_MOON, phase.phase_type)
  57. self.assertRegexpMatches(phase.next_phase_date.isoformat(), "^2019-11-19T")
  58. phase = ephemerides.get_moon_phase(date(2019, 11, 13))
  59. self.assertEqual(MoonPhaseType.WANING_GIBBOUS, phase.phase_type)
  60. self.assertIsNone(phase.time)
  61. self.assertRegexpMatches(phase.next_phase_date.isoformat(), "^2019-11-19T")
  62. def test_moon_phase_last_quarter(self):
  63. phase = ephemerides.get_moon_phase(date(2019, 11, 18))
  64. self.assertEqual(MoonPhaseType.WANING_GIBBOUS, phase.phase_type)
  65. self.assertIsNone(phase.time)
  66. self.assertRegexpMatches(phase.next_phase_date.isoformat(), "^2019-11-19T")
  67. phase = ephemerides.get_moon_phase(date(2019, 11, 19))
  68. self.assertEqual(MoonPhaseType.LAST_QUARTER, phase.phase_type)
  69. self.assertRegexpMatches(phase.next_phase_date.isoformat(), "^2019-11-26T")
  70. phase = ephemerides.get_moon_phase(date(2019, 11, 20))
  71. self.assertEqual(MoonPhaseType.WANING_CRESCENT, phase.phase_type)
  72. self.assertIsNone(phase.time)
  73. self.assertRegexpMatches(phase.next_phase_date.isoformat(), "^2019-11-26T")
  74. def test_moon_phase_prediction(self):
  75. phase = MoonPhase(MoonPhaseType.NEW_MOON, None, None)
  76. self.assertEqual(MoonPhaseType.FIRST_QUARTER, phase.get_next_phase())
  77. phase = MoonPhase(MoonPhaseType.WAXING_CRESCENT, None, None)
  78. self.assertEqual(MoonPhaseType.FIRST_QUARTER, phase.get_next_phase())
  79. phase = MoonPhase(MoonPhaseType.FIRST_QUARTER, None, None)
  80. self.assertEqual(MoonPhaseType.FULL_MOON, phase.get_next_phase())
  81. phase = MoonPhase(MoonPhaseType.WAXING_GIBBOUS, None, None)
  82. self.assertEqual(MoonPhaseType.FULL_MOON, phase.get_next_phase())
  83. phase = MoonPhase(MoonPhaseType.FULL_MOON, None, None)
  84. self.assertEqual(MoonPhaseType.LAST_QUARTER, phase.get_next_phase())
  85. phase = MoonPhase(MoonPhaseType.WANING_GIBBOUS, None, None)
  86. self.assertEqual(MoonPhaseType.LAST_QUARTER, phase.get_next_phase())
  87. phase = MoonPhase(MoonPhaseType.LAST_QUARTER, None, None)
  88. self.assertEqual(MoonPhaseType.NEW_MOON, phase.get_next_phase())
  89. phase = MoonPhase(MoonPhaseType.WANING_CRESCENT, None, None)
  90. self.assertEqual(MoonPhaseType.NEW_MOON, phase.get_next_phase())
  91. def test_get_ephemerides_raises_exception_on_out_of_date_range(self):
  92. with self.assertRaises(OutOfRangeDateError):
  93. ephemerides.get_ephemerides(Position(0, 0), date(1789, 5, 5))
  94. def test_get_moon_phase_raises_exception_on_out_of_date_range(self):
  95. with self.assertRaises(OutOfRangeDateError):
  96. ephemerides.get_moon_phase(date(1789, 5, 5))
  97. if __name__ == "__main__":
  98. unittest.main()