casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
AMueller.h
Go to the documentation of this file.
00001 //# AMueller.h:  Additive closure errors
00002 //# Copyright (C) 1996,1997,2000,2001,2002,2003
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be adressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //#
00027 
00028 #ifndef SYNTHESIS_AMUELLER_H
00029 #define SYNTHESIS_AMUELLER_H
00030 
00031 #include <casa/aips.h>
00032 #include <casa/BasicSL/Complex.h>
00033 #include <synthesis/MeasurementComponents/StandardVisCal.h>
00034 #include <synthesis/MeasurementComponents/CalCorruptor.h>
00035 
00036 namespace casa { //# NAMESPACE CASA - BEGIN
00037 
00038 class VisBuffGroupAcc;
00039 
00040 class AMueller : public MMueller {
00041 public:
00042 
00043   // Constructor
00044   AMueller(VisSet& vs);
00045   AMueller(const Int& nAnt);
00046 
00047   virtual ~AMueller();
00048 
00049   // Return the type enum
00050   virtual Type type() { return VisCal::A; };
00051 
00052   // Return type name as string
00053   virtual String typeName()     { return "A Mueller"; };
00054   virtual String longTypeName() { return "A Mueller (baseline-based)"; };
00055 
00056   // Algebraic type of Mueller matrix 
00057   //  (this is the key distinguishing characteristic)
00058   virtual Mueller::MuellerType muellerType() { return Mueller::AddDiag2; };
00059 
00060   // Local setsolve (overrides preavg)
00061   using SolvableVisCal::setSolve;
00062   // Parameters particular to this class:
00063   //    fitorder: Order of the polynomial fit.  If 0, it is just an average.
00064   virtual void setSolve(const Record& solvepar);
00065 
00066   // AMueller's caltables have polynomial orders where channels would normally
00067   // go.  setSolve() above sets the number of "channels", but
00068   // SolvableVisCal::setSolveChannelization() would just reset it to 1 if it
00069   // was not overrode here.
00070   virtual void setSolveChannelization(VisSet& vs);
00071 
00072   // Size up the solving arrays, etc.  (supports combine)
00073   virtual Int sizeUpSolve(VisSet& vs, Vector<Int>& nChunkPerSol);
00074 
00075   // The fitorder = 0 version (in M) skips LinearFitSVD by just averaging.
00076   virtual Bool useGenericGatherForSolve() {return fitorder_p != 0;}
00077 
00078   // Only called if useGenericGatherForSolve() == True.  If
00079   // useGenericGatherForSolve() == True, then genericGatherAndSolve() will call
00080   // AMueller's selfSolveOne().  Otherwise MMueller's selfGatherAndSolve() will
00081   // do everything.
00082   virtual Bool useGenericSolveOne() {return False;}
00083 
00084   // Per-solution self-solving inside generic gather.  Flexible enough for
00085   // fitorder != 0, but overkill otherwise.
00086   virtual void selfSolveOne(VisBuffGroupAcc& vbga);
00087 
00088   virtual void storeNCT();
00089 
00090   virtual void setApply() {SolvableVisCal::setApply();}
00091   virtual void setApply(const Record& applypar);
00092 
00093   // Apply this calibration to vb.  AMueller does NOT support trial
00094   //                                and ignores it!
00095   virtual void applyCal(VisBuffer& vb, Cube<Complex>& Vout, Bool trial=False);
00096 
00097   // Freq dependence
00098   virtual Bool freqDepPar() { return False; };
00099   virtual Bool freqDepMat() {
00100     return fitorder_p != 0 || nChanPar() > 1; // The latter is for applying.
00101   }
00102 
00103   // We do not normalize by the model, since we are estimating
00104   //  directly from the data  (we should optimize here by avoiding 
00105   //  the model I/O)
00106   virtual Bool normalizable() {return False;};
00107 
00108   // Specialize corrupt to pre-zero model for corruption
00109   //using VisMueller::corrupt;
00110   virtual void corrupt(VisBuffer& vb);
00111   //virtual void corrupt(VisBuffer& vb, Cube<Complex>& Mout);
00112 
00113   // Set (repeatedly, unfortunately) whether or not subtraction is being done,
00114   // and IF fitorder == 0, sync matrices for current meta data (VisMueller
00115   // override).  (Mueller matrices aren't used for fitorder != 0.)
00116   void syncCalMat(const Bool& doInv)
00117   {
00118     doSub_p = doInv;
00119     if(fitorder_p == 0)
00120       VisMueller::syncCalMat(doInv);
00121   }
00122 
00123 protected:
00124   virtual Int nPar() {
00125     if(nCorr_p < 0)
00126       hurl("nPar()", "nPar() called before being set.");
00127     return nCorr_p;
00128   }
00129 
00130 private:
00131   void init();  // Common code for the c'tors.
00132 
00133   // Logs and throws msg as an exception from origin.
00134   void hurl(const String& origin, const String& msg);
00135 
00136   // Initialized to 0 in the initialization lists of the c'tors.
00137   Int fitorder_p;  // Stores the order of the fitted polynomials.
00138 
00139   Bool doSub_p; // For apply, whether or not to subtract or give the continuum
00140                 // estimate.
00141   Int  nCorr_p; // # of correlations.  -1 if not yet known.
00142 
00143   // Resized and set to impossible values in init().
00144   Vector<Double> lofreq_p; // Lowest and highest frequencies (Hz) used
00145   Vector<Double> hifreq_p; // to make the fit.
00146   Vector<uInt> totnumchan_p; // The total number of input channels that will be
00147                              // looked at (including masked ones!)
00148   Vector<Bool> spwApplied_p;  // Just keeps track of which spws have been
00149                               // applied to.
00150 };
00151 
00152 // Additive noise
00153 // In practice, this is not really solvable, but it
00154 //   is a SVM because we need access to general simulation methods
00155 class ANoise : public SolvableVisMueller {
00156 public:
00157 
00158   // Constructor
00159   ANoise(VisSet& vs);
00160   ANoise(const Int& nAnt);
00161 
00162   virtual ~ANoise();
00163 
00164   // Return the type enum
00165   virtual Type type() { return VisCal::ANoise; };
00166 
00167   // Return type name as string
00168   virtual String typeName()     { return "A Noise"; };
00169   virtual String longTypeName() { return "A Noise (baseline-based)"; };
00170 
00171   // Algebraic type of Mueller matrix 
00172   //  (this is the key distinguishing characteristic)
00173   virtual Mueller::MuellerType muellerType() { return Mueller::AddDiag2; };
00174 
00175   // Overide solvability
00176   virtual Bool isSolvable() { return False; };
00177 
00178   // this is inherently freqdep:
00179   virtual Bool freqDepPar() { return True; };
00180 
00181   virtual void createCorruptor(const VisIter& vi, const Record& simpar, const Int nSim);
00182 
00183 protected:
00184   // umm... 2 for each of parallel hands?
00185   virtual Int nPar() { return 2; };
00186 
00187   // Jones matrix elements are trivial
00188   virtual Bool trivialMuellerElem() { return (!simOnTheFly()); };
00189 
00190   // override VC default of timeDepMat=F for OTF simulatio:
00191   virtual Bool timeDepMat() { return simOnTheFly(); };
00192 
00193   // Calculate an ensemble of Mueller matrices (all baselines, channels)
00194   // overrriding VisCal::calcAllMueller
00195   virtual void calcAllMueller();
00196 
00197   // Calculate a single Mueller matrix by some means
00198   // override SolvableVisMueller::calcOneMueller
00199   virtual void calcOneMueller(Vector<Complex>& mat, Vector<Bool>& mOk,
00200                               const Vector<Complex>& par, const Vector<Bool>& pOk);
00201 
00202 private:
00203   ANoiseCorruptor *acorruptor_p;
00204 
00205 };
00206 
00207 } //# NAMESPACE CASA - END
00208 
00209 #endif