From f4125e782017350d38e64a12e28c35645f6a0036 Mon Sep 17 00:00:00 2001
From: Ger van Diepen <diepen@astron.nl>
Date: Fri, 28 Jan 2011 14:32:42 +0000
Subject: [PATCH] bug 1638: Initial version

---
 CEP/DP3/DPPP/include/DPPP/PhaseShift.h |  93 ++++++++++++++++++++
 CEP/DP3/DPPP/src/PhaseShift.cc         | 113 +++++++++++++++++++++++++
 2 files changed, 206 insertions(+)
 create mode 100644 CEP/DP3/DPPP/include/DPPP/PhaseShift.h
 create mode 100644 CEP/DP3/DPPP/src/PhaseShift.cc

diff --git a/CEP/DP3/DPPP/include/DPPP/PhaseShift.h b/CEP/DP3/DPPP/include/DPPP/PhaseShift.h
new file mode 100644
index 00000000000..b66049a7907
--- /dev/null
+++ b/CEP/DP3/DPPP/include/DPPP/PhaseShift.h
@@ -0,0 +1,93 @@
+//# PhaseShift.h: DPPP step class to average in time and/or freq
+//# Copyright (C) 2010
+//# ASTRON (Netherlands Institute for Radio Astronomy)
+//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
+//#
+//# This file is part of the LOFAR software suite.
+//# The LOFAR software suite is free software: you can redistribute it and/or
+//# modify it under the terms of the GNU General Public License as published
+//# by the Free Software Foundation, either version 3 of the License, or
+//# (at your option) any later version.
+//#
+//# The LOFAR software suite is distributed in the hope that it will be useful,
+//# but WITHOUT ANY WARRANTY; without even the implied warranty of
+//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//# GNU General Public License for more details.
+//#
+//# You should have received a copy of the GNU General Public License along
+//# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>.
+//#
+//# $Id$
+//#
+//# @author Ger van Diepen
+
+#ifndef DPPP_PHASESHIFT_H
+#define DPPP_PHASESHIFT_H
+
+// @file
+// @brief DPPP step class to average in time and/or freq
+
+#include <DPPP/DPInput.h>
+#include <DPPP/DPBuffer.h>
+#include <measures/Measures/UVWMachine.h>
+
+namespace LOFAR {
+
+  namespace DPPP {
+    class ParSet;
+
+    // @ingroup NDPPP
+
+    // This class is a DPStep class calculating the weighted average of
+    // data in time and/or frequency.
+    // <br>
+    // Only unflagged data points are used. The average is calculated as
+    // <tt>sum(data*weight) / sum(weight)</tt> and the sum of the weights
+    // is the weight of the new data point. If all data point to use are
+    // flagged, the resulting data point and weight are set to zero and flagged.
+    //
+    // It keeps track of the FullResFlags. It sets them if the corresponding
+    // data point is flagged. Note that multiple FullResFlags elements map to
+    // a single data point if some averaging was done before.
+
+    class PhaseShift: public DPStep
+    {
+    public:
+      // Construct the object.
+      // Parameters are obtained from the parset using the given prefix.
+      PhaseShift (DPInput*, const ParSet&, const string& prefix);
+
+      virtual ~PhaseShift();
+
+      // Process the data.
+      // It keeps the data.
+      // When processed, it invokes the process function of the next step.
+      virtual bool process (const DPBuffer&);
+
+      // Finish the processing of this step and subsequent steps.
+      virtual void finish();
+
+      // Update the general info.
+      virtual void updateInfo (DPInfo&);
+
+      // Show the step parameters.
+      virtual void show (std::ostream&) const;
+
+      // Show the timings.
+      virtual void showTimings (std::ostream&, double duration) const;
+
+    private:
+      //# Data members.
+      DPInput*         itsInput;
+      string           itsName;
+      DPBuffer         itsBuf;
+      string           itsRaStr;
+      string           itsDecStr;
+      casa::UVWMachine itsMachine;
+      NSTimer          itsTimer;
+    };
+
+  } //# end namespace
+}
+
+#endif
diff --git a/CEP/DP3/DPPP/src/PhaseShift.cc b/CEP/DP3/DPPP/src/PhaseShift.cc
new file mode 100644
index 00000000000..5f94bd211ed
--- /dev/null
+++ b/CEP/DP3/DPPP/src/PhaseShift.cc
@@ -0,0 +1,113 @@
+//# PhaseShift.cc: DPPP step class to average in time and/or freq
+//# Copyright (C) 2010
+//# ASTRON (Netherlands Institute for Radio Astronomy)
+//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
+//#
+//# This file is part of the LOFAR software suite.
+//# The LOFAR software suite is free software: you can redistribute it and/or
+//# modify it under the terms of the GNU General Public License as published
+//# by the Free Software Foundation, either version 3 of the License, or
+//# (at your option) any later version.
+//#
+//# The LOFAR software suite is distributed in the hope that it will be useful,
+//# but WITHOUT ANY WARRANTY; without even the implied warranty of
+//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//# GNU General Public License for more details.
+//#
+//# You should have received a copy of the GNU General Public License along
+//# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>.
+//#
+//# $Id$
+//#
+//# @author Ger van Diepen
+
+#include <lofar_config.h>
+#include <DPPP/PhaseShift.h>
+#include <DPPP/DPBuffer.h>
+#include <DPPP/DPInfo.h>
+#include <DPPP/ParSet.h>
+#include <Common/LofarLogger.h>
+#include <casa/Arrays/ArrayMath.h>
+#include <iostream>
+#include <iomanip>
+
+using namespace casa;
+
+namespace LOFAR {
+  namespace DPPP {
+
+    PhaseShift::PhaseShift (DPInput* input,
+                            const ParSet& parset, const string& prefix)
+      : itsInput  (input),
+        itsName   (prefix),
+        itsRaStr  (parset.getString(prefix+"ra", "")),
+        itsDecStr (parset.getString(prefix+"dec", ""))
+    {}
+
+    PhaseShift::~PhaseShift()
+    {}
+
+    void PhaseShift::updateInfo (DPInfo& info)
+    {
+      // Default phase center is the original one.
+      MDirection newDir(info.originalPhaseCenter());
+      if (itsRaStr.empty() && itsDecStr.empty()) {
+        itsRa  = MVTime::read (itsRaStr);
+        itsDec = MVTime::read (itsDecStr);
+        newDir = MDirection(itsRa, itsDec, MDirection::J2000);
+      }
+      new casa::UVWMachine(info.phaseCentre(), newDir, false, true);
+      info.setNewPhaseCenter (newDir);
+    }
+
+    void PhaseShift::show (std::ostream& os) const
+    {
+      os << "PhaseShift " << itsName << std::endl;
+      os << "  ra:             " << itsRaStr << std::endl;
+      os << "  dec:            " << itsDecStr << std::endl;
+    }
+
+    void PhaseShift::showTimings (std::ostream& os, double duration) const
+    {
+      os << "  ";
+      FlagCounter::showPerc1 (os, itsTimer.getElapsed(), duration);
+      os << " PhaseShift " << itsName << endl;
+    }
+
+    bool PhaseShift::process (const DPBuffer& buf)
+    {
+      itsTimer.start();
+      RefRows rowNrs(buf.getRowNrs());
+      itsBuf.getUVW()  = itsInput->fetchUVW (buf, rowNrs);
+      itsBuf.getData().resize (buf.getData().shape());
+      const Complex* indata = buf.getData().data();
+      Complex* outdata = itsBuf.getData().data();
+      uint ncorr = buf.getData().shape()[0];
+      uint nchan = buf.getData().shape()[1];
+      uint ntime = buf.getData().shape()[2];
+      VectorIterator uvwIter(itsBuf.getUVW());
+      for (uint i=0; i<ntime; ++i) {
+        // Convert the uvw coordinates and get the phase shift term.
+        itsMachine.convertUVW (phase, uvwIter.vector());
+        Complex phasor(cos(phase), sin(phase));
+        // Shift the phase of the data.
+        for (uint j=0; j<nchan; ++j) {
+          for (uint k=0; j<ncorr; ++k) {
+            *outdata = *indata * phasor;
+          }
+        }
+        uvwIter.next();
+     }
+     itsTimer.stop();
+     getNextStep()->process (buf);
+     return true;
+    }
+
+    void PhaseShift::finish()
+    {
+      // Let the next steps finish.
+      getNextStep()->finish();
+    }
+
+  } //# end namespace
+}
-- 
GitLab