SingleDishSkyCal.h

Go to the documentation of this file.
00001 //# SingleDishSkyCal.h: Single dish sky calibration
00002 //# Copyright (C) 2014
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //# National Astronomical Observatory of Japan, Japan.
00005 //#
00006 //# This library is free software; you can redistribute it and/or modify it
00007 //# under the terms of the GNU Library General Public License as published by
00008 //# the Free Software Foundation; either version 2 of the License, or (at your
00009 //# option) any later version.
00010 //#
00011 //# This library is distributed in the hope that it will be useful, but WITHOUT
00012 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00014 //# License for more details.
00015 //#
00016 //# You should have received a copy of the GNU Library General Public License
00017 //# along with this library; if not, write to the Free Software Foundation,
00018 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00019 //#
00020 //# Correspondence concerning AIPS++ should be addressed as follows:
00021 //#        Internet email: aips2-request@nrao.edu.
00022 //#        Postal address: AIPS++ Project Office
00023 //#                        National Radio Astronomy Observatory
00024 //#                        520 Edgemont Road
00025 //#                        Charlottesville, VA 22903-2475 USA
00026 //#
00027 //#
00028 //# $Id$
00029 
00030 //#! Create an include 'guard', containing your class name in the all
00031 //#! upper case format implied below.  This prevents multiple inclusion
00032 //#! of this header file during pre-processing.
00033 //#!
00034 //#! Note that the leading "AIPS_" identifies the package to which your class
00035 //#! belongs.  Other packages include dish, vlbi, nfra, synthesis, atnf...
00036 //#! If you are contributing a new class to one of these packages, be
00037 //#! sure to replace "AIPS_" with (for instance) "DISH_" or "ATNF_".
00038 
00039 #ifndef _SYNTHESIS_SINGLEDISH_SKY_CAL_H_
00040 #define _SYNTHESIS_SINGLEDISH_SKY_CAL_H_
00041 
00042 //#! Includes go here
00043 #include <synthesis/MeasurementComponents/SolvableVisCal.h>
00044 #include <synthesis/MeasurementComponents/SkyCal.h>
00045 
00046 namespace casa { //# NAMESPACE CASA - BEGIN
00047 
00048 //# Forward Declarations
00049 
00050 // <summary>
00051 //#! A one line summary of the class.   This summary (shortened a bit
00052 //#! if necessary so that it fits along with the "ClassFileName.h" in 75
00053 //#! characters) should also appear as the first line of this file.
00054 //#! Be sure to use the word "abstract" here if this class is, indeed,
00055 //#! an abstract base class.
00056 // </summary>
00057 
00058 // <use visibility=local>   or   <use visibility=export>
00059 //#! If a class is intended for use by application programmers, or
00060 //#! people writing other libraries, then specify that this class
00061 //#! has an "export" visibility:  it defines an interface that
00062 //#! will be seen outside of its module.  On the other hand, if the
00063 //#! class has a "local" visibility, then it is known and used only
00064 //#! within its module.
00065 
00066 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00067 //#! for example:
00068 //#!  <reviewed reviewer="pshannon@nrao.edu" date="1994/10/10" tests="tMyClass, t1MyClass" demos="dMyClass, d1MyClass">
00069 //#!  This is a well-designed class, without any obvious problems.
00070 //#!  However, the addition of several more demo programs would
00071 //#!  go a *long* way towards making it more usable.
00072 //#!  </reviewed>
00073 //#!
00074 //#! (In time, the documentation extractor will be able handle reviewed
00075 //#! attributes spread over more than one line.)
00076 //#!
00077 //#! see "Coding Standards and Guidelines"  (AIPS++ note 167) and
00078 //#! "AIPS++ Code Review Process" (note 170) for a full explanation
00079 //#! It is up to the class author (the programmer) to fill in these fields:
00080 //#!     tests, demos
00081 //#! The reviewer fills in
00082 //#!     reviewer, date
00083 // </reviewed>
00084 
00085 // <prerequisite>
00086 //#! Classes or concepts you should understand before using this class.
00087 //   <li> SomeClass
00088 //   <li> SomeOtherClass
00089 //   <li> some concept
00090 // </prerequisite>
00091 //
00092 // <etymology>
00093 //#! Except when it is obvious (e.g., "Array") explain how the class name
00094 //#! expresses the role of this class.  Example: IPosition is short for
00095 //#! "Integral Position" - a specialized integer vector for specifying
00096 //#! array dimensions and indices.
00097 // </etymology>
00098 //
00099 // <synopsis>
00100 //#! What does the class do?  How?  For whom?  This should include code
00101 //#! fragments as appropriate to support text.  Code fragments shall be
00102 //#! delimited by <srcblock> </srcblock> tags.  The synopsis section will
00103 //#! usually be dozens of lines long.
00104 // </synopsis>
00105 //
00106 // <example>
00107 //#! One or two concise (~10-20 lines) examples, with a modest amount of
00108 //#! text to support code fragments.  Use <srcblock> and </srcblock> to
00109 //#! delimit example code.
00110 // </example>
00111 //
00112 // <motivation>
00113 //#! Insight into a class is often provided by a description of
00114 //#! the circumstances that led to its conception and design.  Describe
00115 //#! them here.
00116 // </motivation>
00117 //
00118 // <templating arg=T>
00119 //#! A list of member functions that must be provided by classes that
00120 //#! appear as actual template arguments.  For example:  imagine that you
00121 //#! are writing a templated sort class, which does a quicksort on a
00122 //#! list of arbitrary objects.  Anybody who uses your templated class
00123 //#! must make sure that the actual argument class (say, Int or
00124 //#! String or Matrix) has comparison operators defined.
00125 //#! This tag must be repeated for each template formal argument in the
00126 //#! template class definition -- that's why this tag has the "arg" attribute.
00127 //#! (Most templated classes, however, are templated on only a single
00128 //#! argument.)
00129 //    <li>
00130 //    <li>
00131 // </templating>
00132 //
00133 // <thrown>
00134 //#! A list of exceptions thrown if errors are discovered in the function.
00135 //#! This tag will appear in the body of the header file, preceding the
00136 //#! declaration of each function which throws an exception.
00137 //    <li>
00138 //    <li>
00139 // </thrown>
00140 //
00141 // <todo asof="yyyy/mm/dd">
00142 //#! A List of bugs, limitations, extensions or planned refinements.
00143 //#! The programmer should fill in a date in the "asof" field, which
00144 //#! will usually be the date at which the class is submitted for review.
00145 //#! If, during the review, new "todo" items come up, then the "asof"
00146 //#! date should be changed to the end of the review period.
00147 //   <li> add this feature
00148 //   <li> fix this bug
00149 //   <li> start discussion of this possible extension
00150 // </todo>
00151 
00152 class SingleDishSkyCal : public SolvableVisCal
00153 {
00154 public:
00155 
00156   // Constructor
00157   SingleDishSkyCal(VisSet& vs);
00158   SingleDishSkyCal(const MSMetaInfoForCal& msmc);  // preferred ctor
00159   SingleDishSkyCal(const Int& nAnt);
00160 
00161   // Destructor
00162   virtual ~SingleDishSkyCal();
00163 
00164   // Return the type of this calibration matrix (actual type of derived class).
00165   //    (Must be implemented in specializations!)
00166   //
00167   // 2015/03/19 (gmoellen): Use VisCal::M here, so that it is sorted 
00168   //    correctly in the VisEquation relative to "B TSYS"
00169   virtual Type type() { return VisCal::M; }
00170   
00171   // Return type name as string (ditto)
00172   virtual String typeName()     { return "SD SKY"; }
00173   virtual String longTypeName() { return "SD SKY (sky spectra)"; }
00174 
00175   // Return Matrix type
00176   // single dish calibration is antenna-based
00177   virtual VisCalEnum::MatrixType matrixType() { return VisCalEnum::JONES; }
00178 
00179   // Mueller matrix type (must be implemented in Mueller specializations!)
00180   virtual Mueller::MuellerType muellerType() { return Mueller::AddDiag2; }
00181 
00182   // Return the parameter type
00183   // so far single dish calibration is real
00184   virtual VisCalEnum::VCParType parType() { return VisCalEnum::REAL; }
00185 
00186   // Number of pars per ant/bln
00187   // TODO: nPar should refer numCorr in input MS
00188   virtual Int nPar() { return 2; }
00189 
00190   // Total number of (complex) parameters per solve
00191   //  (specialize to jive with ant- or bln-basedness, etc.)
00192   virtual Int nTotalPar() { return nPar(); }
00193 
00194   // Does normalization by MODEL_DATA commute with this VisCal?
00195   //   (if so, permits pre-solve time-averaging)
00196   virtual Bool normalizable() { return False; }
00197 
00198   // Hazard a guess at the parameters (solveCPar) given the data
00199   virtual void guessPar(VisBuffer& vb);
00200 
00201   // Differentiate VB model w.r.t. Cal  parameters (no 2nd derivative yet)
00202   virtual void differentiate(CalVisBuffer& cvb);
00203   virtual void differentiate(VisBuffer& vb,        
00204                              Cube<Complex>& V,     
00205                              Array<Complex>& dV,
00206                              Matrix<Bool>& Vflg);
00207 
00208   // Differentiate VB model w.r.t. Source parameters
00209   virtual void diffSrc(VisBuffer& vb,        
00210                        Array<Complex>& dV);
00211 
00212   // Apply refant (implemented in SVJ)
00213   virtual void reReference() {}
00214 
00215   // Accumulate another VisCal onto this one
00216   virtual void accumulate(SolvableVisCal* incr,
00217                           const Vector<Int>& fields);
00218 
00219   // Determine and apply flux density scaling
00220   virtual void fluxscale(const String& outfile,
00221                          const Vector<Int>& refFieldIn,
00222                          const Vector<Int>& tranFieldIn,
00223                          const Vector<Int>& inRefSpwMap,
00224                          const Vector<String>& fldNames,
00225                          const Float& inGainThres,
00226                          const String& antSel,
00227                          const String& timerangeSel,
00228                          const String& scanSel,
00229                          fluxScaleStruct& oFluxScaleStruct,
00230                          const String& oListFile,
00231                          const Bool& incremental,
00232                          const Int& fitorder,
00233                          const Bool& display);
00234 
00235   // Use generic data gathering mechanism for solve
00236   virtual Bool useGenericGatherForSolve() { return False; }
00237 
00238   // Report state:
00239   virtual void listCal(const Vector<Int> ufldids, const Vector<Int> uantids,
00240                        const Matrix<Int> uchanids,  //const Int& spw, const Int& chan,
00241                        const String& listfile="",const Int& pagerows=50);
00242 
00243 
00244   // Local setApply
00245   virtual void setApply(const Record& apply);
00246 
00247   // In general, we are freq-dep
00248   virtual Bool freqDepPar() { return True; }
00249   
00250   // New CalTable handling
00251   virtual void keepNCT();
00252 
00253   // Self- gather and/or solve prototypes
00254   //  (triggered by useGenericGatherForSolve=F or useGenericSolveOne=F)
00255   virtual void selfGatherAndSolve(VisSet& vs, VisEquation& ve);
00256 
00257 protected:
00258 
00259   // The number of sets of parameters under consideration
00260   // This states size of third axis of SolveAllRPar
00261   virtual Int& nElem() { return nAnt(); }
00262 
00263   // Number of Calibration matrices on ant/bln axis
00264   virtual Int nCalMat() { return nAnt(); }
00265 
00266   // Are the parameters the matrix elements? 
00267   //   (or is a non-trivial calculation required?)
00268   //    (Must be implemented in specializations!)
00269   virtual Bool trivialMuellerElem() { return False; }
00270 
00271   // Initialize solve parameters (shape)
00272   virtual void initSolvePar();
00273 
00274   // Invalidate diff cal matrices generically 
00275   inline virtual void invalidateDiffCalMat() {}
00276 
00277   // overwride syncMeta2
00278   virtual void syncMeta2(const vi::VisBuffer2& vb);
00279 
00280   // Sync matrices generically for current meta data 
00281   virtual void syncCalMat(const Bool& doInv=False);
00282 
00283   // Synchronize the differentiated calibration 
00284   virtual void syncDiffMat();
00285 
00286   // Synchronize weight scale factors
00287   virtual void syncWtScale();
00288 
00289   // Perform weight scale calculation (specializable)
00290   template<class ScalingScheme>
00291   void calcWtScale();
00292 
00293   // Normalize a (complex) solution array (generic)
00294   virtual Float calcPowerNorm(Array<Float>& amp, const Array<Bool>& ok);
00295 
00296   // Invalidate cal matrices generically 
00297   virtual void invalidateCalMat() {}
00298 
00299   // Row-by-row apply to a Cube<Complex> (generic)
00300   virtual void applyCal(VisBuffer& vb, Cube<Complex>& Vout,Bool trial=False);
00301   virtual void applyCal2(vi::VisBuffer2& vb, 
00302                          Cube<Complex>& Vout,Cube<Float>& Wout,
00303                          Bool trial=False);
00304 
00305   // Fill caltable by traversing MS
00306   // Accessor is responsible for accessing data stored either
00307   // in DATA or FLOAT_DATA
00308   template<class Accessor>
00309   inline void traverseMS(MeasurementSet const &ms);
00310 
00311   // access to current calibration data
00312   inline Cube<Complex> &currentSky() { return (*currentSky_[currSpw()]); }
00313   inline Cube<Bool> &currentSkyOK() { return (*currentSkyOK_[currSpw()]); }
00314   inline SkyCal<Complex, Complex> &engineC() { return (*engineC_[currSpw()]); }
00315   inline SkyCal<Float, Float> &engineF() { return (*engineF_[currSpw()]); }
00316 
00317   // arrange data selection according to calibration mode
00318   virtual String configureSelection(MeasurementSet const &ms) = 0;
00319 
00320   // current antenna
00321   Int currAnt_;
00322   Vector<Double> interval_;
00323 
00324   // Single Dish Calibration algebra wrapper (per Spw)
00325   PtrBlock<SkyCal<Complex, Complex> *> engineC_;
00326   PtrBlock<SkyCal<Float, Float> *> engineF_;
00327 
00328   // Current Sky spectra
00329   PtrBlock<Cube<Complex> *> currentSky_; // [nSpw]([1,2],nChanMat,nAnt)
00330   PtrBlock<Cube<Bool> *> currentSkyOK_;  // [nSpw]([1,2],nChanMat,nAnt)
00331 
00332 private:
00333   void initializeSky();
00334   void finalizeSky();
00335   void updateWt2(Matrix<Float> &weight, const Int& antenna1);
00336 };
00337 
00338 class SingleDishPositionSwitchCal : public SingleDishSkyCal 
00339 {
00340 public:
00341 
00342   // Constructor
00343   SingleDishPositionSwitchCal(VisSet& vs);
00344   SingleDishPositionSwitchCal(const MSMetaInfoForCal& msmc);  // preferred ctor
00345   SingleDishPositionSwitchCal(const Int& nAnt);
00346 
00347   // Destructor
00348   virtual ~SingleDishPositionSwitchCal();
00349 
00350   // Return type name as string (ditto)
00351   virtual String typeName()     { return "SDSKY_PS"; }
00352   virtual String longTypeName() { return "SDSKY_PS (position switch sky subtraction)"; }
00353 
00354   // data selection for position switch calibration
00355   virtual String configureSelection(MeasurementSet const &ms);
00356 
00357 };
00358   
00359 class SingleDishRasterCal : public SingleDishSkyCal 
00360 {
00361 public:
00362 
00363   // Constructor
00364   SingleDishRasterCal(VisSet& vs);
00365   SingleDishRasterCal(const MSMetaInfoForCal& msmc);  // preferred ctor
00366   SingleDishRasterCal(const Int& nAnt);
00367 
00368   // Destructor
00369   virtual ~SingleDishRasterCal();
00370 
00371   // Return type name as string (ditto)
00372   virtual String typeName()     { return "SDSKY_RASTER"; }
00373   virtual String longTypeName() { return "SDSKY_RASTER (position switch sky subtraction specific to OTF raster observation)"; }
00374 
00375   // local setSolve
00376   virtual void setSolve(const Record& solve);
00377   
00378   // data selection specific to otfraster mode
00379   virtual String configureSelection(MeasurementSet const &ms);
00380 
00381 private:
00382   // edge detection parameter for otfraster mode
00383   Float fraction_;
00384   Int numEdge_;
00385 };
00386 
00387 class SingleDishOtfCal : public SingleDishSkyCal 
00388 {
00389 public:
00390 
00391   // Constructor
00392   SingleDishOtfCal(VisSet& vs);
00393   //  SingleDishOtfCal(const MSMetaInfoForCal& msmc);  // preferred ctor   ****ctor needs an MS!
00394   // Renaud: disabledSingleDishOtfCal(const Int& nAnt);
00395 
00396   // Destructor
00397   virtual ~SingleDishOtfCal();
00398 
00399   // Return type name as string (ditto)
00400   virtual String typeName()     { return "SDSKY_OTF"; }
00401   virtual String longTypeName() { return "SDSKY_OTF (position switch sky subtraction specific to OTF fast scan)"; }
00402 
00403   // Data selection specific to otf mode
00404   virtual String configureSelection(MeasurementSet const &ms);
00405   virtual void setSolve(const Record& solve);
00406 
00407 private:
00408   // Edge detection parameters for otf mode
00409   Float fraction_;
00410   Float pixel_scale_;
00411 
00412   // MeasurementSet filtered with user-specified selection
00413   const MeasurementSet & msSel_ ;
00414 
00415 };
00416 
00417 } //# NAMESPACE CASA - END
00418 
00419 #endif /* _SYNTHESIS_SINGLEDISH_SKY_CAL_H_ */
00420 
00421 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1