casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FreqAxisTVI.h
Go to the documentation of this file.
1 //# FreqAxisTVI.h: This file contains the interface definition of the MSTransformManager class.
2 //#
3 //# CASA - Common Astronomy Software Applications (http://casa.nrao.edu/)
4 //# Copyright (C) Associated Universities, Inc. Washington DC, USA 2011, All rights reserved.
5 //# Copyright (C) European Southern Observatory, 2011, All rights reserved.
6 //#
7 //# This library is free software; you can redistribute it and/or
8 //# modify it under the terms of the GNU Lesser General Public
9 //# License as published by the Free software Foundation; either
10 //# version 2.1 of the License, or (at your option) any later version.
11 //#
12 //# This library is distributed in the hope that it will be useful,
13 //# but WITHOUT ANY WARRANTY, without even the implied warranty of
14 //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 //# Lesser General Public License for more details.
16 //#
17 //# You should have received a copy of the GNU Lesser General Public
18 //# License along with this library; if not, write to the Free Software
19 //# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 //# MA 02111-1307 USA
21 //# $Id: $
22 
23 #ifndef FreqAxisTVI_H_
24 #define FreqAxisTVI_H_
25 
26 // Base class
28 
29 // VI/VB framework
30 #include <msvis/MSVis/VisBuffer2.h>
32 
33 // TVI framework
35 
36 // Measurement Set
38 
39 // NOTE: See implementation include below
40 
41 
42 namespace casa { //# NAMESPACE CASA - BEGIN
43 
44 namespace vi { //# NAMESPACE VI - BEGIN
45 
47 // FreqAxisTVI class
49 
50 template<class T> class FreqAxisTransformEngine; // Forward declaration
51 template<class T> class FreqAxisTransformEngine2; // Forward declaration
52 
54 {
55 
56 public:
57 
58  // Lifecycle
59  FreqAxisTVI(ViImplementation2 * inputVii);
60  ~FreqAxisTVI();
61 
62  // Navigation methods
63  virtual void origin ();
64  virtual void next ();
65 
66  // General TVI info (common for all sub-classes)
68  casacore::Bool flagCategoryExists () const {return false;}
69 
70  // casacore::List of methods that should be implemented by derived classes
71  // virtual void flag(casacore::Cube<casacore::Bool>& flagCube) const = 0;
72  // virtual void floatData (casacore::Cube<casacore::Float> & vis) const = 0;
73  // virtual void visibilityObserved (casacore::Cube<casacore::Complex> & vis) const = 0;
74  // virtual void visibilityCorrected (casacore::Cube<casacore::Complex> & vis) const = 0;
75  // virtual void visibilityModel (casacore::Cube<casacore::Complex> & vis) const = 0;
76  // virtual void weightSpectrum(casacore::Cube<casacore::Float> &weightSp) const = 0;
77  // virtual void sigmaSpectrum (casacore::Cube<casacore::Float> &sigmaSp) const = 0;
78  // virtual casacore::Vector<casacore::Double> getFrequencies ( casacore::Double time, casacore::Int frameOfReference,casacore::Int spectralWindowId, casacore::Int msId) const = 0;
79  // virtual void writeFlag (const casacore::Cube<casacore::Bool> & flagCube) = 0;
80 
81  // Common transformation for all sub-classes
84  casacore::Int spectralWindowId, casacore::Int msId) const;
88 
89 protected:
90 
91  // Method implementing main loop (with auxiliary data)
92  template <class T> void transformFreqAxis( casacore::Cube<T> const &inputDataCube,
93  casacore::Cube<T> &outputDataCube,
94  FreqAxisTransformEngine<T> &transformer) const
95  {
96  // Re-shape output data cube
97  outputDataCube.resize(getVisBuffer()->getShape(),false);
98 
99  // Get data shape for iteration
100  const casacore::IPosition &inputShape = inputDataCube.shape();
101  casacore::uInt nRows = inputShape(2);
102  casacore::uInt nCorrs = inputShape(0);
103 
104  // Initialize input-output planes
105  casacore::Matrix<T> inputDataPlane;
106  casacore::Matrix<T> outputDataPlane;
107 
108  // Initialize input-output vectors
109  casacore::Vector<T> inputDataVector;
110  casacore::Vector<T> outputDataVector;
111 
112  for (casacore::uInt row=0; row < nRows; row++)
113  {
114  // Assign input-output planes by reference
115  transformer.setRowIndex(row);
116  inputDataPlane.reference(inputDataCube.xyPlane(row));
117  outputDataPlane.reference(outputDataCube.xyPlane(row));
118 
119  for (casacore::uInt corr=0; corr < nCorrs; corr++)
120  {
121  // Assign input-output vectors by reference
122  transformer.setCorrIndex(corr);
123  inputDataVector.reference(inputDataPlane.row(corr));
124  outputDataVector.reference(outputDataPlane.row(corr));
125 
126  // Transform data
127  transformer.transform(inputDataVector,outputDataVector);
128  }
129  }
130 
131  return;
132  }
133 
134  // Method implementing main loop (with auxiliary data)
135  template <class T> void transformFreqAxis2( const casacore::IPosition &inputShape,
136  FreqAxisTransformEngine2<T> &transformer,
137  casacore::Int parallelCorrAxis=-1) const
138  {
139  casacore::uInt nRows = inputShape(2);
140  if (parallelCorrAxis >= 0)
141  {
142  for (casacore::uInt row=0; row < nRows; row++)
143  {
144  transformer.setRowIndex(row);
145  transformer.setCorrIndex(parallelCorrAxis);
146  transformer.transform();
147  }
148  }
149  else
150  {
151  casacore::uInt nCorrs = inputShape(0);
152  for (casacore::uInt row=0; row < nRows; row++)
153  {
154  transformer.setRowIndex(row);
155 
156  for (casacore::uInt corr=0; corr < nCorrs; corr++)
157  {
158  transformer.setCorrIndex(corr);
159 
160  // jagonzal: Debug code
161  /*
162  VisBuffer2 *vb = getVii()->getVisBuffer();
163  if (vb->rowIds()(row)==0 and corr==0)
164  {
165  transformer.setDebug(True);
166  }
167  else
168  {
169  transformer.setDebug(False);
170  }
171  */
172  transformer.transform();
173  }
174  }
175  }
176 
177  return;
178  }
179 
180  void initialize();
181 
182  // Form spwInpChanIdxMap_p via calls to underlying Vii
183  void formChanMap();
184 
186  mutable std::map<casacore::Int,casacore::uInt > spwOutChanNumMap_p; // Must be accessed from const methods
187  mutable std::map<casacore::Int,std::vector<casacore::Int> > spwInpChanIdxMap_p; // Must be accessed from const methods
188 };
189 
191 // FreqAxisTransformEngine class
193 
194 template<class T> class FreqAxisTransformEngine
195 {
196 
197 public:
198 
200  virtual void setRowIndex(casacore::uInt row) {row_p = row;}
201  virtual void setCorrIndex(casacore::uInt corr) {corr_p = corr;}
202 
203 protected:
204 
207 
208 };
209 
211 // FreqAxisTransformEngine2 class
213 
214 template<class T> class FreqAxisTransformEngine2
215 {
216 
217 public:
218 
220  {
221  debug_p = false;
222  inputData_p = inputData;
223  outputData_p = outputData;
224  }
225 
227  {
228  rowIndex_p = row;
231 
232  return;
233  }
234 
236  {
237  corrIndex_p = corr;
240 
241  return;
242  }
243 
244  void setDebug(bool debug) { debug_p = debug;}
245 
246  virtual void transform() {}
247 
248 protected:
249 
255 
256 };
257 
258 } //# NAMESPACE VI - END
259 
260 } //# NAMESPACE CASA - END
261 
262 #endif /* FreqAxisTVI_H_ */
263 
virtual void reference(const Array< T > &other)
Make this matrix a reference to other.
A Vector of integers, for indexing into Array&lt;T&gt; objects.
Definition: IPosition.h:119
int Int
Definition: aipstype.h:50
virtual void origin()
Navigation methods.
virtual void setCorrIndex(casacore::uInt corr)
Definition: FreqAxisTVI.h:201
casacore::Bool flagCategoryExists() const
Determine whether FLAG_CATEGORY is valid.
Definition: FreqAxisTVI.h:68
virtual void time(casacore::Vector< double > &t) const override
Return MJD midpoint of interval.
void weight(casacore::Matrix< casacore::Float > &weight) const
Return weight.
std::map< casacore::Int, casacore::uInt > spwOutChanNumMap_p
Definition: FreqAxisTVI.h:186
virtual void flag(casacore::Cube< casacore::Bool > &flags) const override
Return flag for each polarization, channel and row.
FreqAxisTVI(ViImplementation2 *inputVii)
Lifecycle.
const IPosition & shape() const
The length of each axis of the cube.
Definition: Cube.h:292
A 3-D Specialization of the Array class.
void writeFlagRow(const casacore::Vector< casacore::Bool > &flag)
casacore::List of methods that should be implemented by derived classes virtual void flag(casacore::C...
void setMatrixIndex(casacore::uInt rowIndex)
ostream-like interface to creating log messages.
Definition: LogIO.h:167
casacore::LogIO logger_p
Definition: FreqAxisTVI.h:185
void formChanMap()
Form spwInpChanIdxMap_p via calls to underlying Vii.
Vector< T > row(size_t i)
Returns a reference to the i&#39;th row.
std::map< casacore::Int, std::vector< casacore::Int > > spwInpChanIdxMap_p
Definition: FreqAxisTVI.h:187
virtual VisBuffer2 * getVisBuffer() const override
casacore::Bool existsColumn(VisBufferComponent2 id) const
General TVI info (common for all sub-classes)
double Double
Definition: aipstype.h:55
void resize(size_t nx, size_t ny, size_t nz, Bool copyValues=False)
Definition: Cube.h:138
virtual void setRowIndex(casacore::uInt row)
Definition: FreqAxisTVI.h:200
void setRowIndex(casacore::uInt row)
Definition: FreqAxisTVI.h:226
virtual void transform(casacore::Vector< T > &, casacore::Vector< T > &)
Definition: FreqAxisTVI.h:199
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
VisibilityIterator2 iterates through one or more readonly MeasurementSets.
void setCorrIndex(casacore::uInt corr)
Definition: FreqAxisTVI.h:235
FreqAxisTransformEngine2(DataCubeMap *inputData, DataCubeMap *outputData)
Definition: FreqAxisTVI.h:219
bool debug
casacore::Vector< casacore::Int > getChannels(casacore::Double time, casacore::Int frameOfReference, casacore::Int spectralWindowId, casacore::Int msId) const
void sigma(casacore::Matrix< casacore::Float > &sigma) const
Return sigma.
Matrix< T > xyPlane(size_t zplane)
Extract a plane as a matrix referencing the original data.
VisibilityIterator2 iterates through one or more readonly MeasurementSets.
virtual void next()
void flagRow(casacore::Vector< casacore::Bool > &flagRow) const
Return row flag.
virtual casacore::Int nRows() const override
Return the number of rows in the current iteration.
void transformFreqAxis(casacore::Cube< T > const &inputDataCube, casacore::Cube< T > &outputDataCube, FreqAxisTransformEngine< T > &transformer) const
Method implementing main loop (with auxiliary data)
Definition: FreqAxisTVI.h:92
virtual void reference(const Array< T > &other)
Create a reference to &quot;other&quot;, which must be of dimension one.
void setVectorIndex(casacore::uInt vectorIndex)
virtual casacore::Int msId() const override
reference to actual ms in interator
unsigned int uInt
Definition: aipstype.h:51
void transformFreqAxis2(const casacore::IPosition &inputShape, FreqAxisTransformEngine2< T > &transformer, casacore::Int parallelCorrAxis=-1) const
Method implementing main loop (with auxiliary data)
Definition: FreqAxisTVI.h:135