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/meas/MeasUDF/MeasEngine.h>
34 #include <casacore/measures/Measures/MPosition.h>
35 #include <casacore/measures/Measures/MCPosition.h>
36 #include <casacore/measures/Measures/MeasConvert.h>
37 
38 namespace casacore {
39 
40  // <summary>
41  // Engine for TaQL UDF Position conversions
42  // </summary>
43 
44  // <use visibility=export>
45 
46  // <reviewed reviewer="" date="" tests="tMeas.cc">
47  // </reviewed>
48 
49  // <prerequisite>
50  //# Classes you should understand before using this one.
51  // <li> EngineBase
52  // </prerequisite>
53 
54  // <synopsis>
55  // PositionEngine defines Engines (user defined functions) that can be used
56  // in TaQL to convert Measures for positions.
57  // In this way such derived values appear to be ordinary TaQL functions.
58  //
59  // In TaQL these functions can be called like:
60  // <srcblock>
61  // meas.pos (toref, pos)
62  // meas.wgs (pos)
63  // meas.itrfxyz (pos)
64  // For example,
65  // meas.pos ('ITRF', [1e6m,1e6m,1e6m], 'WGS84')
66  // </srcblock>
67  // <ul>
68  // <li> <src>toref</src> is a single constant string defining the
69  // reference frame to convert to. Note it should be omitted for
70  // the functions (e.g., meas.wgs) with an implicit destination
71  // reference frame.
72  // The reference type WGS84 or ITRF can optionally have the suffix
73  // XYZ, LLH, LL (or LONLAT) and H (or HEIGHT) telling how the result
74  // should be returned.
75  // <li> <src>pos</src> specifies the position(s) which can be done in
76  // various ways.
77  // <ul>
78  // <li> An array of positions given as xyz, as lonlat, as lon-lat-height
79  // or as height. The latter is taken towards the pole.
80  // Note that specifying as lon-lat-height precludes use of units
81  // (angle and length units cannot be mixed in a TaQL value).
82  // It can be given as a single list or a multi-dim array.
83  // If given as lonlat it can be followed by an array defining
84  // the height for each lon,lat pair (their sizes should match).
85  // Finally it can be followed by a string defining the source
86  // reference type, which defaults to ITRF for x,y,z and WGS84
87  // for lon,lat.
88  // The source reference type can contain the suffix XYZ, LLH, LL
89  // or H to tell how the values are specified. If no suffix is given,
90  // it is derived from the unit of the first value (angle means LL,
91  // length means XYZ).
92  // <li> If a single constant position is used, it can be given as
93  // 1, 2 or 3 scalar values, optionally followed by the source
94  // reference type. If x,y,z or lon,lat or lon,lat,h or h is given
95  // is derived in the same way as above.
96  // <li> The name of a column in a table or a subset of it such as
97  // <src>POSITION[0,]</src>. Often this is a TableMeasures column
98  // which is recognized as such, also its source reference frame.
99  // If such a column is used in a expression, it will not be
100  // recognized as a TableMeasures column and its reference frame
101  // should be given.
102  // <li> As a list containing (case-insensitive) names of known
103  // observatories such as 'WSRT' or 'VLA'.
104  // </ul>
105  // </ul>
106  //
107  // The result of the function is an array with shape [2|3,pos] if
108  // lon,lat(,h) or x,y,z is returned and shape [pos] if height is returned.
109  // The last element is the shape of the position argument. It is omitted if
110  // it has length 1. In such a case getting the height results in a scalar.
111  // </synopsis>
112 
113  // <example>
114  // <srcblock>
115  // // Get the WGS84 lon,lat of WSRT (in degrees).
116  // meas.wgsll ('WSRT') deg
117  // // Get the ITRF x,y,z of WSRT and VLA.
118  // meas.itrfxyz (['WSRT', 'VLA'])
119  // </srcblock>
120  // </example>
121 
122  // <motivation>
123  // It makes it possible to handle measures in TaQL.
124  // </motivation>
125 
126  class PositionEngine: public MeasEngine<MPosition>
127  {
128  public:
130 
131  virtual ~PositionEngine();
132 
133  // Get the value type. It also gives the nr of output values per position.
134  // 0=default, 1=height, 2=angles, 3=xyz
135  Int valueType() const
136  { return itsValueType; }
137 
138  // Get the values.
140  MPosition::Types toRefType,
141  Int toValueType);
142 
143  // Get the positions.
145 
146  // Handle the argument(s) giving the input positions and reference type.
147  // The position can be a column in a table.
148  void handlePosition (Int toValueType,
149  const std::vector<TENShPtr>& args,
150  uInt& argnr);
151 
152  private:
153  virtual String stripMeasType (const String& type);
154  virtual void deriveAttr (const Unit& unit, Int nval);
155  // Let a derived class set its value type.
156  // By default is does nothing.
157  virtual void setValueType (Int valueType);
158 
159  // Make an MPosition from xyz or height,angles.
161  const Quantity& q1,
162  const Quantity& q2) const;
163  void handleScalars (const TENShPtr& e1, const TENShPtr& e2,
164  const TENShPtr& e3, Int nval);
165  void handleObservatory (const TENShPtr& operand);
166  void handlePosArray (const TENShPtr& angles, const TENShPtr& height);
167  virtual void handleValues (TableExprNode& operand,
168  const TableExprId& id,
169  Array<MPosition>& positions);
170 
171  //# Data members.
172  //# 0=unknown, 1=height, 2=angles, 3=xyz, -3=angles,height
174  };
175 
176 } //end namespace
177 
178 #endif
const Unit & unit() const
Get the unit of the function's result.
Definition: BaseEngine.h:123
Types
Types of known MPositions Warning: The order defines the order in the translation matrix FromTo in t...
Definition: MPosition.h:94
Array< MPosition > getPositions(const TableExprId &id)
Get the positions.
Int valueType() const
Get the value type.
MPosition makePosition(const Quantity &qh, const Quantity &q1, const Quantity &q2) const
Make an MPosition from xyz or height,angles.
virtual void setValueType(Int valueType)
Let a derived class set its value type.
virtual String stripMeasType(const String &type)
Let a derived class strip part of the reference type.
void handleScalars(const TENShPtr &e1, const TENShPtr &e2, const TENShPtr &e3, Int nval)
void handleObservatory(const TENShPtr &operand)
virtual void deriveAttr(const Unit &unit, Int nval)
Let a derived class derive its attributes.
virtual void handleValues(TableExprNode &operand, const TableExprId &id, Array< MPosition > &positions)
Let a derive class handle the values.
Array< Double > getArrayDouble(const TableExprId &id, MPosition::Types toRefType, Int toValueType)
Get the values.
void handlePosArray(const TENShPtr &angles, const TENShPtr &height)
void handlePosition(Int toValueType, const std::vector< TENShPtr > &args, uInt &argnr)
Handle the argument(s) giving the input positions and reference type.
String: the storage and methods of handling collections of characters.
Definition: String.h:225
this file contains all the compiler specific defines
Definition: mainpage.dox:28
unsigned int uInt
Definition: aipstype.h:51
int Int
Definition: aipstype.h:50