casacore
PositionEngine.h
Go to the documentation of this file.
1 //# PositionEngine.h: Engine for TaQL UDF Position conversions
2 //# Copyright (C) 2011
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 MEAS_POSITIONENGINE_H
29 #define MEAS_POSITIONENGINE_H
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
33 #include <casacore/tables/TaQL/ExprNode.h>
34 #include <casacore/measures/Measures/MPosition.h>
35 #include <casacore/measures/Measures/MCPosition.h>
36 #include <casacore/measures/Measures/MeasConvert.h>
37 #include <casacore/measures/TableMeasures/ArrayMeasColumn.h>
38 
39 namespace casacore {
40 
41 // <summary>
42 // Engine for TaQL UDF Position conversions
43 // </summary>
44 
45 // <use visibility=export>
46 
47 // <reviewed reviewer="" date="" tests="tMeas.cc">
48 // </reviewed>
49 
50 // <prerequisite>
51 //# Classes you should understand before using this one.
52 // <li> EngineBase
53 // </prerequisite>
54 
55 // <synopsis>
56 // PositionEngine defines Engines (user defined functions) that can be used in TaQL
57 // to convert Measures for positions.
58 // In this way such derived values appear to be ordinary TaQL functions.
59 //
60 // In TaQL these functions can be called like:
61 // <srcblock>
62 // meas.pos (toref, pos, fromref)
63 // meas.itrf (pos, fromref)
64 // meas.wgs84 (pos, fromref)
65 // For example,
66 // meas.pos ('ITRF', [1e6m,1e6m,1e6m], 'WGS84')
67 // </srcblock>
68 // <ul>
69 // <li>
70 // <src>toref</src> is a single constant string.
71 // <li>
72 // <src>pos</src> can have various value types. A single numeric array is
73 // a series of RA,DEC in J2000. If given as a set, the last argument of the
74 // set can be the reference types of the values in the set. The values can
75 // be strings (indicating planetary objects) or value pairs giving lon,lat.
76 // The default reference type is J2000.
77 // </ul>
78 // All functions have data type double and unit radian.
79 
80 // Positions can be given like:
81 // [x1,y1,z1,x2,y2,z2,...], fromRef
82 // [lon1,lat1,lon2,lat2,...], fromRef
83 // [lon1,lat1,lon2,lat2,...], [h1,h2,...], fromRef
84 // where fromRef is the reference type optionally followed by _xxx
85 // where xxx can be 'xyz' or 'll' to specify if the values are given as xyz
86 // or as lon,lat.
87 // If xxx is not given, it will be derived from the unit type of the values
88 // (length means xyz, angle means lon,lat with default height is 0).
89 // If xxx nor units are given, 3 values means xyz and 2 values means lon,lat.
90 // If heights are also given, xxx must be 'll' if it is also given.
91 //
92 // A position can also be a table column which usually knows its type.
93 // It can also be an expression (e.g. POSITION[0,]) which also knows the type.
94 // </synopsis>
95 
96 // <motivation>
97 // It makes it possible to handle measures in TaQL.
98 // </motivation>
99 
101  {
102  public:
103  PositionEngine();
104 
105  // Get the reference type.
107  { return itsRefType; }
108 
109  // Get the value type. It also gives the nr of output values per position.
110  // 0=default, 1=height, 2=angles, 3=xyz
111  Int valueType() const
112  { return itsValueType; }
113 
114  // Get the shape.
115  const IPosition& shape() const
116  { return itsShape; }
117 
118  // Get the dimensionality.
119  Int ndim() const
120  { return itsNDim; }
121 
122  // Tell if the expression is constant.
123  Bool isConstant() const
124  { return itsConstants.size() > 0; }
125 
126  // Get the unit.
127  const Unit& unit() const
128  { return itsOutUnit; }
129 
130  // Get the values.
132  MPosition::Types toRefType,
133  Int toValueType);
134 
135  // Get the positions.
137 
138  // Handle the argument(s) giving the input positions and reference type.
139  // The position can be a column in a table.
140  void handlePosition (Int toValueType,
142  uInt& argnr);
143 
144  // Handle a position reference type and optional suffix.
145  void handlePosType (TableExprNodeRep* operand);
146 
147  private:
148  void makeDefaults (const Unit& unit);
149  // Make an MPosition from xyz or angles,height.
150  MPosition makePosition (const Quantity& qh,
151  const Quantity& q1,
152  const Quantity& q2) const;
154  TableExprNodeRep* heightNode);
155  void handleObservatory (TableExprNodeRep* operand);
156  void handlePosArray (TableExprNodeRep*& operand);
157  void handlePosArray (TableExprNodeRep* angles, TableExprNodeRep* height);
158  void handleConstant (TableExprNodeRep* operand);
159  void handleValues (TableExprNode& operand,
160  const TableExprId& id,
161  Array<MPosition>& positions);
162 
163  //# Data members.
172  //# 0=default, 1=xyz, 2=angles, 3=height
175  };
176 
177 } //end namespace
178 
179 #endif
A Vector of integers, for indexing into Array<T> objects.
Definition: IPosition.h:119
A Measure: position on Earth.
Definition: MPosition.h:79
int Int
Definition: aipstype.h:47
void handlePosition(Int toValueType, PtrBlock< TableExprNodeRep * > &args, uInt &argnr)
Handle the argument(s) giving the input positions and reference type.
void handleConstant(TableExprNodeRep *operand)
Handle class for a table column expression tree.
Definition: ExprNode.h:578
CountedPtr< MPosition::Convert > itsConvert
Engine for TaQL UDF Position conversions.
Abstract base class for a node in a table column expression tree.
Definition: ExprNodeRep.h:150
Read only access to table array Measure columns.
Definition: MBaseline.h:45
ArrayMeasColumn< MPosition > itsMeasCol
defines physical units
Definition: Unit.h:189
MPosition::Types itsRefType
Int ndim() const
Get the dimensionality.
void handleScalars(TableExprNodeRep *e1, TableExprNodeRep *e2, TableExprNodeRep *heightNode)
Referenced counted pointer for constant data.
Definition: CountedPtr.h:86
Int valueType() const
Get the value type.
void handlePosArray(TableExprNodeRep *&operand)
Array< MPosition > itsConstants
void makeDefaults(const Unit &unit)
MPosition makePosition(const Quantity &qh, const Quantity &q1, const Quantity &q2) const
Make an MPosition from xyz or angles,height.
void handleObservatory(TableExprNodeRep *operand)
Array< Double > getArrayDouble(const TableExprId &id, MPosition::Types toRefType, Int toValueType)
Get the values.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:39
const IPosition & shape() const
Get the shape.
A drop-in replacement for Block<T*>.
Definition: Block.h:861
const Unit & unit() const
Get the unit.
Types
Types of known MPositions Warning: The order defines the order in the translation matrix FromTo in t...
Definition: MPosition.h:94
void handlePosType(TableExprNodeRep *operand)
Handle a position reference type and optional suffix.
MPosition::Types refType() const
Get the reference type.
The identification of a TaQL selection subject.
Definition: TableExprId.h:98
void handleValues(TableExprNode &operand, const TableExprId &id, Array< MPosition > &positions)
Array< MPosition > getPositions(const TableExprId &id)
Get the positions.
this file contains all the compiler specific defines
Definition: mainpage.dox:28
unsigned int uInt
Definition: aipstype.h:48
Bool isConstant() const
Tell if the expression is constant.