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> UVW_J2000 is the UVW coordinates in J2000 (in meters)
77 // <li> STOKES makes it possible to convert Stokes of data, flag, or weight.
78 // <li> BASELINE is baseline selection using CASA syntax.
79 // <li> TIME is baseline selection using CASA syntax.
80 // <li> UVDIST is UV-distance selection using CASA syntax.
81 // <li> SPW is spectral window selection using CASA syntax.
82 // <li> FIELD is field selection using CASA syntax.
83 // <li> ARRAY is array selection using CASA syntax.
84 // <li> SCAN is scan selection using CASA syntax.
85 // <li> STATE is state selection using CASA syntax.
86 // <li> OBS is observation selection using CASA syntax.
87 // <li> ANTNAME is the name of the given antenna.
88 // </ul>
89 // The first functions have data type double and unit radian (except UVW).
90 // The HADEC, AZEL, and UVW functions return arrays while the others return
91 // scalars.
92 // <br>The STOKES function can have data type Complex, Double or Bool.
93 // <br>The latter functions are selection functions and return a Bool scalar.
94 //
95 // This class is meant for a MeasurementSet, but can be used for any table
96 // containing an ANTENNA and FIELD subtable and the relevant columns in the
97 // main table (ANTENNA1 and/or ANTENNA2, FIELD_ID, and TIME).
98 // <br>In principle the array center is the Observatory position, which is
99 // taken from the Measures Observatory table using the telescope name found
100 // in the OBSERVATION subtable. However, if the subtable is not defined or
101 // empty or if the telescope name is unknown, the position of the first antenna
102 // is used as the array position.
103 //
104 // The engine can also be used for a CASA Calibration Table. It understands
105 // how it references the MeasurementSets. Because calibration tables contain
106 // no ANTENNA2 columns, functions XX2 are the same as XX1.
107 // </synopsis>
108 
109 // <motivation>
110 // It makes it possible to do queries on these values without having
111 // to add columns for them.
112 // </motivation>
113 
114  class UDFMSCal: public UDFBase
115  {
116  public:
117  // Define the possible 'column' types.
121  // Define the possible selection types.
123 
124  // Create object the given ColType and SelType.
125  UDFMSCal (ColType, Int arg);
126 
127  // Create the object for getting a value from a column in a subtable.
128  // <group>
129  explicit UDFMSCal (const String& funcName);
130  UDFMSCal (const String& funcName, const String& subtabName,
131  const String& idColName, Int arg=0);
132  UDFMSCal (const String& funcName, const String& subtabName,
133  const String& idColName, const String& colName);
134  // </group>
135 
136  // Function to create an object.
137  static UDFBase* makeHA (const String&);
138  static UDFBase* makeHA1 (const String&);
139  static UDFBase* makeHA2 (const String&);
140  static UDFBase* makeHADEC (const String&);
141  static UDFBase* makeHADEC1 (const String&);
142  static UDFBase* makeHADEC2 (const String&);
143  static UDFBase* makePA1 (const String&);
144  static UDFBase* makePA2 (const String&);
145  static UDFBase* makeLAST (const String&);
146  static UDFBase* makeLAST1 (const String&);
147  static UDFBase* makeLAST2 (const String&);
148  static UDFBase* makeAZEL1 (const String&);
149  static UDFBase* makeAZEL2 (const String&);
150  static UDFBase* makeUVW (const String&);
151  static UDFBase* makeWvl (const String&);
152  static UDFBase* makeWvls (const String&);
153  static UDFBase* makeUvwWvl (const String&);
154  static UDFBase* makeUvwWvls (const String&);
155  static UDFBase* makeStokes (const String&);
156  static UDFBase* makeBaseline (const String&);
157  static UDFBase* makeTime (const String&);
158  static UDFBase* makeUVDist (const String&);
159  static UDFBase* makeSpw (const String&);
160  static UDFBase* makeField (const String&);
161  static UDFBase* makeArray (const String&);
162  static UDFBase* makeScan (const String&);
163  static UDFBase* makeState (const String&);
164  static UDFBase* makeObs (const String&);
165  static UDFBase* makeAnt1Name (const String&);
166  static UDFBase* makeAnt2Name (const String&);
167  static UDFBase* makeAnt1Col (const String&);
168  static UDFBase* makeAnt2Col (const String&);
169  static UDFBase* makeStateCol (const String&);
170  static UDFBase* makeObsCol (const String&);
171  static UDFBase* makeSpwCol (const String&);
172  static UDFBase* makePolCol (const String&);
173  static UDFBase* makeFieldCol (const String&);
174  static UDFBase* makeProcCol (const String&);
175  static UDFBase* makeSubCol (const String&);
176 
177  // Setup the object.
178  virtual void setup (const Table&, const TaQLStyle&);
179 
180  // Get the value.
181  virtual Bool getBool (const TableExprId& id);
182  virtual Int64 getInt (const TableExprId& id);
183  virtual Double getDouble (const TableExprId& id);
184  virtual DComplex getDComplex (const TableExprId& id);
185  virtual String getString (const TableExprId& id);
186  virtual Array<Bool> getArrayBool (const TableExprId& id);
187  virtual Array<Int64> getArrayInt (const TableExprId& id);
188  virtual Array<Double> getArrayDouble (const TableExprId& id);
189  virtual Array<DComplex> getArrayDComplex (const TableExprId& id);
190  virtual Array<String> getArrayString (const TableExprId& id);
191 
192  // Let a derived class recreate its column objects in case a selection
193  // has to be applied.
194  virtual void recreateColumnObjects (const Vector<uInt>& rownrs);
195 
196  private:
197  // Setup the Stokes conversion.
198  void setupStokes (const Table& table,
200 
201  // Setup the baseline selection.
202  void setupSelection (const Table& table,
203  PtrBlock<TableExprNodeRep*>& operands);
204 
205  // Setup direction conversion if a direction is explicitly given.
206  void setupDir (TableExprNodeRep*& operand);
207 
208  // Setup getting column values from a subtable.
209  void setupGetValue (const Table& table,
210  PtrBlock<TableExprNodeRep*>& operands);
211 
212  // Setup getting the wavelength information.
213  void setupWvls (const Table& table,
214  PtrBlock<TableExprNodeRep*>& operands,
215  uInt nargMax);
216 
217  // Get the rownr in the subtable for GetValue.
218  // If itsArg==1 it uses indirection using itsDDIds.
219  Int64 getRowNr (const TableExprId& id);
220 
221  // Convert the UVW coordinates to wavelengths for the full spectrum.
223 
224  //# Data members.
227  TableExprNode itsDataNode; //# for stokes, selections and getvalues
228  TableExprNode itsIdNode; //# node giving rowid for getvalues
231  Int itsArg; //# antnr or SelType or getValueType
232  //# -1 subtable can be empty
233  //# 0 normal subtable
234  //# 1 indirect subtable via DATA_DESC_ID
239  //# Preallocate arrays to avoid having to construct them too often.
240  //# Makes it thread-unsafe though.
243  Vector<Int> itsDDIds; //# spw or pol ids from DATA_DESCRIPTION
244  vector<Double> itsWavel;
245  vector<Vector<Double> > itsWavels;
246  };
247 
248 
249  // <summary>
250  // Error handler class for MSSel selection
251  // </summary>
252  // <synopsis>
253  // This error handler ignores the errors rising from the MSSel parsers.
254  // </synopsis>
256  {
257  public:
259  {}
261  {}
262  virtual void reportError (const char*, const String)
263  {}
264  };
265 
266 
267 } //end namespace
268 
269 #endif
static UDFBase * makeHADEC1(const String &)
static UDFBase * makeAnt1Name(const String &)
Vector< Int > itsDDIds
Definition: UDFMSCal.h:243
static UDFBase * makeObsCol(const String &)
String itsSubColName
Definition: UDFMSCal.h:238
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:47
void setupSelection(const Table &table, PtrBlock< TableExprNodeRep * > &operands)
Setup the baseline selection.
LatticeExprNode arg(const LatticeExprNode &expr)
virtual void reportError(const char *, const String)
Definition: UDFMSCal.h:262
static UDFBase * makeLAST1(const String &)
static UDFBase * makeField(const String &)
Main interface class to a read/write table.
Definition: Table.h:149
virtual Int64 getInt(const TableExprId &id)
static UDFBase * makeAnt1Col(const String &)
static UDFBase * makeProcCol(const String &)
PtrBlock< TableExprNodeRep * > & operands()
Get the operands.
Definition: UDFBase.h:281
Handle class for a table column expression tree.
Definition: ExprNode.h:578
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:122
static UDFBase * makeObs(const String &)
virtual DComplex getDComplex(const TableExprId &id)
Vector< Double > itsTmpVector
Definition: UDFMSCal.h:241
static UDFBase * makeUvwWvl(const String &)
Abstract base class for a user-defined TaQL function.
Definition: UDFBase.h:233
static UDFBase * makeLAST(const String &)
virtual Double getDouble(const TableExprId &id)
Abstract base class for a node in a table column expression tree.
Definition: ExprNodeRep.h:150
static UDFBase * makeUvwWvls(const String &)
virtual String getString(const TableExprId &id)
Int64 getRowNr(const TableExprId &id)
Get the rownr in the subtable for GetValue.
StokesConverter itsStokesConv
Definition: UDFMSCal.h:226
StokesConverter converts any set of polarizations into any other one.
static UDFBase * makeBaseline(const String &)
static UDFBase * makeSpw(const String &)
void setupWvls(const Table &table, PtrBlock< TableExprNodeRep * > &operands, uInt nargMax)
Setup getting the wavelength information.
void setupStokes(const Table &table, PtrBlock< TableExprNodeRep * > &operands)
Setup the Stokes conversion.
virtual Array< Double > getArrayDouble(const TableExprId &id)
static UDFBase * makeFieldCol(const String &)
static UDFBase * makeSubCol(const String &)
TableExprNode itsIdNode
Definition: UDFMSCal.h:228
static UDFBase * makeStateCol(const String &)
static UDFBase * makeWvls(const String &)
Array< Double > itsTmpUvwWvl
Definition: UDFMSCal.h:242
double Double
Definition: aipstype.h:52
Class with static members defining the TaQL style.
Definition: TaQLStyle.h:64
static UDFBase * makeSpwCol(const String &)
virtual Array< Int64 > getArrayInt(const TableExprId &id)
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:39
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:225
virtual Array< DComplex > getArrayDComplex(const TableExprId &id)
static UDFBase * makePA2(const String &)
A drop-in replacement for Block<T*>.
Definition: Block.h:861
static UDFBase * makeAnt2Col(const String &)
vector< Vector< Double > > itsWavels
Definition: UDFMSCal.h:245
static UDFBase * makeAZEL2(const String &)
String itsSubTabName
Definition: UDFMSCal.h:236
static UDFBase * makeUVW(const String &)
static UDFBase * makeArray(const String &)
static UDFBase * makeLAST2(const String &)
virtual Array< String > getArrayString(const TableExprId &id)
void setupGetValue(const Table &table, PtrBlock< TableExprNodeRep * > &operands)
Setup getting column values from a subtable.
The identification of a TaQL selection subject.
Definition: TableExprId.h:98
static UDFBase * makePolCol(const String &)
vector< Double > itsWavel
Definition: UDFMSCal.h:244
static UDFBase * makeHADEC2(const String &)
TableExprNode itsDataNode
Definition: UDFMSCal.h:227
static UDFBase * makeUVDist(const String &)
static UDFBase * makeStokes(const String &)
virtual void handleError(MSSelectionError &)
Definition: UDFMSCal.h:260
String: the storage and methods of handling collections of characters.
Definition: String.h:223
virtual Bool getBool(const TableExprId &id)
Get the value.
static UDFBase * makeAnt2Name(const String &)
static UDFBase * makePA1(const String &)
static UDFBase * makeHADEC(const String &)
ArrayColumn< Double > itsUvwCol
Definition: UDFMSCal.h:229
static UDFBase * makeScan(const String &)
ColType
Define the possible &#39;column&#39; types.
Definition: UDFMSCal.h:118
static UDFBase * makeAZEL1(const String &)
virtual Array< Bool > getArrayBool(const TableExprId &id)
void setupDir(TableExprNodeRep *&operand)
Setup direction conversion if a direction is explicitly given.
static UDFBase * makeState(const String &)
UDFMSCal(ColType, Int arg)
Create object the given ColType and SelType.
this file contains all the compiler specific defines
Definition: mainpage.dox:28
static UDFBase * makeHA2(const String &)
static UDFBase * makeWvl(const String &)
String itsFuncName
Definition: UDFMSCal.h:235
unsigned int uInt
Definition: aipstype.h:48
Error handler class for MSSel selection.
Definition: UDFMSCal.h:255
static UDFBase * makeHA1(const String &)
static UDFBase * makeHA(const String &)
Function to create an object.
Engine to calculate derived MS values.
Definition: MSCalEngine.h:116
TaQL UDFs to calculate derived MS values.
Definition: UDFMSCal.h:114
String itsIdColName
Definition: UDFMSCal.h:237