casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
StokesConverter.h
Go to the documentation of this file.
00001 //# StokesConverter.h: convert any set of polarizations into any other one
00002 //# Copyright (C) 1997,2001
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 addressed 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: StokesConverter.h 18093 2004-11-30 17:51:10Z ddebonis $
00028 
00029 #ifndef MS_STOKESCONVERTER_H
00030 #define MS_STOKESCONVERTER_H
00031 
00032 #include <casa/aips.h>
00033 #include <casa/Arrays/Vector.h>
00034 #include <casa/Arrays/Matrix.h>
00035 #include <casa/BasicSL/Complex.h>
00036 #include <measures/Measures/Stokes.h>
00037 
00038 namespace casa { //# NAMESPACE CASA - BEGIN
00039 
00040 // <summary>
00041 // StokesConverter converts any set of polarizations into any other one
00042 // </summary>
00043 
00044 // <use visibility=export>
00045 
00046 // <reviewed reviewer="" date="yyyy/mm/dd" tests="tStokesConverter" demos="">
00047 // </reviewed>
00048 
00049 // <prerequisite>
00050 //   <li> <a href="StokesConverter.html"> Stokes </a>
00051 // </prerequisite>
00052 //
00053 // <etymology>
00054 // StokesConverter is a class that converts Stokes Parameters
00055 // </etymology>
00056 //
00057 // <synopsis>
00058 // This class is used to convert polarizations from one system to
00059 // another.
00060 // First the conversion wanted is specified and then large blocks of data
00061 // can be converted.
00062 // <example>
00063 // <srcblock>
00064 // // create converter
00065 //    StokesConverter sc;
00066 //    Vector<Int> out(7),in(4);
00067 // // set the input polarizations   
00068 //    in(0)=Stokes::RR;
00069 //    in(1)=Stokes::LL;
00070 //    in(2)=Stokes::RL;
00071 //    in(3)=Stokes::LR;
00072 // // set the required output  
00073 //    out(0)=Stokes::I;
00074 //    out(1)=Stokes::Q;
00075 //    out(2)=Stokes::U;
00076 //    out(3)=Stokes::V;
00077 //    out(4)=Stokes::Ptotal;
00078 //    out(5)=Stokes::Pangle;
00079 //    out(6)=Stokes::PFlinear;
00080 // // initialize the conversion engine   
00081 //    sc.setConversion(out,in);
00082 // // set up some test data   
00083 //    Vector<Complex> datain(4),dataout(7);
00084 //    datain(0)=1.0;
00085 //    datain(1)=0.9;
00086 //    datain(2)=0.3;
00087 //    datain(3)=0.2;
00088 // // convert the data   
00089 //    sc.convert(dataout,datain);
00090 // </srcblock>
00091 // </example>
00092 // </synopsis>
00093 //
00094 // <motivation>
00095 // Polarization conversion is needed in various places. It makes sense to
00096 // provide all conversion in one place.
00097 // </motivation>
00098 //
00099 // <thrown>
00100 //    <li>
00101 //    <li>
00102 // </thrown>
00103 //
00104 // <todo asof="1997/10/09">
00105 //   <li> cope with incomplete input polarizations sensibly
00106 //   <li> decide what to do about factor 2 between I and RR/LL,XX/YY etc.
00107 // </todo>
00108 
00109 class StokesConverter
00110 {
00111 public:
00112 
00113   // default constructor, does not set up a conversion
00114   StokesConverter();
00115   
00116   // Set up a conversion from in to out.
00117   // The in and out vectors contain a list of polarization present/wanted
00118   // in that order. The in vector should match the data to convert.
00119   // (CORR_TYPE column in SPECTRAL_WINDOW table contains this info)
00120   // The rescale option will correct for crosscorrelation data that
00121   // has been scaled to the level Stokes I (common practice 
00122   // in radioastronomy: even though officially I=XX+YY, in practice
00123   // we need to do I=(XX+YY)/2, set rescale to True to do the latter).
00124   StokesConverter(const Vector<Int>& out, const Vector<Int>& in,
00125                   Bool rescale=False);
00126   
00127   // desctructor
00128   ~StokesConverter();
00129 
00130   // Copy constructor
00131   StokesConverter(const StokesConverter& other);
00132   
00133   // Assignment, 
00134   StokesConverter& operator=(const StokesConverter& other);
00135   
00136   // Change or Set the conversion. Arguments are the same as for
00137   // constructor above.
00138   void setConversion(const Vector<Int>& out, const Vector<Int>& in,
00139                      Bool rescale = False);
00140   
00141   // convert data, first dimension of input must match
00142   // that of the input conversion vector used to set up the conversion.
00143   // Output is resized as needed.
00144   void convert(Array<Complex>& out, const Array<Complex>& in) const;
00145 
00146   // convert flags, first dimension of input must match
00147   // that of the input conversion vector used to set up the conversion.
00148   // Output is resized as needed. All output depending on a flagged input
00149   // will be flagged. 
00150   void convert(Array<Bool>& out, const Array<Bool>& in) const;
00151 
00152   // convert weights, first dimension of input must match
00153   // that of the input conversion vector used to set up the conversion.
00154   // Output is resized as needed.
00155   // Set sigma to True when converting sigma's using this routine.
00156   void convert(Array<Float>& out, const Array<Float>& in,
00157                Bool sigma=False) const;
00158 
00159   // invert flags, first dimension of input must match
00160   // that of the output conversion vector used to set up the conversion.
00161   // Output is resized as needed. All output depending on a flagged input
00162   // will be flagged. This does the inverse operation of convert, allowing
00163   // flagging of converted data to be transferred back to the original data.
00164   void invert(Array<Bool>& out, const Array<Bool>& in) const;
00165 
00166 protected:
00167 
00168   // initialize the polarization conversion matrix
00169   void initConvMatrix();
00170 
00171 private:
00172   Vector<Int> in_p,out_p;
00173   Bool rescale_p;
00174   //# mutable because operator Matrix(Slice,Slice) doesn't have const version
00175   mutable Matrix<Complex> conv_p; 
00176   mutable Matrix<Complex> iquvConv_p;
00177   Bool doIQUV_p;
00178   Matrix<Bool> flagConv_p;
00179   Matrix<Float> wtConv_p;
00180   Matrix<Complex> polConv_p;
00181 };
00182 
00183 
00184 } //# NAMESPACE CASA - END
00185 
00186 #endif