FreqAxisTVI.h

Go to the documentation of this file.
00001 //# FreqAxisTVI.h: This file contains the interface definition of the MSTransformManager class.
00002 //#
00003 //#  CASA - Common Astronomy Software Applications (http://casa.nrao.edu/)
00004 //#  Copyright (C) Associated Universities, Inc. Washington DC, USA 2011, All rights reserved.
00005 //#  Copyright (C) European Southern Observatory, 2011, All rights reserved.
00006 //#
00007 //#  This library is free software; you can redistribute it and/or
00008 //#  modify it under the terms of the GNU Lesser General Public
00009 //#  License as published by the Free software Foundation; either
00010 //#  version 2.1 of the License, or (at your option) any later version.
00011 //#
00012 //#  This library is distributed in the hope that it will be useful,
00013 //#  but WITHOUT ANY WARRANTY, without even the implied warranty of
00014 //#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 //#  Lesser General Public License for more details.
00016 //#
00017 //#  You should have received a copy of the GNU Lesser General Public
00018 //#  License along with this library; if not, write to the Free Software
00019 //#  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00020 //#  MA 02111-1307  USA
00021 //# $Id: $
00022 
00023 #ifndef FreqAxisTVI_H_
00024 #define FreqAxisTVI_H_
00025 
00026 // Base class
00027 #include <msvis/MSVis/TransformingVi2.h>
00028 
00029 // VI/VB framework
00030 #include <msvis/MSVis/VisBuffer2.h>
00031 #include <msvis/MSVis/VisibilityIterator2.h>
00032 
00033 // TVI framework
00034 #include <mstransform/TVI/UtilsTVI.h>
00035 
00036 // Measurement Set
00037 #include <casacore/ms/MSSel/MSSelection.h>
00038 
00039 // NOTE: See implementation include below
00040 
00041 
00042 namespace casa { //# NAMESPACE CASA - BEGIN
00043 
00044 namespace vi { //# NAMESPACE VI - BEGIN
00045 
00047 // FreqAxisTVI class
00049 
00050 template<class T> class FreqAxisTransformEngine; // Forward declaration
00051 template<class T> class FreqAxisTransformEngine2; // Forward declaration
00052 
00053 class FreqAxisTVI : public TransformingVi2
00054 {
00055 
00056 public:
00057 
00058         // Lifecycle
00059         FreqAxisTVI(ViImplementation2 * inputVii,const Record &configuration);
00060         ~FreqAxisTVI();
00061 
00062         // Navigation methods
00063         virtual void origin ();
00064         virtual void next ();
00065 
00066         // General TVI info (common for all sub-classes)
00067     Bool existsColumn (VisBufferComponent2 id) const;
00068     Bool flagCategoryExists () const {return False;}
00069 
00070         // List of methods that should be implemented by derived classes
00071     // virtual void flag(Cube<Bool>& flagCube) const = 0;
00072     // virtual void floatData (Cube<Float> & vis) const = 0;
00073     // virtual void visibilityObserved (Cube<Complex> & vis) const = 0;
00074     // virtual void visibilityCorrected (Cube<Complex> & vis) const = 0;
00075     // virtual void visibilityModel (Cube<Complex> & vis) const = 0;
00076     // virtual void weightSpectrum(Cube<Float> &weightSp) const = 0;
00077     // virtual void sigmaSpectrum (Cube<Float> &sigmaSp) const = 0;
00078     // virtual Vector<Double> getFrequencies (  Double time, Int frameOfReference,Int spectralWindowId, Int msId) const = 0;
00079     // virtual void writeFlag (const Cube<Bool> & flagCube) = 0;
00080 
00081     // Common transformation for all sub-classes
00082     void writeFlagRow (const Vector<Bool> & flag);
00083     Vector<Int> getChannels (   Double time, Int frameOfReference,
00084                                                         Int spectralWindowId, Int msId) const;
00085     void flagRow (Vector<Bool> & flagRow) const;
00086     void weight (Matrix<Float> & weight) const;
00087     void sigma (Matrix<Float> & sigma) const;
00088 
00089 protected:
00090 
00091     // Method implementing main loop  (with auxiliary data)
00092         template <class T> void transformFreqAxis(      Cube<T> const &inputDataCube,
00093                                                                                                 Cube<T> &outputDataCube,
00094                                                                                                 FreqAxisTransformEngine<T> &transformer) const
00095         {
00096                 // Re-shape output data cube
00097                 outputDataCube.resize(getVisBufferConst()->getShape(),False);
00098 
00099                 // Get data shape for iteration
00100                 const IPosition &inputShape = inputDataCube.shape();
00101                 uInt nRows = inputShape(2);
00102                 uInt nCorrs = inputShape(0);
00103 
00104                 // Initialize input-output planes
00105                 Matrix<T> inputDataPlane;
00106                 Matrix<T> outputDataPlane;
00107 
00108                 // Initialize input-output vectors
00109                 Vector<T> inputDataVector;
00110                 Vector<T> outputDataVector;
00111 
00112                 for (uInt row=0; row < nRows; row++)
00113                 {
00114                         // Assign input-output planes by reference
00115                         transformer.setRowIndex(row);
00116                         inputDataPlane.reference(inputDataCube.xyPlane(row));
00117                         outputDataPlane.reference(outputDataCube.xyPlane(row));
00118 
00119                         for (uInt corr=0; corr < nCorrs; corr++)
00120                         {
00121                                 // Assign input-output vectors by reference
00122                                 transformer.setCorrIndex(corr);
00123                                 inputDataVector.reference(inputDataPlane.row(corr));
00124                                 outputDataVector.reference(outputDataPlane.row(corr));
00125 
00126                                 // Transform data
00127                                 transformer.transform(inputDataVector,outputDataVector);
00128                         }
00129                 }
00130 
00131                 return;
00132         }
00133 
00134     // Method implementing main loop  (with auxiliary data)
00135         template <class T> void transformFreqAxis2(     const IPosition &inputShape,
00136                                                                                                 FreqAxisTransformEngine2<T> &transformer,
00137                                                                                                 Int parallelCorrAxis=-1) const
00138         {
00139                 uInt nRows = inputShape(2);
00140                 if (parallelCorrAxis >= 0)
00141                 {
00142                         for (uInt row=0; row < nRows; row++)
00143                         {
00144                                 transformer.setRowIndex(row);
00145                                 transformer.setCorrIndex(parallelCorrAxis);
00146                                 transformer.transform();
00147                         }
00148                 }
00149                 else
00150                 {
00151                         uInt nCorrs = inputShape(0);
00152                         for (uInt row=0; row < nRows; row++)
00153                         {
00154                                 transformer.setRowIndex(row);
00155 
00156                                 for (uInt corr=0; corr < nCorrs; corr++)
00157                                 {
00158                                         transformer.setCorrIndex(corr);
00159 
00160                                         // jagonzal: Debug code
00161                                         VisBuffer2 *vb = getVii()->getVisBuffer();
00162                                         if (vb->rowIds()(row)==0 and corr==0)
00163                                         {
00164                                                 transformer.setDebug(True);
00165                                         }
00166                                         else
00167                                         {
00168                                                 transformer.setDebug(False);
00169                                         }
00170 
00171                                         transformer.transform();
00172                                 }
00173                         }
00174                 }
00175 
00176                 return;
00177         }
00178 
00179         Bool parseConfiguration(const Record &configuration);
00180         void initialize();
00181 
00182         // Form spwInpChanIdxMap_p via calls to underlying Vii
00183         void formSelectedChanMap();
00184 
00185         String spwSelection_p;
00186         mutable LogIO logger_p;
00187         mutable map<Int,uInt > spwOutChanNumMap_p; // Must be accessed from const methods
00188         mutable map<Int,vector<Int> > spwInpChanIdxMap_p; // Must be accessed from const methods
00189 };
00190 
00192 // FreqAxisTransformEngine class
00194 
00195 template<class T> class FreqAxisTransformEngine
00196 {
00197 
00198 public:
00199 
00200         virtual void transform( Vector<T> &,Vector<T> &) {};
00201         virtual void setRowIndex(uInt row) {row_p = row;}
00202         virtual void setCorrIndex(uInt corr) {corr_p = corr;}
00203 
00204 protected:
00205 
00206         uInt row_p;
00207         uInt corr_p;
00208 
00209 };
00210 
00212 // FreqAxisTransformEngine2 class
00214 
00215 template<class T> class FreqAxisTransformEngine2
00216 {
00217 
00218 public:
00219 
00220         FreqAxisTransformEngine2(DataCubeMap *inputData,DataCubeMap *outputData)
00221         {
00222                 debug_p = False;
00223                 inputData_p = inputData;
00224                 outputData_p = outputData;
00225         }
00226 
00227         void setRowIndex(uInt row)
00228         {
00229                 rowIndex_p = row;
00230                 inputData_p->setMatrixIndex(row);
00231                 outputData_p->setMatrixIndex(row);
00232 
00233                 return;
00234         }
00235 
00236         void setCorrIndex(uInt corr)
00237         {
00238                 corrIndex_p = corr;
00239                 inputData_p->setVectorIndex(corr);
00240                 outputData_p->setVectorIndex(corr);
00241 
00242                 return;
00243         }
00244 
00245         void setDebug(Bool debug) { debug_p = debug;}
00246 
00247         virtual void transform() {}
00248 
00249 protected:
00250 
00251         Bool debug_p;
00252         uInt rowIndex_p;
00253         uInt corrIndex_p;
00254         DataCubeMap *inputData_p;
00255         DataCubeMap *outputData_p;
00256 
00257 };
00258 
00259 } //# NAMESPACE VI - END
00260 
00261 } //# NAMESPACE CASA - END
00262 
00263 #endif /* FreqAxisTVI_H_ */
00264 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1