casacore
DirectionEngine.h
Go to the documentation of this file.
1 //# DirectionEngine.h: Engine for TaQL UDF Direction 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_DIRECTIONENGINE_H
29 #define MEAS_DIRECTIONENGINE_H
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
33 #include<casacore/meas/MeasUDF/EpochEngine.h>
34 #include<casacore/meas/MeasUDF/PositionEngine.h>
35 #include <casacore/tables/TaQL/ExprNode.h>
36 #include <casacore/measures/Measures/MDirection.h>
37 #include <casacore/measures/Measures/MCDirection.h>
38 #include <casacore/measures/Measures/MeasConvert.h>
39 #include <casacore/measures/TableMeasures/ArrayMeasColumn.h>
40 
41 namespace casacore {
42 
43 // <summary>
44 // Engine for TaQL UDF Direction conversions
45 // </summary>
46 
47 // <use visibility=export>
48 
49 // <reviewed reviewer="" date="" tests="tMeas.cc">
50 // </reviewed>
51 
52 // <prerequisite>
53 //# Classes you should understand before using this one.
54 // <li> EngineBase
55 // </prerequisite>
56 
57 // <synopsis>
58 // DirectionEngine defines Engines (user defined functions) that can be used
59 // in TaQL to convert Measures for directions.
60 // In this way such derived values appear to be ordinary TaQL functions.
61 //
62 // In TaQL these functions can be called like:
63 // <srcblock>
64 // meas.dir ('APP', 'MOON', date(), [1e6m,1e6m,1e6m], 'WGS84')
65 // </srcblock>
66 // <ul>
67 // <li>
68 // <src>toref</src> is a single constant string.
69 // <li>
70 // <src>pos</src> can have various value types. A single numeric array is
71 // a series of RA,DEC in J2000. If given as a set, the last argument of the
72 // set can be the reference types of the values in the set. The values can
73 // be strings (indicating planetary objects) or value pairs giving lon,lat.
74 // The default reference type is J2000.
75 // </ul>
76 // All such functions return data with type double and unit radian.
77 //
78 // Futhermore, it is possible to get the rise/set date/time of a source given
79 // the source direction, position on earth, and date. These functions
80 // return data with type double and unit d (day).
81 // If the source is visible all day, the rise time is 0 and set time is 1.
82 // If the source is not visible at all, the rise time is 1 and set time is 0.
83 // For example:
84 // meas.riseset ('SUN', date(), 'WSRT')
85 
86 // Directions can be given like:
87 // [x1,y1,z1,x2,y2,z2,...], fromRef
88 // [lon1,lat1,lon2,lat2,...], fromRef
89 // [lon1,lat1,lon2,lat2,...], [h1,h2,...], fromRef
90 // where fromRef is the reference type optionally followed by _xxx
91 // where xxx can be 'xyz' or 'll' to specify if the values are given as xyz
92 // or as lon,lat.
93 // If xxx is not given, it will be derived from the unit type of the values
94 // (length means xyz, angle means lon,lat with default height is 0).
95 // If xxx nor units are given, 3 values means xyz and 2 values means lon,lat.
96 // If heights are also given, xxx must be 'll' if it is also given.
97 //
98 // A direction can also be a table column which usually knows its type.
99 // It can also be an expression (e.g. DIRECTION[0,]) which also knows the type.
100 // </synopsis>
101 
102 // <motivation>
103 // It makes it possible to handle measures in TaQL.
104 // </motivation>
105 
107  {
108  public:
109  DirectionEngine();
110 
111  // Get the reference type.
113  { return itsRefType; }
114 
115  // Get the shape.
116  const IPosition& shape() const
117  { return itsShape; }
118 
119  // Get the dimensionality.
120  Int ndim() const
121  { return itsNDim; }
122 
123  // Tell if the expression is constant.
124  Bool isConstant() const;
125 
126  // Get the unit.
127  const Unit& unit() const
128  { return itsUnit; }
129 
130  // Get the values.
131  // The first Bool tells if rise/set times have to be calculated.
132  // The second Bool tells if direction cosines have to be calculated.
133  Array<Double> getArrayDouble (const TableExprId& id, Bool riseSet,
134  Bool asDirCos);
135 
136  // Get the directions.
138 
139  // Handle the argument(s) giving the input directions and reference type.
140  // The direction can be a column in a table.
142  uInt& argnr, Bool riseSet);
143 
144  // Handle a direction reference type.
145  void handleDirType (TableExprNodeRep* operand);
146 
147  // Set the MeasConvert object.
148  void setConverter (MDirection::Types toType);
149 
150  // Set the possible epoch engine.
151  // It can be done only once.
152  void setEpochEngine (EpochEngine& engine);
153 
154  // Set the possible position engine.
155  // It can be done only once.
156  void setPositionEngine (PositionEngine& engine);
157 
158  private:
160  void handleNames (TableExprNodeRep* operand);
161  void handleDirArray (TableExprNodeRep*& operand);
162  void handleConstant (TableExprNodeRep* operand);
163  void handleValues (TableExprNode& operand,
164  const TableExprId& id,
165  Array<MDirection>& directions);
166 
167  // Calucate the rise and set time of a source for a given position and
168  // epoch. Argument <src>h</src> defines the possible edge of sun/moon.
169  void calcRiseSet (const MDirection& dir,
170  const MPosition& pos,
171  const MEpoch& epoch,
172  double h,
173  double& rise, double& set);
174  int fillRiseSet (double epoch,
175  const MDirection& dir,
176  double lat,
177  double h,
178  const MEpoch& off,
179  double* rise, double* set);
180 
181  //# Data members.
185  MeasFrame itsFrame; //# frame used by converter
188  Vector<Double> itsH; //# diff for sun or moon
194  };
195 
196 } //end namespace
197 
198 #endif
A Vector of integers, for indexing into Array<T> objects.
Definition: IPosition.h:119
void handleDirType(TableExprNodeRep *operand)
Handle a direction reference type.
const Unit & unit() const
Get the unit.
A Measure: astronomical direction.
Definition: MDirection.h:174
A Measure: position on Earth.
Definition: MPosition.h:79
void setEpochEngine(EpochEngine &engine)
Set the possible epoch engine.
int Int
Definition: aipstype.h:50
void handleDirArray(TableExprNodeRep *&operand)
Handle class for a table column expression tree.
Definition: ExprNode.h:614
Int ndim() const
Get the dimensionality.
Container for Measure frame.
Definition: MeasFrame.h:137
Engine for TaQL UDF Position conversions.
void setPositionEngine(PositionEngine &engine)
Set the possible position engine.
Abstract base class for a node in a table column expression tree.
Definition: ExprNodeRep.h:151
void handleDirection(PtrBlock< TableExprNodeRep *> &args, uInt &argnr, Bool riseSet)
Handle the argument(s) giving the input directions and reference type.
Read only access to table array Measure columns.
Definition: MBaseline.h:45
Array< Double > getArrayDouble(const TableExprId &id, Bool riseSet, Bool asDirCos)
Get the values.
A Measure: instant in time.
Definition: MEpoch.h:104
Bool isConstant() const
Tell if the expression is constant.
Types
Types of known MDirections Warning: The order defines the order in the translation matrix FromTo in ...
Definition: MDirection.h:188
PositionEngine * itsPositionEngine
defines physical units
Definition: Unit.h:189
const IPosition & shape() const
Get the shape.
MDirection::Types refType() const
Get the reference type.
ArrayMeasColumn< MDirection > itsMeasCol
void handleValues(TableExprNode &operand, const TableExprId &id, Array< MDirection > &directions)
Array< MDirection > itsConstants
Engine for TaQL UDF Epoch conversions.
Definition: EpochEngine.h:89
MDirection::Convert itsConverter
Engine for TaQL UDF Direction conversions.
void handleScalars(TableExprNodeRep *e1, TableExprNodeRep *e2)
void calcRiseSet(const MDirection &dir, const MPosition &pos, const MEpoch &epoch, double h, double &rise, double &set)
Calucate the rise and set time of a source for a given position and epoch.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
void setConverter(MDirection::Types toType)
Set the MeasConvert object.
A drop-in replacement for Block<T*>.
Definition: Block.h:861
int fillRiseSet(double epoch, const MDirection &dir, double lat, double h, const MEpoch &off, double *rise, double *set)
void handleNames(TableExprNodeRep *operand)
Array< MDirection > getDirections(const TableExprId &id)
Get the directions.
The identification of a TaQL selection subject.
Definition: TableExprId.h:98
MDirection::Types itsRefType
void handleConstant(TableExprNodeRep *operand)
this file contains all the compiler specific defines
Definition: mainpage.dox:28
unsigned int uInt
Definition: aipstype.h:51