casacore
Loading...
Searching...
No Matches
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: casa-feedback@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#ifndef DERIVEDMSCAL_UDFMSCAL_H
27#define DERIVEDMSCAL_UDFMSCAL_H
28
29//# Includes
30#include <casacore/casa/aips.h>
31#include <casacore/derivedmscal/DerivedMC/MSCalEngine.h>
32#include <casacore/ms/MeasurementSets/StokesConverter.h>
33#include <casacore/ms/MSSel/MSSelectionErrorHandler.h>
34#include <casacore/tables/TaQL/UDFBase.h>
35#include <casacore/tables/TaQL/ExprNode.h>
36
37namespace casacore {
38
39// <summary>
40// TaQL UDFs to calculate derived MS values.
41// </summary>
42
43// <use visibility=export>
44
45// <reviewed reviewer="" date="" tests="tDerivedMSCal.cc">
46// </reviewed>
47
48// <prerequisite>
49//# Classes you should understand before using this one.
50// <li> UDFBase
51// </prerequisite>
52
53// <synopsis>
54// UDFMSCal defines UDFs (user defined functions) that can be used in TaQL
55// to get derived MeasurementSet values hourangle, parallactic angle,
56// azimuth/elevation, and local sidereal time.
57// In this way such derived values appear to be ordinary TaQL functions.
58//
59// The following functions can be defined:
60// <ul>
61// <li> HA is the hourangle of the array center (observatory position).
62// <li> HA1 is the hourangle of ANTENNA1.
63// <li> HA2 is the hourangle of ANTENNA2.
64// <li> HADEC is the hourangle/DEC of the array center (observatory position).
65// <li> HADEC1 is the hourangle/DEC of ANTENNA1.
66// <li> HADEC2 is the hourangle/DEC of ANTENNA2.
67// <li> LAST is the local sidereal time of the array center.
68// <li> LAST1 is the local sidereal time of ANTENNA1.
69// <li> LAST2 is the local sidereal time of ANTENNA2.
70// <li> PA1 is the parallactic angle of ANTENNA1.
71// <li> PA2 is the parallactic angle of ANTENNA2.
72// <li> AZEL1 is the azimuth/elevation of ANTENNA1.
73// <li> AZEL2 is the azimuth/elevation of ANTENNA2.
74// <li> ITRF is the PHASE_DIR in ITRF coordinates (depends on TIME only).
75// <li> UVW_J2000 is the UVW coordinates in J2000 (in meters)
76// <li> STOKES makes it possible to convert Stokes of data, flag, or weight.
77// <li> BASELINE is baseline selection using CASA syntax.
78// <li> CORR is correlation 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> FEED is feed selection using CASA syntax.
84// <li> ARRAY is array selection using CASA syntax.
85// <li> SCAN is scan selection using CASA syntax.
86// <li> STATE is state selection using CASA syntax.
87// <li> OBS is observation selection using CASA syntax.
88// <li> ANTNAME is the name of the given antenna.
89// </ul>
90// The first functions have data type double and unit radian (except UVW).
91// The HADEC, AZEL, and UVW functions return arrays while the others return
92// scalars.
93// <br>The STOKES function can have data type Complex, Double or Bool.
94// <br>The latter functions are selection functions and return a Bool scalar.
95//
96// This class is meant for a MeasurementSet, but can be used for any table
97// containing an ANTENNA and FIELD subtable and the relevant columns in the
98// main table (ANTENNA1 and/or ANTENNA2, FIELD_ID, and TIME).
99// <br>In principle the array center is the Observatory position, which is
100// taken from the Measures Observatory table using the telescope name found
101// in the OBSERVATION subtable. However, if the subtable is not defined or
102// empty or if the telescope name is unknown, the position of the first antenna
103// is used as the array position.
104//
105// The engine can also be used for a CASA Calibration Table. It understands
106// how it references the MeasurementSets. Because calibration tables contain
107// no ANTENNA2 columns, functions XX2 are the same as XX1.
108// </synopsis>
109
110// <motivation>
111// It makes it possible to do queries on these values without having
112// to add columns for them.
113// </motivation>
114
115 class UDFMSCal: public UDFBase
116 {
117 public:
118 // Define the possible 'column' types.
122 // Define the possible selection types.
125
126 // Create object the given ColType and SelType.
128
129 // Create the object for getting a value from a column in a subtable.
130 // <group>
131 explicit UDFMSCal (const String& funcName);
132 UDFMSCal (const String& funcName, const String& subtabName,
133 const String& idColName, Int arg=0);
134 UDFMSCal (const String& funcName, const String& subtabName,
135 const String& idColName, const String& colName);
136 // </group>
137
138 // Function to create an object.
139 static UDFBase* makeHA (const String&);
140 static UDFBase* makeHA1 (const String&);
141 static UDFBase* makeHA2 (const String&);
142 static UDFBase* makeHADEC (const String&);
143 static UDFBase* makeHADEC1 (const String&);
144 static UDFBase* makeHADEC2 (const String&);
145 static UDFBase* makePA1 (const String&);
146 static UDFBase* makePA2 (const String&);
147 static UDFBase* makeLAST (const String&);
148 static UDFBase* makeLAST1 (const String&);
149 static UDFBase* makeLAST2 (const String&);
150 static UDFBase* makeAZEL (const String&);
151 static UDFBase* makeAZEL1 (const String&);
152 static UDFBase* makeAZEL2 (const String&);
153 static UDFBase* makeITRF (const String&);
154 static UDFBase* makeUvwWvl (const String&);
155 static UDFBase* makeUvwWvls (const String&);
156 static UDFBase* makeUvwJ2000 (const String&);
157 static UDFBase* makeWvlJ2000 (const String&);
158 static UDFBase* makeWvlsJ2000(const String&);
159 static UDFBase* makeUvwAPP (const String&);
160 static UDFBase* makeWvlAPP (const String&);
161 static UDFBase* makeWvlsAPP (const String&);
162 static UDFBase* makeDelay (const String&);
163 static UDFBase* makeDelay1 (const String&);
164 static UDFBase* makeDelay2 (const String&);
165 static UDFBase* makeStokes (const String&);
166 static UDFBase* makeBaseline (const String&);
167 static UDFBase* makeCorr (const String&);
168 static UDFBase* makeTime (const String&);
169 static UDFBase* makeUVDist (const String&);
170 static UDFBase* makeSpw (const String&);
171 static UDFBase* makeField (const String&);
172 static UDFBase* makeFeed (const String&);
173 static UDFBase* makeArray (const String&);
174 static UDFBase* makeScan (const String&);
175 static UDFBase* makeState (const String&);
176 static UDFBase* makeObs (const String&);
177 static UDFBase* makeAnt1Name (const String&);
178 static UDFBase* makeAnt2Name (const String&);
179 static UDFBase* makeAnt1Col (const String&);
180 static UDFBase* makeAnt2Col (const String&);
181 static UDFBase* makeStateCol (const String&);
182 static UDFBase* makeObsCol (const String&);
183 static UDFBase* makeSpwCol (const String&);
184 static UDFBase* makePolCol (const String&);
185 static UDFBase* makeFieldCol (const String&);
186 static UDFBase* makeProcCol (const String&);
187 static UDFBase* makeSubCol (const String&);
188
189 // Setup the object.
190 virtual void setup (const Table&, const TaQLStyle&);
191
192 // Get the value.
193 virtual Bool getBool (const TableExprId& id);
194 virtual Int64 getInt (const TableExprId& id);
195 virtual Double getDouble (const TableExprId& id);
196 virtual DComplex getDComplex (const TableExprId& id);
197 virtual String getString (const TableExprId& id);
203
204 // Let a derived class recreate its column objects in case a selection
205 // has to be applied.
206 virtual void recreateColumnObjects (const Vector<rownr_t>& rownrs);
207
208 private:
209 // Setup the Stokes conversion.
210 void setupStokes (const Table& table,
211 std::vector<TENShPtr>& operands);
212
213 // Setup the baseline selection.
214 void setupSelection (const Table& table,
215 std::vector<TENShPtr>& operands);
216
217 // Setup direction conversion if a direction is explicitly given.
218 void setupDir (TENShPtr& operand);
219
220 // Setup getting column values from a subtable.
221 void setupGetValue (const Table& table,
222 std::vector<TENShPtr>& operands);
223
224 // Setup getting the wavelength information.
225 void setupWvls (const Table& table,
226 std::vector<TENShPtr>& operands,
227 uInt nargMax);
228
229 // Get the rownr in the subtable for GetValue.
230 // If itsArg==1 it uses indirection using itsDDIds.
232
233 // Convert the UVW coordinates to wavelengths for the full spectrum.
235
236 //# Data members.
239 TableExprNode itsDataNode; //# for stokes, selections and getvalues
240 TableExprNode itsIdNode; //# node giving rowid for getvalues
243 Int itsArg; //# antnr or SelType or getValueType
244 //# -1 subtable can be empty
245 //# 0 normal subtable
246 //# 1 indirect subtable via DATA_DESC_ID
251 //# Preallocate arrays to avoid having to construct them too often.
252 //# Makes it thread-unsafe though.
255 Vector<Int> itsDDIds; //# spw or pol ids from DATA_DESCRIPTION
256 vector<Double> itsWavel;
257 vector<Vector<Double> > itsWavels;
258 };
259
260
261 // <summary>
262 // Error handler class for MSSel selection
263 // </summary>
264 // <synopsis>
265 // This error handler ignores the errors rising from the MSSel parsers.
266 // </synopsis>
268 {
269 public:
270 ~UDFMSCalErrorHandler() override = default;
272 {}
273 void reportError (const char*, const String) override
274 {}
275 };
276
277
278} //end namespace
279
280#endif
String: the storage and methods of handling collections of characters.
Definition String.h:223
std::vector< TENShPtr > & operands()
Get the operands.
Definition UDFBase.h:282
Error handler class for MSSel selection.
Definition UDFMSCal.h:268
void handleError(MSSelectionError &) override
Definition UDFMSCal.h:271
void reportError(const char *, const String) override
Definition UDFMSCal.h:273
~UDFMSCalErrorHandler() override=default
Vector< Int > itsDDIds
Definition UDFMSCal.h:255
static UDFBase * makeUvwJ2000(const String &)
void setupStokes(const Table &table, std::vector< TENShPtr > &operands)
Setup the Stokes conversion.
static UDFBase * makeField(const String &)
static UDFBase * makeUvwWvl(const String &)
static UDFBase * makeUvwAPP(const String &)
Int64 getRowNr(const TableExprId &id)
Get the rownr in the subtable for GetValue.
static UDFBase * makeObs(const String &)
SelType
Define the possible selection types.
Definition UDFMSCal.h:123
static UDFBase * makeAnt1Name(const String &)
static UDFBase * makeWvlsJ2000(const String &)
ArrayColumn< Double > itsUvwCol
Definition UDFMSCal.h:241
Vector< Double > itsTmpVector
Definition UDFMSCal.h:253
TableExprNode itsDataNode
Definition UDFMSCal.h:239
void setupWvls(const Table &table, std::vector< TENShPtr > &operands, uInt nargMax)
Setup getting the wavelength information.
MSCalEngine itsEngine
Definition UDFMSCal.h:237
virtual MArray< String > getArrayString(const TableExprId &id)
virtual Int64 getInt(const TableExprId &id)
virtual DComplex getDComplex(const TableExprId &id)
static UDFBase * makeLAST1(const String &)
static UDFBase * makeHADEC(const String &)
ColType
Define the possible 'column' types.
Definition UDFMSCal.h:119
static UDFBase * makeFeed(const String &)
static UDFBase * makeSubCol(const String &)
static UDFBase * makeAZEL2(const String &)
static UDFBase * makeFieldCol(const String &)
static UDFBase * makeHADEC2(const String &)
static UDFBase * makeState(const String &)
void setupSelection(const Table &table, std::vector< TENShPtr > &operands)
Setup the baseline selection.
static UDFBase * makeHA2(const String &)
static UDFBase * makeAZEL1(const String &)
static UDFBase * makeUVDist(const String &)
static UDFBase * makeTime(const String &)
static UDFBase * makeObsCol(const String &)
static UDFBase * makeHA1(const String &)
Array< Double > toWvls(const TableExprId &)
Convert the UVW coordinates to wavelengths for the full spectrum.
static UDFBase * makeWvlAPP(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.
virtual MArray< Double > getArrayDouble(const TableExprId &id)
static UDFBase * makePA2(const String &)
static UDFBase * makeScan(const String &)
void setupDir(TENShPtr &operand)
Setup direction conversion if a direction is explicitly given.
StokesConverter itsStokesConv
Definition UDFMSCal.h:238
vector< Vector< Double > > itsWavels
Definition UDFMSCal.h:257
static UDFBase * makeWvlJ2000(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 * makeAnt2Name(const String &)
static UDFBase * makeLAST(const String &)
static UDFBase * makeHADEC1(const String &)
virtual MArray< Bool > getArrayBool(const TableExprId &id)
static UDFBase * makeAZEL(const String &)
virtual MArray< Int64 > getArrayInt(const TableExprId &id)
static UDFBase * makeBaseline(const String &)
static UDFBase * makeAnt2Col(const String &)
static UDFBase * makeStokes(const String &)
static UDFBase * makeWvlsAPP(const String &)
UDFMSCal(const String &funcName, const String &subtabName, const String &idColName, Int arg=0)
TableExprNode itsIdNode
Definition UDFMSCal.h:240
virtual void setup(const Table &, const TaQLStyle &)
Setup the object.
static UDFBase * makeCorr(const String &)
virtual Bool getBool(const TableExprId &id)
Get the value.
static UDFBase * makePA1(const String &)
static UDFBase * makePolCol(const String &)
static UDFBase * makeITRF(const String &)
virtual Double getDouble(const TableExprId &id)
virtual MArray< DComplex > getArrayDComplex(const TableExprId &id)
static UDFBase * makeArray(const String &)
static UDFBase * makeStateCol(const String &)
static UDFBase * makeAnt1Col(const String &)
Array< Double > itsTmpUvwWvl
Definition UDFMSCal.h:254
virtual String getString(const TableExprId &id)
static UDFBase * makeDelay1(const String &)
static UDFBase * makeSpw(const String &)
static UDFBase * makeLAST2(const String &)
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 * makeProcCol(const String &)
static UDFBase * makeDelay(const String &)
static UDFBase * makeHA(const String &)
Function to create an object.
vector< Double > itsWavel
Definition UDFMSCal.h:256
static UDFBase * makeSpwCol(const String &)
static UDFBase * makeDelay2(const String &)
static UDFBase * makeUvwWvls(const String &)
this file contains all the compiler specific defines
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition aipsxtype.h:36
std::shared_ptr< TableExprNodeRep > TENShPtr
Definition ExprNodeRep.h:55
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
double Double
Definition aipstype.h:53