UDFMSCal.h

Go to the documentation of this file.
00001 //# UDFMSCal.h: TaQL UDFs to calculate derived MS values
00002 //# Copyright (C) 2010
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 
00028 #ifndef DERIVEDMSCAL_UDFMSCAL_H
00029 #define DERIVEDMSCAL_UDFMSCAL_H
00030 
00031 //# Includes
00032 #include <casacore/casa/aips.h>
00033 #include <casacore/derivedmscal/DerivedMC/MSCalEngine.h>
00034 #include <casacore/ms/MeasurementSets/StokesConverter.h>
00035 #include <casacore/ms/MSSel/MSSelectionErrorHandler.h>
00036 #include <casacore/tables/TaQL/UDFBase.h>
00037 #include <casacore/tables/TaQL/ExprNode.h>
00038 
00039 namespace casacore {
00040 
00041 // <summary>
00042 // TaQL UDFs to calculate derived MS values.
00043 // </summary>
00044 
00045 // <use visibility=export>
00046 
00047 // <reviewed reviewer="" date="" tests="tDerivedMSCal.cc">
00048 // </reviewed>
00049 
00050 // <prerequisite>
00051 //# Classes you should understand before using this one.
00052 //   <li> UDFBase
00053 // </prerequisite>
00054 
00055 // <synopsis>
00056 // UDFMSCal defines UDFs (user defined functions) that can be used in TaQL
00057 // to get derived MeasurementSet values hourangle, parallactic angle,
00058 // azimuth/elevation, and local sidereal time.
00059 // In this way such derived values appear to be ordinary TaQL functions.
00060 //
00061 // The following functions can be defined:
00062 // <ul>
00063 //  <li> HA is the hourangle of the array center (observatory position).
00064 //  <li> HA1 is the hourangle of ANTENNA1.
00065 //  <li> HA2 is the hourangle of ANTENNA2.
00066 //  <li> HADEC is the hourangle/DEC of the array center (observatory position).
00067 //  <li> HADEC1 is the hourangle/DEC of ANTENNA1.
00068 //  <li> HADEC2 is the hourangle/DEC of ANTENNA2.
00069 //  <li> LAST is the local sidereal time of the array center.
00070 //  <li> LAST1 is the local sidereal time of ANTENNA1.
00071 //  <li> LAST2 is the local sidereal time of ANTENNA2.
00072 //  <li> PA1 is the parallactic angle of ANTENNA1.
00073 //  <li> PA2 is the parallactic angle of ANTENNA2.
00074 //  <li> AZEL1 is the azimuth/elevation of ANTENNA1.
00075 //  <li> AZEL2 is the azimuth/elevation of ANTENNA2.
00076 //  <li> UVW_J2000 is the UVW coordinates in J2000 (in meters)
00077 //  <li> STOKES makes it possible to convert Stokes of data, flag, or weight.
00078 //  <li> BASELINE is baseline selection using CASA syntax.
00079 //  <li> CORR is correlation selection using CASA syntax.
00080 //  <li> TIME is baseline selection using CASA syntax.
00081 //  <li> UVDIST is UV-distance selection using CASA syntax.
00082 //  <li> SPW is spectral window selection using CASA syntax.
00083 //  <li> FIELD is field selection using CASA syntax.
00084 //  <li> FEED is feed selection using CASA syntax.
00085 //  <li> ARRAY is array selection using CASA syntax.
00086 //  <li> SCAN is scan selection using CASA syntax.
00087 //  <li> STATE is state selection using CASA syntax.
00088 //  <li> OBS is observation selection using CASA syntax.
00089 //  <li> ANTNAME is the name of the given antenna.
00090 // </ul>
00091 // The first functions have data type double and unit radian (except UVW).
00092 // The HADEC, AZEL, and UVW functions return arrays while the others return
00093 // scalars.
00094 // <br>The STOKES function can have data type Complex, Double or Bool.
00095 // <br>The latter functions are selection functions and return a Bool scalar.
00096 //
00097 // This class is meant for a MeasurementSet, but can be used for any table
00098 // containing an ANTENNA and FIELD subtable and the relevant columns in the
00099 // main table (ANTENNA1 and/or ANTENNA2, FIELD_ID, and TIME).
00100 // <br>In principle the array center is the Observatory position, which is
00101 // taken from the Measures Observatory table using the telescope name found
00102 // in the OBSERVATION subtable. However, if the subtable is not defined or
00103 // empty or if the telescope name is unknown, the position of the first antenna
00104 // is used as the array position.
00105 //
00106 // The engine can also be used for a CASA Calibration Table. It understands
00107 // how it references the MeasurementSets. Because calibration tables contain
00108 // no ANTENNA2 columns, functions XX2 are the same as XX1.
00109 // </synopsis>
00110 
00111 // <motivation>
00112 // It makes it possible to do queries on these values without having
00113 // to add columns for them.
00114 // </motivation>
00115 
00116   class UDFMSCal: public UDFBase
00117   {
00118   public:
00119     // Define the possible 'column' types.
00120     enum ColType {HA, HADEC, PA, LAST, AZEL, NEWUVW,
00121                   UVWWVL, UVWWVLS, NEWUVWWVL, NEWUVWWVLS,
00122                   STOKES, SELECTION, GETVALUE};
00123     // Define the possible selection types.
00124     enum SelType {BASELINE, CORR, TIME, UVDIST, SPW, FIELD,
00125                   FEED, ARRAY, SCAN, STATE, OBS};
00126 
00127     // Create object the given ColType and SelType.
00128     UDFMSCal (ColType, Int arg);
00129 
00130     // Create the object for getting a value from a column in a subtable.
00131     // <group>
00132     explicit UDFMSCal (const String& funcName);
00133     UDFMSCal (const String& funcName, const String& subtabName,
00134               const String& idColName, Int arg=0);
00135     UDFMSCal (const String& funcName, const String& subtabName,
00136               const String& idColName, const String& colName);
00137     // </group>
00138 
00139     // Function to create an object.
00140     static UDFBase* makeHA       (const String&);
00141     static UDFBase* makeHA1      (const String&);
00142     static UDFBase* makeHA2      (const String&);
00143     static UDFBase* makeHADEC    (const String&);
00144     static UDFBase* makeHADEC1   (const String&);
00145     static UDFBase* makeHADEC2   (const String&);
00146     static UDFBase* makePA1      (const String&);
00147     static UDFBase* makePA2      (const String&);
00148     static UDFBase* makeLAST     (const String&);
00149     static UDFBase* makeLAST1    (const String&);
00150     static UDFBase* makeLAST2    (const String&);
00151     static UDFBase* makeAZEL     (const String&);
00152     static UDFBase* makeAZEL1    (const String&);
00153     static UDFBase* makeAZEL2    (const String&);
00154     static UDFBase* makeUVW      (const String&);
00155     static UDFBase* makeWvl      (const String&);
00156     static UDFBase* makeWvls     (const String&);
00157     static UDFBase* makeUvwWvl   (const String&);
00158     static UDFBase* makeUvwWvls  (const String&);
00159     static UDFBase* makeStokes   (const String&);
00160     static UDFBase* makeBaseline (const String&);
00161     static UDFBase* makeCorr     (const String&);
00162     static UDFBase* makeTime     (const String&);
00163     static UDFBase* makeUVDist   (const String&);
00164     static UDFBase* makeSpw      (const String&);
00165     static UDFBase* makeField    (const String&);
00166     static UDFBase* makeFeed     (const String&);
00167     static UDFBase* makeArray    (const String&);
00168     static UDFBase* makeScan     (const String&);
00169     static UDFBase* makeState    (const String&);
00170     static UDFBase* makeObs      (const String&);
00171     static UDFBase* makeAnt1Name (const String&);
00172     static UDFBase* makeAnt2Name (const String&);
00173     static UDFBase* makeAnt1Col  (const String&);
00174     static UDFBase* makeAnt2Col  (const String&);
00175     static UDFBase* makeStateCol (const String&);
00176     static UDFBase* makeObsCol   (const String&);
00177     static UDFBase* makeSpwCol   (const String&);
00178     static UDFBase* makePolCol   (const String&);
00179     static UDFBase* makeFieldCol (const String&);
00180     static UDFBase* makeProcCol  (const String&);
00181     static UDFBase* makeSubCol   (const String&);
00182 
00183     // Setup the object.
00184     virtual void setup (const Table&, const TaQLStyle&);
00185 
00186     // Get the value.
00187     virtual Bool     getBool     (const TableExprId& id);
00188     virtual Int64    getInt      (const TableExprId& id);
00189     virtual Double   getDouble   (const TableExprId& id);
00190     virtual DComplex getDComplex (const TableExprId& id);
00191     virtual String   getString   (const TableExprId& id);
00192     virtual MArray<Bool>     getArrayBool     (const TableExprId& id);
00193     virtual MArray<Int64>    getArrayInt      (const TableExprId& id);
00194     virtual MArray<Double>   getArrayDouble   (const TableExprId& id);
00195     virtual MArray<DComplex> getArrayDComplex (const TableExprId& id);
00196     virtual MArray<String>   getArrayString   (const TableExprId& id);
00197 
00198     // Let a derived class recreate its column objects in case a selection
00199     // has to be applied.
00200     virtual void recreateColumnObjects (const Vector<uInt>& rownrs);
00201 
00202   private:
00203     // Setup the Stokes conversion.
00204     void setupStokes (const Table& table,
00205                       PtrBlock<TableExprNodeRep*>& operands);
00206 
00207     // Setup the baseline selection.
00208     void setupSelection (const Table& table,
00209                          PtrBlock<TableExprNodeRep*>& operands);
00210 
00211     // Setup direction conversion if a direction is explicitly given.
00212     void setupDir (TableExprNodeRep*& operand);
00213 
00214     // Setup getting column values from a subtable.
00215     void setupGetValue (const Table& table,
00216                         PtrBlock<TableExprNodeRep*>& operands);
00217 
00218     // Setup getting the wavelength information.
00219     void setupWvls (const Table& table,
00220                     PtrBlock<TableExprNodeRep*>& operands,
00221                     uInt nargMax);
00222 
00223     // Get the rownr in the subtable for GetValue.
00224     // If itsArg==1 it uses indirection using itsDDIds.
00225     Int64 getRowNr (const TableExprId& id);
00226 
00227     // Convert the UVW coordinates to wavelengths for the full spectrum.
00228     Array<Double> toWvls (const TableExprId&);
00229 
00230     //# Data members.
00231     MSCalEngine     itsEngine;
00232     StokesConverter itsStokesConv;
00233     TableExprNode   itsDataNode;   //# for stokes, selections and getvalues
00234     TableExprNode   itsIdNode;     //# node giving rowid for getvalues
00235     ArrayColumn<Double> itsUvwCol;
00236     ColType         itsType;
00237     Int             itsArg;        //# antnr or SelType or getValueType
00238                                    //# -1 subtable can be empty
00239                                    //#  0 normal subtable
00240                                    //#  1 indirect subtable via DATA_DESC_ID
00241     String          itsFuncName;
00242     String          itsSubTabName;
00243     String          itsIdColName;
00244     String          itsSubColName;
00245     //# Preallocate arrays to avoid having to construct them too often.
00246     //# Makes it thread-unsafe though.
00247     Vector<Double>  itsTmpVector;
00248     Array<Double>   itsTmpUvwWvl;
00249     Vector<Int>     itsDDIds;      //# spw or pol ids from DATA_DESCRIPTION
00250     vector<Double>          itsWavel;
00251     vector<Vector<Double> > itsWavels;
00252   };
00253 
00254 
00255   // <summary>
00256   // Error handler class for MSSel selection
00257   // </summary>
00258   // <synopsis>
00259   // This error handler ignores the errors rising from the MSSel parsers.
00260   // </synopsis>
00261   class UDFMSCalErrorHandler : public MSSelectionErrorHandler
00262   {
00263   public:
00264     virtual ~UDFMSCalErrorHandler()
00265     {}
00266     virtual void handleError (MSSelectionError&)
00267     {}
00268     virtual void reportError (const char*, const String)
00269     {}
00270   };
00271 
00272 
00273 } //end namespace
00274 
00275 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1