From 5a62c9c84002d724a69a46485c327188b6e2c9b4 Mon Sep 17 00:00:00 2001
From: Jan David Mol <mol@astron.nl>
Date: Wed, 9 Feb 2022 22:29:02 +0100
Subject: [PATCH] L2SS-613: Cache positions and calculators. Might as well
 directly calculate what we need in the INIT phase

---
 .../tangostationcontrol/devices/beam.py            | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/tangostationcontrol/tangostationcontrol/devices/beam.py b/tangostationcontrol/tangostationcontrol/devices/beam.py
index 6114e3823..1ca5631b4 100644
--- a/tangostationcontrol/tangostationcontrol/devices/beam.py
+++ b/tangostationcontrol/tangostationcontrol/devices/beam.py
@@ -66,8 +66,14 @@ class Beam(lofar_device):
         self.recv_proxy = DeviceProxy("STAT/RECV/1")
 
         # Retrieve positions from RECV device
-        self.HBAT_reference_itrf = self.recv_proxy.HBAT_reference_itrf_R
-        self.HBAT_antenna_itrf_offsets = self.recv_proxy.HBAT_antenna_itrf_offsets_R
+        HBAT_reference_itrf = self.recv_proxy.HBAT_reference_itrf_R
+        HBAT_antenna_itrf_offsets = self.recv_proxy.HBAT_antenna_itrf_offsets_R
+
+        # a delay calculator for each tile
+        self.HBAT_delay_calculators = [delay_calculator(reference_itrf) for reference_itrf in HBAT_reference_itrf]
+
+        # absolute positions of each antenna element
+        self.HBAT_antenna_positions = [reference_itrf + HBAT_antenna_itrf_offsets for reference_itrf in HBAT_reference_itrf]
 
     # --------
     # internal functions
@@ -83,11 +89,11 @@ class Beam(lofar_device):
 
         for tile in range(96):
             # initialise delay calculator
-            d = delay_calculator(self.HBAT_reference_itrf[tile])
+            d = self.HBAT_delay_calculators[tile]
             d.set_measure_time(timestamp)
 
             # calculate the delays based on the set reference position, the set time and now the set direction and antenna positions
-            delays[tile] = d.convert(pointing_direction[tile], self.HBAT_antenna_itrf_offsets + self.HBAT_reference_itrf[tile])
+            delays[tile] = d.convert(pointing_direction[tile], self.HBAT_antenna_positions[tile])
 
         return delays
 
-- 
GitLab