casacore
UDFMSCal.h
Go to the documentation of this file.
1 //# UDFMSCal.h: TaQL UDFs to calculate derived MS values
2 //# Copyright (C) 2010
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id$
27 
28 #ifndef DERIVEDMSCAL_UDFMSCAL_H
29 #define DERIVEDMSCAL_UDFMSCAL_H
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
33 #include <casacore/derivedmscal/DerivedMC/MSCalEngine.h>
34 #include <casacore/ms/MeasurementSets/StokesConverter.h>
35 #include <casacore/ms/MSSel/MSSelectionErrorHandler.h>
36 #include <casacore/tables/TaQL/UDFBase.h>
37 #include <casacore/tables/TaQL/ExprNode.h>
38 
39 namespace casacore {
40 
41 // <summary>
42 // TaQL UDFs to calculate derived MS values.
43 // </summary>
44 
45 // <use visibility=export>
46 
47 // <reviewed reviewer="" date="" tests="tDerivedMSCal.cc">
48 // </reviewed>
49 
50 // <prerequisite>
51 //# Classes you should understand before using this one.
52 // <li> UDFBase
53 // </prerequisite>
54 
55 // <synopsis>
56 // UDFMSCal defines UDFs (user defined functions) that can be used in TaQL
57 // to get derived MeasurementSet values hourangle, parallactic angle,
58 // azimuth/elevation, and local sidereal time.
59 // In this way such derived values appear to be ordinary TaQL functions.
60 //
61 // The following functions can be defined:
62 // <ul>
63 // <li> HA is the hourangle of the array center (observatory position).
64 // <li> HA1 is the hourangle of ANTENNA1.
65 // <li> HA2 is the hourangle of ANTENNA2.
66 // <li> HADEC is the hourangle/DEC of the array center (observatory position).
67 // <li> HADEC1 is the hourangle/DEC of ANTENNA1.
68 // <li> HADEC2 is the hourangle/DEC of ANTENNA2.
69 // <li> LAST is the local sidereal time of the array center.
70 // <li> LAST1 is the local sidereal time of ANTENNA1.
71 // <li> LAST2 is the local sidereal time of ANTENNA2.
72 // <li> PA1 is the parallactic angle of ANTENNA1.
73 // <li> PA2 is the parallactic angle of ANTENNA2.
74 // <li> AZEL1 is the azimuth/elevation of ANTENNA1.
75 // <li> AZEL2 is the azimuth/elevation of ANTENNA2.
76 // <li> ITRF is the PHASE_DIR in ITRF coordinates (depends on TIME only).
77 // <li> UVW_J2000 is the UVW coordinates in J2000 (in meters)
78 // <li> STOKES makes it possible to convert Stokes of data, flag, or weight.
79 // <li> BASELINE is baseline selection using CASA syntax.
80 // <li> CORR is correlation selection using CASA syntax.
81 // <li> TIME is baseline selection using CASA syntax.
82 // <li> UVDIST is UV-distance selection using CASA syntax.
83 // <li> SPW is spectral window selection using CASA syntax.
84 // <li> FIELD is field selection using CASA syntax.
85 // <li> FEED is feed selection using CASA syntax.
86 // <li> ARRAY is array selection using CASA syntax.
87 // <li> SCAN is scan selection using CASA syntax.
88 // <li> STATE is state selection using CASA syntax.
89 // <li> OBS is observation selection using CASA syntax.
90 // <li> ANTNAME is the name of the given antenna.
91 // </ul>
92 // The first functions have data type double and unit radian (except UVW).
93 // The HADEC, AZEL, and UVW functions return arrays while the others return
94 // scalars.
95 // <br>The STOKES function can have data type Complex, Double or Bool.
96 // <br>The latter functions are selection functions and return a Bool scalar.
97 //
98 // This class is meant for a MeasurementSet, but can be used for any table
99 // containing an ANTENNA and FIELD subtable and the relevant columns in the
100 // main table (ANTENNA1 and/or ANTENNA2, FIELD_ID, and TIME).
101 // <br>In principle the array center is the Observatory position, which is
102 // taken from the Measures Observatory table using the telescope name found
103 // in the OBSERVATION subtable. However, if the subtable is not defined or
104 // empty or if the telescope name is unknown, the position of the first antenna
105 // is used as the array position.
106 //
107 // The engine can also be used for a CASA Calibration Table. It understands
108 // how it references the MeasurementSets. Because calibration tables contain
109 // no ANTENNA2 columns, functions XX2 are the same as XX1.
110 // </synopsis>
111 
112 // <motivation>
113 // It makes it possible to do queries on these values without having
114 // to add columns for them.
115 // </motivation>
116 
117  class UDFMSCal: public UDFBase
118  {
119  public:
120  // Define the possible 'column' types.
124  // Define the possible selection types.
127 
128  // Create object the given ColType and SelType.
130 
131  // Create the object for getting a value from a column in a subtable.
132  // <group>
133  explicit UDFMSCal (const String& funcName);
134  UDFMSCal (const String& funcName, const String& subtabName,
135  const String& idColName, Int arg=0);
136  UDFMSCal (const String& funcName, const String& subtabName,
137  const String& idColName, const String& colName);
138  // </group>
139 
140  // Function to create an object.
141  static UDFBase* makeHA (const String&);
142  static UDFBase* makeHA1 (const String&);
143  static UDFBase* makeHA2 (const String&);
144  static UDFBase* makeHADEC (const String&);
145  static UDFBase* makeHADEC1 (const String&);
146  static UDFBase* makeHADEC2 (const String&);
147  static UDFBase* makePA1 (const String&);
148  static UDFBase* makePA2 (const String&);
149  static UDFBase* makeLAST (const String&);
150  static UDFBase* makeLAST1 (const String&);
151  static UDFBase* makeLAST2 (const String&);
152  static UDFBase* makeAZEL (const String&);
153  static UDFBase* makeAZEL1 (const String&);
154  static UDFBase* makeAZEL2 (const String&);
155  static UDFBase* makeITRF (const String&);
156  static UDFBase* makeUvwWvl (const String&);
157  static UDFBase* makeUvwWvls (const String&);
158  static UDFBase* makeUvwJ2000 (const String&);
159  static UDFBase* makeWvlJ2000 (const String&);
160  static UDFBase* makeWvlsJ2000(const String&);
161  static UDFBase* makeUvwAPP (const String&);
162  static UDFBase* makeWvlAPP (const String&);
163  static UDFBase* makeWvlsAPP (const String&);
164  static UDFBase* makeDelay (const String&);
165  static UDFBase* makeDelay1 (const String&);
166  static UDFBase* makeDelay2 (const String&);
167  static UDFBase* makeStokes (const String&);
168  static UDFBase* makeBaseline (const String&);
169  static UDFBase* makeCorr (const String&);
170  static UDFBase* makeTime (const String&);
171  static UDFBase* makeUVDist (const String&);
172  static UDFBase* makeSpw (const String&);
173  static UDFBase* makeField (const String&);
174  static UDFBase* makeFeed (const String&);
175  static UDFBase* makeArray (const String&);
176  static UDFBase* makeScan (const String&);
177  static UDFBase* makeState (const String&);
178  static UDFBase* makeObs (const String&);
179  static UDFBase* makeAnt1Name (const String&);
180  static UDFBase* makeAnt2Name (const String&);
181  static UDFBase* makeAnt1Col (const String&);
182  static UDFBase* makeAnt2Col (const String&);
183  static UDFBase* makeStateCol (const String&);
184  static UDFBase* makeObsCol (const String&);
185  static UDFBase* makeSpwCol (const String&);
186  static UDFBase* makePolCol (const String&);
187  static UDFBase* makeFieldCol (const String&);
188  static UDFBase* makeProcCol (const String&);
189  static UDFBase* makeSubCol (const String&);
190 
191  // Setup the object.
192  virtual void setup (const Table&, const TaQLStyle&);
193 
194  // Get the value.
195  virtual Bool getBool (const TableExprId& id);
196  virtual Int64 getInt (const TableExprId& id);
197  virtual Double getDouble (const TableExprId& id);
198  virtual DComplex getDComplex (const TableExprId& id);
199  virtual String getString (const TableExprId& id);
200  virtual MArray<Bool> getArrayBool (const TableExprId& id);
201  virtual MArray<Int64> getArrayInt (const TableExprId& id);
205 
206  // Let a derived class recreate its column objects in case a selection
207  // has to be applied.
208  virtual void recreateColumnObjects (const Vector<rownr_t>& rownrs);
209 
210  private:
211  // Setup the Stokes conversion.
212  void setupStokes (const Table& table,
213  std::vector<TENShPtr>& operands);
214 
215  // Setup the baseline selection.
216  void setupSelection (const Table& table,
217  std::vector<TENShPtr>& operands);
218 
219  // Setup direction conversion if a direction is explicitly given.
220  void setupDir (TENShPtr& operand);
221 
222  // Setup getting column values from a subtable.
223  void setupGetValue (const Table& table,
224  std::vector<TENShPtr>& operands);
225 
226  // Setup getting the wavelength information.
227  void setupWvls (const Table& table,
228  std::vector<TENShPtr>& operands,
229  uInt nargMax);
230 
231  // Get the rownr in the subtable for GetValue.
232  // If itsArg==1 it uses indirection using itsDDIds.
234 
235  // Convert the UVW coordinates to wavelengths for the full spectrum.
237 
238  //# Data members.
241  TableExprNode itsDataNode; //# for stokes, selections and getvalues
242  TableExprNode itsIdNode; //# node giving rowid for getvalues
245  Int itsArg; //# antnr or SelType or getValueType
246  //# -1 subtable can be empty
247  //# 0 normal subtable
248  //# 1 indirect subtable via DATA_DESC_ID
253  //# Preallocate arrays to avoid having to construct them too often.
254  //# Makes it thread-unsafe though.
257  Vector<Int> itsDDIds; //# spw or pol ids from DATA_DESCRIPTION
258  vector<Double> itsWavel;
259  vector<Vector<Double> > itsWavels;
260  };
261 
262 
263  // <summary>
264  // Error handler class for MSSel selection
265  // </summary>
266  // <synopsis>
267  // This error handler ignores the errors rising from the MSSel parsers.
268  // </synopsis>
270  {
271  public:
273  {}
275  {}
276  virtual void reportError (const char*, const String)
277  {}
278  };
279 
280 
281 } //end namespace
282 
283 #endif
String: the storage and methods of handling collections of characters.
Definition: String.h:225
std::vector< TENShPtr > & operands()
Get the operands.
Definition: UDFBase.h:287
Error handler class for MSSel selection.
Definition: UDFMSCal.h:270
virtual void handleError(MSSelectionError &)
Definition: UDFMSCal.h:274
virtual void reportError(const char *, const String)
Definition: UDFMSCal.h:276
static UDFBase * makeHADEC1(const String &)
static UDFBase * makePA1(const String &)
String itsIdColName
Definition: UDFMSCal.h:251
Vector< Int > itsDDIds
Definition: UDFMSCal.h:257
static UDFBase * makeSpw(const String &)
void setupStokes(const Table &table, std::vector< TENShPtr > &operands)
Setup the Stokes conversion.
static UDFBase * makeLAST2(const String &)
virtual MArray< Double > getArrayDouble(const TableExprId &id)
Array< Double > toWvls(const TableExprId &)
Convert the UVW coordinates to wavelengths for the full spectrum.
static UDFBase * makeDelay(const String &)
Int64 getRowNr(const TableExprId &id)
Get the rownr in the subtable for GetValue.
SelType
Define the possible selection types.
Definition: UDFMSCal.h:125
static UDFBase * makeStateCol(const String &)
static UDFBase * makeFieldCol(const String &)
ArrayColumn< Double > itsUvwCol
Definition: UDFMSCal.h:243
static UDFBase * makeITRF(const String &)
static UDFBase * makeScan(const String &)
Vector< Double > itsTmpVector
Definition: UDFMSCal.h:255
static UDFBase * makeWvlAPP(const String &)
TableExprNode itsDataNode
Definition: UDFMSCal.h:241
void setupWvls(const Table &table, std::vector< TENShPtr > &operands, uInt nargMax)
Setup getting the wavelength information.
MSCalEngine itsEngine
Definition: UDFMSCal.h:239
static UDFBase * makeTime(const String &)
virtual Int64 getInt(const TableExprId &id)
static UDFBase * makeBaseline(const String &)
virtual DComplex getDComplex(const TableExprId &id)
static UDFBase * makeAnt2Name(const String &)
virtual MArray< Bool > getArrayBool(const TableExprId &id)
ColType
Define the possible 'column' types.
Definition: UDFMSCal.h:121
static UDFBase * makeUVDist(const String &)
String itsFuncName
Definition: UDFMSCal.h:249
static UDFBase * makeAnt1Name(const String &)
static UDFBase * makeSubCol(const String &)
static UDFBase * makeHA2(const String &)
String itsSubTabName
Definition: UDFMSCal.h:250
static UDFBase * makeFeed(const String &)
static UDFBase * makeCorr(const String &)
void setupSelection(const Table &table, std::vector< TENShPtr > &operands)
Setup the baseline selection.
String itsSubColName
Definition: UDFMSCal.h:252
static UDFBase * makeAZEL2(const String &)
static UDFBase * makeArray(const String &)
virtual void recreateColumnObjects(const Vector< rownr_t > &rownrs)
Let a derived class recreate its column objects in case a selection has to be applied.
static UDFBase * makeField(const String &)
static UDFBase * makeAZEL(const String &)
static UDFBase * makeState(const String &)
virtual MArray< Int64 > getArrayInt(const TableExprId &id)
static UDFBase * makeHA(const String &)
Function to create an object.
static UDFBase * makePolCol(const String &)
void setupDir(TENShPtr &operand)
Setup direction conversion if a direction is explicitly given.
StokesConverter itsStokesConv
Definition: UDFMSCal.h:240
static UDFBase * makeObsCol(const String &)
vector< Vector< Double > > itsWavels
Definition: UDFMSCal.h:259
static UDFBase * makeAZEL1(const String &)
UDFMSCal(const String &funcName)
Create the object for getting a value from a column in a subtable.
void setupGetValue(const Table &table, std::vector< TENShPtr > &operands)
Setup getting column values from a subtable.
static UDFBase * makeUvwWvls(const String &)
static UDFBase * makeAnt1Col(const String &)
static UDFBase * makeObs(const String &)
static UDFBase * makeLAST1(const String &)
UDFMSCal(const String &funcName, const String &subtabName, const String &idColName, Int arg=0)
TableExprNode itsIdNode
Definition: UDFMSCal.h:242
static UDFBase * makeUvwWvl(const String &)
virtual void setup(const Table &, const TaQLStyle &)
Setup the object.
virtual MArray< String > getArrayString(const TableExprId &id)
virtual Bool getBool(const TableExprId &id)
Get the value.
virtual Double getDouble(const TableExprId &id)
static UDFBase * makeHADEC(const String &)
static UDFBase * makeWvlsAPP(const String &)
static UDFBase * makeLAST(const String &)
static UDFBase * makeSpwCol(const String &)
static UDFBase * makeDelay2(const String &)
static UDFBase * makeAnt2Col(const String &)
static UDFBase * makeHA1(const String &)
static UDFBase * makeUvwJ2000(const String &)
static UDFBase * makePA2(const String &)
Array< Double > itsTmpUvwWvl
Definition: UDFMSCal.h:256
static UDFBase * makeUvwAPP(const String &)
static UDFBase * makeWvlsJ2000(const String &)
static UDFBase * makeProcCol(const String &)
static UDFBase * makeDelay1(const String &)
virtual String getString(const TableExprId &id)
UDFMSCal(ColType, Int arg)
Create object the given ColType and SelType.
UDFMSCal(const String &funcName, const String &subtabName, const String &idColName, const String &colName)
static UDFBase * makeWvlJ2000(const String &)
static UDFBase * makeHADEC2(const String &)
static UDFBase * makeStokes(const String &)
vector< Double > itsWavel
Definition: UDFMSCal.h:258
virtual MArray< DComplex > getArrayDComplex(const TableExprId &id)
this file contains all the compiler specific defines
Definition: mainpage.dox:28
LatticeExprNode arg(const LatticeExprNode &expr)
unsigned int uInt
Definition: aipstype.h:51
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition: aipsxtype.h:38
int Int
Definition: aipstype.h:50
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
double Double
Definition: aipstype.h:55