casa
$Rev:20696$
|
00001 //# DDMapper.h: this defines DDMapper 00002 //# Copyright (C) 2000,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 //# $Id$ 00027 #ifndef FLAGGING_DDMAPPER_H 00028 #define FLAGGING_DDMAPPER_H 00029 00030 #include <casa/Arrays/Vector.h> 00031 #include <casa/Arrays/Cube.h> 00032 #include <casa/Exceptions/Error.h> 00033 #include <measures/Measures/Stokes.h> 00034 00035 namespace casa { //# NAMESPACE CASA - BEGIN 00036 00037 // <summary> 00038 // Abstract Derived Data Mapper class 00039 // </summary> 00040 00041 // <use visibility=local> 00042 00043 // <reviewed reviewer="" date="" tests="" demos=""> 00044 // </reviewed> 00045 00046 // <synopsis> 00047 // The DDMapper class defines an interface for mapping complex visibilities 00048 // into Float derived values. DDMappers are used by several flagging 00049 // agents. 00050 // </synopsis> 00051 // 00052 // <motivation> 00053 // A lot of algorithms are expressed in terms of some real value 00054 // derived from a set of visibilities (i.e., |XX|, |XX|-|YY|, etc.). The 00055 // DDMapper hierarchy provides a uniform interface for deriving such values. 00056 // </motivation> 00057 // 00058 // <todo asof="2001/04/16"> 00059 // <li> add this feature 00060 // </todo> 00061 00062 class DDMapper 00063 { 00064 protected: 00065 Bool valid; 00066 uShort corrmask; // mask of affected correlations 00067 00068 public: 00069 DDMapper () { valid=False; } 00070 virtual ~DDMapper () {}; 00071 00072 // Given a vector of correlation types, recomputes internal indices. 00073 // returns True if all indices were found successfully. 00074 virtual Bool reset ( const Vector<Int> &corr ) =0; 00075 00076 // Maps a slice of visibilities at (*,ich,irow) from the given 00077 // viscube into a the derived value. 00078 virtual Float map ( const Cube<Complex> &vis,uInt ich,uInt irow ) const =0; 00079 00080 // Returns the "mask" of correlations which are used by this mapper. 00081 // by this mapper. Bit "i" is set if corr. "i" is used. 00082 uShort corrMask () const { return corrmask; } 00083 00084 // Returns True if given correlations is masked 00085 Bool masked (uInt icorr) const { return corrmask&(1<<icorr) != 0; } 00086 00087 // Tells if mapper is valid 00088 Bool isValid () { return valid; } 00089 }; 00090 00091 // <summary> 00092 // DDDummy: dummy mapper, throws an excpetion if any methods are called 00093 // </summary> 00094 // <use visibility=local> 00095 class DDDummy : public DDMapper 00096 { 00097 public: 00098 DDDummy (); 00099 ~DDDummy (); 00100 00101 virtual void puke () const 00102 { throw(AipsError("Uninitialized DDMapper used")); } 00103 00104 virtual Bool reset ( const Vector<Int> & ) 00105 { puke(); return False; } 00106 virtual Float map ( const Cube<Complex> &,uInt,uInt ) const 00107 { puke(); return 0.; } 00108 00109 }; 00110 00111 // <summary> 00112 // DDFunc: maps correlation A into func(A) 00113 // </summary> 00114 // <use visibility=local> 00115 class DDFunc : public DDMapper 00116 { 00117 public: 00118 typedef Float (*FuncSignature)(const Complex &); 00119 00120 DDFunc ( FuncSignature fsig,const String &corr ); 00121 ~DDFunc() {}; 00122 00123 virtual Bool reset ( const Vector<Int> &corr ); 00124 virtual Float map ( const Cube<Complex> &vis,uInt ich,uInt irow ) const; 00125 00126 // Define these functions, because using std::real/imag in getFunction 00127 // matches multiple functions. 00128 static Float real (const Complex&); 00129 static Float imag (const Complex&); 00130 00131 // Static function to map a function name into a function pointer 00132 // Functions currently recognized: ABS ARG NORM RE IM 00133 static FuncSignature getFunction( const String &name ); 00134 00135 // Static function to map string expression into a DDMapper 00136 // Possible syntax is: 00137 // <FUNC> <CC> 00138 // SUM <FUNC> <CC> <CC> 00139 // DIFF <FUNC> <CC> <CC> 00140 // <FUNC> SUM <CC> <CC> 00141 // <FUNC> DIFF <CC> <CC> 00142 static DDMapper * getMapper ( String &desc,const Vector<String> &expr,Bool throw_excp=False ); 00143 00144 protected: 00145 Int icorr; 00146 Stokes::StokesTypes corrtype; 00147 FuncSignature func; 00148 }; 00149 00150 // <summary> 00151 // DDSumFunc: maps two correlations A and B into func(A)+func(B) 00152 // </summary> 00153 // <use visibility=local> 00154 class DDSumFunc : public DDFunc 00155 { 00156 public: 00157 DDSumFunc ( FuncSignature fsig,const String &corr1,const String &corr2 ); 00158 virtual ~DDSumFunc() {}; 00159 00160 virtual Bool reset ( const Vector<Int> &corr ); 00161 virtual Float map ( const Cube<Complex> &vis,uInt ich,uInt irow ) const; 00162 00163 protected: 00164 Int icorr2; 00165 Stokes::StokesTypes corrtype2; 00166 }; 00167 00168 // <summary> 00169 // DDFuncSum: maps two correlations A and B into func(A+B) 00170 // </summary> 00171 // <use visibility=local> 00172 class DDFuncSum : public DDSumFunc 00173 { 00174 public: 00175 DDFuncSum ( FuncSignature fsig,const String &corr1,const String &corr2 ); 00176 virtual ~DDFuncSum() {}; 00177 00178 virtual Float map ( const Cube<Complex> &vis,uInt ich,uInt irow ) const; 00179 }; 00180 00181 // <summary> 00182 // DDFuncDiff: maps two correlations A and B into func(A-B) 00183 // </summary> 00184 // <use visibility=local> 00185 class DDFuncDiff : public DDSumFunc 00186 { 00187 public: 00188 DDFuncDiff ( FuncSignature fsig,const String &corr1,const String &corr2 ); 00189 virtual ~DDFuncDiff() {}; 00190 00191 virtual Float map ( const Cube<Complex> &vis,uInt ich,uInt irow ) const; 00192 }; 00193 00194 // <summary> 00195 // DDDiffFunc: maps two correlations A and B into func(A)-func(B) 00196 // </summary> 00197 // <use visibility=local> 00198 class DDDiffFunc : public DDSumFunc 00199 { 00200 public: 00201 DDDiffFunc ( FuncSignature fsig,const String &corr1,const String &corr2 ); 00202 virtual ~DDDiffFunc() {}; 00203 00204 virtual Float map ( const Cube<Complex> &vis,uInt ich,uInt irow ) const; 00205 }; 00206 00207 // helper function to split an expression into elements 00208 Vector<String> splitExpression( const Vector<String> &expr0 ); 00209 00210 00211 } //# NAMESPACE CASA - END 00212 00213 #endif