casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
RFDataMapper.h
Go to the documentation of this file.
00001 
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_RFDATAMAPPER_H
00028 #define FLAGGING_RFDATAMAPPER_H
00029 
00030 #include <flagging/Flagging/RFChunkStats.h> 
00031 #include <flagging/Flagging/DDMapper.h> 
00032 #include <casa/Arrays/Cube.h>
00033 #include <scimath/Mathematics/RigidVector.h>
00034 #include <casa/Containers/Block.h>
00035 
00036 namespace casa { //# NAMESPACE CASA - BEGIN
00037 
00038 class RFDataMapper;
00039 class VisBuffer;
00040 
00041 // a row mapper member function maps a row to a single value
00042 typedef Float (RFDataMapper::*RowMapperFunc)(uInt);
00043 
00044 // <summary>
00045 // RFDataMapper: maps complex visibilities to a single real value
00046 // </summary>
00047 
00048 // <use visibility=local>
00049 
00050 // <reviewed reviewer="" date="" tests="" demos="">
00051 // </reviewed>
00052 
00053 // <prerequisite>
00054 //   <li> DDMapper
00055 // </prerequisite>
00056 //
00057 // <synopsis>
00058 // RFDataMapper provides a mechanism to derive a single real value from 
00059 // a set of complex visibilities in a specific column, using a user-specified 
00060 // expression (i.e. ABS(XX), ABS(XX)-ABS(YY), etc.) This is used by many 
00061 // flagging agents.
00062 // </synopsis>
00063 //
00064 // <motivation>
00065 // To provide a common mechanism for all flagging agents
00066 // </motivation>
00067 //
00068 // <todo asof="2001/04/16">
00069 //   <li> add this feature
00070 //   <li> fix this bug
00071 //   <li> start discussion of this possible extension
00072 // </todo>
00073 class RFDataMapper
00074 {
00075 public:
00076   // type of data mapper: row or individual correlations
00077   typedef enum { MAPROW,MAPCORR } MapperType;
00078     
00079   // construct from a column and a DDMapper
00080   RFDataMapper( const String &col,DDMapper *map );
00081   // construct from a column and an expression
00082   RFDataMapper( const Vector<String> &expr,const String &defcol = "" );
00083   // destructor
00084   ~RFDataMapper();
00085   
00086   // returns type of mapper
00087   MapperType type ();
00088   
00089   // If the value being mapped into is cyclic (i.e. an angle),
00090   // returns value of full cycle (e.g. 360); otherwise returns 0.
00091   Double getValueCycle ();
00092   // Returns base of a cyclic value (e.g. -180, if value is an angle -180..180)
00093   // If value is non-cyclic, the result is undefined.
00094   Double getValueBase  ();
00095 
00096   // gets a value from the DDMapper
00097   Float mapValue ( uInt ich,uInt irow );
00098   // gets a value from the row mapper
00099   Float mapValue ( uInt irow );
00100 
00101   // uses mapper to compute a correlations mask
00102   RFlagWord corrMask (const VisibilityIterator &vi);
00103   
00104   // point the datamapper at a visbuffer - called for every new buffer
00105   void  setVisBuffer (VisBuffer &vb);
00106 
00107   // returns description
00108   String description () const;
00109   // returns description of expression
00110   String descExpression () const;
00111 
00112   // a cube mapper function maps a visbuffer to a data cube. This
00113   // belongs in private or protected, but the SGI compiler wouldn't hear of it
00114   typedef Cube<Complex> * (*CubeMapperFunc)(VisBuffer &);
00115   
00116 protected:
00117 
00118   // static helper function to interpret constructor parameters into a cube mapper
00119   static CubeMapperFunc getCubeMapper( const String &col,Bool throw_excp = False );
00120       
00121   String expr_desc,desc;           // expression and description of data mapper
00122   DDMapper *ddm;                   // data mapper
00123   RowMapperFunc rowmapper;         // row mapper
00124   Cube<Complex> *pviscube;         // pointer to visibilities cube 
00125   Vector<RigidVector<Double,3> > *puvw; // pointer to UVW matrix
00126   CubeMapperFunc cubemap; // function to map a chunk to a visibility cube
00127   MapperType mytype;
00128   Double full_cycle,cycle_base;     // for cyclic values (i.e. angles)
00129   
00130 // various row mappers
00131   Float dummyRowMapper (uInt);
00132   Float U_RowMapper (uInt);
00133   Float V_RowMapper (uInt);
00134   Float W_RowMapper (uInt);
00135   Float AbsU_RowMapper (uInt);
00136   Float AbsV_RowMapper (uInt);
00137   Float AbsW_RowMapper (uInt);
00138   Float UVD_RowMapper (uInt);
00139   Float UVA_RowMapper (uInt);
00140   Float HA_RowMapper (uInt);
00141   
00142 // required by the HA mapper - sin(declination) of phase center; 
00143   Double sin_dec;
00144 };
00145 
00146 inline RFDataMapper::MapperType RFDataMapper::type ()
00147 { return mytype; }
00148 
00149 inline Float RFDataMapper::mapValue ( uInt ich,uInt irow )
00150 { 
00151   if (pviscube == NULL) {
00152     throw(AipsError("Visibility buffer is unset, cannot get value!"));
00153   }
00154   return ddm->map(*pviscube,ich,irow); 
00155 }
00156 
00157 inline Float RFDataMapper::mapValue ( uInt irow )
00158 { return (this->*rowmapper)(irow); }
00159 
00160 inline String RFDataMapper::description () const
00161 { return desc; }
00162 inline String RFDataMapper::descExpression () const
00163 { return expr_desc; }
00164 
00165 inline Double RFDataMapper::getValueCycle ()
00166 { return full_cycle; }
00167 inline Double RFDataMapper::getValueBase ()
00168 { return cycle_base; }
00169 
00170 
00171 } //# NAMESPACE CASA - END
00172 
00173 #endif