Source code for badidatetime.tests.test_base_calendar

# -*- coding: utf-8 -*-
#
# badidatetime/test/test_base_calendar.py
#
__docformat__ = "restructuredtext en"

import math
import unittest

from ..base_calendar import BaseCalendar
from ..gregorian_calendar import GregorianCalendar


[docs] class TestBaseCalendar(unittest.TestCase): def __init__(self, name): super().__init__(name)
[docs] def setUp(self): self.bc = BaseCalendar() self.gc = GregorianCalendar()
#@unittest.skip("Temporarily skipped")
[docs] def test__HR(self): """ Test the _HR (hour) lambda. """ value = 6 hr = self.bc._HR(value) expected_hr = 0.25 msg = f"_HR should be {expected_hr}, found {hr}." self.assertEqual(expected_hr, hr, msg)
#@unittest.skip("Temporarily skipped")
[docs] def test__MN(self): """ Test the _MN (minute) lambda. """ value = 6 mn = self.bc._MN(value) expected_mn = 0.00416666666666666667 msg = f"_MN should be {expected_mn}, found {mn}." self.assertEqual(expected_mn, mn, msg)
#@unittest.skip("Temporarily skipped")
[docs] def test__SEC(self): """ Test the _SEC (second) lambda. """ value = 6 sec = self.bc._SEC(value) expected_sec = 6.94444444444444444444e-5 msg = f"_SEC should be {expected_sec}, found {sec}." self.assertEqual(expected_sec, sec, msg)
#@unittest.skip("Temporarily skipped")
[docs] def test__MINS(self): """ Test the _MINS (minutes) lambda. """ value = 6 mins = self.bc._MINS(value) expected_mins = 0.1 msg = f"_MINS should be {expected_mins}, found {mins}." self.assertEqual(expected_mins, mins, msg)
#@unittest.skip("Temporarily skipped")
[docs] def test__SECS(self): """ Test the _SECS (seconds) lambda. """ value = 6 secs = self.bc._SECS(value) expected_secs = 0.00166666666666666667 msg = f"_SECS should be {expected_secs}, found {secs}." self.assertEqual(expected_secs, secs, msg)
#@unittest.skip("Temporarily skipped")
[docs] def test__US(self): """ Test the _US (microseconds) lambda. """ value = 600000 msecs = self.bc._US(value) expected_msecs = 0.6 msg = f"_US should be {expected_msecs}, found {msecs}." self.assertEqual(expected_msecs, msecs, msg)
#@unittest.skip("Temporarily skipped")
[docs] def test__ANGLE(self): """ Test the _ANGLE (angle) lambda. """ d, m, s = (23, 26, 21.448) angle = self.bc._ANGLE(d, m, s) expected_angle = 23.43929111111111 msg = f"_ANGLE should be {expected_angle}, found {angle}." self.assertEqual(expected_angle, angle, msg)
#@unittest.skip("Temporarily skipped")
[docs] def test__AMOD(self): """ Test the _AMOD lambda. """ data = ((2, 2, 2), (5, 2, 1), (5, -2, -1)) msg = "Expected {} with args '{}, {}', found {}" for x, y, expected_result in data: result = self.bc._AMOD(x, y) self.assertEqual(expected_result, result, msg.format(expected_result, x, y, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__MOD3(self): """ Test the _MOD3 (modular three) lambda. """ # Test a == b x, a, b = (25, 25, 100) mod3 = self.bc._MOD3(x, a, b) expected_mod3 = x if a == b else a + (x - a) % (b - a) msg = f"_MOD3 should be {expected_mod3}, found {mod3}." self.assertEqual(expected_mod3, mod3, msg) # Test a != b x, a, b = (25, 10, 100) mod3 = self.bc._MOD3(x, a, b) expected_mod3 = x if a == b else a + (x - a) % (b - a) msg = f"_MOD3 should be {expected_mod3}, found {mod3}." self.assertEqual(expected_mod3, mod3, msg)
#@unittest.skip("Temporarily skipped")
[docs] def test__PARTIAL_DAY_TO_HOURS(self): """ Test that the _PARTIAL_DAY_TO_HOURS lambda returns the correct hours. """ day = 1.5 expected_result = 12 result = self.bc._PARTIAL_DAY_TO_HOURS(day) msg = (f"_PARTIAL_DAY_TO_HOURS should be {expected_result}, " f"found (result).") self.assertEqual(expected_result, result, msg)
#@unittest.skip("Temporarily skipped")
[docs] def test__PARTIAL_HOUR_TO_MINUTE(self): """ Test that the _PARTIAL_HOUR_TO_MINUTE lambda returns the correct minutes. """ day = 1.5 expected_result = 30 result = self.bc._PARTIAL_HOUR_TO_MINUTE(day) msg = (f"_PARTIAL_HOUR_TO_MINUTE should be {expected_result}, " f"found (result).") self.assertEqual(expected_result, result, msg)
#@unittest.skip("Temporarily skipped")
[docs] def test__PARTIAL_MINUTE_TO_SECOND(self): """ Test that the _PARTIAL_MINUTE_TO_SECOND lambda returns the correct seconds. """ day = 1.5 expected_result = 30 result = self.bc._PARTIAL_MINUTE_TO_SECOND(day) msg = (f"_PARTIAL_MINUTE_TO_SECOND should be {expected_result}, " f"found (result).") self.assertEqual(expected_result, result, msg)
#@unittest.skip("Temporarily skipped")
[docs] def test__PARTIAL_SECOND_TO_MICROSECOND(self): """ Test that the _PARTIAL_SECOND_TO_MICROSECOND lambda returns the correct microseconds. """ day = 1.5 expected_result = 500000 result = self.bc._PARTIAL_SECOND_TO_MICROSECOND(day) msg = (f"_PARTIAL_SECOND_TO_MICROSECOND should be {expected_result}, " f"found (result).") self.assertEqual(expected_result, result, msg)
#@unittest.skip("Temporarily skipped")
[docs] def test__QUOTIENT(self): """ Test the _QUOTIENT (divid, floor, int) lambda, """ m = 19 n = 2 quotient = self.bc._QUOTIENT(m, n) expected_quotient = int(math.floor(m / n)) msg = f"_QUOTIENT should be {expected_quotient}, found {quotient}." self.assertEqual(expected_quotient, quotient, msg)
#@unittest.skip("Temporarily skipped")
[docs] def test__delta_t(self): """ Test that the _delta_t method returns the correct delta T value for converting between UT and DT time. To check for valid values see: https://planetcalc.com/9200/ """ data = ( ((-600, 1, 1), True, 18719.834672222227), # OK ((0, 1, 1), True, 10583.17733503136), # OK ((900, 1, 1), True, 2199.998764705048), # OK ((900, 3, 1), True, 2198.842046841268), # OK ((905, 1, 1), True, 2165.4555994434895), # OK ((1650, 1, 1), True, 50.13316097312479), # OK ((1750, 1, 1), True, 13.375979008768493), # OK ((1830, 1, 1), True, 7.6550062338922995), # OK ((1885, 1, 1), True, -5.65258999265227), # OK ((1910, 1, 1), True, 10.445380968083992), # OK ((1935, 1, 1), True, 23.81634451255787), # OK ((1951, 1, 1), True, 29.48974515233175), # OK # 2443192.6511574076 JD DT -- 48 AA Ex.10.a ((1977, 2, 1), True, 47.686642722506434), # OK # 2447240.5 JD DT -- +56 AA Ex.15.a ((1988, 3, 20), True, 55.8792447106014), ((2000, 1, 1), True, 63.873832810959236), # OK ((2010, 1, 1), True, 66.71869095312503), ((2010, 1, 1), False, 0.0007722070712167249), ((2020, 1, 1), True, 71.62174845312504), # OK ((2100, 1, 1), True, 202.8381222222219), # -93 WRONG ((2200, 1, 1), True, 442.18133888888855), # 103 WRONG ) msg = "Expected {}, with seconds {}, found {}." for g_date, seconds, expected_result in data: jde = self.gc.jd_from_gregorian_date(g_date) result = self.bc._delta_t(jde, seconds=seconds) self.assertEqual(expected_result, result, msg.format(expected_result, seconds, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__mean_sidereal_time_greenwich(self): """ Test that the _mean_sidereal_time_greenwich method returns the correct mean sidereal time. """ data = ( # 2446895.5 -- 197.693195 -- AA ch.12 p.88 Ex.12.a ((1987, 4, 10), 197.693195090862), # 128.73788708333333 ((1987, 4, 10, 19, 21), 128.73787324433215), ) msg = "Expected {}, for date {}, found {}." for g_date, expected_result in data: jde = self.gc.jd_from_gregorian_date(g_date) tc = self.bc._julian_centuries(jde) result = self.gc._mean_sidereal_time_greenwich(tc) self.assertEqual(expected_result, result, msg.format(expected_result, g_date, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__apparent_sidereal_time_greenwich(self): """ Test that the apparent_sidereal_time_greenwich method returns the correct apparent sidereal time. """ data = ( # 197.69222958 -- AA ch.12 p.88 Ex.12.a ((1987, 4, 10), 197.69222977202386), ((1987, 4, 10, 19, 21), 128.73688780647933), # 128.73690333333334 ((2000, 1, 1), 99.96424623619367), # 99.96424875 ((2024, 3, 20), 178.01765584602592), # 178.0176425 ) msg = "Expected {}, for date {}, found {}." for g_date, expected_result in data: jde = self.gc.jd_from_gregorian_date(g_date) tc = self.bc._julian_centuries(jde) result = self.gc._apparent_sidereal_time_greenwich(tc) self.assertEqual(expected_result, result, msg.format( expected_result, g_date, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__altitude(self): """ Test that the _altitude method returns the correct altitude in degrees. """ func0 = lambda m: m + 1 if m <= 0 else m - 1 if m >= 1 else m def inter_ra(tc, n): a0 = self.bc._sun_apparent_right_ascension(tc - (1 / 36525)) a1 = self.bc._sun_apparent_right_ascension(tc) a2 = self.bc._sun_apparent_right_ascension(tc + (1 / 36525)) return self.bc._interpolation_from_three(a0, a1, a2, n) def inter_de(tc, n): d0 = self.bc._sun_apparent_declination(tc - (1 / 36525)) d1 = self.bc._sun_apparent_declination(tc) d2 = self.bc._sun_apparent_declination(tc + (1 / 36525)) return self.bc._interpolation_from_three(d0, d1, d2, n) SUN = self.bc._SUN_OFFSET PLT = self.bc._STARS_PLANET_OFFSET data = ( # 1988-03-20T00:00:00 -- 0.51766, 0.1213 -> -0.5665074179151752 # AA Ex.15.a at Boston, US (2447240.5, 42.3333, -71.0833, 'SET', PLT, -1.262090300747096), # Greenwich, UK 2024-03-20T00:00:00 -> -0.8331021963100147 (2460389.5, 51.477928, -0.001545, 'SET', SUN, -1.298951201117289), # Tehran, Iran 2024-03-20T00:00:00 -> -0.8332800872601968 (2460389.5, 35.696111, 51.423056, 'SET', SUN, -1.3256207198852623), ) msg = "Expected {}, for jd {}, with lat {} and lon {}, found {}." for jd, lat, lon, sr_ss, offset, expected_result in data: tc = self.bc._julian_centuries(jd) h0 = self.bc._approx_local_hour_angle(tc, lat, offset=offset) ast = self.bc._apparent_sidereal_time_greenwich(tc) dt = self.gc._delta_t(jd) ara = self.bc._sun_apparent_right_ascension(tc) m0 = func0((ara - lon - ast) / 360) alpha = inter_ra(tc, m0 * dt / 86400) # Find alpha delta = inter_de(tc, m0 * dt / 86400) # Find delta # Find the local hour angle m = m0 - h0 / 360 if sr_ss == 'RISE' else m0 + h0 / 360 srt = ast + 360.98564736629 * m h = self.bc._local_hour_angle(srt, lon, alpha) # Get results result = self.bc._altitude(delta, lat, h) self.assertEqual(expected_result, result, msg.format( expected_result, jd, lat, lon, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__approx_local_hour_angle(self): """ Test that the _approx_local_hour_angle method returns the correct angle based on the jde. The variable 'self.bc.latitude' is the latitude in Tehran Iran. """ latitude = 35.682376 offset = self.bc._SUN_OFFSET data = ( ((1844, 3, 20), latitude, offset, 90.88528765885808), ((1988, 3, 20), 42.3333, offset, 90.98302386790827), # AA Ex15.a ((2024, 6, 20), latitude, offset, 109.3196338142018), # Test for combinations of latitude and degrees that cause the # cos_h0 value to be less than -1. ((1844, 4, 10.5), 90, offset, 90.0), # cos_h0 value to be greater than 1. ((1844, 4, 13.5), -90, offset, 60.00000000000001), ) msg = "Expected {}, for date {}, found {}." for g_date, lat, offset, expected_result in data: jde = self.gc.jd_from_gregorian_date(g_date) tc = self.bc._julian_centuries(jde) result = self.bc._approx_local_hour_angle(tc, lat, offset) self.assertEqual(expected_result, result, msg.format( expected_result, g_date, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__sun_rising(self): """ Test that the _sun_rising method returns the correct sunrise. """ epoch_coords = (35.682376, 51.285817, 3.5) data = ( # 1844-03-19T12:00:00Z -> 1844-03-20T15:30:00+03:30 (2394645.0, epoch_coords, (2394644.611313698, 0.757147031371, (6, 10, 17.5044))), # 2024-03-19T12:00:00 -> 2024-03-20T06:08:00+03:30 (06:08) (2460389.0, epoch_coords, (2460388.6108562476, 0.756689581089, (6, 9, 37.98))), # 2024-03-20T00:00:00 -> 2024-03-20T06:08:00+03:30 (06:08) (2460389.5, epoch_coords, (2460389.609863762, 0.755697095301, (6, 8, 12.228))), # 2024-03-20T02:00:00 -> 2024-03-20T06:08:00+03:30 (06:08) (2460389.583333, epoch_coords, (2460389.609863762, 0.755697095301, (6, 8, 12.228))), ) msg = "Expected {}, for jd {}, found {}." for jd, coords, expected_result in data: result = self.bc._sun_rising(jd, *coords[:2]) self.assertEqual(expected_result[0], result, msg.format( expected_result, jd, result)) tz_correction = self.bc._local_zone_correction(result, coords[2]) self.assertEqual(expected_result[1], tz_correction, msg.format( expected_result, jd, coords[2], result)) hms = self.bc._hms_from_decimal_day(tz_correction + 0.5) self.assertEqual(expected_result[2], hms, msg.format( expected_result, jd, coords[2], result))
#@unittest.skip("Temporarily skipped")
[docs] def test__sun_transit(self): """ Test that the _sun_transit method returns the correct transition based on the jde. """ data = ( # 1988-03-20T00:00:00 -- 0.5354166666666667 = 12:51 pm Alt 48 deg # AA Ex.15.a 0.8198 at Boston, US # JD Longitude (2447240.5, -71.0833, 0.7025666125498263), # 2024-03-20T00:00:00 -- 0.5048611111111111 = 12:07 pm, Alt 39 deg # Transit in Greenwich UK with 51.477928 (lat) and -0.001545 (lon) (2460389.5, -0.001545, 0.5050828012152296), # 2024-03-20T00:00:00 -- 0.5076388888888889 = 12:11 pm, Alt 54 deg # Transit in Tehran Iran with 35.696111 (lat) and 51.423056 (lon) (2460389.5, 51.423056, 0.3622660987548922), # 2024-03-20T00:00:00 -- 0.5051123582525348 = 12:07:0.36179588 # Transit in Tehran Iran with 35.696111 (lat) and 51.423056 (lon) (2460389.5, 51.423056, 0.3622660987548922), ) msg = "Expected {}, for jd {}, found {}." for jd, lon, expected_result in data: result = self.bc._sun_transit(jd, lon) self.assertEqual(expected_result, result, msg.format( expected_result, jd, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__sun_setting(self): """ Test that the _sun_setting method returns the correct sunset for a given date represented by a Julian Period day. https://gml.noaa.gov/grad/solcalc/ """ epoch_coords = (35.682376, 51.285817, 3.5) local_coords = (35.7796, -78.6382, -4) data = ( # 1844-03-19T12:00:00 -> 1844-03-19T18:16:00 sunset 0.761111 (2394645.0, epoch_coords, (2394645.1151233846, 0.260956718121, (18, 15, 46.6596))), # 2024-03-19T12:00:00 -> 2024-03-19T18:13:59.1168 (2460389.0, epoch_coords, (2460389.115246079, 0.261079412419, (18, 15, 57.2616))), # 2024-03-20T00:00:00 -> 2024-03-20T18:13:59.1168 (2460389.5, epoch_coords, (2460390.115829568, 0.261662901379, (18, 16, 47.676))), # 2024-03-20T02:00:00 -> 2024-03-20T18:13:59.1168 (2460389.583333, epoch_coords, (2460390.115829568, 0.261662901379, (18, 16, 47.676))), # 2024-04-20T00:00:00 -> 2024-04-20T19:52:378624 DST (19:53) # In Raligh NC, USA (2460420.5, local_coords, (2460420.494296346, 0.327629679348, (19, 51, 47.2032))), ) msg = "Expected {}, for jd {} and zone {}, found {}." for jd, coords, expected_result in data: result = self.bc._sun_setting(jd, *coords[:2]) self.assertEqual(expected_result[0], result, msg.format( expected_result, jd, coords[2], result)) tz_correction = self.bc._local_zone_correction(result, coords[2]) self.assertEqual(expected_result[1], tz_correction, msg.format( expected_result, jd, coords[2], result)) hms = self.bc._hms_from_decimal_day(tz_correction + 0.5) self.assertEqual(expected_result[2], hms, msg.format( expected_result, jd, coords[2], result))
#@unittest.skip("Temporarily skipped")
[docs] def test__rising_setting(self): """ https://www.timeanddate.com/sun/usa/boston?month=3&year=1988 | rise=5.47 am, set=5.56 pm | lat 42.364506, lon -71.038887 | (2447240.5, -71.0833, -5.0, 0), """ SUN = self.bc._SUN_OFFSET PLT = self.bc._STARS_PLANET_OFFSET data = ( # 1988-03-20T00:00:00 -- 0.51766 = , 0.1213 # AA Ex.15.a at Boston, US # JD Latitude Longitude Zone Offset (2447240.5, 42.3333, -71.0833, -5.0, PLT, (0.45043937846904675, 0.9551985415470607)), # 2024-03-20T00:00:00 -- (0.251389 = 6:02, 0.759722 = 18:14) # https://timeanddate.com/sun/uk/greenwich-city?month=3&year=2024 # In Greenwich, UK with 51.477928 (lat) and -0.001545 (lon) (2460389.5, 51.477928, -0.001545, 0, SUN, (0.25124826455377425, 0.7596184745333456)), # 2024-03-20T00:00:00 -- (0.255555 = 6:08, 0.761805 = 18:17) # https://www.timeanddate.com/sun/@112931?month=3&year=2024 # Transit in Tehran Iran with 35.682376 (lat) and 51.285817 (lon) (2460389.5, 35.682376, 51.285817, 3.5, SUN, (0.1098637514187786, 0.6158295672236276)), # 2024-03-20T00:00:00 -- (0.254861 = 6:07 am, 0.761 = 6:16 pm) # Transit in Tehran, Iran with 35.682376 (lat) and 51.285817 (lon) (2460389.5, 35.682376, 51.285817, None, SUN, (0.1098637514187786, 0.6158295672236276)), ) msg = "Expected {}, for jd {}, zone {}, found {}." for jd, lat, lon, zone, offset, expected_result in data: result0 = self.bc._rising_setting(jd, lat, lon, offset=offset, sr_ss='rise') result1 = self.bc._rising_setting(jd, lat, lon, offset=offset, sr_ss='set') result = (result0, result1) self.assertEqual(expected_result, result, msg.format( expected_result, jd, zone, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__nutation_longitude(self): """ Test that the _nutation_longitude method returns the correct values. """ data = ( # 1987-04-10T00:00:00 UT -- 0.001052... AA ch.22 p.148 Ex.22.a (2446895.5, -0.001052173258783292), (2394646.5, 0.004685955021135532), # 1844-03-21 (2451544.5, -0.003867549921252321), # 2000-01-01 ) msg = "Expected {}, for jde {}, found {}." for jde, expected_result in data: tc = self.bc._julian_centuries(jde) result = self.bc._nutation_longitude(tc) self.assertEqual(expected_result, result, msg.format(expected_result, jde, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__nutation_obliquity(self): """ Test that the _nutation_obliquity method returns the correct values. """ data = ( # 1987-04-10T00:00:00 UT -- 0.00262305... AA ch.22 p.148 Ex.22.a (2446895.5, 0.002622907065077194), (2394646.5, -0.0003313196399792), # 1844-03-21 (2451544.5, -0.001601110054347824), # 2000-01-01 ) msg = "Expected {}, for jde {}, found {}." for jde, expected_result in data: tc = self.bc._julian_centuries(jde) result = self.bc._nutation_obliquity(tc) self.assertEqual(expected_result, result, msg.format(expected_result, jde, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__nutation_obliquity_longitude(self): """ Test that the _nutation_obliquity_longitude method returns the correct values. """ data = ( # 1987-04-10T00:00:00 UT -- AA ch.22 p.148 Ex.22.a # 0.001052..., 0.00262305... (2446895.5, False, (-0.001052173258783292, 0.002622907065077194)), # 1844-03-21 (2394646.5, True, (0.26848544569920246, 359.9810167829594)), # 2000-01-01 (2451544.5, True, (359.7784057124561, 359.9082631513499)), ) msg = "Expected {}, for jde {}, found {}." for jde, degrees, expected_result in data: t = self.bc._julian_centuries(jde) result = self.bc._nutation_obliquity_longitude(t, degrees=degrees) self.assertEqual(expected_result, result, msg.format(expected_result, jde, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__moon_mean_anomaly(self): """ Test that the _moon_mean_anomaly method returns the correct values. """ data = ( # 1987-04-10T00:00:00 (2446895.5, 229.27841269605415), # 229.2784 AA p.148 Ex.22.a ) msg = "Expected {}, for jde {}, found {}." for jde, expected_result in data: t = self.bc._julian_centuries(jde) result = self.bc._moon_mean_anomaly(t) self.assertEqual(expected_result, result, msg.format(expected_result, jde, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__moon_latitude(self): """ Test that the _moon_latitude method returns the correct values. """ data = ( # 1987-04-10T00:00:00 (2446895.5, 143.4079066405975), # 143.4079 AA p.148 Ex.22.a ) msg = "Expected {}, for jde {}, found {}." for jde, expected_result in data: t = self.bc._julian_centuries(jde) result = self.bc._moon_latitude(t) self.assertEqual(expected_result, result, msg.format(expected_result, jde, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__sun_earth_mean_anomaly(self): """ Test that the _sun_earth_mean_anomaly method returns the correct values. """ data = ( # 1844-03-21 (2394646.5, 78.34963598562899), # 1987-04-10T00:00:00 -- 94.9792 AA p.148 Ex.22.a (2446895.5, 94.9792011648251), # 1992-10-13T00:00:00 -- 278.99397 AA p.165 Ex.25.a (2448908.5, 278.9925727892901), # 2000-01-01 (2451544.5, 357.03491985845307), ) msg = "Expected {}, for jde {}, found {}." for jde, expected_result in data: t = self.bc._julian_centuries(jde) result = self.bc._sun_earth_mean_anomaly(t) self.assertEqual(expected_result, result, msg.format(expected_result, jde, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__mean_moon_elongation(self): """ Test that the _mean_moon_elongation method returns the correct values. """ data = ( # 1987-04-10T00:00:00 (2446895.5, 136.96231182464544), # 136.9623 AA p.148 Ex.22.a ) msg = "Expected {}, for jde {}, found {}." for jde, expected_result in data: t = self.bc._julian_centuries(jde) result = self.bc._mean_moon_elongation(t) self.assertEqual(expected_result, result, msg.format(expected_result, jde, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__moon_ascending_node_longitude(self): """ Test that the _moon_ascending_node_longitude method returns the correct values. """ data = ( # 1844-03-21 (2394646.5, 258.039325958443), # 1987-04-10T00:00:00 (2446895.5, 11.253083202875985), # 11.2531 AA p.148 Ex.22.a # 2000-01-01 (2451544.5, 125.07099688242339), ) msg = "Expected {}, for jde {}, found {}." for jde, expected_result in data: t = self.bc._julian_centuries(jde) result = self.bc._moon_ascending_node_longitude(t) self.assertEqual(expected_result, result, msg.format(expected_result, jde, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__true_obliquity_of_ecliptic(self): """ Test that the _true_obliquity_of_ecliptic method returns the correct true obliquity of the ecliptic. """ data = ( # 2446895.5 -- 23.4435694... AA p.148 Ex.22.a ((1987, 4, 10), 23.4435691980224), ((1992, 10, 13), 23.440144135213007), # 23.44023 AA Ex.25.a ((2000, 1, 1.5), 23.437687275568372), # 23.4392911 AA p92 ((1950, 1, 1.5), 23.44809805233669), # 23.4457889 AA p92 ) msg = "Expected {}, for date {}, found {}." for g_date, expected_result in data: jde = self.gc.jd_from_gregorian_date(g_date) tc = self.bc._julian_centuries(jde) result = self.gc._true_obliquity_of_ecliptic(tc) self.assertEqual(expected_result, result, msg.format(expected_result, g_date, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__sun_mean_longitude(self): """ Test that the _sun_mean_longitude returns the proper angle from the sun. """ data = ( # 1992-10-13T00:00:00 TD -- 201.80720 AA Ex.25.a (2448908.5, 201.80719650670744), ) msg = "Expected {}, for jde {}, found {}." for jde, expected_result in data: tc = self.bc._julian_centuries(jde) result = self.bc._sun_mean_longitude(tc) self.assertEqual(expected_result, result, msg.format(expected_result, jde, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__eccentricity_earth_orbit(self): """ Test that the _eccentricity_earth_orbit method returns the correct values. """ data = ( # 1992-10-13T00:00:00 -- 0.016711668 AA p.165 Ex.25.a (2448908.5, 0.01671166771493543), ) msg = "Expected {}, for jde {}, found {}." for jde, expected_result in data: t = self.bc._julian_centuries(jde) result = self.bc._eccentricity_earth_orbit(t) self.assertEqual(expected_result, result, msg.format(expected_result, jde, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__sun_apparent_longitude(self): """ Test that the _sun_apparent_longitude returns the proper """ data = ( # 1992-10-13T00:00:00 TD -- 199.9060605... AA Ex.25.b (2448908.5, 199.90893644078398), ) msg = "Expected {}, for jde {}, found {}." for jde, expected_result in data: tc = self.bc._julian_centuries(jde) result = self.bc._sun_apparent_longitude(tc) self.assertEqual(expected_result, result, msg.format(expected_result, jde, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__sun_equation_of_center(self): """ Test that the _sun_equation_of_center method returns the correct values. """ data = ( # 1992-10-13T00:00:00 TD -- -1.89732 AA Ex.25.a (2448908.5, -1.8973292982987633), (2394646.5, 1.8902065487119648), # 1844-03-21 (2451544.5, -0.10114766650438385), # 2000-01-01 ) msg = "Expected {}, for jde {}, found {}." for jde, expected_result in data: t = self.bc._julian_centuries(jde) result = self.bc._sun_equation_of_center(t) self.assertEqual(expected_result, result, msg.format(expected_result, jde, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__sun_true_longitude(self): """ Test that the _sun_true_longitude returns the proper """ data = ( # 1992-10-13T00:00:00 TD -- 199.907347 AA Ex.25.b (2448908.5, 199.90986720840868), ) msg = "Expected {}, for jde {}, found {}." for jde, expected_result in data: tc = self.bc._julian_centuries(jde) result = self.bc._sun_true_longitude(tc) self.assertEqual(expected_result, result, msg.format(expected_result, jde, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__sun_apparent_right_ascension(self): """ Test that the _sun_apparent_right_ascension method returns the correct angle based on the jde. """ data = ( # 1988-03-19T00:00:00 -- 40.68021 AA Ex.15.a #(2447239.5, 358.7231216620047), # 1988-03-20T00:00:00 -- 41.73129 AA Ex.15.a #(2447240.5, 359.6349480462671), # 1988-03-21T00:00:00 -- 42.78204 AA Ex.15.a #(2447241.5, 0.5462272546171956), # 1992-10-13T00:00:00 TD -- 198.37817916... AA Ex.25.b (2448908.5, 198.38083123459006), ) msg = "Expected {}, for jde {}, found {}." for jde, expected_result in data: tc = self.bc._julian_centuries(jde) result = self.bc._sun_apparent_right_ascension(tc) self.assertEqual(expected_result, result, msg.format(expected_result, jde, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__sun_apparent_declination(self): """ Test that the _apparent_declination method returns the proper apparent declination measured (from 0° to 90°) from the equator, positive to the north, negative to the south. """ data = ( # 1988-03-19T00:00:00 -- 18.04761 AA Ex.15.a #(2447239.5, 359.4684977578814), # 1988-03-20T00:00:00 -- 18.44092 AA Ex.15.a #(2447240.5, 359.8480298854421), # 1988-03-21T00:00:00 -- 18.82742 AA Ex.15.a #(2447241.5, 0.2273912943419768), # 1992-10-13T00:00:00 -- -7.783872 -- AA Ex.25.b (2448908.5, -7.78504080260712), ) msg = "Expected {}, for jde {}, found {}." for jd, expected_result in data: tc = self.bc._julian_centuries(jd) result = self.bc._sun_apparent_declination(tc) self.assertEqual(expected_result, result, msg.format(expected_result, jd, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__heliocentric_ecliptical_longitude(self): """ Test that the _heliocentric_ecliptical_longitude method returns the correct values. """ data = ( (2394646.5, True, 180.501420262321), # 1844-03-21 # 1992-10-13T00:00:00 -- 19.907372 AA Ex.25.b (2448908.5, True, 19.907371990725), (2451544.5, True, 99.868072457384), # 2000-01-01 ) msg = "Expected {}, for jde {}, found {}." for jde, degrees, expected_result in data: tm = self.bc._julian_millennia(jde) result = self.bc._heliocentric_ecliptical_longitude(tm, degrees) # We need to use approximately equal to solve issues with # Python 3.10 and 3.11. val = math.isclose(expected_result, result, rel_tol=0, abs_tol=1e-9) self.assertTrue(val, msg.format(expected_result, jde, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__heliocentric_ecliptical_latitude(self): """ Test that the _heliocentric_ecliptical_latitude method returns the correct values. """ data = ( (2394646.5, True, 359.99985945941), # 1844-03-21 # 1992-10-13T00:00:00 -- -0.000179 AA Ex.25.b (2448908.5, True, 359.999820987496), (2451544.5, True, 359.999810027916), # 2000-01-01 ) msg = "Expected {}, for jde {}, found {}." for jde, degrees, expected_result in data: tm = self.bc._julian_millennia(jde) result = self.bc._heliocentric_ecliptical_latitude(tm, degrees) self.assertEqual(expected_result, result, msg.format(expected_result, jde, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__radius_vector(self): """ Test that the _radius_vector method returns the correct values. """ data = ( (2394646.5, True, 57.116215635928), # 1844-03-21 # 1992-10-13T00:00:00 -- 0.99760775 (57.15871368454215) AA Ex.25.b (2448908.5, True, 57.15871365675), (2451544.5, True, 56.340762239128), # 2000-01-01 ) msg = "Expected {}, for jde {}, found {}." for jde, degrees, expected_result in data: tm = self.bc._julian_millennia(jde) result = self.bc._radius_vector(tm, degrees) self.assertEqual(expected_result, result, msg.format(expected_result, jde, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__apparent_solar_longitude(self): """ Test that the _apparent_solar_longitude method returns the longitude of sun at moment tee. Equinox & Solstice Calculator: https://stellafane.org/misc/equinox.html Solar Position Calculator: https://gml.noaa.gov/grad/solcalc/ | Greenwich: | lat: 51, 29, 36.24 N (51.4934) | lon: 00, 00, 05.562 W (-0.001545) Data from the book pages 225, 446 and 452 +-------------------------+----------+-----------------+------------+ | | Solar | Approximate | Season | | Name | Longitude| Date | Length | +=========================+==========+=================+============+ | Vernal (spring) equinox | 0◦ | March 20 | 92.76 days | +-------------------------+----------+-----------------+------------+ | Summer solstice | 90◦ | June 21 | 93.65 days | +-------------------------+----------+-----------------+------------+ | Autumnal (fall) equinox | 180◦ | September 22−23 | 89.84 days | +-------------------------+----------+-----------------+------------+ | Winter solstice | 270◦ | December 21−22 | 88.99 days | +-------------------------+----------+-----------------+------------+ """ data = ( # (2024, 3, 20) Vernal equinox 2024-03-20T03:06:04 UTC (2460389.759722, 359.740938790093), # 0 # (2024, 6, 20) Summer solstice 2024-06-20T20:50:23 UTC (2460483.238888, 90.449821636455), # 90 # (2024, 9, 22) Autumnal equinox 2024-09-22T12:43:12 UTC (2460576.561111, 180.161497145808), # 180 # (2024, 12, 21) Winter solstice 2024-12-21T09:19:54 UTC (2460666.279166, 270.074119473989), # 270 # (1800, 3, 20) Vernal equinox 1800-03-20T20:11:48 UTC (2378575.181945, 359.401753831233), # 0 # (1800, 6, 21) Summer solstice 1800-06-21T17:51:29 UTC (2378667.9875, 89.32041245143), # 90 # (1800, 9, 23) Autumnal equinox 1800-09-23T07:25:31 UTC (2378761.118055, 178.907448509213), # 180 # (1800, 12, 22) Winter solstice 1800-12-22T00:16:24 (2378850.522222, 268.615086297708), # 270 # (2073, 3, 20) Vernal equinox 2073-03-20T00:12:24 UTC (2478286.520833, 359.55382375668), # 0 # (2073, 6, 20) Summer solstice 2073-06-20T17:06:18 UTC (2478379.927777, 90.197366193355), # 90 # (2073, 9, 22) Autumnal equinox 2073-09-22T09:14:10 UTC (2478473.273611, 179.871063138558), # 180 # (2073, 12, 21) Winter solstice 2073-12-21T06:49:41 UTC (2478563.072222, 269.780008293968), # 270 # All the dates below are from the CC Appendix C Sample Data p452 # (-586, 7, 24) (1507231.5, 118.207154305186), # 118.98911336371384 # (576, 5, 20) (1931579.5, 58.47508540703), # 59.119741 # (1288, 4, 2) (2191584.5, 12.816213952552), # 13.498220 # (1553, 9, 19) (2288542.5, 175.003325857397), # 176.059431 # (1768, 6, 19) (2366978.5, 88.027595925087), # 88.567428 # (1941, 9, 29) (2430266.5, 185.090224449767), # 185.945867 # (2038, 11, 10) (2465737.5, 227.070783444347), # 228.184879 # (2094, 7, 18) (2486076.5, 115.381213164408), # 116.439352 # 1992-10-13T00:00:00 DT -- 199.9060605... AA Ex.25.b (2448908.5, 199.835133937607), ) msg = "Expected {}, for jde {}, found {}." for jde, expected_result in data: result = self.bc._apparent_solar_longitude(jde) # We need to use approximately equal to solve issues with # Python 3.10 and 3.11. val = math.isclose(expected_result, result, rel_tol=0, abs_tol=1e-9) self.assertTrue(val, msg.format(expected_result, jde, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__apparent_solar_latitude(self): """ Test that the _apparent_solar_latitudemethod returns the correct values. """ data = ( # 1992-10-13T00:00:00 DT -- 0.000172 AA Ex.25.b (2448908.5, 0.000173905958), ) msg = "Expected {}, for jde {}, found {}." for jde, expected_result in data: result = self.bc._apparent_solar_latitude(jde) self.assertEqual(expected_result, result, msg.format(expected_result, jde, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__aberration(self): """ Test that the _aberration method returns the correct aberration of the given date in degrees. """ data = ( # (2024, 3, 20) Vernal equinox 2024-03-20T03:06:04 UTC (389.759722222, True, -0.005707963671), (389.759722222, False, -0.005708184088), ) msg = "Expected {}, for jd {}, found {}." for jd, fixed, expected_result in data: tm = self.bc._julian_millennia(jd) result = self.bc._aberration(tm, fixed=fixed) self.assertEqual(expected_result, result, msg.format(expected_result, jd, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__approx_julian_day_for_equinoxes_or_solstices(self): """ Test that the _approx_julian_day_for_equinoxes_or_solstices method returns a Julian day of the equinoxes or solstices. """ data = ( (500, self.bc._SPRING, 1903760.376019375), (500, self.bc._SUMMER, 1903854.104661875), (500, self.bc._AUTUMN, 1903946.9228224999), (500, self.bc._WINTER, 1904035.8380625), (2000, self.bc._SPRING, 2451623.80984), (2000, self.bc._SUMMER, 2451716.56767), (2000, self.bc._AUTUMN, 2451810.21715), (2000, self.bc._WINTER, 2451900.05952), ) msg = "Expected {}, for year {} at angle {}, found {}." for year, season, expected_result in data: result = self.bc._approx_julian_day_for_equinoxes_or_solstices( year, lam=season) self.assertEqual(expected_result, result, msg.format(expected_result, year, season, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__find_moment_of_equinoxes_or_solstices(self): """ Test that the _find_moment_of_equinoxes_or_solstices method returns the correct equinoxe and solstice R.D. moments for the given years. """ SP = self.bc._SPRING SM = self.bc._SUMMER AU = self.bc._AUTUMN WN = self.bc._WINTER seasons = {SP: 'SPRING', SM: 'SUMMER', AU: 'AUTUMN', WN: 'WINTER'} data = ( # Vernal Equinox ((900, 3, 1), SP, (900, 3, 15, 18, 19, 15.618)), ((1788, 3, 19, 22, 16), SP, (1788, 3, 19, 22, 16, 44.9328)), ((1844, 3, 20, 11, 53), SP, (1844, 3, 20, 11, 53, 50.2404)), ((1951, 3, 21, 10, 26), SP, (1951, 3, 21, 10, 26, 44.4444)), # AA p.180 Ex 27.a ((1962, 6, 1), SM, (1962, 6, 21, 21, 25, 6.024)), # AA p.182 Table 27.e ((2000, 3, 20, 7, 35), SP, (2000, 3, 20, 7, 36, 37.8648)), # Should be 2018-03-20T16:16:36 DT ((2018, 3, 20), SP, (2018, 3, 20, 16, 16, 23.9268)), # Should be 2022-03-20T15:34:33 DT ((2022, 3, 20), SP, (2022, 3, 20, 15, 34, 40.1052)), ((2024, 3, 20, 3, 6), SP, (2024, 3, 20, 3, 7, 49.116)), # Should be 2026-03-20T14:47:05 DT ((2026, 3, 20), SP, (2026, 3, 20, 14, 46, 50.8152)), ((2038, 3, 20, 12, 40), SP, (2038, 3, 20, 12, 42, 2.2752)), # Should be 2043-03-20T17:28:58 DT ((2043, 3, 20), SP, (2043, 3, 20, 17, 29, 7.3788)), # Should be 2047-03-20T16:53:53 DT ((2047, 3, 20), SP, (2047, 3, 20, 16, 54, 14.0436)), # Should be 2051-03-20T16:00:28 DT ((2051, 3, 20), SP, (2051, 3, 20, 16, 0, 23.2344)), # Should be 2055-03-20T15:30:03 DT ((2055, 3, 20), SM, (2055, 6, 21, 8, 40, 54.624)), ((2064, 3, 19, 19, 37), SP, (2064, 3, 19, 19, 40, 13.7136)), ((2100, 3, 20, 13, 3), SP, (2100, 3, 20, 13, 6, 30.1896)), ((2150, 3, 20, 16, 1), SP, (2150, 3, 20, 16, 6, 35.9064)), ((2200, 3, 20, 18, 40), SP, (2200, 3, 20, 18, 48, 6.642)), ((2211, 3, 21, 10, 38), SP, (2211, 3, 21, 10, 45, 29.9484)), # Summer Solstice ((900, 6, 1), SM, (900, 6, 17, 6, 32, 44.2104)), ((2000, 6, 1), SM, (2000, 6, 21, 1, 48, 45.3528)), # Autumn Equinox ((900, 9, 1), AU, (900, 9, 18, 8, 35, 1.41)), ((2000, 9, 1), AU, (2000, 9, 22, 17, 28, 41.6784)), # Winter Solstice ((900, 12, 1), WN, (900, 12, 16, 11, 38, 22.236)), ((2000, 12, 1), WN, (2000, 12, 21, 13, 38, 47.1696)), ) msg = "Expected '{}' during the {}, found '{}'" for date, season, expected_result in data: jde = self.gc.jd_from_gregorian_date(date) result = self.bc._find_moment_of_equinoxes_or_solstices( jde, lam=season) result = self.gc.gregorian_date_from_jd(result) result = self.gc.ymdhms_from_date(result) self.assertEqual( expected_result, result, msg.format(expected_result, seasons[season], result))
#@unittest.skip("Temporarily skipped")
[docs] def test__decimal_from_dms(self): """ Test that the method _decimal_from_dms correctly converts degrees, minutes, and seconds into a decimal number. https://warble.com/blog/2017/11/05/virtually-hovering-over-holy-places/ | The Shrine of Baha’u’llah: 32°56’36.86″N, 35°5’30.38″ E | The Shrine of The Bab: 32°48’52.49″N, 34°59’13.91″ E | The Guardian’s Resting Place: 51°37’21.85″N, 0°08’35.57″ W """ data = ( # Statue of Liberty latitude (US) ((40, 41, 21.29, 'N'), 40.68924722222222), # Statue of Liberty longitude (US) ((74, 2, 40.29, 'W'), -74.044525), # The Shrine of Baha’u’llah latitude (IL) ((32, 56, 36.86, 'N'), 32.943572222222215), # The Shrine of Baha’u’llah longitude (IL) ((35, 5, 30.37, 'E'), 35.091769444444445), # Sydney Opera House latitude (AU) ((-33, 51, 24.37, 'S'), -33.856769444444446), # Sydney Opera House longitude (AU) ((151, 12, 54.43, 'E'), 151.21511944444444), ) msg = "Expected {} with '{}', found {}." for args, expected_result in data: result = self.bc._decimal_from_dms(*args) self.assertEqual(expected_result, result, msg.format(expected_result, args, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__dms_from_decimal(self): """ Test that the _dms_from_decimal method correctly converts a decimal representation of a latitude or longitude into degrees, minutes, and seconds. """ data = ( # Statue of Liberty latitude (US) ((40.68924722222222, 'lat'), (40, 41, 21.28999999999559, 'N')), # Statue of Liberty longitude (US) ((-74.044525, 'lon'), (74, 2, 40.28999999997495, 'W')), # The Shrine of Baha’u’llah latitude (IL) ((32.943572222222215, 'lat'), (32, 56, 36.85999999997529, 'N')), # The Shrine of Baha’u’llah longitude (IL) ((35.091769444444445, 'lon'), (35, 5, 30.37000000000207, 'E')), # Sydney Opera House latitude (AU) ((-33.856769444444446, 'lat'), (33, 51, 24.370000000004175, 'S')), # Sydney Opera House longitude (AU) ((151.21511944444444, 'lon'), (151, 12, 54.42999999998388, 'E')), ) msg = "Expected {} with '{}', found {}." for args, expected_result in data: result = self.bc._dms_from_decimal(*args) self.assertEqual(expected_result, result, msg.format(expected_result, args, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__degrees_from_hms(self): """ Test that the _degrees_from_hms method converts hours, minutes, and seconds into degrees properly. """ data = ( ((1, 0, 0), 15.0), ((2, 0, 0), 30.0), ((24, 0, 0), 360.0), ) msg = "Expected {} with h,m,s {}, found {}." for args, expected_result in data: result = self.bc._degrees_from_hms(*args) self.assertEqual(expected_result, result, msg.format(expected_result, args, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__hms_from_degrees(self): """ Test that the _hms_from_degrees method converts degrees to hours, minutes, and seconds properly. """ data = ( (15., (1, 0, 0)), (30., (2, 0, 0)), (360, (24, 0, 0)), ) msg = "Expected {} with degrees {}, found {}." for degrees, expected_result in data: result = self.bc._hms_from_degrees(degrees) self.assertEqual(expected_result, result, msg.format(expected_result, degrees, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__seconds_from_dhms(self): """ Test that the _seconds_from_dhms method converts hours minutes, and seconds to seconds. """ err_msg0 = ("If microseconds is greater that zero the second argument " "cannot have a decimal, found {}.") data = ( ((0, 10, 2, 5), 0, True, 36125), ((1, 0, 0, 0), 0, True, 86400), ((0, 10, 2, 5.5), 0, True, 36125.5), ((0, 10, 2, 5, 500000), 0, True, 36125.5), ((0, 10, 2, 5, 500000), -5.0, True, 18125.5), ((1, 10, 2, 5.5, 500000), 0, False, err_msg0.format(5.5)) ) msg = "Expected {} with h,m,s {}, found {}." for args, zone, valid, expected_result in data: if valid: result = self.bc._seconds_from_dhms(*args, zone=zone) self.assertEqual(expected_result, result, msg.format(expected_result, args, result)) else: with self.assertRaises(AssertionError) as cm: self.bc._seconds_from_dhms(*args) message = str(cm.exception) self.assertEqual(expected_result, message)
#@unittest.skip("Temporarily skipped")
[docs] def test__dhms_from_seconds(self): """ Test that the _dhms_from_seconds method converts seconds into hours, minutes, and seconds properly. """ data = ( (36125, 0, False, (0, 10, 2, 5)), (86400, 0, False, (1, 0, 0, 0)), (36125.5, 0, False, (0, 10, 2, 5.5)), (36125.5, 0, True, (0, 10, 2, 5, 500000)), (36125.5, -5.0, False, (0, 5, 2, 5.5)), (36125.5, -5.0, True, (0, 5, 2, 5, 500000)), ) msg = "Expected {} with seconds {}, found {}." for seconds, zone, us, expected_result in data: result = self.bc._dhms_from_seconds(seconds, zone, us=us) self.assertEqual(expected_result, result, msg.format(expected_result, seconds, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__tz_decimal_from_dhms(self): """ Test that the _tz_decimal_from_dhms method converts hours, minutes, and seconds of a time zone to a decimal number representing degrees. """ data = ( ((0, 10, 2, 5), 0.41811342592592593), ((1, 0, 0, 0), 1.0), ) msg = "Expected {} with h,m,s {}, found {}." for args, expected_result in data: result = self.bc._tz_decimal_from_dhms(*args) self.assertEqual(expected_result, result, msg.format(expected_result, args, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__tz_dhms_from_decimal(self): """ Test that the _tz_dhms_from_decimal method returns converts a decimal number to hours, minutes, and seconds. """ data = ( (0.41811342592592593, (0, 10, 2, 5)), (1.0, (1, 0, 0, 0)), ) msg = "Expected {} with decimal {}, found {}." for dec, expected_result in data: result = self.bc._tz_dhms_from_decimal(dec) self.assertEqual(expected_result, result, msg.format(expected_result, dec, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__hms_from_decimal_day(self): """ Test that the _hms_from_decimal_day method returns hours, minutes, and seconds deom a decimal number. """ data = ( (0.5, False, (12, 0, 0.0)), (0.25, False, (6, 0, 0.0)), (0.1, False, (2, 24, 0.0)), (0.1774306, False, (4, 15, 30.0024)), (1.75757575, True, (18, 10, 54, 544800)), (0.90005, True, (21, 36, 4, 320000)), ) msg = "Expected {} with decimal {} and us {}, found {}." for dec, us, expected_result in data: result = self.bc._hms_from_decimal_day(dec, us=us) self.assertEqual(expected_result, result, msg.format(expected_result, dec, us, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__decimal_day_from_hms(self): """ Test that the _decimal_day_from_hms method returns the correct decimal part of the day. """ err_msg0 = ("Seconds cannot have a decimal value if microseconds " "are used.") data = ( ((12, 0, 0.0), 0.5), ((6, 0, 0.0), 0.25), ((2, 24, 0.0), 0.1), ((4, 15, 30), 0.17743055555555556), ((4, 15, 30, 500000), 0.17743634259259258), ((4, 15, 30.5), 0.17743634259259258), ((4, 15, 30.5, 500000), err_msg0), ((4, 15, 30.5, 500000), err_msg0), ) msg = "Expected {} with hms {}, found {}." for hms, expected_result in data: if isinstance(expected_result, str): with self.assertRaises(AssertionError) as cm: self.bc._decimal_day_from_hms(*hms) result = str(cm.exception) else: result = self.bc._decimal_day_from_hms(*hms) self.assertEqual(expected_result, result, msg.format(expected_result, hms, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__sec_microsec_from_seconds(self): """ Test that the _sec_microsec_from_seconds method returns the seconds and microseconds from a second + partian as in 10.75 seconds. """ data = ( (-18000, (-18000, 0)), (-18000.5, (-18000, 500000)), (100.125, (100, 125000)), ) msg = "Expected {} with second {}, found {}." for second, expected_result in data: result = self.bc._sec_microsec_from_seconds(second) self.assertEqual(expected_result, result, msg.format(expected_result, second, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__sin_deg(self): """ Test that the _sin_deg method returns the sine of theta (given in degrees). """ theta = 90.0 result = self.bc._sin_deg(theta) expected_result = 1.0 msg = f"Expected {expected_result}, found {result}." self.assertEqual(expected_result, result, msg)
#@unittest.skip("Temporarily skipped")
[docs] def test__cos_deg(self): """ Test that the _cos_deg method returns the cosine of theta (given in degrees). """ theta = 90.0 result = self.bc._cos_deg(theta) expected_result = 6.123233995736766e-17 # is 0? msg = f"Expected {expected_result}, found {result}." self.assertEqual(expected_result, result, msg)
#@unittest.skip("Temporarily skipped")
[docs] def test__sigma(self): """ Test that the sigma method returns a sum of the provided lists wuth the given function (condition). """ lists = ((0, 1, 2, 3, 4, 5, 6, 7, 8, 9), (1, 2, 3, 4, 5, 6, 7, 8, 9, 0), (2, 3, 4, 5, 6, 7, 8, 9, 0, 1)) func = lambda x, y, z, : x * y * z result = self.bc._sigma(lists, func) expected_result = 1260 msg = f"Expected {expected_result}, found {result}." self.assertEqual(expected_result, result, msg)
#@unittest.skip("Temporarily skipped")
[docs] def test__poly(self): """ Test the poly (polynomial) lambda. """ # Test not 'x' x = 10 a = () poly = self.bc._poly(x, a) expected_poly = 0 msg = f"POLY should be {expected_poly}, found {poly}." self.assertEqual(expected_poly, poly, msg) # Test 'a' has a value x = 0.1 a = (1, 2, 3, 4) poly = self.bc._poly(x, a) expected_poly = 1.234 msg = f"POLY should be {expected_poly}, found {poly}." self.assertEqual(expected_poly, poly, msg)
#@unittest.skip("Temporarily skipped")
[docs] def test__days_in_years(self): """ Test that the _days_in_years method returns the number of days including year one (Gregorian) to the given year. """ data = ( (1, False, 365), (1, True, 365), (2024, False, 739251), (2024, True, 739251), (3000, False, 1095727), (3000, True, 1095727), ) msg = "Expected {} with year {} and alt {}, found {}." for year, alt, expected_result in data: result = self.bc._days_in_years(year, alt=alt) self.assertEqual(expected_result, result, msg.format(expected_result, year, alt, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__meeus_from_exact(self): """ Test that the _meeus_from_exact method returns the correct difference needed to compensate for the differences in the exact and the Meeus algorithms. """ err_msg = ("Astronomical JD {} lies in the Gregorian reform gap " "(1582-10-05 through 1582-10-14); no Meeus JD exists.") data = ( (1757640.5, True, 1757640.5), # 0 (100, 2, 28) (1757641.5, True, 1757642.5), # 1 (100, 3, 1) (1794164.5, True, 1794165.5), # 1 (200, 2, 28) (1794165.5, True, 1794167.5), # 2 (200, 3, 1) (1830688.5, True, 1830690.5), # 2 (300, 2, 28) (1830689.5, True, 1830692.5), # 3 (300, 3, 1) (1903737.5, True, 1903740.5), # 3 (500, 2, 28) (1903738.5, True, 1903742.5), # 4 (500, 3, 1) (1940261.5, True, 1940265.5), # 4 (600, 2, 28) (1940262.5, True, 1940267.5), # 5 (600, 3, 1) (1976785.5, True, 1976790.5), # 5 (700, 2, 28) (1976787.5, True, 1976793.5), # 6 (700, 3, 1) (2049834.5, True, 2049840.5), # 6 (900, 2, 28) (2049836.5, True, 2049843.5), # 7 (900, 3, 1) (2086358.5, True, 2086365.5), # 7 (1000, 2, 28) (2086360.5, True, 2086368.5), # 8 (1000, 3, 1) (2122882.5, True, 2122890.5), # 8 (1100, 2, 28) (2122884.5, True, 2122893.5), # 9 (1100, 3, 1) (2195931.5, True, 2195940.5), # 9 (1300, 2, 28) (2195933.5, True, 2195943.5), # 10 (1300, 3, 1) (2232455.5, True, 2232465.5), # 10 (1400, 2, 28) (2232457.5, True, 2232468.5), # 11 (1400, 3, 1) (2268979.5, True, 2268990.5), # 11 (1500, 2, 28) (2268981.5, True, 2268993.5), # 12 (1500, 3, 1) (2299147.5, True, 2299159.5), # 12 (1582, 10, 4) (2299158.5, True, 2299160.5), # 2 (1582, 10, 15) # 2 (2024, 3, 20, 18, 14, 51.648) (2460388.26032, True, 2460390.26032), # 12 (1582, 10, 5) (2299148.5, False, err_msg.format(2299148.5)), # 3 (1582, 10, 14) (2299158.4999, False, err_msg.format(2299158.4999)), ) msg = "Expected {} for jd {}, found {}" for jd, valid, expected_result in data: if valid: result = self.bc._meeus_from_exact(jd) self.assertEqual(expected_result, result, msg.format( expected_result, jd, result)) else: with self.assertRaises(ValueError) as cm: self.bc._meeus_from_exact(jd) message = str(cm.exception) self.assertEqual(expected_result, message)
#@unittest.skip("Temporarily skipped")
[docs] def test__exact_from_meeus(self): """ Test that the _exact_from_meeus method returns the correct difference needed to compensate for the differences in the Meeus and the exact algorithms. """ err_msg0 = "Invalid historic (Meeus) JD {}." data = ( (1757640.5, True, 1757640.5), # 0 (100, 2, 28) (1757642.5, True, 1757641.5), # 1 (100, 3, 1) (1794165.5, True, 1794164.5), # 1 (200, 2, 28) (1794167.5, True, 1794165.5), # 2 (200, 3, 1) (1830690.5, True, 1830688.5), # 2 (300, 2, 28) (1830692.5, True, 1830689.5), # 3 (300, 3, 1) (1903740.5, True, 1903737.5), # 3 (500, 2, 28) (1903742.5, True, 1903738.5), # 4 (500, 3, 1) (1940265.5, True, 1940261.5), # 4 (600, 2, 28) (1940267.5, True, 1940262.5), # 5 (600, 3, 1) (1976790.5, True, 1976785.5), # 5 (700, 2, 28) (1976792.5, True, 1976786.5), # 6 (700, 3, 1) (2049840.5, True, 2049834.5), # 6 (900, 2, 28) (2049842.5, True, 2049835.5), # 7 (900, 3, 1) (2086365.5, True, 2086358.5), # 7 (1000, 2, 28) (2086367.5, True, 2086359.5), # 8 (1000, 3, 1) (2122890.5, True, 2122882.5), # 8 (1100, 2, 28) (2122892.5, True, 2122883.5), # 9 (1100, 3, 1) (2195940.5, True, 2195931.5), # 9 (1300, 2, 28) (2195942.5, True, 2195932.5), # 10 (1300, 3, 1) (2232465.5, True, 2232455.5), # 10 (1400, 2, 28) (2232467.5, True, 2232456.5), # 11 (1400, 3, 1) (2268990.5, True, 2268979.5), # 11 (1500, 2, 28) (2268992.5, True, 2268980.5), # 12 (1500, 3, 1) (2299159.5, True, 2299147.5), # 12 (1582, 10, 4) (2299160.5, True, 2299158.5), # 2 (1582, 10, 15) # Non existant Meeus days (1757641.5, False, err_msg0.format(1757641.5)), # 1 (100, 2, 29) (1794166.5, False, err_msg0.format(1794166.5)), # 2 (200, 2, 29) (1830691.5, False, err_msg0.format(1830691.5)), # 3 (300, 2, 29) (1903741.5, False, err_msg0.format(1903741.5)), # 4 (500, 2, 29) (1940266.5, False, err_msg0.format(1940266.5)), # 5 (600, 2, 29) (1976791.5, False, err_msg0.format(1976791.5)), # 6 (700, 2, 29) (2049841.5, False, err_msg0.format(2049841.5)), # 7 (900, 2, 29) (2086366.5, False, err_msg0.format(2086366.5)), # 8 (1000, 2, 29) (2122891.5, False, err_msg0.format(2122891.5)), # 9 (1100, 2, 29) (2195941.5, False, err_msg0.format(2195941.5)), # 10 (1300, 2, 29) (2232466.5, False, err_msg0.format(2232466.5)), # 11 (1400, 2, 29) (2268991.5, False, err_msg0.format(2268991.5)), # 12 (1500, 2, 29) ) msg = "Expected {} for jd {}, found {}" for jd, valid, expected_result in data: if valid: result = self.bc._exact_from_meeus(jd) self.assertEqual(expected_result, result, msg.format( expected_result, jd, result)) else: with self.assertRaises(ValueError) as cm: self.bc._exact_from_meeus(jd) message = str(cm.exception) self.assertEqual(expected_result, message)
#@unittest.skip("Temporarily skipped")
[docs] def test__coterminal_angle(self): """ Test that the _coterminal_angle method converts degrees greater or less that 360 degrees to a number between 0 and 360 degrees. """ data = ( (1000, 280.0), (-361, 359.0), ) msg = "Expected {} with degrees {}, found {}." for degrees, expected_result in data: result = self.bc._coterminal_angle(degrees) self.assertEqual(expected_result, result, msg.format(expected_result, degrees, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__interpolation_from_three(self): """ Test that the _interpolation_from_three method interpolates from three values an estimate of a forth value. See AA Example 3.a and 3.b """ data = ( ((0.884226, 0.884226, 0.870531, 0.18125), False, 0.8827599395507812), ((0.884226, 0.884226, 0.870531, 0.18125), True, 39.42104118955078), ((1.3814294, 1.3812213, 1.3812453, 0.39660), False, 1.381203046655538), ((1.3814294, 1.3812213, 1.3812453, 0.39660), True, 44.45672224665554), ) msg = "Expected {} with {}, found {}." for args, normalize, expected_result in data: result = self.bc._interpolation_from_three( *args, normalize=normalize) self.assertEqual(expected_result, result, msg.format(expected_result, args, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__truncate_decimal(self): """ Test that the _truncate_decimal method correctly truncates a decimal value. """ data = ( ((10.1212123456789, 6), 10.121212), ((0.01234, 3), 0.012), ((1.0123456789, 12), 1.0123456789), ((1.123, 20), 1.123), ) msg = "Expected {} with args {}, found {}." for args, expected_result in data: result = self.bc._truncate_decimal(*args) self.assertEqual(expected_result, result, msg.format(expected_result, args, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__xor_boolean(self): """ Test that the _xor_boolean tests that any number of booleans can all be False or only one True. """ data = ( ((False, False, False), True), ((True, False, False), True), ((False, True, False), True), ((False, False, True), True), ((True,), True), ((False,), True), ((True, True), False), ((True, False, True), False), ) msg = "Expected {} with booleans {}, found {}." for booleans, expected_result in data: result = self.bc._xor_boolean(booleans) self.assertEqual(expected_result, result, msg.format( expected_result, booleans, result))
#@unittest.skip("Temporarily skipped")
[docs] def test__local_zone_correction(self): """ Test that the _local_zone_correction method converts a Julian Period day fraction to the without zone information to one with zone information. """ epoch_longitude = 51.285817 epoch_zone = 3.5 local_zone = -4.0 err_msg0 = ("If the zone is not None, the zone value must be between " "-180 and 180, found zone: {}.") err_msg1 = "Both the time zone and longitude cannot be None." data = ( # 1844-03-19T12:00:00 -> 1844-03-19T18:16:00 sunset 0.761111 (2394645.115702063, epoch_zone, None, False, True, (0.261535396334, (18, 16, 36.66))), (2460421.4948800434, local_zone, None, False, True, (0.328213376924, (19, 52, 37.6356))), # Same as the first except using longitude to determine zone. (2394645.115702063, None, epoch_longitude, False, True, (0.121637921315, (14, 55, 9.516))), (2394645.115702063, None, epoch_longitude, True, True, (2394645.1216379213, (14, 55, 9.516))), (2394645.0, 181, None, False, False, err_msg0.format(181)), (2394645.0, -181, None, False, False, err_msg0.format(-181)), (2394645.0, None, None, False, False, err_msg1), ) msg = "Expected {} with jd {}, zone {}, and lon {}, found {}." for jd, zone, lon, mod_jd, valid, expected_result in data: if valid: result = self.bc._local_zone_correction(jd, zone, lon, mod_jd=mod_jd) self.assertEqual(expected_result[0], result, msg.format( expected_result, jd, zone, lon, result)) hms = self.bc._hms_from_decimal_day(result + 0.5) self.assertEqual(expected_result[1], hms, msg.format( expected_result, jd, zone, lon, result)) else: with self.assertRaises(AssertionError) as cm: self.bc._local_zone_correction(jd, zone, lon) message = str(cm.exception) self.assertEqual(expected_result, message)