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
115class UDFMSCal : public UDFBase {
116 public:
117 // Define the possible 'column' types.
135 // Define the possible selection types.
137
138 // Create object the given ColType and SelType.
140
141 // Create the object for getting a value from a column in a subtable.
142 // <group>
143 explicit UDFMSCal(const String& funcName);
144 UDFMSCal(const String& funcName, const String& subtabName, const String& idColName, Int arg = 0);
145 UDFMSCal(const String& funcName, const String& subtabName, const String& idColName,
146 const String& colName);
147 // </group>
148
149 // Function to create an object.
150 static UDFBase* makeHA(const String&);
151 static UDFBase* makeHA1(const String&);
152 static UDFBase* makeHA2(const String&);
153 static UDFBase* makeHADEC(const String&);
154 static UDFBase* makeHADEC1(const String&);
155 static UDFBase* makeHADEC2(const String&);
156 static UDFBase* makePA1(const String&);
157 static UDFBase* makePA2(const String&);
158 static UDFBase* makeLAST(const String&);
159 static UDFBase* makeLAST1(const String&);
160 static UDFBase* makeLAST2(const String&);
161 static UDFBase* makeAZEL(const String&);
162 static UDFBase* makeAZEL1(const String&);
163 static UDFBase* makeAZEL2(const String&);
164 static UDFBase* makeITRF(const String&);
165 static UDFBase* makeUvwWvl(const String&);
166 static UDFBase* makeUvwWvls(const String&);
167 static UDFBase* makeUvwJ2000(const String&);
168 static UDFBase* makeWvlJ2000(const String&);
169 static UDFBase* makeWvlsJ2000(const String&);
170 static UDFBase* makeUvwAPP(const String&);
171 static UDFBase* makeWvlAPP(const String&);
172 static UDFBase* makeWvlsAPP(const String&);
173 static UDFBase* makeDelay(const String&);
174 static UDFBase* makeDelay1(const String&);
175 static UDFBase* makeDelay2(const String&);
176 static UDFBase* makeStokes(const String&);
177 static UDFBase* makeBaseline(const String&);
178 static UDFBase* makeCorr(const String&);
179 static UDFBase* makeTime(const String&);
180 static UDFBase* makeUVDist(const String&);
181 static UDFBase* makeSpw(const String&);
182 static UDFBase* makeField(const String&);
183 static UDFBase* makeFeed(const String&);
184 static UDFBase* makeArray(const String&);
185 static UDFBase* makeScan(const String&);
186 static UDFBase* makeState(const String&);
187 static UDFBase* makeObs(const String&);
188 static UDFBase* makeAnt1Name(const String&);
189 static UDFBase* makeAnt2Name(const String&);
190 static UDFBase* makeAnt1Col(const String&);
191 static UDFBase* makeAnt2Col(const String&);
192 static UDFBase* makeStateCol(const String&);
193 static UDFBase* makeObsCol(const String&);
194 static UDFBase* makeSpwCol(const String&);
195 static UDFBase* makePolCol(const String&);
196 static UDFBase* makeFieldCol(const String&);
197 static UDFBase* makeProcCol(const String&);
198 static UDFBase* makeSubCol(const String&);
199
200 // Setup the object.
201 virtual void setup(const Table&, const TaQLStyle&);
202
203 // Get the value.
204 virtual Bool getBool(const TableExprId& id);
205 virtual Int64 getInt(const TableExprId& id);
206 virtual Double getDouble(const TableExprId& id);
207 virtual DComplex getDComplex(const TableExprId& id);
208 virtual String getString(const TableExprId& id);
214
215 // Let a derived class recreate its column objects in case a selection
216 // has to be applied.
217 virtual void recreateColumnObjects(const Vector<rownr_t>& rownrs);
218
219 private:
220 // Setup the Stokes conversion.
221 void setupStokes(const Table& table, std::vector<TENShPtr>& operands);
222
223 // Setup the baseline selection.
224 void setupSelection(const Table& table, std::vector<TENShPtr>& operands);
225
226 // Setup direction conversion if a direction is explicitly given.
227 void setupDir(TENShPtr& operand);
228
229 // Setup getting column values from a subtable.
230 void setupGetValue(const Table& table, std::vector<TENShPtr>& operands);
231
232 // Setup getting the wavelength information.
233 void setupWvls(const Table& table, std::vector<TENShPtr>& operands, uInt nargMax);
234
235 // Get the rownr in the subtable for GetValue.
236 // If itsArg==1 it uses indirection using itsDDIds.
238
239 // Convert the UVW coordinates to wavelengths for the full spectrum.
241
242 // # Data members.
245 TableExprNode itsDataNode; // # for stokes, selections and getvalues
246 TableExprNode itsIdNode; // # node giving rowid for getvalues
249 Int itsArg; // # antnr or SelType or getValueType
250 // # -1 subtable can be empty
251 // # 0 normal subtable
252 // # 1 indirect subtable via DATA_DESC_ID
253 std::string itsFuncName;
257 // # Preallocate arrays to avoid having to construct them too often.
258 // # Makes it thread-unsafe though.
261 Vector<Int> itsDDIds; // # spw or pol ids from DATA_DESCRIPTION
262 vector<Double> itsWavel;
263 vector<Vector<Double>> itsWavels;
264};
265
266// <summary>
267// Error handler class for MSSel selection
268// </summary>
269// <synopsis>
270// This error handler ignores the errors rising from the MSSel parsers.
271// </synopsis>
273 public:
274 ~UDFMSCalErrorHandler() override = default;
275 void handleError(MSSelectionError&) override {}
276 void reportError(const char*, const String) override {}
277};
278
279} // namespace casacore
280
281#endif
MSSelectionErrorHandler()
The default constructor generates the message "Table error".
String: the storage and methods of handling collections of characters.
Definition String.h:355
std::vector< TENShPtr > & operands()
Get the operands.
Definition UDFBase.h:277
UDFBase()
Only default constructor is needed.
Error handler class for MSSel selection.
Definition UDFMSCal.h:272
void handleError(MSSelectionError &) override
Definition UDFMSCal.h:275
void reportError(const char *, const String) override
Definition UDFMSCal.h:276
~UDFMSCalErrorHandler() override=default
Vector< Int > itsDDIds
Definition UDFMSCal.h:261
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:136
static UDFBase * makeAnt1Name(const String &)
static UDFBase * makeWvlsJ2000(const String &)
ArrayColumn< Double > itsUvwCol
Definition UDFMSCal.h:247
Vector< Double > itsTmpVector
Definition UDFMSCal.h:259
TableExprNode itsDataNode
Definition UDFMSCal.h:245
void setupWvls(const Table &table, std::vector< TENShPtr > &operands, uInt nargMax)
Setup getting the wavelength information.
MSCalEngine itsEngine
Definition UDFMSCal.h:243
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:118
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:244
vector< Vector< Double > > itsWavels
Definition UDFMSCal.h:263
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:246
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:260
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:262
static UDFBase * makeSpwCol(const String &)
std::string itsFuncName
Definition UDFMSCal.h:253
static UDFBase * makeDelay2(const String &)
static UDFBase * makeUvwWvls(const String &)
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
LatticeExprNode arg(const LatticeExprNode &expr)
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:56
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