From 8a0ff95f709358e1c22b6e8ae00b2cffc4723a43 Mon Sep 17 00:00:00 2001
From: Jan David Mol <mol@astron.nl>
Date: Thu, 7 Feb 2013 12:49:17 +0000
Subject: [PATCH] Task #3916: Added cos(dec) correction to ra for tied-array
 rings, to properly map the tied-array rings on the non-linear radec
 coordinate system.

---
 RTCP/Run/src/LOFAR/Parset.py          |  4 +++-
 RTCP/Run/src/LOFAR/RingCoordinates.py | 23 ++++++++++++++++++++---
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/RTCP/Run/src/LOFAR/Parset.py b/RTCP/Run/src/LOFAR/Parset.py
index 8a3ac9e36ff..de3445852ba 100644
--- a/RTCP/Run/src/LOFAR/Parset.py
+++ b/RTCP/Run/src/LOFAR/Parset.py
@@ -202,11 +202,13 @@ class Parset(util.Parset.Parset):
           self.setdefault("Observation.Beam[%s].tabRingSize" % (b,),0.0)
 
           dirtype = self["Observation.Beam[%s].directionType" % (b,)]  
+          center_angle1 = float(self["Observation.Beam[%s].angle1" % (b,)])
+          center_angle2 = float(self["Observation.Beam[%s].angle2" % (b,)])
           dm = int(self.get("OLAP.dispersionMeasure",0))
 
           nrrings = int(self["Observation.Beam[%s].nrTabRings" % (b,)]) 
           width   = float(self["Observation.Beam[%s].tabRingSize" % (b,)]) 
-          ringcoordinates = RingCoordinates( nrrings, width )
+          ringcoordinates = RingCoordinates( nrrings, width, (center_angle1, center_angle2), dirtype )
           ringset = [
             { "angle1": angle1,
               "angle2": angle2,
diff --git a/RTCP/Run/src/LOFAR/RingCoordinates.py b/RTCP/Run/src/LOFAR/RingCoordinates.py
index fc82d772aea..02e52a3c2d1 100644
--- a/RTCP/Run/src/LOFAR/RingCoordinates.py
+++ b/RTCP/Run/src/LOFAR/RingCoordinates.py
@@ -1,11 +1,28 @@
 #!/usr/bin/python
 
-from math import sqrt
+from math import sqrt, cos, pi
 
 class RingCoordinates:
-    def __init__(self, numrings, width):
+    def __init__(self, numrings, width, center, dirtype):
         self.numrings = numrings
         self.width    = width
+        self.center   = center
+        self.dirtype  = dirtype
+
+    def cos_adjust(self, offset):
+        if dirtype != "J2000" and dirtype != "B1950":
+          return offset
+
+        # warp coordinates closer to the NCP
+
+        cos_dec = cos(self.center[1] + offset[1])
+        epsilon = 0.0001
+
+        if cos_dec > epsilon:
+            return (offset[0]/cos_dec, offset[1])
+        else:
+            return offset
+
 
     def len_edge(self):
         """
@@ -120,5 +137,5 @@ class RingCoordinates:
               l += dl[side]
               m += dm[side]
 
-        return coordinates
+        return map(self.cos_adjust, coordinates)
 
-- 
GitLab