casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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>
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.
129  UDFMSCal (ColType, Int arg);
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);
202  virtual MArray<Double> getArrayDouble (const TableExprId& id);
203  virtual MArray<DComplex> getArrayDComplex (const TableExprId& id);
204  virtual MArray<String> getArrayString (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<uInt>& 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.
233  Int64 getRowNr (const TableExprId& id);
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
static UDFBase * makeHADEC1(const String &)
static UDFBase * makeAnt1Name(const String &)
Vector< Int > itsDDIds
Definition: UDFMSCal.h:257
static UDFBase * makeObsCol(const String &)
String itsSubColName
Definition: UDFMSCal.h:252
virtual MArray< DComplex > getArrayDComplex(const TableExprId &id)
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
LatticeExprNode arg(const LatticeExprNode &expr)
static UDFBase * makeAZEL(const String &)
static UDFBase * makeFeed(const String &)
virtual void reportError(const char *, const String)
Definition: UDFMSCal.h:276
static UDFBase * makeLAST1(const String &)
static UDFBase * makeField(const String &)
Main interface class to a read/write table.
Definition: Table.h:153
virtual Int64 getInt(const TableExprId &id)
static UDFBase * makeAnt1Col(const String &)
static UDFBase * makeProcCol(const String &)
virtual MArray< Int64 > getArrayInt(const TableExprId &id)
Handle class for a table column expression tree.
Definition: ExprNode.h:155
virtual void recreateColumnObjects(const Vector< uInt > &rownrs)
Let a derived class recreate its column objects in case a selection has to be applied.
SelType
Define the possible selection types.
Definition: UDFMSCal.h:125
static UDFBase * makeObs(const String &)
virtual DComplex getDComplex(const TableExprId &id)
Vector< Double > itsTmpVector
Definition: UDFMSCal.h:255
static UDFBase * makeUvwWvl(const String &)
Abstract base class for a user-defined TaQL function.
Definition: UDFBase.h:236
static UDFBase * makeCorr(const String &)
static UDFBase * makeLAST(const String &)
virtual Double getDouble(const TableExprId &id)
void setupDir(TENShPtr &operand)
Setup direction conversion if a direction is explicitly given.
static UDFBase * makeWvlsJ2000(const String &)
static UDFBase * makeUvwWvls(const String &)
virtual String getString(const TableExprId &id)
Int64 getRowNr(const TableExprId &id)
Get the rownr in the subtable for GetValue.
static UDFBase * makeWvlJ2000(const String &)
void setupGetValue(const Table &table, std::vector< TENShPtr > &operands)
Setup getting column values from a subtable.
StokesConverter itsStokesConv
Definition: UDFMSCal.h:240
StokesConverter converts any set of polarizations into any other one.
static UDFBase * makeBaseline(const String &)
static UDFBase * makeDelay(const String &)
static UDFBase * makeSpw(const String &)
static UDFBase * makeDelay1(const String &)
static UDFBase * makeFieldCol(const String &)
static UDFBase * makeSubCol(const String &)
TableExprNode itsIdNode
Definition: UDFMSCal.h:242
static UDFBase * makeStateCol(const String &)
static UDFBase * makeDelay2(const String &)
Array< Double > itsTmpUvwWvl
Definition: UDFMSCal.h:256
double Double
Definition: aipstype.h:55
static UDFBase * makeUvwAPP(const String &)
Class with static members defining the TaQL style.
Definition: TaQLStyle.h:64
static UDFBase * makeSpwCol(const String &)
void setupWvls(const Table &table, std::vector< TENShPtr > &operands, uInt nargMax)
Setup getting the wavelength information.
static UDFBase * makeUvwJ2000(const String &)
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
Array< Double > toWvls(const TableExprId &)
Convert the UVW coordinates to wavelengths for the full spectrum.
virtual void setup(const Table &, const TaQLStyle &)
Setup the object.
static UDFBase * makeTime(const String &)
MSCalEngine itsEngine
Definition: UDFMSCal.h:239
static UDFBase * makePA2(const String &)
virtual MArray< Double > getArrayDouble(const TableExprId &id)
static UDFBase * makeAnt2Col(const String &)
vector< Vector< Double > > itsWavels
Definition: UDFMSCal.h:259
static UDFBase * makeAZEL2(const String &)
void setupSelection(const Table &table, std::vector< TENShPtr > &operands)
Setup the baseline selection.
String itsSubTabName
Definition: UDFMSCal.h:250
static UDFBase * makeArray(const String &)
static UDFBase * makeLAST2(const String &)
void setupStokes(const Table &table, std::vector< TENShPtr > &operands)
Setup the Stokes conversion.
The identification of a TaQL selection subject.
Definition: TableExprId.h:97
static UDFBase * makePolCol(const String &)
vector< Double > itsWavel
Definition: UDFMSCal.h:258
static UDFBase * makeHADEC2(const String &)
TableExprNode itsDataNode
Definition: UDFMSCal.h:241
static UDFBase * makeITRF(const String &)
static UDFBase * makeUVDist(const String &)
virtual MArray< String > getArrayString(const TableExprId &id)
static UDFBase * makeStokes(const String &)
virtual void handleError(MSSelectionError &)
Definition: UDFMSCal.h:274
String: the storage and methods of handling collections of characters.
Definition: String.h:223
std::vector< TENShPtr > & operands()
Get the operands.
Definition: UDFBase.h:288
virtual Bool getBool(const TableExprId &id)
Get the value.
static UDFBase * makeAnt2Name(const String &)
static UDFBase * makePA1(const String &)
static UDFBase * makeWvlAPP(const String &)
static UDFBase * makeHADEC(const String &)
virtual MArray< Bool > getArrayBool(const TableExprId &id)
ArrayColumn< Double > itsUvwCol
Definition: UDFMSCal.h:243
static UDFBase * makeScan(const String &)
ColType
Define the possible &#39;column&#39; types.
Definition: UDFMSCal.h:121
static UDFBase * makeAZEL1(const String &)
static UDFBase * makeState(const String &)
UDFMSCal(ColType, Int arg)
Create object the given ColType and SelType.
static UDFBase * makeHA2(const String &)
String itsFuncName
Definition: UDFMSCal.h:249
static UDFBase * makeWvlsAPP(const String &)
unsigned int uInt
Definition: aipstype.h:51
Error handler class for MSSel selection.
Definition: UDFMSCal.h:269
static UDFBase * makeHA1(const String &)
static UDFBase * makeHA(const String &)
Function to create an object.
Engine to calculate derived MS values.
Definition: MSCalEngine.h:118
TaQL UDFs to calculate derived MS values.
Definition: UDFMSCal.h:117
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42
String itsIdColName
Definition: UDFMSCal.h:251