casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SingleDishSkyCal.h
Go to the documentation of this file.
1 //# SingleDishSkyCal.h: Single dish sky calibration
2 //# Copyright (C) 2014
3 //# Associated Universities, Inc. Washington DC, USA.
4 //# National Astronomical Observatory of Japan, Japan.
5 //#
6 //# This library is free software; you can redistribute it and/or modify it
7 //# under the terms of the GNU Library General Public License as published by
8 //# the Free Software Foundation; either version 2 of the License, or (at your
9 //# option) any later version.
10 //#
11 //# This library is distributed in the hope that it will be useful, but WITHOUT
12 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14 //# License for more details.
15 //#
16 //# You should have received a copy of the GNU Library General Public License
17 //# along with this library; if not, write to the Free Software Foundation,
18 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
19 //#
20 //# Correspondence concerning AIPS++ should be addressed as follows:
21 //# Internet email: aips2-request@nrao.edu.
22 //# Postal address: AIPS++ Project Office
23 //# National Radio Astronomy Observatory
24 //# 520 Edgemont Road
25 //# Charlottesville, VA 22903-2475 USA
26 //#
27 //#
28 //# $Id$
29 
30 //#! Create an include 'guard', containing your class name in the all
31 //#! upper case format implied below. This prevents multiple inclusion
32 //#! of this header file during pre-processing.
33 //#!
34 //#! Note that the leading "AIPS_" identifies the package to which your class
35 //#! belongs. Other packages include dish, vlbi, nfra, synthesis, atnf...
36 //#! If you are contributing a new class to one of these packages, be
37 //#! sure to replace "AIPS_" with (for instance) "DISH_" or "ATNF_".
38 
39 #ifndef _SYNTHESIS_SINGLEDISH_SKY_CAL_H_
40 #define _SYNTHESIS_SINGLEDISH_SKY_CAL_H_
41 
42 //#! Includes go here
45 
46 namespace casa { //# NAMESPACE CASA - BEGIN
47 
48 //# Forward Declarations
49 
50 // <summary>
51 //#! A one line summary of the class. This summary (shortened a bit
52 //#! if necessary so that it fits along with the "ClassFileName.h" in 75
53 //#! characters) should also appear as the first line of this file.
54 //#! Be sure to use the word "abstract" here if this class is, indeed,
55 //#! an abstract base class.
56 // </summary>
57 
58 // <use visibility=local> or <use visibility=export>
59 //#! If a class is intended for use by application programmers, or
60 //#! people writing other libraries, then specify that this class
61 //#! has an "export" visibility: it defines an interface that
62 //#! will be seen outside of its module. On the other hand, if the
63 //#! class has a "local" visibility, then it is known and used only
64 //#! within its module.
65 
66 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
67 //#! for example:
68 //#! <reviewed reviewer="pshannon@nrao.edu" date="1994/10/10" tests="tMyClass, t1MyClass" demos="dMyClass, d1MyClass">
69 //#! This is a well-designed class, without any obvious problems.
70 //#! However, the addition of several more demo programs would
71 //#! go a *long* way towards making it more usable.
72 //#! </reviewed>
73 //#!
74 //#! (In time, the documentation extractor will be able handle reviewed
75 //#! attributes spread over more than one line.)
76 //#!
77 //#! see "Coding Standards and Guidelines" (AIPS++ note 167) and
78 //#! "AIPS++ Code Review Process" (note 170) for a full explanation
79 //#! It is up to the class author (the programmer) to fill in these fields:
80 //#! tests, demos
81 //#! The reviewer fills in
82 //#! reviewer, date
83 // </reviewed>
84 
85 // <prerequisite>
86 //#! Classes or concepts you should understand before using this class.
87 // <li> SomeClass
88 // <li> SomeOtherClass
89 // <li> some concept
90 // </prerequisite>
91 //
92 // <etymology>
93 //#! Except when it is obvious (e.g., "casacore::Array") explain how the class name
94 //#! expresses the role of this class. Example: casacore::IPosition is short for
95 //#! "Integral Position" - a specialized integer vector for specifying
96 //#! array dimensions and indices.
97 // </etymology>
98 //
99 // <synopsis>
100 //#! What does the class do? How? For whom? This should include code
101 //#! fragments as appropriate to support text. Code fragments shall be
102 //#! delimited by <srcblock> </srcblock> tags. The synopsis section will
103 //#! usually be dozens of lines long.
104 // </synopsis>
105 //
106 // <example>
107 //#! One or two concise (~10-20 lines) examples, with a modest amount of
108 //#! text to support code fragments. Use <srcblock> and </srcblock> to
109 //#! delimit example code.
110 // </example>
111 //
112 // <motivation>
113 //#! Insight into a class is often provided by a description of
114 //#! the circumstances that led to its conception and design. Describe
115 //#! them here.
116 // </motivation>
117 //
118 // <templating arg=T>
119 //#! A list of member functions that must be provided by classes that
120 //#! appear as actual template arguments. For example: imagine that you
121 //#! are writing a templated sort class, which does a quicksort on a
122 //#! list of arbitrary objects. Anybody who uses your templated class
123 //#! must make sure that the actual argument class (say, casacore::Int or
124 //#! casacore::String or casacore::Matrix) has comparison operators defined.
125 //#! This tag must be repeated for each template formal argument in the
126 //#! template class definition -- that's why this tag has the "arg" attribute.
127 //#! (Most templated classes, however, are templated on only a single
128 //#! argument.)
129 // <li>
130 // <li>
131 // </templating>
132 //
133 // <thrown>
134 //#! A list of exceptions thrown if errors are discovered in the function.
135 //#! This tag will appear in the body of the header file, preceding the
136 //#! declaration of each function which throws an exception.
137 // <li>
138 // <li>
139 // </thrown>
140 //
141 // <todo asof="yyyy/mm/dd">
142 //#! A casacore::List of bugs, limitations, extensions or planned refinements.
143 //#! The programmer should fill in a date in the "asof" field, which
144 //#! will usually be the date at which the class is submitted for review.
145 //#! If, during the review, new "todo" items come up, then the "asof"
146 //#! date should be changed to the end of the review period.
147 // <li> add this feature
148 // <li> fix this bug
149 // <li> start discussion of this possible extension
150 // </todo>
151 
153 {
154 public:
155 
156  // Constructor
158  SingleDishSkyCal(const MSMetaInfoForCal& msmc); // preferred ctor
160 
161  // Destructor
162  virtual ~SingleDishSkyCal();
163 
164  // Return the type of this calibration matrix (actual type of derived class).
165  // (Must be implemented in specializations!)
166  //
167  // 2015/03/19 (gmoellen): Use VisCal::M here, so that it is sorted
168  // correctly in the VisEquation relative to "B TSYS"
169  virtual Type type() { return VisCal::M; }
170 
171  // Return type name as string (ditto)
172  virtual casacore::String typeName() { return "SD SKY"; }
173  virtual casacore::String longTypeName() { return "SD SKY (sky spectra)"; }
174 
175  // Return casacore::Matrix type
176  // single dish calibration is antenna-based
178 
179  // Mueller matrix type (must be implemented in Mueller specializations!)
181 
182  // Return the parameter type
183  // so far single dish calibration is real
185 
186  // Number of pars per ant/bln
187 // virtual casacore::Int nPar() { return nCorr_[currSpw()]; }
188  virtual casacore::Int nPar() { return 2; }
189 
190  // Total number of (complex) parameters per solve
191  // (specialize to jive with ant- or bln-basedness, etc.)
192  virtual casacore::Int nTotalPar() { return nPar(); }
193 
194  // Does normalization by MODEL_DATA commute with this VisCal?
195  // (if so, permits pre-solve time-averaging)
196  virtual casacore::Bool normalizable() { return false; }
197 
198  // Hazard a guess at the parameters (solveCPar) given the data
199  virtual void guessPar(VisBuffer& vb);
200 
201  // Differentiate VB model w.r.t. Cal parameters (no 2nd derivative yet)
202  virtual void differentiate(CalVisBuffer& cvb);
203  virtual void differentiate(VisBuffer& vb,
207 
208  // Differentiate VB model w.r.t. Source parameters
209  virtual void diffSrc(VisBuffer& vb,
211 
212  // Apply refant (implemented in SVJ)
213  virtual void reReference() {}
214 
215  // Accumulate another VisCal onto this one
216  virtual void accumulate(SolvableVisCal* incr,
217  const casacore::Vector<casacore::Int>& fields);
218 
219  // Determine and apply flux density scaling
220  virtual void fluxscale(const casacore::String& outfile,
221  const casacore::Vector<casacore::Int>& refFieldIn,
222  const casacore::Vector<casacore::Int>& tranFieldIn,
223  const casacore::Vector<casacore::Int>& inRefSpwMap,
224  const casacore::Vector<casacore::String>& fldNames,
225  const casacore::Float& inGainThres,
226  const casacore::String& antSel,
227  const casacore::String& timerangeSel,
228  const casacore::String& scanSel,
229  fluxScaleStruct& oFluxScaleStruct,
230  const casacore::String& oListFile,
231  const casacore::Bool& incremental,
232  const casacore::Int& fitorder,
233  const casacore::Bool& display);
234 
235  // Use generic data gathering mechanism for solve
236  virtual casacore::Bool useGenericGatherForSolve() { return false; }
237 
238  // Report state:
239  virtual void listCal(const casacore::Vector<casacore::Int> ufldids, const casacore::Vector<casacore::Int> uantids,
240  const casacore::Matrix<casacore::Int> uchanids, //const casacore::Int& spw, const casacore::Int& chan,
241  const casacore::String& listfile="",const casacore::Int& pagerows=50);
242 
243 
244  // Local setApply
246  virtual void setApply(const casacore::Record& apply);
247 
248  // In general, we are freq-dep
249  virtual casacore::Bool freqDepPar() { return true; }
250 
251  // New CalTable handling
252  virtual void keepNCT();
253 
254  // Self- gather and/or solve prototypes
255  // (triggered by useGenericGatherForSolve=F or useGenericSolveOne=F)
256  virtual void selfGatherAndSolve(VisSet& vs, VisEquation& ve);
257 
258 protected:
259 
260  // The number of sets of parameters under consideration
261  // This states size of third axis of SolveAllRPar
262  virtual casacore::Int& nElem() { return nAnt(); }
263 
264  // Number of Calibration matrices on ant/bln axis
265  virtual casacore::Int nCalMat() { return nAnt(); }
266 
267  // Are the parameters the matrix elements?
268  // (or is a non-trivial calculation required?)
269  // (Must be implemented in specializations!)
270  virtual casacore::Bool trivialMuellerElem() { return false; }
271 
272  // Initialize solve parameters (shape)
273  virtual void initSolvePar();
274 
275  // Invalidate diff cal matrices generically
276  inline virtual void invalidateDiffCalMat() {}
277 
278  // overwride syncMeta2
279  virtual void syncMeta2(const vi::VisBuffer2& vb);
280 
281  // Sync matrices generically for current meta data
282  virtual void syncCalMat(const casacore::Bool& doInv=false);
283 
284  // Synchronize the differentiated calibration
285  virtual void syncDiffMat();
286 
287  // Synchronize weight scale factors
288  virtual void syncWtScale();
289 
290  // Perform weight scale calculation (specializable)
291  template<class ScalingScheme>
292  void calcWtScale();
293 
294  // Normalize a (complex) solution array (generic)
296 
297  // Invalidate cal matrices generically
298  virtual void invalidateCalMat() {}
299 
300  // Row-by-row apply to a casacore::Cube<casacore::Complex> (generic)
301  virtual void applyCal(VisBuffer& vb, casacore::Cube<casacore::Complex>& Vout,casacore::Bool trial=false);
302  virtual void applyCal2(vi::VisBuffer2& vb,
304  casacore::Bool trial=false);
305 
306  // Fill caltable by traversing MS
307  // Accessor is responsible for accessing data stored either
308  // in DATA or FLOAT_DATA
309  template<class Accessor>
310  inline void traverseMS(casacore::MeasurementSet const &ms);
311 
312  // access to current calibration data
317 
318  // arrange data selection according to calibration mode
320 
321  // current antenna
324 
325  // Single Dish Calibration algebra wrapper (per Spw)
328 
329  // Current Sky spectra
332 
333 private:
334  void initializeSky();
335  void finalizeSky();
336  void updateWt2(casacore::Matrix<casacore::Float> &weight, const casacore::Int& antenna1);
337  void initializeCorr();
338 
339  // number of correlations per spw
341 
342  // list of timestamps and intervals for each observation, spw, and antenna
343  // as a nested map with key obsId (outermost), spwId, antennaId (innermost)
344  std::map<std::pair<casacore::Int, casacore::Int>, std::map<casacore::Int, casacore::Matrix<casacore::Double> > > wtScaleData_;
345 };
346 
348 {
349 public:
350 
351  // Constructor
353  SingleDishPositionSwitchCal(const MSMetaInfoForCal& msmc); // preferred ctor
355 
356  // Destructor
358 
359  // Return type name as string (ditto)
360  virtual casacore::String typeName() { return "SDSKY_PS"; }
361  virtual casacore::String longTypeName() { return "SDSKY_PS (position switch sky subtraction)"; }
362 
363  // data selection for position switch calibration
365 
366 };
367 
369 {
370 public:
371 
372  // Constructor
374  SingleDishRasterCal(const MSMetaInfoForCal& msmc); // preferred ctor
376 
377  // Destructor
378  virtual ~SingleDishRasterCal();
379 
380  // Return type name as string (ditto)
381  virtual casacore::String typeName() { return "SDSKY_RASTER"; }
382  virtual casacore::String longTypeName() { return "SDSKY_RASTER (position switch sky subtraction specific to OTF raster observation)"; }
383 
384  // local setSolve
385  virtual void setSolve(const casacore::Record& solve);
386 
387  // data selection specific to otfraster mode
389 
390 private:
391  // edge detection parameter for otfraster mode
394 };
395 
397 {
398 public:
399 
400  // Constructor
402  // SingleDishOtfCal(const MSMetaInfoForCal& msmc); // preferred ctor ****ctor needs an MS!
403  // Renaud: disabledSingleDishOtfCal(const casacore::Int& nAnt);
404 
405  // Destructor
406  virtual ~SingleDishOtfCal();
407 
408  // Return type name as string (ditto)
409  virtual casacore::String typeName() { return "SDSKY_OTF"; }
410  virtual casacore::String longTypeName() { return "SDSKY_OTF (position switch sky subtraction specific to OTF fast scan)"; }
411 
412  // casacore::Data selection specific to otf mode
414  virtual void setSolve(const casacore::Record& solve);
415 
416 private:
417  // Edge detection parameters for otf mode
420 
421  // casacore::MeasurementSet filtered with user-specified selection
423 
424 };
425 
426 } //# NAMESPACE CASA - END
427 
428 #endif /* _SYNTHESIS_SINGLEDISH_SKY_CAL_H_ */
429 
430 
virtual casacore::Bool useGenericGatherForSolve()
Use generic data gathering mechanism for solve.
casacore::Float fraction_
Edge detection parameters for otf mode.
int Int
Definition: aipstype.h:50
const casacore::MeasurementSet & msSel_
casacore::MeasurementSet filtered with user-specified selection
virtual casacore::MeasurementSet selectMS(casacore::MeasurementSet const &ms)=0
arrange data selection according to calibration mode
std::map< std::pair< casacore::Int, casacore::Int >, std::map< casacore::Int, casacore::Matrix< casacore::Double > > > wtScaleData_
list of timestamps and intervals for each observation, spw, and antenna as a nested map with key obsI...
virtual casacore::Int nPar()
Number of pars per ant/bln virtual casacore::Int nPar() { return nCorr_[currSpw()]; }...
virtual ~SingleDishPositionSwitchCal()
Destructor.
virtual Type type()
Return the type of this calibration matrix (actual type of derived class).
virtual casacore::MeasurementSet selectMS(casacore::MeasurementSet const &ms)
data selection specific to otfraster mode
virtual casacore::Int nCalMat()
Number of Calibration matrices on ant/bln axis.
casacore::Vector< casacore::Double > interval_
void updateWt2(casacore::Matrix< casacore::Float > &weight, const casacore::Int &antenna1)
void apply(const Jones &j1, VisVector &v, const Jones &j2)
Apply a pair of Jones to a VisVector:
virtual casacore::MeasurementSet selectMS(casacore::MeasurementSet const &ms)
casacore::Data selection specific to otf mode
void traverseMS(casacore::MeasurementSet const &ms)
Fill caltable by traversing MS Accessor is responsible for accessing data stored either in DATA or FL...
virtual casacore::String longTypeName()
SingleDishPositionSwitchCal(VisSet &vs)
Constructor.
CalVisBuffer extends VisBuffer to support storage and recall of associated residual and differentiate...
Definition: CalVisBuffer.h:65
SingleDishRasterCal(VisSet &vs)
Constructor.
void calcWtScale()
Perform weight scale calculation (specializable)
virtual casacore::String longTypeName()
casacore::PtrBlock< casacore::Cube< casacore::Bool > * > currentSkyOK_
virtual void diffSrc(VisBuffer &vb, casacore::Array< casacore::Complex > &dV)
Differentiate VB model w.r.t.
virtual void selfGatherAndSolve(VisSet &vs, VisEquation &ve)
Self- gather and/or solve prototypes (triggered by useGenericGatherForSolve=F or useGenericSolveOne=F...
SingleDishOtfCal(VisSet &vs)
Constructor.
virtual casacore::String longTypeName()
virtual void setApply()
Set the application parameters.
virtual casacore::MeasurementSet selectMS(casacore::MeasurementSet const &ms)
data selection for position switch calibration
virtual void listCal(const casacore::Vector< casacore::Int > ufldids, const casacore::Vector< casacore::Int > uantids, const casacore::Matrix< casacore::Int > uchanids, const casacore::String &listfile="", const casacore::Int &pagerows=50)
Report state:
casacore::Int & nAnt()
Definition: VisCal.h:237
virtual casacore::String typeName()
Return type name as string (ditto)
VisVector & V()
Access to matrix renderings of Visibilities.
Definition: VisCal.h:270
virtual casacore::String typeName()
Return type name as string (ditto)
virtual void guessPar(VisBuffer &vb)
Hazard a guess at the parameters (solveCPar) given the data.
casacore::PtrBlock< casacore::Cube< casacore::Complex > * > currentSky_
Current Sky spectra.
SkyCal< casacore::Float, casacore::Float > & engineF()
virtual void differentiate(CalVisBuffer &cvb)
Differentiate VB model w.r.t.
SingleDishSkyCal(VisSet &vs)
Constructor.
virtual void applyCal(VisBuffer &vb, casacore::Cube< casacore::Complex > &Vout, casacore::Bool trial=false)
Row-by-row apply to a casacore::Cube&lt;casacore::Complex&gt; (generic)
struct casa::SolvableVisCal::fluxScaleStruct fluxScaleStruct
virtual VisCalEnum::VCParType parType()
Return the parameter type so far single dish calibration is real.
virtual void applyCal2(vi::VisBuffer2 &vb, casacore::Cube< casacore::Complex > &Vout, casacore::Cube< casacore::Float > &Wout, casacore::Bool trial=false)
casacore::PtrBlock< SkyCal< casacore::Complex, casacore::Complex > * > engineC_
Single Dish Calibration algebra wrapper (per Spw)
Type
Allowed types of VisCal matrices - &#39;correct&#39; order enum Type{UVMOD,Mf,M,K,B,G,D,C,E,P,T,EP,F}; enum Type{Test=0,ANoise,M,KAntPos,K,B,G,J,D,X,C,P,E,T,F,A,ALL};.
Definition: VisCal.h:62
virtual casacore::Bool normalizable()
Does normalization by MODEL_DATA commute with this VisCal? (if so, permits pre-solve time-averaging) ...
virtual casacore::String typeName()
Return type name as string (ditto)
LatticeExprNode amp(const LatticeExprNode &left, const LatticeExprNode &right)
This function finds sqrt(left^2+right^2).
virtual void keepNCT()
New CalTable handling.
A hierarchical collection of named fields of various types.
Definition: Record.h:180
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
casacore::Cube< casacore::Bool > & currentSkyOK()
virtual ~SingleDishSkyCal()
Destructor.
casacore::Float pixel_scale_
virtual Mueller::MuellerType muellerType()
Mueller matrix type (must be implemented in Mueller specializations!)
virtual void syncWtScale()
Synchronize weight scale factors.
casacore::Int & currSpw()
Current in-focus spw.
Definition: VisCal.h:247
float Float
Definition: aipstype.h:54
casacore::PtrBlock< SkyCal< casacore::Float, casacore::Float > * > engineF_
virtual ~SingleDishRasterCal()
Destructor.
A drop-in replacement for Block&lt;T*&gt;.
Definition: WProjectFT.h:54
casacore::Int currAnt_
current antenna
virtual VisCalEnum::MatrixType matrixType()
Return casacore::Matrix type single dish calibration is antenna-based.
SkyCal< casacore::Complex, casacore::Complex > & engineC()
A Table intended to hold astronomical data (a set of Measurements).
virtual void syncMeta2(const vi::VisBuffer2 &vb)
overwride syncMeta2
casacore::Vector< casacore::Int > nCorr_
number of correlations per spw
virtual casacore::Bool freqDepPar()
In general, we are freq-dep.
virtual void reReference()
Apply refant (implemented in SVJ)
virtual ~SingleDishOtfCal()
SingleDishOtfCal(const MSMetaInfoForCal&amp; msmc); // preferred ctor ****ctor needs an MS! Renaud: disab...
virtual void fluxscale(const casacore::String &outfile, const casacore::Vector< casacore::Int > &refFieldIn, const casacore::Vector< casacore::Int > &tranFieldIn, const casacore::Vector< casacore::Int > &inRefSpwMap, const casacore::Vector< casacore::String > &fldNames, const casacore::Float &inGainThres, const casacore::String &antSel, const casacore::String &timerangeSel, const casacore::String &scanSel, fluxScaleStruct &oFluxScaleStruct, const casacore::String &oListFile, const casacore::Bool &incremental, const casacore::Int &fitorder, const casacore::Bool &display)
Determine and apply flux density scaling.
virtual casacore::String longTypeName()
VisBuffer2s encapsulate one chunk of visibility data for processing.
Definition: VisBuffer2.h:141
casacore::Cube< casacore::Complex > & currentSky()
access to current calibration data
virtual void invalidateCalMat()
Invalidate cal matrices generically.
const MSMetaInfoForCal & msmc() const
Access to the MSMetaInfoForCal (throws if none)
Definition: VisCal.h:338
casacore::Vector< T > solve(const casacore::Matrix< T > &A, const casacore::Vector< T > &y, double &ferr, double &berr)
Given a matrix &quot;A&quot;, and given some vector &quot;y&quot; which is the right hand side of the equation &quot;Ax=y&quot;...
String: the storage and methods of handling collections of characters.
Definition: String.h:223
VisBuffers encapsulate one chunk of visibility data for processing.
Definition: VisBuffer.h:153
virtual casacore::Bool trivialMuellerElem()
Are the parameters the matrix elements? (or is a non-trivial calculation required?) (Must be implemented in specializations!)
casacore::Float fraction_
edge detection parameter for otfraster mode
virtual void setSolve()
Set the solving parameters.
virtual casacore::Int nTotalPar()
Total number of (complex) parameters per solve (specialize to jive with ant- or bln-basedness, etc.)
virtual void accumulate(SolvableVisCal *incr, const casacore::Vector< casacore::Int > &fields)
Accumulate another VisCal onto this one.
virtual void syncCalMat(const casacore::Bool &doInv=false)
Sync matrices generically for current meta data.
virtual void syncDiffMat()
Synchronize the differentiated calibration.
virtual casacore::Int & nElem()
The number of sets of parameters under consideration This states size of third axis of SolveAllRPar...
virtual casacore::Float calcPowerNorm(casacore::Array< casacore::Float > &amp, const casacore::Array< casacore::Bool > &ok)
Normalize a (complex) solution array (generic)
virtual void invalidateDiffCalMat()
Invalidate diff cal matrices generically.
virtual void initSolvePar()
Initialize solve parameters (shape)
virtual casacore::String typeName()
Return type name as string (ditto)