casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SolveDataBuffer.h
Go to the documentation of this file.
1 //# SolveDataBuffer.h: A container for data and residuals for solving
2 //# Copyright (C) 2008
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id: VisBuffer.h,v 19.14 2006/02/28 04:48:58 mvoronko Exp $
27 
28 #ifndef SYNTHESIS_SOLVEDATABUFFER_H
29 #define SYNTHESIS_SOLVEDATABUFFER_H
30 
31 #include <casa/aips.h>
32 #include <msvis/MSVis/VisBuffer2.h>
33 #include <casa/Arrays/Array.h>
34 #include <casa/Arrays/Cube.h>
35 #include <casa/Arrays/Matrix.h>
36 namespace casa { //# NAMESPACE CASA - BEGIN
37 
38 //#forward
39 
40 //<summary>SolveDataBuffer is a container for VisBuffer2 data and related residual and differentiation results related to generic calibration solving </summary>
41 //
42 // <use visibility=export>
43 //
44 // <reviewed reviewer="" date="" tests="" demos="">
45 
46 // <prerequisite>
47 // <li> <linkto class="VisBuffer">VisBuffer</linkto>
48 // </prerequisite>
49 //
50 // <etymology>
51 // SolveDataBuffer is a Buffer for Solving Data
52 // </etymology>
53 //
54 //<synopsis>
55 //
56 //
57 //</synopsis>
58 
59 //<todo>
60 // <li> write todo list
61 //</todo>
62 
63 
64 
66 {
67 public:
68  // Generic ctor
70 
71  // Create from a VisBuffer2
73 
74  // Copy construct
75  // current iteration (or reattach).
76  SolveDataBuffer(const SolveDataBuffer& sdb);
77 
78  // Destructor
80 
81  // Assignment
83 
84  // Does SDB contain finite weight?
85  bool Ok();
86 
87  // Divide corrected by model
88  // NB: disable for now, may not be needed...
89  //void divideCorrByModel();
90 
91  // Apply amp-only or phase-only to data
92  void enforceAPonData(const casacore::String& apmode);
93 
94  // Zero flagged weights, and optionally the cross-hand weights
95  void enforceSolveWeights(const casacore::Bool pHandOnly);
96 
97  // Set the focus channel
98  // (forms references to focus-channel flag/data/model)
99  void setFocusChan(const casacore::Int focusChan=-1);
100 
101  // Size/init/finalize the residuals workspaces
102  void sizeResiduals(const casacore::Int& nPar,const casacore::Int& nDiff);
103  void initResidWithModel();
104  void finalizeResiduals();
105 
106  // Manage working weights
107  void updateWorkingFlags();
109 
110  // Delete the workspaces
111  void cleanUp();
112 
113  // Return pol basis
114  casacore::String polBasis() const;
115 
116  // VB2-like data access methods (mostly const)
117  casacore::Int nRows() const { return vb_->nRows(); };
118  casacore::Int nAntennas() const { return nAnt_; }; // stored on ctor
119  const casacore::Vector<int>& observationId() const { return vb_->observationId(); };
120  const casacore::Vector<casacore::Int>& arrayId() const { return vb_->arrayId(); };
121  const casacore::Vector<casacore::Int>& antenna1() const { return vb_->antenna1(); };
122  const casacore::Vector<casacore::Int>& antenna2() const { return vb_->antenna2(); };
125  const casacore::Vector<casacore::Int>& scan() const { return vb_->scan(); };
126  const casacore::Vector<casacore::Double>& time() const { return vb_->time(); };
128  const casacore::Vector<casacore::Int>& fieldId() const { return vb_->fieldId(); };
129  casacore::Int nChannels() const { return vb_->nChannels(); };
130  const casacore::Vector<casacore::Double>& freqs() const { return freqs_; }; // stored on ctor
131  casacore::Double centroidFreq() const { return centroidFreq_; }; // calc/stored on ctor
135 
136  // The feedPa
138 
139  // These are not const, because we will generally amend them:
143 
144  // <group>
145 
146  // Access functions
147  //
148  // Access to focus-channel slices of the flags, data, and model
151 
154 
157 
160 
161  // Working weights and flags
162  // const versions return infocus versions if working versions are empty!
167  (residFlagCube_p.nelements()==0 ?
169 
170 
171 
172  // Workspace for the residual visibilities
175 
176  // Workspace for flags of the residuals
179 
180  // Workspace for the differentiated residuals
183 
184  //</group>
185 
186  // Print out data, weights, flags for debugging purposes
187  void reportData();
188 
189 protected:
190 
191  // Handle copy from the input VB2
192  void initFromVB(const vi::VisBuffer2& vb);
193 
194 
195 private:
196 
197  // The underlying VisBuffer2
199 
200  // The number of antennas
202 
203  // The frequencies
204  // Currently, assumed uniform over rows
207 
208  // The correlation types
209  // Currently, assumed uniform over rows
210  // (private; used only by polBasis, currently)
212 
213  // The feedPa
214  // Currently, assumed uniform (per antenna) over rows
216 
217  // Array reference objects for things in the vb we need to mess with
221 
222 
223  // The current in-focus channel
225 
226  // actual storage for the data
231 
234 
238 
239 
240 };
241 
242 
243 class SDBList
244 {
245 public:
246 
247  // Construct empty list
248  SDBList();
249 
250  // Destructor
251  ~SDBList();
252 
253  // How many SDBs?
254  casacore::Int nSDB() const { return nSDB_; };
255 
256  // Generate a new SDB from an input VB2
257  void add(const vi::VisBuffer2& vb);
258 
259  // Access an SDB by index
261 
262  // Aggregate meta info
263  int aggregateObsId() const;
264  int aggregateScan() const;
265  int aggregateSpw() const;
266  int aggregateFld() const;
267  double aggregateTime() const;
268  double aggregateTimeCentroid() const;
269 
270  // Return pol basis
271  casacore::String polBasis() const;
272 
273  // How many antennas
274  // Currently, this insists on uniformity over all SDBs
275  int nAntennas() const;
276 
277  // How man correlations
278  // Currently, this insists on uniformity over all SDBs
279  int nCorrelations() const;
280 
281  // How many data chans?
282  // Currently, this insists on uniformity over all SDBs
283  int nChannels() const;
284 
285  // The frequencies
286  // Currently, this insists on uniformity over all SDBs
287  const casacore::Vector<double>& freqs() const;
288 
289  // ~Centroid frequency over all SDBs
291 
292  // Simple centroid of per-SDB centroidFreqs
293  // NB: this differs from centroidFreq in that it is _not_ a simple average of all SDB channel freqs
294  // this matters when different SDBs have different spws with different bandwidths/channelizations
295  // Eventually, this aggregation should be weighted by aggregate bandwidth, but this is not
296  // yet available from the VB2.
298 
299  // Does the SDBList contain usable data?
300  // (at least one SDB, with non-zero net weight)
301  bool Ok();
302 
303  // Aggregated methods
304  void enforceAPonData(const casacore::String& apmode);
305  void enforceSolveWeights(const casacore::Bool pHandOnly);
306  void sizeResiduals(const casacore::Int& nPar, const casacore::Int& nDiff);
307  void initResidWithModel();
308  void finalizeResiduals();
309  // NB: disable for now, may not be needed...
310  // void divideCorrByModel();
311 
312 
313  // Manage working flags and weights
314  void updateWorkingFlags();
315  void updateWorkingWeights(casacore::Bool doL1=false,casacore::Float clamp=0.0);
316 
317  // Print out data, weights, flags for debugging purposes
318  void reportData();
319 
320  // Extend baseline-dependent flags to all SDBs in the list
321  // This uniformizes the baseline-dependent flags
322  // NB: Cross-hands only, for now!
323  void extendBaselineFlags();
324 
325 private:
326 
327  // How many SDBs contained herein
329 
330  // Keep SDBs as a list of pointers
332 
333  // Aggregate frequency storage (so we can calculate once-ish and return a reference)
335  mutable double aggCentroidFreq_;
336  mutable bool aggCentroidFreqOK_;
337 
338 };
339 
340 
341 
342 } //# NAMESPACE CASA - END
343 
344 #endif
345 
const casacore::Vector< casacore::Int > & arrayId() const
casacore::Cube< casacore::Bool > fC_
casacore::Cube< casacore::Bool > & residFlagCube()
Workspace for flags of the residuals.
const casacore::Vector< casacore::Int > & fieldId() const
casacore::Vector< double > freqs_
The frequencies Currently, assumed uniform over rows.
int Int
Definition: aipstype.h:50
const casacore::Cube< casacore::Complex > & visCubeModel() const
SDBList()
Construct empty list.
double aggregateTimeCentroid() const
virtual const casacore::Vector< casacore::Int > & antenna2() const =0
size_t nelements() const
How many elements does this array have? Product of all axis lengths.
Definition: ArrayBase.h:99
casacore::Int nSDB() const
How many SDBs?
casacore::Array< casacore::Complex > diffResiduals_p
casacore::Int nAntennas() const
casacore::Int nSDB_
How many SDBs contained herein.
casacore::Int nChannels() const
casacore::Cube< casacore::Bool > workingFlagCube_p
void sizeResiduals(const casacore::Int &nPar, const casacore::Int &nDiff)
Size/init/finalize the residuals workspaces.
casacore::Double centroidFreq() const
~Centroid frequency over all SDBs
casacore::Cube< casacore::Float > infocusWtSpec_p
const casacore::Cube< casacore::Complex > & visCubeCorrected() const
casacore::Int nRows() const
VB2-like data access methods (mostly const)
SolveDataBuffer & operator()(casacore::Int i)
Access an SDB by index.
casacore::Int nAnt_
The number of antennas.
casacore::Double centroidFreq() const
casacore::Cube< casacore::Float > wS_
virtual const casacore::Vector< casacore::Int > & arrayId() const =0
casacore::Int focusChan_p
The current in-focus channel.
virtual const casacore::Cube< casacore::Complex > & visCubeCorrected() const =0
virtual const casacore::Matrix&lt;CStokesVector&gt; &amp; vis () const = 0; // [nF,nR] virtual void setVis (cas...
bool Ok()
Does the SDBList contain usable data? (at least one SDB, with non-zero net weight) ...
const casacore::Vector< double > & freqs() const
The frequencies Currently, this insists on uniformity over all SDBs.
casacore::Cube< casacore::Complex > residuals_p
casacore::Cube< casacore::Complex > & infocusVisCube()
virtual casacore::Int nPar()
M currently has just 2 complex parameters, i.e., both parallel hands.
void cleanUp()
Delete the workspaces.
~SDBList()
Destructor.
int aggregateScan() const
casacore::Vector< int > corrs_
The correlation types Currently, assumed uniform over rows (private; used only by polBasis...
void updateWorkingWeights(casacore::Bool, casacore::Float clamp=0.0)
void initResidWithModel()
virtual const casacore::Cube< casacore::Complex > & visCubeModel() const =0
virtual void reference(const Array< T > &other)
Make this cube a reference to other.
const casacore::Cube< casacore::Complex > & infocusModelVisCube() const
virtual const casacore::Vector< casacore::Int > & dataDescriptionIds() const =0
virtual casacore::Int dataDescriptionId () const = 0; virtual void setDataDescriptionId (casacore::In...
vi::VisBuffer2 * vb_
The underlying VisBuffer2.
void updateWorkingWeights(casacore::Bool doL1=false, casacore::Float clamp=0.0)
const casacore::Vector< casacore::Double > & freqs() const
casacore::Cube< casacore::Bool > residFlagCube_p
SolveDataBuffer is a container for VisBuffer2 data and related residual and differentiation results r...
const casacore::Cube< casacore::Bool > & residFlagCube() const
casacore::Vector< casacore::Bool > & flagRow()
These are not const, because we will generally amend them:
casacore::Cube< casacore::Complex > & residuals()
Workspace for the residual visibilities.
bool Ok()
Does SDB contain finite weight?
void enforceSolveWeights(const casacore::Bool pHandOnly)
Zero flagged weights, and optionally the cross-hand weights.
void finalizeResiduals()
const casacore::Cube< casacore::Complex > & residuals() const
casacore::Cube< casacore::Float > & weightSpectrum()
int aggregateSpw() const
void add(const vi::VisBuffer2 &vb)
Generate a new SDB from an input VB2.
casacore::Double aggregateCentroidFreq() const
Simple centroid of per-SDB centroidFreqs NB: this differs from centroidFreq in that it is not a simpl...
void sizeResiduals(const casacore::Int &nPar, const casacore::Int &nDiff)
casacore::Cube< casacore::Float > workingWtSpec_p
virtual const casacore::Vector< casacore::Int > & observationId() const =0
const casacore::Vector< casacore::Int > & scan() const
double Double
Definition: aipstype.h:55
void setFocusChan(const casacore::Int focusChan=-1)
Set the focus channel (forms references to focus-channel flag/data/model)
void enforceSolveWeights(const casacore::Bool pHandOnly)
virtual casacore::Int nRows() const =0
Returns the number of rows in this VisBuffer.
casacore::Int nCorrelations() const
virtual const casacore::Vector< casacore::Int > & scan() const =0
const casacore::Vector< casacore::Int > & dataDescriptionIds() const
casacore::Cube< casacore::Bool > & infocusFlagCube()
Access functions.
const casacore::Cube< casacore::Float > & infocusWtSpec() const
const casacore::Cube< casacore::Bool > & infocusFlagCube() const
casacore::String polBasis() const
Return pol basis.
int nChannels() const
How many data chans? Currently, this insists on uniformity over all SDBs.
const casacore::Vector< int > & observationId() const
casacore::Cube< casacore::Bool > & workingFlagCube()
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
void updateWorkingFlags()
Manage working weights.
casacore::Cube< casacore::Complex > infocusModelVisCube_p
virtual const casacore::Vector< casacore::Int > & fieldId() const =0
const casacore::Vector< casacore::Double > & timeCentroid() const
void reportData()
Print out data, weights, flags for debugging purposes.
float Float
Definition: aipstype.h:54
const casacore::Vector< casacore::Int > & antenna1() const
void reportData()
Print out data, weights, flags for debugging purposes.
SolveDataBuffer & operator=(const SolveDataBuffer &sdb)
Assignment.
casacore::Vector< casacore::Bool > fR_
Array reference objects for things in the vb we need to mess with.
casacore::Vector< float > feedPa_
The feedPa Currently, assumed uniform (per antenna) over rows.
casacore::Cube< casacore::Complex > infocusVisCube_p
A drop-in replacement for Block&lt;T*&gt;.
Definition: WProjectFT.h:54
virtual casacore::Int nCorrelations() const =0
Returns the number of correlations along the visCube correlation axis.
casacore::Cube< casacore::Bool > infocusFlagCube_p
actual storage for the data
int nAntennas() const
How many antennas Currently, this insists on uniformity over all SDBs.
casacore::Cube< casacore::Bool > & flagCube()
const casacore::Vector< casacore::Int > & antenna2() const
const casacore::Vector< casacore::Int > & spectralWindow() const
const casacore::Cube< casacore::Float > & const_workingWtSpec() const
double aggCentroidFreq_
SolveDataBuffer()
Generic ctor.
virtual const casacore::Vector< casacore::Double > & timeCentroid() const =0
casacore::PtrBlock< SolveDataBuffer * > SDB_
Keep SDBs as a list of pointers.
virtual casacore::Int nChannels() const =0
int nCorrelations() const
How man correlations Currently, this insists on uniformity over all SDBs.
virtual const casacore::Vector< casacore::Bool > & flagRow() const =0
VisBuffer2s encapsulate one chunk of visibility data for processing.
Definition: VisBuffer2.h:141
~SolveDataBuffer()
Destructor.
virtual const casacore::Cube< casacore::Bool > & flagCube() const =0
casacore::String polBasis() const
Return pol basis.
casacore::Vector< double > freqs_
Aggregate frequency storage (so we can calculate once-ish and return a reference) ...
void enforceAPonData(const casacore::String &apmode)
Aggregated methods.
void updateWorkingFlags()
NB: disable for now, may not be needed...
casacore::Array< casacore::Complex > & diffResiduals()
Workspace for the differentiated residuals.
const casacore::Cube< casacore::Complex > & infocusVisCube() const
casacore::Cube< casacore::Float > & infocusWtSpec()
double aggregateTime() const
casacore::Cube< casacore::Complex > & infocusModelVisCube()
String: the storage and methods of handling collections of characters.
Definition: String.h:223
void enforceAPonData(const casacore::String &apmode)
Divide corrected by model NB: disable for now, may not be needed...
void extendBaselineFlags()
Extend baseline-dependent flags to all SDBs in the list This uniformizes the baseline-dependent flags...
int aggregateFld() const
int aggregateObsId() const
Aggregate meta info.
virtual void reference(const Array< T > &other)
Create a reference to &quot;other&quot;, which must be of dimension one.
const casacore::Vector< casacore::Double > & time() const
const casacore::Vector< casacore::Float > & feedPa() const
The feedPa.
void initFromVB(const vi::VisBuffer2 &vb)
Handle copy from the input VB2.
const casacore::Array< casacore::Complex > & diffResiduals() const
const casacore::Cube< casacore::Bool > & const_workingFlagCube() const
virtual const casacore::Cube< casacore::Float > & weightSpectrum() const =0
virtual const casacore::Matrix&lt;casacore::Float&gt; &amp; weightMat () const = 0; // [nC,nR] virtual void set...
virtual const casacore::Vector< casacore::Double > & time() const =0
virtual const casacore::Vector< casacore::Int > & spectralWindows() const =0
Returns the spectral window ID for the specified row.
casacore::Cube< casacore::Float > & workingWtSpec()
Working weights and flags const versions return infocus versions if working versions are empty! ...