casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
PolOuterProduct.h
Go to the documentation of this file.
00001 //# PolOuterProduct.h: Definition for PolOuterProduct
00002 //# Copyright (C) 2007
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 //# $Id$
00028 
00029 #ifndef SYNTHESIS_POLOUTERPRODUCT_H
00030 #define SYNTHESIS_POLOUTERPRODUCT_H
00031 
00032 
00033 #include <casa/Arrays/Vector.h>
00034 #include <casa/Arrays/Matrix.h>
00035 #include <scimath/Mathematics/RigidVector.h>
00036 #include <coordinates/Coordinates/StokesCoordinate.h>
00037 #include <ms/MeasurementSets/MSIter.h> // Just to get MSIter::{Linear,Circular}!
00038 #include <synthesis/TransformMachines/CFDefs.h>
00039 namespace casa{
00040   // <summary>  
00041   //  Class to encapsulate the A-Term outer product (the Mueller Matrix in feed-polarization basis)
00042   // </summary>
00043   
00044   // <use visibility=export>
00045   // <prerequisite>
00046   // </prerequisite>
00047   // <etymology>
00048   //   
00049   // </etymology>
00050   //
00051   // <synopsis> 
00052   // 
00053   //</synopsis>
00054   using namespace CFDefs;
00055   class PolOuterProduct 
00056   {
00057     public:
00058     enum GenericVBPol {GPP, GPQ, GQP, GQQ, JUSTWRONGVBPOL};
00059     enum CrossPolGeneric{PP,     PP2Q,   P2QP,   P2QP2Q,
00060                          PQ2P,   PQ,     P2QQ2P, P2QQ,
00061                          Q2PP,   Q2PP2Q, QP,     QP2Q,
00062                          Q2PQ2P, Q2PQ,   QQ2P,   QQ,
00063                          JUSTWRONGGENERIC};
00064     enum CrossPolCircular{RR,     RR2L,   R2LR,   R2LR2L,
00065                           RL2R,   RL,     R2LL2R, R2LL,
00066                           L2RR,   L2RR2L, LR,     LR2L,
00067                           L2RL2R, L2RL,   LL2R,   LL,
00068                           JUSTWRONGCIRCULAR};
00069     enum CrossPolLinear{XX,     XX2Y,   X2YX,   X2YX2Y,
00070                         XY2X,   XY,     X2YY2X, X2YY,
00071                         Y2XX,   Y2XX2Y, YX,     YX2Y,
00072                         Y2XY2X, Y2XY,   YY2X,   YY,
00073                         JUSTWRONGLINEAR};
00074     enum MuellerType {DIAGONAL=0, HYBRID, FULL};
00075     //
00076     //========================= Administrative Parts ==========================
00077     //------------------------------------------------------------------
00078     //
00079     PolOuterProduct (MuellerType type=DIAGONAL) 
00080     {
00081       polMap_p.resize(4,4);polMap_p=-1;
00082       init(type);
00083     };
00084     //
00085     //------------------------------------------------------------------
00086     //
00087     PolOuterProduct (const Matrix<Int>& polMap) 
00088     {
00089       //      assert(polMap.shape() == IPosition(2,4,4));
00090 
00091       polMap_p.assign(polMap); 
00092       init();
00093     };
00094     //
00095     //------------------------------------------------------------------
00096     //
00097     virtual ~PolOuterProduct () {};
00098     //
00099     //============================= Functional Parts ============================
00100     //------------------------------------------------------------------
00101     //
00102     void init(MuellerType type=DIAGONAL)
00103     {
00104       muellerType_p = type;
00105       makeMap();
00106       nelement_p=countNElements();
00107     };
00108     //
00109     //------------------------------------------------------------------
00110     //
00111     void makePolMap(const Vector<CrossPolCircular>& pols);
00112     //
00113     //------------------------------------------------------------------
00114     //
00115     inline void setElement(const RigidVector<Int,2>& element,const Int& pos)   
00116     {polMap_p(element(0),element(1)) = pos;}
00117     //
00118     //------------------------------------------------------------------
00119     //
00120     inline void setElement(const CrossPolCircular& element, const Int& pos)             
00121     {RigidVector<Int,2> loc=getMuellerElement(element); setElement(loc,pos);}
00122     //
00123     //------------------------------------------------------------------
00124     //
00125     inline Int getPolEnum(const RigidVector<Int, 2>& element)   
00126     {return invIndexMap_p(element(0), element(1));};
00127     //
00128     //------------------------------------------------------------------
00129     //
00130     inline RigidVector<Int,2> getMuellerElement(const CrossPolCircular& element) 
00131     {return indexMap_p(element);}
00132     //
00133     //------------------------------------------------------------------
00134     //
00135     inline Bool isSet(const RigidVector<Int,2> element)
00136     {return (polMap_p(element(0), element(1)) >= 0);};
00137     //
00138     //------------------------------------------------------------------
00139     //
00140     inline Bool isSet(const CrossPolCircular& element) 
00141     {return isSet(getMuellerElement(element));}
00142     //
00143     //------------------------------------------------------------------
00144     //
00145     inline Int countNElements() 
00146     {
00147       Int n=0;
00148       for (Int i=0;i<4;i++)
00149         for (Int j=0;j<4;j++)
00150           if (polMap_p(i,j) >= 0) n++;
00151       return n;
00152     }
00153     //
00154     //------------------------------------------------------------------
00155     //
00156     inline Int nelements() {return nelement_p;};
00157     //
00158     //------------------------------------------------------------------
00159     //
00160     const Vector<RigidVector<Int,2> >& getIndexMap() {return indexMap_p;};
00161     //
00162     //------------------------------------------------------------------
00163     //
00164     const Matrix<Int>& getPolMap() {return polMap_p;}
00165     PolMapType& makePolMat(const Vector<Int>& vbPol, const Vector<Int>& vbPol2ImMap);
00166     PolMapType& makePol2CFMat(const Vector<Int>& vbPol, const Vector<Int>& vbPol2ImMap);
00167     PolMapType& makeConjPolMat(const Vector<Int>& vbPol, const Vector<Int>& vbPol2ImMap);
00168     PolMapType& makeConjPol2CFMat(const Vector<Int>& vbPol, const Vector<Int>& vbPol2ImMap);
00169     void initCFMaps(const Vector<Int>& visPol, const Vector<Int>& visPolsUsed);
00170 
00171     inline PolMapType& getPolMat() {return outerProduct2VBPolMap_p;};
00172     inline PolMapType& getConjPolMat() {return conjOuterProduct2VBPolMap_p;};
00173     inline PolMapType& getPol2CFMat() {return outerProductIndex2VBPolMap_p;};
00174     inline PolMapType& getConjPol2CFMat() {return conjOuterProductIndex2VBPolMap_p;};
00175     //
00176     //============================= Protected Parts ============================
00177     //
00178   protected:
00179     // LogIO& logIO() {return logIO_p;}
00180     // LogIO logIO_p;
00181     RigidVector<RigidVector<Int, 4>, 4> muellerRows_p, conjMuellerRows_p;
00182     Matrix<Int> polMap_p, invIndexMap_p;
00183     Vector<RigidVector<Int,2> > indexMap_p;
00184     PolMapType outerProduct2VBPolMap_p, outerProductIndex2VBPolMap_p, 
00185       conjOuterProduct2VBPolMap_p, conjOuterProductIndex2VBPolMap_p, cfIndices_p;
00186     MuellerType muellerType_p;
00187     Int nelement_p;
00188 
00189     PolMapType& makePol2CFMat_p(const Vector<Int>& vbPol, 
00190                                 const Vector<Int>& vbPol2ImMap,
00191                                 PolMapType& outerProdNdx2VBPolMap);
00192     PolMapType& makePolMat_p(const Vector<Int>& vbPol, 
00193                              const Vector<Int>& vbPol2ImMap,
00194                              PolMapType& outerProd2VBPolMap,
00195                              RigidVector<RigidVector<Int, 4>, 4>& mRows);
00196 
00197     virtual void makeMap()
00198     {
00199       //
00200       // Make the (damn) mappings!  Phew.
00201       //
00202 
00203       RigidVector<Int,4> el;
00204       el(0)=PP;     el(1)=PP2Q;   el(2)=P2QP;    el(3)=P2QP2Q;  muellerRows_p(GPP) = el;
00205       el(0)=PQ2P;   el(1)=PQ;     el(2)=P2QQ2P;  el(3)=P2QQ;    muellerRows_p(GPQ) = el;
00206       el(0)=Q2PP;   el(1)=Q2PP2Q; el(2)=QP;      el(3)=QP2Q;    muellerRows_p(GQP) = el;
00207       el(0)=Q2PQ2P; el(1)=Q2PQ;   el(2)=QQ2P;    el(3)=QQ;      muellerRows_p(GQQ) = el;
00208 
00209       el(0)=QQ;     el(1)=QQ2P;   el(2)=Q2PQ;   el(3)=Q2PQ2P;   conjMuellerRows_p(GPP)=el;
00210       el(0)=QP2Q;   el(1)=QP;     el(2)=Q2PP2Q; el(3)=Q2PP;     conjMuellerRows_p(GPQ)=el;
00211       el(0)=P2QQ;   el(1)=P2QQ2P; el(2)=PQ;     el(3)=PQ2P;     conjMuellerRows_p(GQP)=el;
00212       el(0)=P2QP2Q; el(1)=P2QP;   el(2)=PP2Q;   el(3)=PP;       conjMuellerRows_p(GQQ)=el;
00213 
00214 
00215 
00216       // Pol-enum to 2-index
00217       indexMap_p.resize(16);
00218 
00219       indexMap_p(RR)     = RigidVector<Int,2>(0,0);      
00220       indexMap_p(RR2L)   = RigidVector<Int,2>(0,1);    
00221       indexMap_p(R2LR)   = RigidVector<Int,2>(0,2);    
00222       indexMap_p(R2LR2L) = RigidVector<Int,2>(0,3);
00223 
00224       indexMap_p(RL2R)   = RigidVector<Int,2>(1,0);      
00225       indexMap_p(RL)     = RigidVector<Int,2>(1,1);      
00226       indexMap_p(R2LL2R) = RigidVector<Int,2>(1,2);      
00227       indexMap_p(R2LL)   = RigidVector<Int,2>(1,3);      
00228 
00229       indexMap_p(L2RR)   = RigidVector<Int,2>(2,0);     
00230       indexMap_p(L2RR2L) = RigidVector<Int,2>(2,1);     
00231       indexMap_p(LR)     = RigidVector<Int,2>(2,2);     
00232       indexMap_p(LR2L)   = RigidVector<Int,2>(2,3);     
00233 
00234       indexMap_p(L2RL2R) = RigidVector<Int,2>(3,0); 
00235       indexMap_p(L2RL)   = RigidVector<Int,2>(3,1);
00236       indexMap_p(LL2R)   = RigidVector<Int,2>(3,2);
00237       indexMap_p(LL)     = RigidVector<Int,2>(3,3);
00238 
00239 
00240       // 2-Index to Pol-enum
00241       invIndexMap_p.resize(4,4);
00242       
00243       invIndexMap_p(0,0)=RR;     invIndexMap_p(0,1)=RR2L;   invIndexMap_p(0,2)=R2LR;   invIndexMap_p(0,3)=R2LR2L;
00244       invIndexMap_p(1,0)=RL2R;   invIndexMap_p(1,1)=RL;     invIndexMap_p(1,2)=R2LL2R; invIndexMap_p(1,3)=R2LL;
00245       invIndexMap_p(2,0)=L2RR;   invIndexMap_p(2,1)=L2RR2L; invIndexMap_p(2,2)=LR;     invIndexMap_p(2,3)=LR2L;
00246       invIndexMap_p(3,0)=L2RL2R; invIndexMap_p(3,1)=L2RL;   invIndexMap_p(3,2)=LL2R;   invIndexMap_p(3,3)=LL;
00247     };
00248 
00249   };
00250   //
00251   //------------------------------------------------------------------
00252   //
00253   PolOuterProduct::GenericVBPol translateStokesToGeneric(const Int& stokes) ;
00254   Int translateGenericToStokes(const PolOuterProduct::GenericVBPol& gPol, 
00255                                const MSIter::PolFrame& polFrame=MSIter::Circular);
00256 };
00257 
00258 #endif