From a3fc9adb03cda570d4be65ba959507b5225f4cd2 Mon Sep 17 00:00:00 2001
From: thijs snijder <snijder@astron.nl>
Date: Fri, 25 Feb 2022 10:34:11 +0100
Subject: [PATCH] fixed test_sun code and added description of what is
 happening

---
 .../test/beam/test_delays.py                  | 26 ++++++++++++-------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/tangostationcontrol/tangostationcontrol/test/beam/test_delays.py b/tangostationcontrol/tangostationcontrol/test/beam/test_delays.py
index e5fb81e08..5acb49f5a 100644
--- a/tangostationcontrol/tangostationcontrol/test/beam/test_delays.py
+++ b/tangostationcontrol/tangostationcontrol/test/beam/test_delays.py
@@ -22,24 +22,32 @@ class TestDelays(base.TestCase):
 
     def test_sun(self):
         # # create a frame tied to the reference position
-        reference_itrf = [3826577.066, 461022.948, 5064892.786]  # CS002LBA, in ITRF2005 epoch 2012.5
+        #reference_itrf = [3826577.066, 461022.948, 5064892.786]  # CS002LBA, in ITRF2005 epoch 2012.5
+        reference_itrf = [3826577.066, 461022.948, 5064892.786]
         d = delay_calculator(reference_itrf)
 
         for i in range(24):
-            # # set the timestamp to solve for
-            timestamp = datetime.datetime(2022, 1, 27, i, 28, 0)  # 9:28 sunrise this particular day
+
+            # set the time to the winter solstice (21 december 16:58) as this is the time with the least change in sunlight
+            timestamp = datetime.datetime(2021, 12, 21, i, 58, 0)
             d.set_measure_time(timestamp)
 
-            # compute the delays for an antennas w.r.t. the reference position
 
-            # # obtain the direction vector for a specific pointing
-            direction = "J2000", "0deg", "0deg"
+            # point to the sun
+            direction = "SUN", "0deg", "0deg"
 
             # calculate the delays based on the set reference position, the set time and now the set direction and antenna positions.
             pointing = d.measure.direction(*direction)
-            dir = d.get_direction_vector(pointing)
-
-            self.assertTrue(0.95 <= sqrt(pow(dir[0],2) + pow(dir[1],2)) <= 1.05, f"direction vector  x: {pow(dir[0],2)} y: {pow(dir[1],2)} z: {pow(dir[2],2)}")
+            direction = d.get_direction_vector(pointing)
+
+            """
+            direction[2] is the z-coordinate of ITRF, which points to the north pole. 
+            This direction is constant when pointing to the sun, as the earth rotates, 
+            but changes slowly due to the earths rotation around the sun.
+            The summer and winter solstices are when these values are at their peaks and the changes are the smallest.
+            This test takes the value at the winter solstice and checks whether the measured values are near enough to that. 
+            """
+            self.assertAlmostEqual(-0.3977784695213487, direction[2], 4)
 
     def test_identical_location(self):
         # # create a frame tied to the reference position
-- 
GitLab