From 8eccb84c7d48c26dd9a6f7a99aa82d937f401fa2 Mon Sep 17 00:00:00 2001
From: Jan David Mol <mol@astron.nl>
Date: Fri, 11 Apr 2025 10:01:33 +0000
Subject: [PATCH] L2SS-2277: Fix XST swap in gRPC

---
 README.md                                 |  1 +
 tangostationcontrol/VERSION               |  2 +-
 tangostationcontrol/rpc/proxy/__init__.py |  0
 tangostationcontrol/rpc/statistics.py     |  2 +-
 tests/rpc/test_statistics.py              | 12 ++++++++++--
 5 files changed, 13 insertions(+), 4 deletions(-)
 create mode 100644 tangostationcontrol/rpc/proxy/__init__.py

diff --git a/README.md b/README.md
index ff4ab2ddc..f48ba0328 100644
--- a/README.md
+++ b/README.md
@@ -150,6 +150,7 @@ Next change the version in the following places:
    through [https://git.astron.nl/lofar2.0/tango/-/tags](Deploy Tags)
 
 # Release Notes
+* 0.48.1 Fix exposing correct triangle of XSTs in gRPC service
 * 0.48.0 Add Antennafield to gRPC server
 * 0.47.2 Fix ZMQ hostname to subscribe to in gRPC server
 * 0.47.1 Move GrafanaAPIV3 RPC interface to Opah repo
diff --git a/tangostationcontrol/VERSION b/tangostationcontrol/VERSION
index 55a021680..cffa44cf3 100644
--- a/tangostationcontrol/VERSION
+++ b/tangostationcontrol/VERSION
@@ -1 +1 @@
-0.47.2
+0.48.1
diff --git a/tangostationcontrol/rpc/proxy/__init__.py b/tangostationcontrol/rpc/proxy/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/tangostationcontrol/rpc/statistics.py b/tangostationcontrol/rpc/statistics.py
index c856c8f8e..d164c67fc 100644
--- a/tangostationcontrol/rpc/statistics.py
+++ b/tangostationcontrol/rpc/statistics.py
@@ -206,7 +206,7 @@ class Statistics(statistics_pb2_grpc.StatisticsServicer, LastStatisticsMessagesM
             )
             for antenna1 in range(nr_antennas)
             for antenna2 in range(nr_antennas)
-            if antenna1 <= antenna2
+            if antenna2 <= antenna1
         ]
 
         frequency_band = self._message_to_frequency_band(xst_message)
diff --git a/tests/rpc/test_statistics.py b/tests/rpc/test_statistics.py
index 7d2fd3ad9..d5d758f53 100644
--- a/tests/rpc/test_statistics.py
+++ b/tests/rpc/test_statistics.py
@@ -176,19 +176,27 @@ class TestStatistics(base.TestCase):
             xst_message["integration_interval"], reply.result.integration_interval, 6
         )
 
-        # verify all data is there
+        # verify all baselines are there
         self.assertEqual(
             set(
                 [
                     (a, b)
                     for a in range(N_pn * A_pn)
                     for b in range(N_pn * A_pn)
-                    if a <= b
+                    if b <= a
                 ]
             ),
             set([(b.antenna1, b.antenna2) for b in reply.result.baselines]),
         )
 
+        # verify all baselines actually have data (and do not take data from
+        # the wrong half of the matrix that is filled with zeroes)
+        for b in reply.result.baselines:
+            self.assertNotEqual(0.0, b.xx.power_db, msg=f"{b}")
+            self.assertNotEqual(0.0, b.xy.power_db, msg=f"{b}")
+            self.assertNotEqual(0.0, b.yx.power_db, msg=f"{b}")
+            self.assertNotEqual(0.0, b.yy.power_db, msg=f"{b}")
+
         # verify data matches input
         xst_data = (
             numpy.array(xst_message["xst_data_real"])
-- 
GitLab